The Datadog Lambda Library is responsible for:
dd-tracelibrary, letting customers trace their Lambda functions with Datadog’s tracing libraries, currently available for Node.js, Python, and Ruby with more runtimes coming soon.
Datadog distributes the Lambda Library as a Lambda Layer and open-source package for Python, Node.js, and Ruby. Go is also supported with a package to include in your project. Datadog is working on support for new languages and runtimes; if there is another runtime you would like Datadog to support, reach out to the Datadog support team.
The Datadog Lambda Layer ARN includes a region, language runtime, and version. Construct yours in the following format:
Golang: Since Go binaries are statically linked, Datadog offers a package you can import into your project. No Lambda Layer is required.
Java: Datadog offers a library you can import into your project. No Lambda Layer is required.
Note: The Datadog Lambda Layer and client libraries include the X-Ray SDK as a dependency, so you don’t need to explicitly install it in your projects.
This plugin attaches the Datadog Lambda Library for Node.js and Python to your functions using layers. At deploy time, it generates new handler functions that wrap your existing functions and initializes the Lambda Library.
You can install the plugin with one of the following commands.
npm install --save-dev serverless-plugin-datadog # for NPM users yarn add --dev serverless-plugin-datadog # for Yarn users
Then, in your
serverless.yml, add the following:
plugins: - serverless-plugin-datadog
Configure the library by adding the following section to your
serverless.yml. The default values are listed, as well as whether the field is required.
custom: datadog: # Whether to add the Lambda Layers, or expect the user to bring their own. Defaults to true. addLayers: true # The log level, set to DEBUG for extended logging. Defaults to info. logLevel: "info" # Send custom metrics via logs with the help of Datadog Forwarder Lambda function (recommended). Defaults to false. flushMetricsToLogs: false # Which Datadog Site to send data to, only needed when flushMetricsToLogs is false. Defaults to datadoghq.com. site: datadoghq.com # datadoghq.eu for Datadog EU # Datadog API Key, only needed when flushMetricsToLogs is false apiKey: "" # Datadog API Key encrypted using KMS, only needed when flushMetricsToLogs is false apiKMSKey: "" # Enable tracing on Lambda functions and API Gateway integrations. Defaults to true enableXrayTracing: true # Enable tracing on Lambda function using dd-trace, datadog's APM library. Requires datadog log forwarder to be set up. Defaults to true. enableDDTracing: true # When set, the plugin will try to subscribe the lambda's cloudwatch log groups to the forwarder with the given arn. forwarder: arn:aws:lambda:us-east-1:000000000000:function:datadog-forwarder
flushMetricsToLogs: true is recommended for submitting custom metrics via CloudWatch logs with the help of Datadog Forwarder.
<!–## AWS SAM
To enable X-Ray tracing by default for your Lambda functions and API Gateways, add the
Api::TracingEnabled keys to the Globals section of your
template.yaml. Also, add your Datadog API key and any other environment variables (see table below):
Globals: Function: Tracing: Active Environment: Variables: DD_API_KEY: YOUR_DATADOG_API_KEY Api: TracingEnabled: true
You can also include the Datadog Lambda Library directly in your project either from source or with the standard package manager for your runtime.
Note: AWS SAM supports downloading Lambda Layers for local development.
You can configure the Datadog Lambda Library by adding environment variables to your Lambda functions:
|Environment Variable||Description||Required||Default||Accepted Values|
|Your Datadog API key||Yes||Datadog API key|
|Use instead of ||No||KMS-encrypted Datadog API key|
|Set if using the EU instance of Datadog||No|
|Enable zero latency asynchronous custom metrics||No|
|Enable detailed logs for the Datadog Lambda Layer||No|
Additional helpful documentation, links, and articles: