Add a Go service
The Go Library provides tracing and metrics for Go-based applications via wrappers and SDK calls that your application can use to instrument web requests and other workloads. For more details about the Go library, see the SolarWinds APM Go GitHub repo.
Get started
Before you start
Verify the following to ensure the library can collect and transmit data:
-
The platform where your APM library will be installed is supported.
-
Your firewall configuration permits TCP/HTTPS/TLS outbound connections to
otel.collector.xx-yy.cloud.solarwinds.com
(orapm.collector.xx-yy.cloud.solarwinds.com
when using legacy mode) port443
, wherexx-yy
is determined by the URL you use to access SolarWinds Observability SaaS, described in Data centers and endpoint URIs. See Firewall or access control requirements.If your firewall or access control requirements do not allow such connections, configure the library to send data through a proxy.
Remove other APM libraries from your Go application before using the SolarWinds Observability Go Library.
To enable instrumentation for a Go application and send the data to SolarWinds Observability:
-
In SolarWinds Observability SaaS, click Add Data at the top.
-
In the Add Data dialog Intro, click Monitor my application performance.
-
Click Go.
-
Type a name for your service and select the environment. Click Next.
-
Create or select an API Ingestion token to use when sending your collected service data by doing either of the following:
- Select Generate New Token and enter an Ingestion Token Name, and then click Next.
- Select Use Existing Token and select an ingestion token from the list, and then click Next.
-
Use the following command to install the Go Library in your project.
go get github.com/solarwinds/apm-go
-
Initialize the library for monitoring. This is most often done in the main function of your project.
// Initialize the SolarWinds APM library cb, err := swo.Start( // Optionally add service-level resource attributes semconv.ServiceName("my-service"), semconv.ServiceVersion("v0.0.1"), attribute.String("environment", "testing"), ) if err != nil { // Handle error } // This function returned from 'Start()' will tell the apm library to // shut down, often deferred until the end of 'main()'. defer cb()
-
Instrument the code using an instrumentation library. Libraries supported by SolarWinds include:
-
Any of the instrumentation libraries available in opentelemetry-go-contrib
For net/http servers, SolarWinds recommends using our wrapper to correctly attribute distributed trace data.
-
For SQL: XSAM/otelsql
For even more instrumentation options, OpenTelemetry provides a registry to find libraries, plugins, integrations, and other useful tools for extending OpenTelemetry.
Each library is at a different maturity level, as the OpenTelemetry landscape is developing at a rapid pace.
Alternatively, you can manually instrument your code using the OpenTelemetry SDK and it will be properly propagated to SolarWinds Observability. See Manual Instrumentation in the OpenTelemetry Go documentation.
-
-
Configure environment variables that define the Service key and APM collector endpoint for your service and organization. Use the code provided under Configure in the Add Data dialog or manually create the following environment variables:
-
SW_APM_SERVICE_KEY
— The Service key is used to identify your account and the service being instrumented. It should be in the form ofYourApiToken:YourServiceName
.Replace
YourApiToken
with the SolarWinds Observability API token (ingestion type) generated for this service, and replaceYourServiceName
with your chosen name for this service. See API Tokens. -
SW_APM_COLLECTOR
— The collector is the ingestion endpoint the library connects to and exports data to. It should be defined using the formathost:port
. , and typically is in the formatapm.collector.xx-yy.cloud.solarwinds.com
, where xx-yy represents the data center that is hosting your organization's data.To determine the endpoint for your organization, see Data centers and endpoint URIs. The port is optional and defaults to
443
.
-
-
Wait for the Go Library to successfully connect to the SolarWinds APM collector and for the Waiting for Connection button in SolarWinds Observability to change to OK. It may take several requests for traces to show up.
-
Click OK to finish setting up the service.
To view data collected for the newly configured entity in the Entity Explorer, click the name of the entity type in the confirmation dialog in the lower-left corner. It may take a few seconds for data to appear for the newly created entity. See Entity Explorer for details.
For transaction and trace data to appear in the Entity Explorer and Traces Explorer, your service must be running and in use.