AWS Lambda Functions
This document outlines the process of automatically instrumenting AWS Lambda functions using OpenTelemetry (OTel) layers. It details the necessary steps for adding Lambda layers, configuring environment variables, and integrating the OpenTelemetry Collector for effective observability.
This integration works for Metrics and Traces. Since OpenTelemetry Logs support is unstable for most languages, we recommend using the Cloudwatch exporter for bringing AWS Lambda logs into ObserveNow
OpenTelemetry provides auto-instrumentation support for the following AWS Lambda runtimes: Java, JavaScript, Python, Ruby
Before instrumenting your application, you must add the OpenTelemetry Collector Lambda layer. Follow these steps:
- Navigate to the Lambda function you intend to instrument
- In the Layers section of the Designer, click Add a layer
- Under Specify an ARN, enter the ARN for the OTel Collector Lambda layer, ensuring to replace <region> with the appropriate AWS region for your Lambda function.Find the most recent Collector layer release here
- Make sure to use the layer in the same region as your Lambda functions. The community publishes layers in all available regions. Example: arn:aws:lambda:<region>:184161586896:layer:opentelemetry-collector-amd64-0_11_0:1
Note: Ensure that the layers are deployed in the same AWS region as your Lambda function, as Lambda layers are region-specific resources.
Add the instrumentation layer corresponding to your selected programming language by following the same steps as above:
- For Python example: arn:aws:lambda::184161586896:layer:opentelemetry-python-0_10_0:1
- Find the most recent instrumentation layer release for your language and use it’s ARN after changing the <region> tag to the region your Lambda
Note: Ensure that the layers are deployed in the same AWS region as your Lambda function, as Lambda layers are region-specific resources.
- Adjust the entry point of your application by configuring the AWS_LAMBDA_EXEC_WRAPPER environment variable according to your programming language.
- For Node.js, Java, or Ruby: AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
- For Python: AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument
- Create an environment variable to specify the configuration file for the OpenTelemetry Collector: OPENTELEMETRY_COLLECTOR_CONFIG_FILE=/var/task/collector.yaml
The configuration of the OTel Collector Lambda layer follows the OpenTelemetry standard.
By default, the OTel Collector Lambda layer uses the config.yaml. Since we want to use a customization, create a collector.yaml file in the root directory
Metrics collected from Lamda function can be viewed under the Explore section of ObserveNow Grafana
Traces collected from Lamda function can be viewed under the Explore section of ObserveNowGrafana