Python

Instructions for manually installing the Lumigo tracer in a Lambda Python environment

Overview

This page will help you to set up the Lumigo tracer. This allows for manual tracing of your Lambda functions.

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!')
  }

Finally, 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.

Framework Support

Lumigo's Manual Tracing can be configured for many popular frameworks

Chalice

Add the following lines to your Lambda function's file to enable Chalice support for Lumigo:

from lumigo_tracer import LumigoChalice
...
app = Chalice(app_name='hello-world')
app = LumigoChalice(app)
...

Remember to set your Lumigo token as the value of the LUMIGO_TRACER_TOKEN environment variable.

Sentry/Raven Lambda Integration

To enable Sentry/Raven integration, simply add the @lumigo_tracer decorator beneath the Raven decorator for your handler function:

from lumigo_tracer import lumigo_tracer
...
@RavenLambdaWrapper()
@lumigo_tracer()
def lambda_handler(event, context):
  return {
    'statusCode': 200,
    'body': json.dumps('Hi!')
  }

Remember to set your Lumigo token as the value of the LUMIGO_TRACER_TOKEN environment variable.

📘

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


Did this page help you?