Trace AWS Lambda Python functions

To achieve complete observability over AWS Lambda Python functions, Lumigo's distributed tracing supports both automatic instrumentation and manual instrumentation.

Automatic instrumentation

By using Lumigo lambda layer our auto-tracing feature automatically adds the Lumigo tracer to your functions, instrumenting your entire code base, without changing a single line of code.

Instrumenting functions via the Lumigo UI

You can easily instrument your functions via the Lumigo UI. To do so:

  • Go to the Functions page
  • Select the functions you want to instrument
  • Click Auto-trace or the Tracing toggle

Lumigo auto-tracing allows you to instrument your functions automatically, without touching your function source code. This can save you time, reduce your package size, and keep your tracing needs from impacting your functional code. Learn more about auto-tracing

Manual instrumentation

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.

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 step functions

If your function is part of a set of step functions, add the flag step_function=True to the @lumigo_tracer decorator. Learn more about our step function support on our GitHub repository .

Advanced configuration with environment variables

Environment VariableExample ValueDescription
LUMIGO_SECRET_MASKING_REGEX["regex1", "regex2"]Prevents Lumigo from sending keys that match the supplied regular expressions. All regular expressions are case-insensitive. By default, Lumigo applies the following regular expressions: [".*pass.*", ".*key.*", ".*secret.*", ".*credential.*", ".*passphrase.*"]. More granular masking for specific parts are available with parameters in the following rows:
LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_BODIES["regex1", "regex2"]Secret masking for HTTP request bodies.
LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_HEADERS["regex1", "regex2"]Secret masking for HTTP request headers.
LUMIGO_SECRET_MASKING_REGEX_HTTP_RESPONSE_BODIES["regex1", "regex2"]Secret masking for HTTP response bodies.
LUMIGO_SECRET_MASKING_REGEX_HTTP_RESPONSE_HEADERS["regex1", "regex2"]Secret masking for HTTP response headers.
LUMIGO_SECRET_MASKING_REGEX_HTTP_QUERY_PARAMS["regex1", "regex2"]Secret masking for HTTP query parameters.
LUMIGO_SECRET_MASKING_REGEX_ENVIRONMENT["regex1", "regex2"]Secret masking for environment variables.
LUMIGO_DOMAINS_SCRUBBER["regex1", "regex2"]Prevents Lumigo from collecting both request and response details from a list of domains. This accepts a comma-separated list of regular expressions that is JSON-formatted. By default, the tracer uses ["secretsmanager\..*\.amazonaws\.com", "ssm\..*\.amazonaws\.com", "kms\..*\.amazonaws\.com"]. These defaults are overridden when you define a different list of regular expressions.
LUMIGO_PROPAGATE_W3CTRUEAdds W3C TraceContext headers to outgoing HTTP requests. This enables distributed transactions between Serverless applications and services traced with OpenTelemetry.
LUMIGO_SWITCH_OFFTRUEDisables the lumigo tracer without the need to remove it.
LUMIGO_DEBUGTRUEEnables debug logging for the lumigo tracer
LUMIGO_STEP_FUNCTIONTrueEnhanced tracing of lambdas triggered by AWS Step Functions