Send your AWS Lambda Traces to SigNoz
Overview
This documentation provides a detailed walkthrough on how to set up an AWS Lambda function to collect AWS Lambda traces using OpenTelemetry auto-instrumentation. This will enable you to automatically sends your Lambda traces to SigNoz, enabling you to trace the activities of your Lambda function.
Here’s a quick summary of what we’ll be doing in this detailed documentation.
- Creating a Lambda Function
- Adding Language-specific Auto-instrumentation Layer
- Adding OpenTelemetry Collector Lambda Layer
- Visualize the traces in SigNoz
Prerequisites
- AWS account with full access to AWS Lambda.
AWS Lambda Auto-Instrumentation for Tracing
Creating a Lambda Function
Firstly, create a Lambda function in the language of your choice.
Navigate to AWS Lambda service on the AWS console, and click on the Create Function button present on the top right corner of the page.
In the Create funtion page, select Author from scatch.
In the Basic information section, provide an appropriate Function name, and Runtime based on the language in which you want to write your function.
Select the Architecture as per your requirement.
Click on Create function to create the function.
Next, we will create the Lambda function. The function will make a REST API call to the URL: https://api.restful-api.dev/objects?id=3&id=5
, print the response and return the same. The URL will get the object details of the objects with ID 3 and 5.
On your machine, create a folder, say auto-instrument-tracing-lambda
.
Add a file lambda_function.py
in that folder with the lambda function code which will be as follows:
import json
import requests
def lambda_handler(event, context):
res = requests.get('https://api.restful-api.dev/objects?id=3&id=5')
print(res.json())
return {
'statusCode': 200,
'body': res.json()
}
Inside the folder, create a new directory named package
into which you will install your dependencies.
$ mkdir package
Install the dependencies in the package
directory using the command:
$ pip install --target ./package requests
Create a .zip file with the installed libraries at the root.
$ cd package
$ zip -r ../auto-instrument-tracing-lambda.zip .
This generates a auto-instrument-tracing-lambda.zip
file in your project directory.
Add the lambda_function.py
file to the root of the .zip file using the following command:
$ cd ..
$ zip auto-instrument-tracing-lambda.zip lambda_function.py
In the Code tab on the Lambda function page, click on Upload from button and choose .zip from the dropdown. Upload the auto-instrument-tracing-lambda.zip
file. Now, you can test the lambda function.
Adding Language-specific Auto-instrumentation Layer
The language-specific auto-instrumentation lambda layers automatically instrument your Lambda function code with OpenTelemetry auto-instrumentation package for your specific language. Each language and region has its own layer ARN.
If your Lambda is already instrumented with an OpenTelemetry SDK, you can skip this step.
In order to auto-instrument your Lambda function, follow the steps:
- Go to the Lambda function you want to auto-instrument.
- In the Layers section, click on Add a layer.
- In the Choose a layer section, select Specify an ARN option.
- Choose the correct ARN based on the language, ensure you replace the
<region>
with your region (ex.us-east-1
):
arn:aws:lambda:<region>:184161586896:layer:opentelemetry-python-0_11_0:1
The latest releases of the layers can be found in the OpenTelemetry Lambda Layers GitHub repository.
Navigate to the Configuration tab within your function, and select Environment variables from the left navigation menu.
Add the following environment variables.
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument
OTEL_PROPAGATORS=tracecontext
OTEL_TRACES_SAMPLER=always_on
Adding OpenTelemetry Collector Lambda Layer
The collector Lambda layer allows you to forward traces from your Lambda function to SigNoz without impacting response times due to exporter latency.
In order to install the OpenTelemetry Collector Lambda layer, follow these steps:
- Go to the Lambda function.
- In the Layers section, click on Add a layer.
- In the Choose a layer section, select Specify an ARN option.
- Choose the correct ARN based on your funciton architecture, ensure you replace the
<region>
with your region (ex.us-east-1
):
arn:aws:lambda:<region>:184161586896:layer:opentelemetry-collector-amd64-0_12_0:1
- Add the followwing
collector.yaml
file to your project to configure the collector to send the traces to SigNoz:
# collector.yaml
receivers:
otlp:
protocols:
grpc:
endpoint: 'localhost:4317'
http:
endpoint: 'localhost:4318'
processors:
batch: {}
exporters:
otlp:
endpoint: "ingest.{region}.signoz.cloud:443"
tls:
insecure: false
headers:
"signoz-ingestion-key": "<SIGNOZ_INGESTION_KEY>"
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp]
Depending on the choice of your region for SigNoz cloud, the otlp endpoint will vary according to this table.
Region | Endpoint |
---|---|
US | ingest.us.signoz.cloud:443 |
IN | ingest.in.signoz.cloud:443 |
EU | ingest.eu.signoz.cloud:443 |
Navigate to the Configuration tab within your function, and select Environment variables from the left navigation menu.
Add the following environment variable:
OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml
Visualize the traces in SigNoz
Go to the SigNoz Cloud URL and head over to the Traces from the left navigation menu.
You should be able to see the trace details appearing on the List View and the Traces tab.