AWS Lambda
For AWS Lambda, Datadog provides a dedicated library,datadog-lambda-js, which wraps dd-trace and adds Lambda-specific functionality:
- Cold start detection and tagging
- Automatic flushing of traces before the Lambda function returns
- Lambda layer support for zero-code-change installation
- Enhanced metrics via the Datadog Lambda Extension
Install via Datadog Lambda layer (recommended)
The easiest approach is to add the Datadog Lambda layer to your function. The layer includes both the Datadog Agent (as a Lambda Extension) anddd-trace pre-configured for Lambda.
For manual layer installation, see the Datadog Lambda documentation.
Install via npm
npm
yarn
Usage
Wrap your Lambda handler withdatadog-lambda-js:
handler.js
Key Lambda considerations
Flush interval: In Lambda,dd-trace automatically sets flushInterval to 0 when AWS_LAMBDA_FUNCTION_NAME is set, ensuring traces are flushed synchronously at the end of each invocation rather than on a timer.
Cold starts: The tracer adds some initialization overhead. Lambda layers and the Datadog Extension minimize cold start impact.
Agent connectivity: The Datadog Lambda Extension runs in the same execution environment as your function and listens on localhost:8126, so no network configuration is needed when using the extension.
Environment variables for Lambda
DD_API_KEY (or use AWS Secrets Manager) and DD_SITE to route data to the correct Datadog region.
Google Cloud Functions
dd-trace automatically detects Google Cloud Functions via theFUNCTION_NAME (deprecated runtimes) or K_SERVICE (newer runtimes) environment variables. When detected:
profiling.enableddefaults tofalsetelemetry.enableddefaults tofalseremoteConfig.enableddefaults tofalse- The service name defaults to the function name
index.js
Azure Functions
dd-trace automatically detects Azure Functions via theWEBSITE_SITE_NAME environment variable. When detected, serverless defaults are applied (same as Lambda/GCF).
dd-trace includes a built-in azure-functions plugin:
index.js
azure-functions plugin is listed in the available integrations and is enabled by default.
Serverless defaults
When dd-trace detects a serverless environment (Lambda, GCF, or Azure Functions), it applies these defaults automatically:| Option | Default in serverless | Notes |
|---|---|---|
crashtracking.enabled | false | Crash tracking requires a long-lived process |
profiling.enabled | false | Profiling overhead is not suitable for short-lived functions |
telemetry.enabled | false | Reduces noise from short-lived invocations |
remoteConfig.enabled | false | Remote config requires a persistent connection |
flushInterval | 0 (Lambda only) | Flush synchronously before execution context freezes |
| Service name | Function/service name | Inferred from AWS_LAMBDA_FUNCTION_NAME, K_SERVICE, or WEBSITE_SITE_NAME |
