Elven Observability: Lambda Instrumentation
Prerequisites- OTel Collector installed on an EC2 instance
- Documentation
- Organization registered in Elven Observability
- Lambda Function
- Allow traffic from Lambda to the EC2 running the Collector if it is not publicly accessible: documentation
Instrumentation
Without Serverless Framework
Instrumentation is performed via the AWS console.
Configuring Environment Variables
- Go to the Lambda function, scroll down, click on the Configuration tab, select the Environment variables section, and click Edit.
2. Add the following environment variables by clicking on Add Environment Variables.
AWS_LAMBDA_EXEC_WRAPPER="/opt/otel-handler"
OTEL_TRACES_SAMPLER="always_on"
OTEL_TRACES_EXPORTER="otlp"
OTEL_METRICS_EXPORTER="otlp"
OTEL_LOG_LEVEL="DEBUG"
OTEL_PROPAGATORS="tracecontext,baggage, xray"
OTEL_LAMBDA_TRACE_MODE="capture"
OTEL_EXPORTER_OTLP_ENDPOINT=""
OTEL_SERVICE_NAME=""
OTEL_RESOURCE_ATTRIBUTES="service.name=,environment="
- Only the last three variables need to be modified:
EC2_URL_HERE
: The EC2 IP address or DNS if it was configuredLAMBDA-NAME
: The name of the service that will appear in traces and metricsENVIRONMENT
:dev
,hml
, orprd
, depending on the environment being instrumented
Configuring the Instrumentation Layer
- In the Code tab, scroll down to the Layers section and click on Add a Layer.
2. Choose the Specify an ARN option and paste this ARN:arn:aws:lambda:us-east-1:184161586896:layer:opentelemetry-nodejs-0_9_0:4
3. Finally, click Verify, then Add.
With Serverless Framework
This is done in the serverless.yaml
file where the Lambdas are configured, as shown in the example below:
It’s important to note that this configuration must be done for each function!
The configurations are the same as those performed in Configuring Environment Variables and Configuring the Instrumentation Layer.
org:
app:
service:
provider:
name: aws
runtime: nodejs20.x
functions:
:
handler:
layers:
- arn:aws:lambda:us-east-1:184161586896:layer:opentelemetry-nodejs-0_9_0:4
environment:
AWS_LAMBDA_EXEC_WRAPPER: "/opt/otel-handler"
OTEL_TRACES_SAMPLER: "always_on"
OTEL_TRACES_EXPORTER: "otlp"
OTEL_METRICS_EXPORTER: "otlp"
OTEL_LOG_LEVEL: "DEBUG"
OTEL_LAMBDA_TRACE_MODE: "capture"
OTEL_PROPAGATORS: "tracecontext,baggage, xray"
OTEL_EXPORTER_OTLP_ENDPOINT: ""
OTEL_SERVICE_NAME: ""
OTEL_RESOURCE_ATTRIBUTES: "service.name=,environment="
:
handler:
layers:
- arn:aws:lambda:us-east-1:184161586896:layer:opentelemetry-nodejs-0_9_0:4
environment:
AWS_LAMBDA_EXEC_WRAPPER: "/opt/otel-handler"
OTEL_TRACES_SAMPLER: "always_on"
OTEL_TRACES_EXPORTER: "otlp"
OTEL_METRICS_EXPORTER: "otlp"
OTEL_LOG_LEVEL: "DEBUG"
OTEL_LAMBDA_TRACE_MODE: "capture"
OTEL_PROPAGATORS: "tracecontext,baggage, xray"
OTEL_EXPORTER_OTLP_ENDPOINT: ""
OTEL_SERVICE_NAME: ""
OTEL_RESOURCE_ATTRIBUTES: "service.name=,environment="
Once done, simply deploy the changes.