Package: lumigo-tracer
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.12UsageThe 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 layersWhen configuring your Lambda functions, include the appropriate Lambda Layer ARNfrom these tablesNote- Lambda Layers are an optional feature. If you decide to use this capability, the list of Lambda layers available is availablehere..Learn more in ourdocumentation on auto-instrumentation.With Serverless frameworkTo configure the Serverless Framework to work with Lumigo, simply install our plugin:serverless-lumigo-pluginManuallyTo manually configure Lumigo in your Lambda functions:Install the package:pipinstalllumigo_tracerImport the package in your Lambda code:`fromlumigo_tracerimportlumigo_tracer`Next, wrap yourhandlerin Lumigo'stracefunction (note: replaceYOUR-TOKEN-HEREwith your Lumigo API token):@lumigo_tracer(token='YOUR-TOKEN-HERE')defmy_lambda(event,context):print('I can finally troubleshoot!')Your function is now fully instrumentedConfiguration@lumigo/python_traceroffers several different configuration options. Pass these to the Lambda function as environment variables:LUMIGO_DEBUG=TRUE- Enables debug loggingLUMIGO_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.*"].We support more granular masking using the following parameters. If not given, the above configuration is the fallback:LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_BODIES,LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_HEADERS,LUMIGO_SECRET_MASKING_REGEX_HTTP_RESPONSE_BODIES,LUMIGO_SECRET_MASKING_REGEX_HTTP_RESPONSE_HEADERS,LUMIGO_SECRET_MASKING_REGEX_HTTP_QUERY_PARAMS,LUMIGO_SECRET_MASKING_REGEX_ENVIRONMENT.LUMIGO_DOMAINS_SCRUBBER=[".*secret.*"]- 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"].Note- These defaults are overridden when you define a different list of regular expressions.LUMIGO_PROPAGATE_W3C=TRUE- Add W3C TraceContext headers to outgoing HTTP requests. This enables uninterrupted transactions with applications traced with OpenTelemetry.LUMIGO_SWITCH_OFF=TRUE- In the event a critical issue arises, this turns off all actions that Lumigo takes in response to your code. This happens without a deployment, and is picked up on the next function run once the environment variable is present.Step FunctionsIf your function is part of a set of step functions, you can add the flagstep_function: trueto the Lumigo tracer import. Alternatively, you can configure the step function using an environment variableLUMIGO_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)defmy_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 ErrorsLumigo provides thereport_errorfunction, which you can use to publish error logs that are visible to the entire platform. To log programmatic errors:Import thereport_errorfunction with the following code:from lumigo_tracer import report_errorUse thereport_errorfunction with the message you wish to send:report_error("your-message-here")Adding Execution TagsYou can add execution tags to a function with dynamic values using the parameteradd_execution_tag.These tags will be searchable from within the Lumigo platform.LimitationsUp to 50 execution tagsEach tag key length can have 50 characters at most.Each tag value length can have 70 characters at most.ContributingContributions 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 machineGetting your machine ready to develop against the package is a straightforward process:Clone this repository, and open a CLI in the cloned directoryCreate a virtual environment for the projectvirtualenv venv -p python3Activate the virtualenv:. venv/bin/activateInstall dependencies:pip install -r requirements.txtRun the setup script:python setup.py develop.Runpre-commit installin your repository to install pre-commit hooksNote: 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 -> InterpreterRunning the test suiteWe've provided an easy way to run the unit test suite:To run all unit tests, simply runpy.testin the root folder.To deploy services for component tests, runsls deployfrom the root test directory. This only needs to take place when the resources change.To run component tests, add the--allflag:py.test --all