This page explains how to auto-instrument and monitor applications running on AWS Lambda using the AWS Distro for OpenTelemetry (ADOT). ADOT is an OpenTelemetry collector layer managed by and optimized for AWS.

Alternatively, you can use the Axiom Lambda Extension to send Lambda function logs and platform events to Axiom. For more information, see AWS Lambda.

Axiom detects the extension and provides you with quick filters and a dashboard. For more information on how this enriches your Axiom organization, see AWS Lambda app.

ADOT Lambda collector layer

AWS Distro for OpenTelemetry Lambda provides a plug-and-play user experience by automatically instrumenting a Lambda function. It packages OpenTelemetry together with an out-of-the-box configuration for AWS Lambda and OTLP in an easy-to-setup layer. You can turn on and off OpenTelemetry for your Lambda function without changing your code.

With the ADOT collector layer, you can send telemetry data to Axiom with a simple configuration.

To determine the best method to send data from different AWS services, see Send data from AWS to Axiom.

Prerequisites

Set up ADOT Lambda layer

This example creates a new Lambda function and applies the ADOT Lambda layer to it with the proper configuration.

You can deploy your Lambda function with the choice of your runtime. This example uses the Python3.10 runtime.

1

Create a new Lambda function

Create a new Lambda function with the following content. For more information on creating Lambda functions, see the AWS documentation.

import json

print('Loading function')


def lambda_handler(event, context):
    #print("Received event: " + json.dumps(event, indent=2))
    print("value1 = " + event['key1'])
    print("value2 = " + event['key2'])
    print("value3 = " + event['key3'])
    return event['key1']  # Echo back the first key value
    #raise Exception('Something went wrong')
2

Add the ADOT Lambda layer

Add a new ADOT Lambda layer to your function with the following ARN (Amazon Resource Name). For more information on adding layers to your function, see the AWS documentation.

arn:aws:lambda:AWS_REGION:901920570463:layer:aws-otel-python-ARCH-VERSION
  • Replace AWS_REGION with the AWS Region to send the request to. For example, us-west-1.
  • Replace ARCH with the system architecture type. For example, arm64.
  • Replace VERSION with the latest version number specified in the AWS documentation. For example, ver-1-25-0:1.
3

Create the collector configuration file

The configuration file is a YAML file that contains the configuration for the OpenTelemetry collector. Create the configuration file /var/task/collector.yaml with the following content. This tells the collector to receive telemetry data from the OTLP receiver and export it to Axiom.

receivers:
  otlp:
    protocols:
      grpc:
      http:

exporters:
  otlphttp:
    compression: gzip
    endpoint: https://api.axiom.co
    headers:
      authorization: Bearer API_TOKEN
      x-axiom-dataset: DATASET_NAME

service:
  pipelines:
    logs:
      receivers: [otlp]
      exporters: [otlphttp]
    traces:
      receivers: [otlp]
      exporters: [otlphttp]
  • Replace API_TOKEN with the Axiom API token you have generated. For added security, store the API token in an environment variable.
  • Replace DATASET_NAME with the name of the Axiom dataset where you want to send data.
4

Set environment variables

Set the following environment variables. For more information on setting environment variables, see the AWS documentation.

AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument
OPENTELEMETRY_COLLECTOR_CONFIG_FILE: /var/task/collector.yaml
  • AWS_LAMBDA_EXEC_WRAPPER wraps the function handler with the OpenTelemetry Lambda wrapper. This layer enables the auto-instrumentation for your Lambda function by initializing the OpenTelemetry agent and handling the lifecycle of spans.
  • OPENTELEMETRY_COLLECTOR_CONFIG_FILE specified the location of the collector configuration file.
5

Run your function and observe telemetry data in Axiom

As the app runs, it sends traces to Axiom. To view the traces:

  1. In Axiom, click the Stream tab.
  2. Click your dataset.