AWS Lambda
This guide walks you through instrumenting AWS Lambda with OpenTelemetry and Middleware. These instructions can also be found on the Installation page in your Middleware Account.
Prerequisites
The only languages currently supported by this serverless feature are Python, Java, and Node.js. Navigate here for more information on instrumenting Lambda with OpenTelemetry.
1 Python Version
Python 3.8
and Python 3.9
2 Java Version
Java 8
, Java 11
, and Java 17 (Corretto)
3 Node Version
Node.js v14+
Install
Step 1: Add OTel Collector Layer
Step 1a: Access layer-collector/
Navigate to the opentelemtry-lambda repository and access the layer-collector
Step 1b: Match AWS Region and CPU Architecture
Copy the Amazon Resource Name (ARN) and set the configuration to match the AWS region and CPU architecture of your lambda function like the following example:
arn:aws:lambda:us-east-2:184161586896:layer:opentelemetry-collector-amd64-0_4_0:1
Step 1c: Add Layer
Navigate to Lambda -> Functions -> YOUR_FUNCTION -> Layers and click Add Layer
Step 1d: Specify ARN
Navigate to Choose Layer and specify the ARN you configured earlier
Step 1e: Add New Collector
Verify your new OTel Collector Layer and click Add
Step 2: Add OTel Instrumentation Layer
Step 2a: Access Language-Specific Layer
Navigate to the opentelemtry-lambda repository and access the layer-<PROGRAMMING_LANGUAGE>/
Step 2b: Match AWS Region and CPU Architecture
Copy the Amazon Resource Name (ARN) and set the configuration to match the AWS region and CPU architecture of your lambda function like the following example:
arn:aws:lambda:us-east-2:184161586896:layer:opentelemetry-python-0_4_0:1
Step 2c: Add Layer
Navigate to Lambda -> Functions -> YOUR_FUNCTION -> Layers and click Add Layer
Step 2d: Specify ARN
Navigate to Choose Layer and specify the ARN you configured earlier
Step 2e: Add New Collector
Verify your new OTel Collector Layer and click Add
Step 3: Set Environment Variables
Step 3a: Navigate to Environment Variables
Navigate to Lambda -> Functions -> YOUR_FUNCTION -> Configuration > Environment Variables
Step 3b: Change Your App Entry Point
Change your application's entry point:
Node.js
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
Step 4: Verify OTel Log Collection
Import OpenTelemetry in the Code source editor of your function. Deploy and test your application to ensure OpenTelemetry logs should be visible.
Step 5: Export Your Telemetry Data
Step 5a: Set Environment Variables
Navigate to Lambda -> Functions -> YOUR_FUNCTION -> Configuration > Environment Variables
Step 5b: Route Telemetry Data to Middleware
Initialize and save the following variables:
Access YOUR_MIDDLEWARE_URL
from the home page of your Middleware account. YOUR_ACCOUNT_KEY
is your personal Middleware password which can be injected programmatically or as a declaration.
OTEL_EXPORTER_OTLP_ENDPOINT=https://<MW_UID>.middleware.io:443 OTEL_RESOURCE_ATTRIBUTES=mw.account_key="<MW_API_KEY>"
Step 5c: Verify Installation
Deploy and Test your application to ensure logs from OpenTelemetry no longer appear. Check your Middleware account for traces by navigating to APM -> Services and finding the name of your function in the services list.
Need assistance or want to learn more about Middleware? Contact our support team in Slack.