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

  1. 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="<EC2_URL_HERE>" 
  OTEL_SERVICE_NAME="<LAMBDA-NAME>"
  OTEL_RESOURCE_ATTRIBUTES="service.name=<LAMBDA_NAME>,environment=<ENVIRONMENT>" 
				
			
  1. Only the last three variables need to be modified:
  • EC2_URL_HERE: The EC2 IP address or DNS if it was configured
  • LAMBDA-NAME: The name of the service that will appear in traces and metrics
  • ENVIRONMENT: dev, hml, or prd, depending on the environment being instrumented

Configuring the Instrumentation Layer

  1. 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: <ORG_NAME> 
app: <APP_NAME> 
service: <SERVICE_NAME> 

provider: 
  name: aws 
  runtime: nodejs20.x 

functions: 
  <LAMBDA_NAME_1>:
    handler: <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: "<EC2_URL_HERE>" 
      OTEL_SERVICE_NAME: "<LAMBDA_NAME>" 
      OTEL_RESOURCE_ATTRIBUTES: "service.name=<LAMBDA_NAME>,environment=<ENVIRONMENT>" 
  <LAMBDA_NAME_2>:
    handler: <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: "<EC2_URL_HERE>" 
      OTEL_SERVICE_NAME: "<LAMBDA_NAME>" 
      OTEL_RESOURCE_ATTRIBUTES: "service.name=<LAMBDA_NAME>,environment=<ENVIRONMENT>"
				
			

Once done, simply deploy the changes.

Scroll to Top