The `datadog-lambda` library enables comprehensive monitoring, tracing, and logging for AWS Lambda functions in Datadog. It provides a Python wrapper to automatically instrument Lambda handlers, collect metrics, send traces, and forward logs to Datadog. The current version is 8.123.0 and it maintains a rapid release cadence, often several times a week, to keep pace with new features and bug fixes, typically bundling updates from `dd-trace-py`.
pip install datadog-lambdaVerified import paths — ran on the pinned version, not inferred.
To instrument an AWS Lambda function, import `datadog_lambda_wrapper` and apply it as a decorator to your handler function. The library automatically captures metrics, logs, and traces. Remember that for actual deployment, using the Datadog AWS Lambda Layer is the recommended and most common approach, rather than `pip installing` the library into your deployment package, as the layer includes the necessary dependencies and potentially the Datadog Agent extension.
Disable profiling (`DD_PROFILING_ENABLED=false`) or use a Python runtime of 3.13 or older if profiling is critical. Monitor future releases for Python 3.14 support.
Be aware of your runtime's bundled `dd-trace-py` version when developing. Check the release notes of `datadog-lambda` for the exact `dd-trace-py` version bundled for your target Python runtime.
Always review the Datadog documentation for a comprehensive list of required and optional environment variables and ensure they are correctly set in your Lambda function configuration.
For production deployments, utilize the Datadog AWS Lambda Layer. Consult the Datadog documentation for the latest ARN for your region and desired Python runtime. Avoid mixing `pip install` with the Lambda layer unless specifically instructed.
Upgrade to version 8.123.0 or newer to ensure more accurate cold start reporting with Lambda Managed Runtimes. Users upgrading might observe changes in their cold start metric trends.
Ensure the `datadog-lambda` package is included in your Lambda deployment package (e.g., by running `pip install -t . datadog-lambda` and zipping, or using a build tool that includes dependencies) or that the correct Datadog Lambda layer ARN is attached to your function in the AWS console or IaC definition.
Set one of the required Datadog API key environment variables (e.g., `DD_API_KEY` with your API key, `DD_KMS_API_KEY` for a KMS-encrypted key, or `DD_API_KEY_SECRET_ARN` for a Secrets Manager ARN) on your AWS Lambda function. If using KMS or Secrets Manager, ensure the Lambda's IAM role has the necessary `kms:Decrypt` or `secretsmanager:GetSecretValue` permissions.
Modify your Lambda function to return a dictionary (JSON object) instead of a raw string. For example, instead of `return 'Hello'`, use `return {'statusCode': 200, 'body': 'Hello from Lambda!'}`.Upgrade the `dd-trace-py` library to a version that supports your `openai` library version (e.g., `ddtrace==2.2` or newer for `openai>=1.0`). This usually means updating the `datadog-lambda` layer to its latest version, which typically bundles an updated `dd-trace-py`.
No dependency data recorded yet.