Instrument your AWS Lambda function for Splunk Observability Cloud π
Use the Splunk OpenTelemetry Lambda layer to automatically instrument your AWS Lambda functions for many programming languages. To get started, use the guided setup or follow the instructions manually.
Generate customized instructions using the guided setup π
To generate a template that instruments your Lambda function using the Splunk OpenTelemetry Lambda layer, use the AWS Lambda guided setup. To access the AWS Lambda guided setup, follow these steps:
Log in to Splunk Observability Cloud.
Open the AWS Lambda guided setup . Optionally, you can navigate to the guided setup on your own:
In the navigation menu, select
to open the Integrate Your Data page.In the integration filter menu, select All.
In the Search field, search for AWS Lambda.
Select the AWS Lambda tile to open the AWS Lambda guided setup.
Install the Splunk OpenTelemetry Lambda layer manually π
Follow these instructions to install the Splunk OpenTelemetry Lambda layer:
To instrument .NET functions, see Instrument your .NET AWS Lambda function for Splunk Observability Cloud.
For Python functions using the Serverless Framework, see Serverless Framework support.
Check compatibility and requirements π
The Splunk OpenTelemetry Lambda Layer supports the following runtimes in AWS Lambda:
Java 8 and 11
Python 3.8 and 3.9
Node.js 14 and higher
Ruby 2.7
Go 1.20
The Lambda Layer requires 49 MB on-disk in standard x86_64 systems.
For more information, search for Lambda runtimes and other system requirements on the AWS documentation website.
Install the AWS Lambda layer π
Follow these steps to instrument your function using the Splunk OpenTelemetry Lambda layer:
In the AWS Lambda console, select the function that you want to instrument.
In the Layers section, select Add a layer, then select Specify an ARN.
Copy the Amazon Resource Name (ARN) for the region of your Lambda function from the list matching your architecture:
<h3>Splunk OpenTelemetry Lambda Layer</h3> <pre> arn:aws:lambda:us-east-2:254067382080:layer:splunk-apm:499 arn:aws:lambda:us-east-1:254067382080:layer:splunk-apm:92 arn:aws:lambda:eu-central-1:254067382080:layer:splunk-apm:92 arn:aws:lambda:us-west-1:254067382080:layer:splunk-apm:92 arn:aws:lambda:us-west-2:254067382080:layer:splunk-apm:92 arn:aws:lambda:ap-south-1:254067382080:layer:splunk-apm:91 arn:aws:lambda:ap-northeast-1:254067382080:layer:splunk-apm:91 arn:aws:lambda:ap-northeast-2:254067382080:layer:splunk-apm:91 arn:aws:lambda:ap-southeast-1:254067382080:layer:splunk-apm:91 arn:aws:lambda:ap-southeast-2:254067382080:layer:splunk-apm:90 arn:aws:lambda:ca-central-1:254067382080:layer:splunk-apm:90 arn:aws:lambda:eu-west-1:254067382080:layer:splunk-apm:90 arn:aws:lambda:eu-west-2:254067382080:layer:splunk-apm:90 arn:aws:lambda:eu-west-3:254067382080:layer:splunk-apm:90 arn:aws:lambda:eu-north-1:254067382080:layer:splunk-apm:90 arn:aws:lambda:sa-east-1:254067382080:layer:splunk-apm:90 arn:aws:lambda:eu-south-1:254067382080:layer:splunk-apm:37 arn:aws:lambda:ap-northeast-3:254067382080:layer:splunk-apm:37 arn:aws:lambda:ap-east-1:254067382080:layer:splunk-apm:37 arn:aws:lambda:af-south-1:254067382080:layer:splunk-apm:37 arn:aws:lambda:me-south-1:254067382080:layer:splunk-apm:37 </pre>
<h3>Splunk OpenTelemetry Lambda Layer (arm64)</h3> <pre> arn:aws:lambda:us-east-2:254067382080:layer:splunk-apm-arm:41 arn:aws:lambda:us-east-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:eu-central-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:us-west-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:us-west-2:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-south-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-northeast-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-northeast-2:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-southeast-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-southeast-2:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ca-central-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:eu-west-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:eu-west-2:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:eu-west-3:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:eu-north-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:sa-east-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:eu-south-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-northeast-3:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:ap-east-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:af-south-1:254067382080:layer:splunk-apm-arm:23 arn:aws:lambda:me-south-1:254067382080:layer:splunk-apm-arm:23 </pre>
Paste the selected ARN in the Specify an ARN field and select Add.
Check that the Splunk layer appears in the Layers table.
Note
You can automate the update of the Lambda layer using the AWS CLI or other automation tools.
Configure the Splunk OpenTelemetry Lambda layer π
Follow these steps to add the required configuration for the Splunk OpenTelemetry Lambda layer:
In the AWS Lambda console, open the function that you are instrumenting.
Navigate to Configuration, then Environment variables.
Select Edit.
Add each of the following environment variables by selecting Add environment variable:
Environment variable
Description
SPLUNK_REALM
To find the realm of your Splunk Observability Cloud account, open the navigation menu in Splunk Observability Cloud, select Organizations section.
, and select your username. The realm name appears in theSPLUNK_ACCESS_TOKEN
A Splunk authentication token that lets exporters send data directly to Splunk Observability Cloud. See Authentication token. To send data to a Splunk OTel Collector in EC2, see Send serverless spans directly to Splunk Observability Cloud.
AWS_LAMBDA_EXEC_WRAPPER
Set the value for the
AWS_LAMBDA_EXEC_WRAPPER
environment variable:# Select the most appropriate value # Wraps regular handlers that implement RequestHandler /opt/otel-handler # Same as otel-handler, but proxied through API Gateway, # with HTTP context propagation activated /opt/otel-proxy-handler # Wraps streaming handlers that implement RequestStreamHandler /opt/otel-stream-handler
Note
Only AWS SDK v2 instrumentation is activated by default. To instrument other libraries, modify your code to include the corresponding library instrumentation from the OpenTelemetry Java SDK.
/opt/otel-instrument
/opt/nodejs-otel-handler
/opt/ruby-otel-handler .. note:: The Graviton2 ARM64 architecture is not supported for Ruby Lambda functions.
Donβt set the
AWS_LAMBDA_EXEC_WRAPPER
environment variable.OTEL_SERVICE_NAME
The name of your service.
(Optional)
OTEL_RESOURCE_ATTRIBUTES
Define the name of the deployment environment of your function by setting this environment variable to
deployment.environment=<name-of-your-environment>
.Select Save and check that the environment variables appear in the table.
To configure the mode of metric ingest, see Metrics configuration.
Note
By default, the layer sends telemetry to a Collector instance on localhost.
Instrument Go functions in AWS Lambda π
To instrument a Go function in AWS Lambda for Splunk APM, follow these steps:
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
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 https://github.com/signalfx/tracing-examples/blob/main/opentelemetry-tracing/opentelemetry-lambda/go/example.go on GitHub.
Serverless Framework support π
Some features of the Serverless Framework might impact OpenTelemetry tracing of Python Lambda functions.
Python libraries compression π
The zip
feature of pythonRequirements
allows packing and deploying Lambda dependencies as compressed files. To instrument packages compressed using the Serverless Framework, set the SPLUNK_LAMBDA_SLS_ZIP
environment variable to true
. For more information, see https://github.com/serverless/serverless-python-requirements#dealing-with-lambdas-size-limitations on GitHub.
Slim feature π
The Slim feature reduces the size of Lambda packages by removing some files, including dist-info
folders. Some of the files removed by the Slim feature are required by the OpenTelemetry Python autoinstrumentation. Deactivate the slim
option in your serverless.yml file or define custom slimPatterns
. For more information, see https://github.com/serverless/serverless-python-requirements#slim-package on GitHub.
Send serverless spans directly to Splunk Observability Cloud π
By default, the Splunk OpenTelemetry Lambda layer sends telemetry to a Collector running alongside the Lambda.
To send spans directly to Splunk Observability Cloud from an AWS Lambda function instrumented using the Splunk Lambda layer add the following environment variables:
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL
with the valuehttp/protobuf
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
with the valuehttps://ingest.<realm>.signalfx.com/v2/trace/otlp
, substituting<realm>
with the name of your organizationβs realm.
Check that data appears in Splunk Observability Cloud π
Each time the AWS Lambda function runs, trace and metric data appears in Splunk Observability Cloud. If no data appears, see Troubleshoot the Splunk OpenTelemetry Lambda Layer.