Home

Awesome

CircleCI Version codecov

This is lumigo/python_tracer, Lumigo's Python agent for distributed tracing and performance monitoring.

Supported Python Runtimes: 3.6, 3.7, 3.8, 3.9, 3.10, 3.11 and 3.12

Usage

The package allows you to pursue automated metric gathering through Lambda Layers, automated metric gathering and instrumentation through the Serverless framework, or manual metric creation and implementation.

With Lambda layers

Note - Lambda Layers are an optional feature. If you decide to use this capability, the list of Lambda layers available is available here..

Learn more in our documentation on auto-instrumentation.

With Serverless framework

Manually

To manually configure Lumigo in your Lambda functions:

pip install lumigo_tracer
`from lumigo_tracer import lumigo_tracer`
@lumigo_tracer(token='YOUR-TOKEN-HERE')
def my_lambda(event, context):
    print('I can finally troubleshoot!')

Configuration

@lumigo/python_tracer offers several different configuration options. Pass these to the Lambda function as environment variables:

Step Functions

If your function is part of a set of step functions, you can add the flag step_function: true to the Lumigo tracer import. Alternatively, you can configure the step function using an environment variable LUMIGO_STEP_FUNCTION=True. When this is active, Lumigo tracks all states in the step function in a single transaction, easing debugging and observability.

@lumigo_tracer(token='XXX', step_function=True)
def my_lambda(event, context):
    print('Step function visibility!')

Note: the tracer adds the key "_lumigo" to the return value of the function.

If you override the "Parameters" configuration, add "_lumigo.$": "$._lumigo" to ensure this value is still present.

Below is an example configuration for a Lambda function that is part of a step function that has overridden its parameters:

"States": {
    "state1": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-west-2:ACCOUNT:function:FUNCTION_NAME",
      "Parameters": {
          "Changed": "parameters",
          "_lumigo.$": "$._lumigo"
        },
      "Next": "state2"
    },
    "state2": {
      "Type": "pass",
      "End": true
    }
}

Logging Programmatic Errors

Lumigo provides the report_error function, which you can use to publish error logs that are visible to the entire platform. To log programmatic errors:

Adding Execution Tags

You can add execution tags to a function with dynamic values using the parameter add_execution_tag.

These tags will be searchable from within the Lumigo platform.

Limitations

Contributing

Contributions to this project are welcome from all! Below are a couple pointers on how to prepare your machine, as well as some information on testing.

Preparing your machine

Getting your machine ready to develop against the package is a straightforward process:

  1. Clone this repository, and open a CLI in the cloned directory
  2. Create a virtual environment for the project virtualenv venv -p python3
  3. Activate the virtualenv: . venv/bin/activate
  4. Install dependencies: pip install -r requirements.txt
  5. Run the setup script: python setup.py develop.
  6. Run pre-commit install in your repository to install pre-commit hooks

Note: If you are using pycharm, ensure that you set it to use the virtualenv virtual environment manager. This is available in the menu under PyCharm -> Preferences -> Project -> Interpreter

Running the test suite

We've provided an easy way to run the unit test suite: