Docs » Instrument back-end applications to send spans to Splunk APM » Instrument Go applications for Splunk Observability Cloud » Instrument a Go application for Splunk Observability Cloud

Instrument a Go application for Splunk Observability Cloud πŸ”—

The Splunk Distribution of OpenTelemetry Go can instrument your Go application or service. To get started, use the guided setup or follow the instructions manually.

Generate customized instructions using the guided setup πŸ”—

To generate all the basic installation commands for your environment and application, use the Go guided setup. To access the Go guided setup, follow these steps:

  1. Log in to Observability Cloud.

  2. Open the Go guided setup. Optionally, you can navigate to the guided setup on your own:

    1. In the left navigation menu, select Data Management.

    2. Select Add Integration to open the Integrate Your Data page.

    3. In the integration filter menu, select By Product.

    4. Select the APM product.

    5. Select the Go tile to open the Go guided setup.

Install the Splunk Distribution of OpenTelemetry Go manually πŸ”—

Follow these instructions to install the Splunk Distribution of OpenTelemetry Go.

Install and activate the Go instrumentation πŸ”—

Follow these steps to instrument your application using the Go instrumentation:

  1. Check that you meet the requirements. See Go instrumentation compatibility and requirements.

  2. Install the distribution:

    go get github.com/signalfx/splunk-otel-go/distro
    
  3. Set the OTEL_SERVICE_NAME environment variable:

    export OTEL_SERVICE_NAME=<yourServiceName>
    
  4. (Optional) Set the endpoint URL if the Splunk Distribution of OpenTelemetry Collector is running on a different host:

    export OTEL_EXPORTER_OTLP_ENDPOINT=<yourCollectorEndpoint>:<yourCollectorPort>
    
  5. (Optional) Set the version and environment name:

    export OTEL_RESOURCE_ATTRIBUTES="service.version=<version>,deployment.environment=<environment>"
    
  6. Add the instrumentation using the distro package:

    package main
    
    import (
       "context"
       "github.com/signalfx/splunk-otel-go/distro"
    )
    
    func main() {
       sdk, err := distro.Run()
       if err != nil {
          panic(err)
       }
       // Flush all spans before the application exits
       defer func() {
          if err := sdk.Shutdown(context.Background()); err != nil {
             panic(err)
          }
       }()
    
       // ...
    
  7. Activate additional instrumentations. For more information, see Supported libraries and frameworks.

  8. (Optional) To link APM and RUM data, activate the HTTP instrumentation. See Server trace information.

If no data appears in Observability > APM, see Troubleshoot Go instrumentation for Splunk Observability Cloud.

Note

If you need to add custom attributes to spans or want to manually generate spans, instrument your Go application or service manually. See Custom Go instrumentation for Splunk Observability Cloud.

Enable metrics collection πŸ”—

Caution

The OpenTelemetry Go Metrics API is a release candidate. Use it for evaluation purposes only. Don’t use it in production environments. Some features might have restrictions, limited stability, or might change in next versions. Limited support is provided on best-effort basis.

To enable automatic runtime metric collection, you need to set the OTLP_METRICS_EXPORTER environment variable.

export OTLP_METRICS_EXPORTER=otlp

Deploy the Go instrumentation in Kubernetes πŸ”—

To deploy the Go instrumentation in Kubernetes, configure the Kubernetes Downward API to expose environment variables to Kubernetes resources.

The following example shows how to update a deployment to expose environment variables by adding the OTel configuration under the .spec.template.spec.containers.env section:

apiVersion: apps/v1
kind: Deployment
spec:
  selector:
    matchLabels:
      app: your-application
  template:
    spec:
      containers:
        - name: myapp
          env:
            - name: SPLUNK_OTEL_AGENT
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://$(SPLUNK_OTEL_AGENT):4317"
            - name: OTEL_SERVICE_NAME
              value: "<serviceName>"
            - name: OTEL_RESOURCE_ATTRIBUTES
              value: "deployment.environment=<environmentName>"

Send data directly to Observability Cloud πŸ”—

By default, all telemetry is sent to the local instance of the Splunk Distribution of OpenTelemetry Collector.

If you need to send data directly to Observability Cloud, set the following environment variables:

export SPLUNK_ACCESS_TOKEN=<access_token>
export SPLUNK_REALM=<realm>

To obtain an access token, see Retrieve and manage user API access tokens using Splunk Observability Cloud.

In the ingest endpoint URL, realm is the Observability Cloud realm, for example, us0. To find the realm name of your account, follow these steps:

  1. Open the left navigation menu in Observability Cloud.

  2. Select Settings.

  3. Select your username.

The realm name appears in the Organizations section.

Note

For more information on the ingest API endpoints, see Send APM traces.