Docs » Supported integrations in Splunk Observability Cloud » Instrument back-end applications to send spans to Splunk APM » Instrument Go applications for Splunk Observability Cloud » Instrument your Go application for Splunk Observability Cloud

Instrument your 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 Splunk Observability Cloud.

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

    1. In the 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 πŸ”—

If you don’t use the guided setup, follow these instructions to manually 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 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.

Deploy the Go instrumentation in Kubernetes or Azure πŸ”—

To deploy the Go instrumentation in Kubernetes or Azure, 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 Splunk 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 Splunk Observability Cloud, set the following environment variables:

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

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

To find your Splunk realm, see Note about realms.

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

Specify the source host πŸ”—

To override the host used by the agent, use the environment variable OTEL_RESOURCE_ATTRIBUTES to set your host’s name to the desired source:

export OTEL_RESOURCE_ATTRIBUTES=host.name=<host_name>