Docs » Instrument serverless functions for Splunk Observability Cloud » Instrument AWS Lambda functions for Splunk Observability Cloud » Instrument your AWS Lambda function for Splunk Observability Cloud » Instrument your Go Lambda function for Splunk Observability Cloud

Instrument your Go Lambda function for Splunk Observability Cloud đź”—

To instrument a Go function in AWS Lambda for Splunk APM, follow these steps:

  1. Run the following commands to install the otellambda and the Splunk OTel Go distribution:

    go get -u go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda
    go get -u github.com/signalfx/splunk-otel-go/distro
    
  2. Create a wrapper for the OpenTelemetry instrumentation in your function’s code. For example:

    package main
    
    import (
       "context"
       "fmt"
    
       "github.com/aws/aws-lambda-go/lambda"
       "github.com/signalfx/splunk-otel-go/distro"
       "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda"
       "go.opentelemetry.io/otel"
    )
    
    func main() {
       distro.Run()
       flusher := otel.GetTracerProvider().(otellambda.Flusher)
       lambda.Start(otellambda.InstrumentHandler(HandleRequest, otellambda.WithFlusher(flusher)))
    }
    
    type MyEvent struct {
       Name string `json:"name"`
    }
    
    func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
       return fmt.Sprintf("Hello %s!", name.Name), nil
    }
    

    Note

    For a full example, see OpenTelemetry Lambda tracing examples on GitHub.

  3. Configure the required environment variables. See Configure the Splunk OpenTelemetry Lambda layer.

See Instrument your AWS Lambda function for Splunk Observability Cloud for more information.