Python
Instructions for installing the Lumigo tracer in a AWS Lambda function using a Python runtime
The lumigo_tracer
package is Lumigo's Python agent for distributed tracing and performance monitoring on AWS Lambda. It allows you to pursue automated metric gathering through Lambda Layers, automated metric gathering and instrumentation.
Setup
Add the Lumigo Tracer to your application
To begin, add the following line to your requirements.txt
file:
lumigo_tracer
Next, open your Lambda function code. Import the lumigo tracer so that it may be used locally:
from lumigo_tracer import lumigo_tracer
Once you've imported the tracer, add the lumigo_tracer
decorator to your Lambda function's handler.
@lumigo_tracer()
def my_lambda(event, context):
print('I can view this line now')
Once these two steps have been completed, your code should resemble the following example:
import json
from lumigo_tracer import lumigo_tracer
...
@lumigo_tracer()
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': json.dumps('Hi!')
}
Connect Your Lumigo Account
Set your Lumigo token as the LUMIGO_TRACER_TOKEN
environment variable of your Lambda function; refer to the Using AWS Lambda environment variables documentation for more information. Your Lumigo token is available in Settings -> Tracing -> Manual tracing
, see the Lumigo Tokens documentation.
We advise you to use the most secure available to you to store secrets such as your LUMIGO_TRACER_TOKEN
; refer to AWS Lambda's Securing environment variables documentation for guidance on keeping the values of your Lambda environment variables secure.
Using Lambda Layers?
You can find our Python Lambda Layer here.
Using Step Functions?
Monitor your step functions by adding the flag
step_function=True
to your@lumigo_tracer
decorator.Learn more about our step function support on our GitHub repository
Library support
Databases
Library | Supported versions |
---|---|
pymongo | 3.12.x |
redis | 3.7.x |
SQLAlchemy | 1.3.x |
Do you need Lumigo to support a different package?
If Lumigo does not yet support a package you use, please contact our support.
Tracing through containers and OpenTelemetry
To be able to trace scenarios in which a Lambda function sends HTTP requests to an application instrumented with OpenTelemetry, like those using the Lumigo OpenTelemetry Distro for JS and Lumigo OpenTelemetry Distro for Python or other OpenTelemetry SDKs, the Lumigo Python tracer can optionally add W3C TraceContext HTTP headers to outgoing requests.
The support of W3C TraceContext in the Lambda Python tracer is currently opt-in via the LUMIGO_PROPAGATE_W3C=true
environment variable.
Supported tracer and layer versions
W3C TraceContext is supported by the
lumigo_tracer
package v1.1.206 and above. The minimum layer versions are listed here by AWS region (applicable to all supported Python runtimes).
Why opt-in?
We have implemented support for W3C TraceContext in the Lambda Python tracer as opt-in out of an abundance of caution. In some seldom cases, like invoking some Apple APIs, the HTTP request is signed, based on the current headers it has, before our tracer can interact with it by adding the W3C TraceContext
traceparent
header, and that may cause issues. Note that most AWS APIs use Signature Version 4 (SigV4) to sign requests, and the Lambda Python tracer will not add the W3C TraceContexttraceparent
headers to them.We may consider changing the W3C TraceContext to be opt-out later down the road, based on your feedback.
Updated 8 months ago