Serverless plugin to automagically instrument your Lambda functions with Datadog
Installations
npm install serverless-plugin-datadog
Developer
DataDog
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
NPM Version
Statistics
96 Stars
752 Commits
49 Forks
15 Watching
21 Branches
323 Contributors
Updated on 21 Nov 2024
Languages
TypeScript (95.18%)
Shell (2.7%)
Python (1.65%)
JavaScript (0.39%)
Ruby (0.09%)
Total Downloads
Cumulative downloads
Total Downloads
16,889,197
Last day
-1.5%
23,215
Compared to previous day
Last week
1%
128,148
Compared to previous week
Last month
-2.3%
551,110
Compared to previous month
Last year
37.4%
6,882,467
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Peer Dependencies
1
Datadog recommends the Serverless Framework Plugin for developers using the Serverless Framework to deploy their serverless applications. The plugin automatically enables instrumentation for applications to collect metrics, traces, and logs by:
- Installing the Datadog Lambda library to your Lambda functions as a Lambda layer.
- Installing the Datadog Lambda Extension to your Lambda functions as a Lambda layer (
addExtension
) or subscribing the Datadog Forwarder to your Lambda functions' log groups (forwarderArn
). - Making the required configuration changes, such as adding environment variables or additional tracing layers, to your Lambda functions.
Getting started
To quickly get started, follow the installation instructions for Python, Node.js, Ruby, Java, Go, or .NET and view your function's enhanced metrics, traces, and logs in Datadog.
After installation is complete, configure the advanced options to suit your monitoring needs.
Upgrade
Each version of the plugin is published with a specific set of versions of the Datadog Lambda layers. To pick up new features and bug fixes provided by the latest versions of Datadog Lambda layers, upgrade the serverless framework plugin. Test the new version before applying it on your production applications.
Configuration parameters
To further configure your plugin, use the following custom parameters in your serverless.yml
:
Parameter | Description |
---|---|
site | Set which Datadog site to send data to, such as datadoghq.com (default), datadoghq.eu , us3.datadoghq.com , us5.datadoghq.com , ap1.datadoghq.com , or ddog-gov.com . This parameter is required when collecting telemetry using the Datadog Lambda Extension. |
apiKey | Datadog API key. This parameter is required when collecting telemetry using the Datadog Lambda Extension. Alternatively, you can also set the DATADOG_API_KEY environment variable in your deployment environment. |
appKey | Datadog app key. Only needed when the monitors field is defined. Alternatively, you can also set the DATADOG_APP_KEY environment variable in your deployment environment. |
apiKeySecretArn | An alternative to using the apiKey field. The ARN of the secret that is storing the Datadog API key in AWS Secrets Manager. Remember to add the secretsmanager:GetSecretValue permission to the Lambda execution role. |
apiKMSKey | An alternative to using the apiKey field. Datadog API key encrypted using KMS. Remember to add the kms:Decrypt permission to the Lambda execution role. |
env | When set along with addExtension , a DD_ENV environment variable is added to all Lambda functions with the provided value. Otherwise, an env tag is added to all Lambda functions with the provided value. Defaults to the stage value of the serverless deployment. |
service | When set along with addExtension , a DD_SERVICE environment variable is added to all Lambda functions with the provided value. Otherwise, a service tag is added to all Lambda functions with the provided value. Defaults to the service value of the serverless project. |
version | When set along with addExtension , a DD_VERSION environment variable is added to all Lambda functions with the provided value. When set along with forwarderArn , a version tag is added to all Lambda functions with the provided value. |
tags | A comma separated list of key :value pairs as a single string. When set along with extensionLayerVersion , a DD_TAGS environment variable is added to all Lambda functions with the provided value. When set along with forwarderArn , the plugin parses the string and sets each key :value pair as a tag on all Lambda functions. |
enableXrayTracing | Set true to enable X-Ray tracing on the Lambda functions and API Gateway integrations. Defaults to false . |
enableDDTracing | Enable Datadog tracing on the Lambda function. Defaults to true . |
enableASM | Enable Datadog Application Security Management (ASM) on the Lambda function. Requires the Datadog extension to be present (using addExtension or manually added) and enableDDTracing . Defaults to false . |
enableDDLogs | Enable Datadog log collection using the Lambda Extension. Defaults to true . Note: This setting has no effect on logs sent by the Datadog Forwarder. |
monitors | When defined, the Datadog plugin configures monitors for the deployed function. Requires setting DATADOG_API_KEY and DATADOG_APP_KEY in your environment. To learn how to define monitors, see To Enable and Configure a Recommended Serverless Monitor. |
captureLambdaPayload | Captures incoming and outgoing AWS Lambda payloads in the Datadog APM spans for Lambda invocations. Defaults to false . |
enableSourceCodeIntegration | Enable Datadog Source Code Integration for the function. Defaults to true . |
uploadGitMetadata | Enable Git metadata uploading for the function, as a part of source code integration. Set this to false if you have the Datadog Github Integration installed, as it renders Git metadata uploading unnecessary. Defaults to true . |
subscribeToAccessLogs | Enable automatic subscription of the Datadog Forwarder to API Gateway access log groups. Requires setting forwarderArn . Defaults to true . |
subscribeToExecutionLogs | Enable automatic subscription of the Datadog Forwarder to HTTP API and Websocket log groups. Requires setting forwarderArn . Defaults to true . |
forwarderArn | The ARN of the Datadog Forwarder to be subscribed to the Lambda or API Gateway log groups. |
addLayers | Whether to install the Datadog Lambda library as a layer. Defaults to true . Set to false when you plan to package the Datadog Lambda library to your function's deployment package on your own so that you can install a specific version of the Datadog Lambda library (Python or Node.js). |
addExtension | Whether to install the Datadog Lambda Extension as a layer. Defaults to true . When enabled, it's required to set the apiKey and site . |
exclude | When set, this plugin ignores all specified functions. Use this parameter if you have any functions that should not include Datadog functionality. Defaults to [] . |
enabled | When set to false , the Datadog plugin stays inactive. Defaults to true . You can control this option using an environment variable. For example, use enabled: ${strToBool(${env:DD_PLUGIN_ENABLED, true})} to activate/deactivate the plugin during deployment. Alternatively, you can also use the value passed in through --stage to control this option—see example. |
customHandler | When set, the specified handler is set as the handler for all the functions. |
failOnError | When set, this plugin throws an error if any custom Datadog monitors fail to create or update. This occurs after deploy, but will cause the result of serverless deploy to return a nonzero exit code (to fail user CI). Defaults to false . |
logLevel | The log level for Datadog's lambda extension and tracing libraries. Set to DEBUG for extended logging. It does not affect which user logs are forwarded to Datadog. |
skipCloudformationOutputs | Set to true if you want to skip adding Datadog Cloudformation Outputs for your stack. This is useful if you are running into the 200 output limit which can cause the stack creation to fail. |
enableColdStartTracing | Set to false to disable Cold Start Tracing. Used in NodeJS and Python. Defaults to true . |
coldStartTraceMinDuration | Sets the minimum duration (in milliseconds) for a module load event to be traced via Cold Start Tracing. Number. Defaults to 3 . |
coldStartTraceSkipLibs | optionally skip creating Cold Start Spans for a comma-separated list of libraries. Useful to limit depth or skip known libraries. Default depends on runtime. |
subdomain | Set an optional subdomain to use for app URLs which are printed to output. Defaults to app . |
enableProfiling | Enable the Datadog Continuous Profiler with true . Supported in Beta for NodeJS and Python. Defaults to false . |
encodeAuthorizerContext | When set to true for Lambda authorizers, the tracing context will be encoded into the response for propagation. Supported for NodeJS and Python. Defaults to true . |
decodeAuthorizerContext | When set to true for Lambdas that are authorized via Lambda authorizers, it will parse and use the encoded tracing context (if found). Supported for NodeJS and Python. Defaults to true . |
apmFlushDeadline | Used to determine when to submit spans before a timeout occurs, in milliseconds. When the remaining time in an AWS Lambda invocation is less than the value set, the tracer attempts to submit the current active spans and all finished spans. Supported for NodeJS and Python. Defaults to 100 milliseconds. |
enableStepFunctionsTracing | Enable automatic subscription of the Datadog Forwarder to Step Function log groups and Step Functions tracing. If no Step Function log groups are configured, then they are automatically created. Requires setting forwarderArn . Defaults to false . |
propagateUpstreamTrace | When set to true , downstream Stepfunction invocation traces merge with upstream Stepfunction invocations. Defaults to false . |
redirectHandlers | Optionally disable handler redirection if set to false . This should only be set to false when APM is fully disabled. Defaults to true . |
To use any of these parameters, add a custom > datadog section to your serverless.yml similar to this example: |
1custom: 2 datadog: 3 apiKeySecretArn: "{Datadog_API_Key_Secret_ARN}" 4 enableXrayTracing: false 5 enableDDTracing: true 6 enableDDLogs: true 7 subscribeToAccessLogs: true 8 forwarderArn: arn:aws:lambda:us-east-1:000000000000:function:datadog-forwarder 9 exclude: 10 - dd-excluded-function
Webpack
If you are using a bundler, such as webpack, see Serverless Tracing and Webpack.
TypeScript
You may encounter the error of missing type definitions. To resolve the error, add datadog-lambda-js
and dd-trace
to the devDependencies
list of your project's package.json.
If you are using serverless-typescript, make sure that serverless-datadog
is above the serverless-typescript
entry in your serverless.yml
. The plugin will automatically detect .ts
files.
1plugins: 2 - serverless-plugin-datadog 3 - serverless-typescript
Disable Plugin for Particular Environment
If you'd like to turn off the plugin based on the environment (passed via --stage
), you can use something similar to the example below.
1provider: 2 stage: ${self:opt.stage, 'dev'} 3 4custom: 5 staged: ${self:custom.stageVars.${self:provider.stage}, {}} 6 7 stageVars: 8 dev: 9 dd_enabled: false 10 11 datadog: 12 enabled: ${self:custom.staged.dd_enabled, true}
Serverless Monitors
There are seven recommended monitors with default values pre-configured.
Monitor | Metrics | Threshold | Serverless Monitor ID |
---|---|---|---|
High Error Rate | aws.lambda.errors /aws.lambda.invocations | >= 10% | high_error_rate |
Timeout | aws.lambda.duration.max /aws.lambda.timeout | >= 1 | timeout |
Out of Memory | aws.lambda.enhanced.out_of_memory | > 0 | out_of_memory |
High Iterator Age | aws.lambda.iterator_age.maximum | >= 24 hrs | high_iterator_age |
High Cold Start Rate | aws.lambda.enhanced.invocations(cold_start:true) /aws.lambda.enhanced.invocations | >= 20% | high_cold_start_rate |
High Throttles | aws.lambda.throttles /aws.lambda.invocations | >= 20% | high_throttles |
Increased Cost | aws.lambda.enhanced.estimated_cost | ↑20% | increased_cost |
To Enable and Configure a Recommended Serverless Monitor
To create a recommended monitor, you must use its respective serverless monitor ID. Note that you must also set the DATADOG_API_KEY
and DATADOG_APP_KEY
in your environment.
If you’d like to further configure the parameters for a recommended monitor, you can directly define the parameter values below the serverless monitor ID. Parameters not specified under a recommended monitor will use the default recommended value. The query
parameter for recommended monitors cannot be directly modified and will default to using the query
valued as defined above; however, you may change the threshold value in query
by re-defining it within the options
parameter. To delete a monitor, remove the monitor from the serverless.yml
template. For further documentation on how to define monitor parameters, see the Datadog Monitors API.
Monitor creation occurs after the function is deployed. In the event that a monitor is unsuccessfully created, the function will still be successfully deployed.
To create a recommended monitor with the default values
Define the appropriate serverless monitor ID without specifying any parameter values
1custom: 2 datadog: 3 addLayers: true 4 monitors: 5 - high_error_rate:
To configure a recommended monitor
1custom: 2 datadog: 3 addLayers: true 4 monitors: 5 - high_error_rate: 6 name: "High Error Rate with Modified Warning Threshold" 7 message: "More than 10% of the function’s invocations were errors in the selected time range. Notify @data.dog@datadoghq.com @slack-serverless-monitors" 8 tags: ["modified_error_rate", "serverless", "error_rate"] 9 require_full_window: true 10 priority: 2 11 options: 12 include_tags: true 13 notify_audit: true 14 thresholds: 15 warning: 0.05 16 critical: 0.1
To delete a monitor
Removing the serverless monitor ID and its parameters will delete the monitor.
To Enable and Configure a Custom Monitor
To define a custom monitor, you must define a unique serverless monitor ID string in addition to passing in the API key and Application key, DATADOG_API_KEY
and DATADOG_APP_KEY
, in your environment. The query
parameter is required but every other parameter is optional. Define a unique serverless monitor ID string and specify the necessary parameters below. For further documentation on monitor parameters, see the Datadog Monitors API.
1custom: 2 datadog: 3 addLayers: true 4 monitors: 5 - custom_monitor_id: 6 name: "Custom Monitor" 7 query: "max(next_1w):forecast(avg:system.load.1{*}, 'linear', 1, interval='60m', history='1w', model='default') >= 3" 8 message: "Custom message for custom monitor. Notify @data.dog@datadoghq.com @slack-serverless-monitors" 9 tags: ["custom_monitor", "serverless"] 10 priority: 3 11 options: 12 enable_logs_sample: true 13 require_full_window: true 14 include_tags: false 15 notify_audit: true 16 notify_no_data: false 17 thresholds: 18 warning: 2 19 critical: 3
Breaking Changes
- When used in conjunction with the Datadog Extension, this plugin sets
service
andenv
tags through environment variables instead of Lambda resource tags. - The
enableTags
parameter was replaced by the newservice
,env
parameters.
- The Datadog Lambda Extension is now the default mechanism for transmitting telemetry to Datadog.
Working with serverless-plugin-warmup
This library is compatible at best effort with serverless-plugin-warmup. If you want to exclude the warmer function from Datadog, use the exclude
feature of this library.
To properly package your application, this plugin must be listed after serverless-plugin-warmup
in your serverless.yml
file:
1plugins: 2 - serverless-plugin-warmup 3 - serverless-plugin-datadog
Opening Issues
If you encounter a bug with this package, let us know by filing an issue! Before opening a new issue, please search the existing issues to avoid duplicates.
When opening an issue, include your Serverless Framework version, Python/Node.js version, and stack trace if available. Also, please include the steps to reproduce when appropriate.
You can also open an issue for a feature request.
Contributing
If you find an issue with this package and have a fix, open a pull request following the procedures.
Community
For product feedback and questions, join the #serverless
channel in the Datadog community on Slack.
License
Unless explicitly stated otherwise, all files in this repository are licensed under the Apache License Version 2.0.
This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pppg-cpfq-h7wr
Reason
Found 23/30 approved changesets -- score normalized to 7
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 23 are checked with a SAST tool
Reason
branch protection is not maximal on development and all release branches
Details
- Info: 'allow deletion' disabled on branch 'main'
- Info: 'force pushes' disabled on branch 'main'
- Warn: 'branch protection settings apply to administrators' is disabled on branch 'main'
- Warn: 'stale review dismissal' is disabled on branch 'main'
- Warn: required approving review count is 1 on branch 'main'
- Info: codeowner review is required on branch 'main'
- Warn: 'last push approval' is disabled on branch 'main'
- Info: status check found to merge onto on branch 'main'
- Info: PRs are required in order to make changes on branch 'main'
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/integration_tests.yml:1
- Warn: no topLevel permission defined: .github/workflows/monitor_api_integration_test.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Info: Possibly incomplete results: error parsing shell code: reached EOF without closing quote ': .github/workflows/publish.yml:42
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:70: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration_tests.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/integration_tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration_tests.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/integration_tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration_tests.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/integration_tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/monitor_api_integration_test.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/monitor_api_integration_test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/monitor_api_integration_test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/monitor_api_integration_test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/monitor_api_integration_test.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/monitor_api_integration_test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/publish.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/DataDog/serverless-plugin-datadog/publish.yml/main?enable=pin
- Warn: downloadThenRun not pinned by hash: .github/workflows/build.yml:76
- Info: 0 out of 18 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 downloadThenRun dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
5.8
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to serverless-plugin-datadog
datadog-cdk-constructs-v2
CDK Construct Library to automatically instrument Python and Node Lambda functions with Datadog using AWS CDK v2
datadog-lambda-js
Lambda client library that supports hybrid tracing in node js
@datadog/datadog-ci
Run datadog actions from the CI.
dd-trace
Datadog APM tracing client for JavaScript