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.

We advise you to use the most secure available to you to store secrets such as your LUMIGO_TRACER_TOKEN; additionally, AWS provides integrations for AWS Key Management Service that keep the values of your Lambda environment variables secure.

📘

Using Lambda Layers?

You can find our Python Lambda Layer here.

Learn more about Lambda Layers

👍

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.


Did this page help you?