Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
datadog-lambda-js
Advanced tools
The datadog-lambda-js npm package is designed to help you monitor and trace your AWS Lambda functions with Datadog. It provides tools to automatically collect and send metrics, logs, and traces from your Lambda functions to Datadog, enabling you to gain insights into the performance and behavior of your serverless applications.
Automatic Tracing
This feature allows you to automatically trace your Lambda function executions. By wrapping your handler with the `datadog` function, you can send traces to Datadog without manually instrumenting your code.
const { datadog } = require('datadog-lambda-js');
const handler = datadog(async (event, context) => {
// Your Lambda function code here
return { statusCode: 200, body: 'Hello, world!' };
});
module.exports.handler = handler;
Custom Metrics
This feature allows you to send custom metrics from your Lambda functions to Datadog. You can use the `sendDistributionMetric` function to send metrics with specific values and tags.
const { sendDistributionMetric } = require('datadog-lambda-js');
const handler = async (event, context) => {
// Your Lambda function code here
sendDistributionMetric('my_custom_metric', 42, 'tag:value');
return { statusCode: 200, body: 'Hello, world!' };
};
module.exports.handler = handler;
Log Forwarding
This feature enables you to forward logs from your Lambda functions to Datadog. By wrapping your handler with the `datadog` function, logs generated within your Lambda function will be automatically sent to Datadog.
const { datadog } = require('datadog-lambda-js');
const handler = datadog(async (event, context) => {
console.log('This is a log message');
return { statusCode: 200, body: 'Hello, world!' };
});
module.exports.handler = handler;
The aws-xray-sdk package is an AWS service that provides tracing capabilities for AWS Lambda functions. It allows you to trace requests as they travel through your entire application, including Lambda functions, and visualize the trace data in the AWS X-Ray console. While it offers tracing similar to datadog-lambda-js, it is specific to the AWS ecosystem and does not provide the same level of integration with Datadog.
The serverless-plugin-datadog package is a Serverless Framework plugin that automatically instruments your Lambda functions with Datadog. It provides similar functionality to datadog-lambda-js but is designed to work within the Serverless Framework, making it easier to integrate Datadog monitoring into your serverless applications.
Datadog Lambda Library for Node.js enables enhanced Lambda metrics, distributed tracing, and custom metric submission from AWS Lambda functions.
Follow the installation instructions, and view your function's enhanced metrics, traces and logs in Datadog.
Once installed, you should be able to submit custom metrics from your Lambda function.
Check out the instructions for submitting custom metrics from AWS Lambda functions.
Once installed, you should be able to view your function's traces in Datadog.
For additional details on trace collection, take a look at collecting traces from AWS Lambda functions.
For additional details on trace and log connection, check out the official documentation for Datadog trace client.
The fs
module is disabled by default. If you want to enable it you have to set the environment variable DD_TRACE_DISABLED_PLUGINS
to ''
or to a comma-separated list of the plugins you want to disable. See the full list of supported plugins here.
By default, the Datadog trace id gets automatically injected into the logs for correlation, if using console
or a logging library supported for automatic trace id injection. You have to manually inject the trace id, if using other logging libraries. See additional details on connecting logs and traces.
Set the environment variable DD_LOGS_INJECTION
to false
to disable this feature.
You can use your own logger to log layer error and debug logs instead of default console
usage.
For example, using the Pino logger:
const { datadog } = require("datadog-lambda-js");
const logger = require("pino")();
// convert message string to object metadata and message
const messageToObject = (stringMessage) => {
const { message, status, ...metadata } = JSON.parse(stringMessage);
return [metadata, message];
};
async function myHandler(event, context) {
// ...
}
// Use your own logger
module.exports.myHandler = datadog(myHandler, {
logger: {
debug: (message) => logger.debug(...messageToObject(message)),
error: (message) => logger.error(...messageToObject(message)),
},
});
Set to true
(recommended) to send custom metrics asynchronously (with no added latency to your Lambda function executions) through CloudWatch Logs with the help of Datadog Forwarder. Defaults to false
. If set to false
, you also need to set DD_API_KEY
and DD_SITE
.
If DD_FLUSH_TO_LOG
is set to false
(not recommended), the Datadog API Key must be defined by setting one of the following environment variables:
kms:Decrypt
permissionIf DD_FLUSH_TO_LOG
is set to false
(not recommended), and your data need to be sent to the Datadog EU site, you must set DD_SITE
to datadoghq.eu
. Defaults to datadoghq.com
.
Set to debug
enable debug logs from the Datadog Lambda Library. Defaults to info
.
Generate enhanced Datadog Lambda integration metrics, such as, aws.lambda.enhanced.invocations
and aws.lambda.enhanced.errors
. Defaults to true
.
Location of your original Lambda handler.
Initialize the Datadog tracer when set to true
. Defaults to false
.
Inject Datadog trace id into logs for correlation. Defaults to true
.
Set to true
to merge the X-Ray trace and the Datadog trace, when using both the X-Ray and Datadog tracing. Defaults to false
.
If you encounter a bug with this package, we want to hear about it. Before opening a new issue, search the existing issues to avoid duplicates.
When opening an issue, include the Datadog Lambda Layer version, Node version, and stack trace if available. In addition, include the steps to reproduce when appropriate.
You can also open an issue for a feature request.
If you find an issue with this package and have a fix, please feel free to open a pull request following the procedures.
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 2019 Datadog, Inc.
FAQs
Lambda client library that supports hybrid tracing in node js
The npm package datadog-lambda-js receives a total of 1,060,966 weekly downloads. As such, datadog-lambda-js popularity was classified as popular.
We found that datadog-lambda-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.