Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datadog-lambda-js

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datadog-lambda-js - npm Package Compare versions

Comparing version 9.115.0 to 9.116.0

2

dist/constants.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.STREAM_RESPONSE = exports.HANDLER_STREAMING = exports.datadogLambdaVersion = void 0;
exports.datadogLambdaVersion = "9.115.0";
exports.datadogLambdaVersion = "9.116.0";
// Response streaming functions

@@ -6,0 +6,0 @@ exports.HANDLER_STREAMING = Symbol.for("aws.lambda.runtime.handler.streaming");

/// <reference types="node" />
/// <reference types="node" />
export declare class KMSService {

@@ -3,0 +4,0 @@ private encryptionContext;

@@ -100,3 +100,4 @@ "use strict";

this.globalTags = this.getGlobalTags(context);
this.statsDClient = new hot_shots_1.StatsD({ host: "127.0.0.1", closingFlushInterval: 1 });
// About 200 chars per metric, so 8KB buffer size holds approx 40 metrics per request
this.statsDClient = new hot_shots_1.StatsD({ host: "127.0.0.1", closingFlushInterval: 1, maxBufferSize: 8192 });
return [2 /*return*/];

@@ -103,0 +104,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
type Console = typeof console;
type wrappedConsole = Console & {
[K in LogMethod]: {
__wrapped?: boolean;
};
};
import { TraceContextService } from "./trace-context-service";
type LogMethod = "log" | "info" | "debug" | "error" | "warn" | "trace";
/**

@@ -7,3 +15,3 @@ * Patches console output to include DataDog's trace context.

*/
export declare function patchConsole(cnsle: Console, contextService: TraceContextService): void;
export declare function patchConsole(cnsle: wrappedConsole, contextService: TraceContextService): void;
/**

@@ -13,2 +21,3 @@ * Removes log patching to add DataDog's trace context.

export declare function unpatchConsole(cnsle: Console): void;
export {};
//# sourceMappingURL=patch-console.d.ts.map
import { SpanContextWrapper } from "./span-context-wrapper";
export interface StepFunctionContext {
"step_function.execution_name": string;
"step_function.execution_id": string;
"step_function.execution_input": object;
"step_function.execution_role_arn": string;
"step_function.execution_start_time": string;
"step_function.state_machine_name": string;
"step_function.state_machine_arn": string;
"step_function.state_entered_time": string;
"step_function.state_name": string;
"step_function.state_retry_count": number;
interface NestedStepFunctionContext {
execution_id: string;
state_entered_time: string;
state_name: string;
root_execution_id: string;
serverless_version: string;
}
interface LambdaRootStepFunctionContext {
execution_id: string;
state_entered_time: string;
state_name: string;
trace_id: string;
dd_p_tid: string;
serverless_version: string;
}
interface LegacyStepFunctionContext {
execution_id: string;
state_entered_time: string;
state_name: string;
}
export type StepFunctionContext = NestedStepFunctionContext | LambdaRootStepFunctionContext | LegacyStepFunctionContext;
export declare const TRACE_ID = "traceId";

@@ -28,3 +37,11 @@ export declare const PARENT_ID = "spanId";

private numberToBinaryString;
private extractStateMachineContext;
private isValidContextObject;
/**
* Parse a list of trace tags such as [_dd.p.tid=66bcb5eb00000000,_dd.p.dm=-0] and return the
* value of the _dd.p.tid tag or an empty string if not found.
*/
private parsePTid;
}
export {};
//# sourceMappingURL=step-function-service.d.ts.map
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,2 +22,17 @@ exports.StepFunctionContextService = exports.DD_P_TID = exports.PARENT_ID = exports.TRACE_ID = void 0;

exports.DD_P_TID = "_dd.p.tid";
// Type Guard Functions
function isStepFunctionRootContext(obj) {
return typeof (obj === null || obj === void 0 ? void 0 : obj.root_execution_id) === "string" && typeof (obj === null || obj === void 0 ? void 0 : obj.serverless_version) === "string";
}
function isLambdaRootContext(obj) {
return (typeof (obj === null || obj === void 0 ? void 0 : obj.trace_id) === "string" &&
typeof (obj === null || obj === void 0 ? void 0 : obj.dd_p_tid) === "string" &&
typeof (obj === null || obj === void 0 ? void 0 : obj.serverless_version) === "string");
}
function isLegacyContext(obj) {
return (typeof (obj === null || obj === void 0 ? void 0 : obj.execution_id) === "string" &&
typeof (obj === null || obj === void 0 ? void 0 : obj.state_entered_time) === "string" &&
typeof (obj === null || obj === void 0 ? void 0 : obj.state_name) === "string" &&
(obj === null || obj === void 0 ? void 0 : obj.serverless_version) === undefined);
}
var StepFunctionContextService = /** @class */ (function () {

@@ -23,2 +49,3 @@ function StepFunctionContextService(event) {

StepFunctionContextService.prototype.setContext = function (event) {
var _a;
// It is safe to mark this as a singleton since this method will be

@@ -28,79 +55,39 @@ // always triggered by the same event.

return;
// Execution
var execution = event.Execution;
if (typeof execution !== "object") {
(0, utils_1.logDebug)("event.Execution is not an object.");
return;
// Extract Payload if available (Legacy lambda parsing)
if (typeof ((_a = event === null || event === void 0 ? void 0 : event.Payload) === null || _a === void 0 ? void 0 : _a._datadog) === "object" || this.isValidContextObject(event === null || event === void 0 ? void 0 : event.Payload)) {
event = event.Payload;
}
var executionID = execution.Id;
if (typeof executionID !== "string") {
(0, utils_1.logDebug)("event.Execution.Id is not a string.");
return;
// Extract _datadog if available (JSONata v1 parsing)
if (typeof event._datadog === "object") {
event = event._datadog;
}
var executionInput = execution.Input;
var executionName = execution.Name;
if (typeof executionName !== "string") {
(0, utils_1.logDebug)("event.Execution.Name is not a string.");
// Extract the common context variables
var stateMachineContext = this.extractStateMachineContext(event);
if (stateMachineContext === null)
return;
var execution_id = stateMachineContext.execution_id, state_entered_time = stateMachineContext.state_entered_time, state_name = stateMachineContext.state_name;
if (typeof event["serverless-version"] === "string" && event["serverless-version"] === "v1") {
if (typeof event.RootExecutionId === "string") {
this.context = {
execution_id: execution_id,
state_entered_time: state_entered_time,
state_name: state_name,
root_execution_id: event.RootExecutionId,
serverless_version: event["serverless-version"],
};
}
else if (typeof event["x-datadog-trace-id"] === "string" && typeof event["x-datadog-tags"] === "string") {
this.context = {
execution_id: execution_id,
state_entered_time: state_entered_time,
state_name: state_name,
trace_id: event["x-datadog-trace-id"],
dd_p_tid: this.parsePTid(event["x-datadog-tags"]),
serverless_version: event["serverless-version"],
};
}
}
var executionRoleArn = execution.RoleArn;
if (typeof executionRoleArn !== "string") {
(0, utils_1.logDebug)("event.Execution.RoleArn is not a string.");
return;
else {
this.context = { execution_id: execution_id, state_entered_time: state_entered_time, state_name: state_name };
}
var executionStartTime = execution.StartTime;
if (typeof executionStartTime !== "string") {
(0, utils_1.logDebug)("event.Execution.StartTime is not a string.");
return;
}
// State
var state = event.State;
if (typeof state !== "object") {
(0, utils_1.logDebug)("event.State is not an object.");
return;
}
var stateRetryCount = state.RetryCount;
if (typeof stateRetryCount !== "number") {
(0, utils_1.logDebug)("event.State.RetryCount is not a number.");
return;
}
var stateEnteredTime = state.EnteredTime;
if (typeof stateEnteredTime !== "string") {
(0, utils_1.logDebug)("event.State.EnteredTime is not a string.");
return;
}
var stateName = state.Name;
if (typeof stateName !== "string") {
(0, utils_1.logDebug)("event.State.Name is not a string.");
return;
}
// StateMachine
var stateMachine = event.StateMachine;
if (typeof stateMachine !== "object") {
(0, utils_1.logDebug)("event.StateMachine is not an object.");
return;
}
var stateMachineArn = stateMachine.Id;
if (typeof stateMachineArn !== "string") {
(0, utils_1.logDebug)("event.StateMachine.Id is not a string.");
return;
}
var stateMachineName = stateMachine.Name;
if (typeof stateMachineName !== "string") {
(0, utils_1.logDebug)("event.StateMachine.Name is not a string.");
return;
}
var context = {
"step_function.execution_name": executionName,
"step_function.execution_id": executionID,
"step_function.execution_input": executionInput !== null && executionInput !== void 0 ? executionInput : {},
"step_function.execution_role_arn": executionRoleArn,
"step_function.execution_start_time": executionStartTime,
"step_function.state_entered_time": stateEnteredTime,
"step_function.state_machine_arn": stateMachineArn,
"step_function.state_machine_name": stateMachineName,
"step_function.state_name": stateName,
"step_function.state_retry_count": stateRetryCount,
};
this.context = context;
};

@@ -111,8 +98,21 @@ Object.defineProperty(StepFunctionContextService.prototype, "spanContext", {

return null;
var traceId = this.deterministicSha256HashToBigIntString(this.context["step_function.execution_id"], exports.TRACE_ID);
var parentId = this.deterministicSha256HashToBigIntString(this.context["step_function.execution_id"] +
"#" +
this.context["step_function.state_name"] +
"#" +
this.context["step_function.state_entered_time"], exports.PARENT_ID);
var traceId;
var ptid;
if (isStepFunctionRootContext(this.context)) {
traceId = this.deterministicSha256HashToBigIntString(this.context.root_execution_id, exports.TRACE_ID);
ptid = this.deterministicSha256HashToBigIntString(this.context.root_execution_id, exports.DD_P_TID);
}
else if (isLambdaRootContext(this.context)) {
traceId = this.context.trace_id;
ptid = this.context.dd_p_tid;
}
else if (isLegacyContext(this.context)) {
traceId = this.deterministicSha256HashToBigIntString(this.context.execution_id, exports.TRACE_ID);
ptid = this.deterministicSha256HashToBigIntString(this.context.execution_id, exports.DD_P_TID);
}
else {
(0, utils_1.logDebug)("StepFunctionContext doesn't match any known formats!");
return null;
}
var parentId = this.deterministicSha256HashToBigIntString(this.context.execution_id + "#" + this.context.state_name + "#" + this.context.state_entered_time, exports.PARENT_ID);
var sampleMode = trace_context_service_1.SampleMode.AUTO_KEEP;

@@ -128,3 +128,2 @@ try {

});
var ptid = this.deterministicSha256HashToBigIntString(this.context["step_function.execution_id"], exports.DD_P_TID);
ddSpanContext._trace.tags["_dd.p.tid"] = id(ptid, 10).toString(16);

@@ -151,3 +150,3 @@ if (ddSpanContext === null)

StepFunctionContextService.prototype.deterministicSha256Hash = function (s, type) {
// returns 128 bits hash unless mostSignificant64Bits options is set to true.
// returns upper or lower 64 bits of the hash
var _this = this;

@@ -172,2 +171,44 @@ var hash = new sha256_js_1.Sha256();

};
StepFunctionContextService.prototype.extractStateMachineContext = function (event) {
if (this.isValidContextObject(event)) {
return {
execution_id: event.Execution.Id,
state_entered_time: event.State.EnteredTime,
state_name: event.State.Name,
};
}
(0, utils_1.logDebug)("Cannot extract StateMachine context! Invalid execution or state data.");
return null;
};
StepFunctionContextService.prototype.isValidContextObject = function (context) {
var _a, _b, _c;
return (typeof ((_a = context === null || context === void 0 ? void 0 : context.Execution) === null || _a === void 0 ? void 0 : _a.Id) === "string" &&
typeof ((_b = context === null || context === void 0 ? void 0 : context.State) === null || _b === void 0 ? void 0 : _b.EnteredTime) === "string" &&
typeof ((_c = context === null || context === void 0 ? void 0 : context.State) === null || _c === void 0 ? void 0 : _c.Name) === "string");
};
/**
* Parse a list of trace tags such as [_dd.p.tid=66bcb5eb00000000,_dd.p.dm=-0] and return the
* value of the _dd.p.tid tag or an empty string if not found.
*/
StepFunctionContextService.prototype.parsePTid = function (traceTags) {
var e_1, _a;
if (traceTags) {
try {
for (var _b = __values(traceTags.split(",")), _c = _b.next(); !_c.done; _c = _b.next()) {
var tag = _c.value;
if (tag.includes("_dd.p.tid=")) {
return tag.split("=")[1];
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}
return "";
};
return StepFunctionContextService;

@@ -174,0 +215,0 @@ }());

@@ -15,3 +15,4 @@ import { Context } from "aws-lambda";

sns = "sns",
sqs = "sqs"
sqs = "sqs",
stepFunctions = "states"
}

@@ -29,5 +30,5 @@ export declare enum eventSubTypes {

* api-gateway | application-load-balancer | cloudwatch-logs |
* cloudwatch-events | cloudfront | dynamodb | kinesis | s3 | sns | sqs
* cloudwatch-events | cloudfront | dynamodb | kinesis | s3 | sns | sqs | states
*/
export declare function parseEventSource(event: any): eventTypes.apiGateway | eventTypes.applicationLoadBalancer | eventTypes.cloudFront | eventTypes.cloudWatchEvents | eventTypes.cloudWatchLogs | eventTypes.dynamoDB | eventTypes.eventBridge | eventTypes.kinesis | eventTypes.lambdaUrl | eventTypes.s3 | eventTypes.sns | eventTypes.sqs | undefined;
export declare function parseEventSource(event: any): eventTypes.apiGateway | eventTypes.applicationLoadBalancer | eventTypes.cloudFront | eventTypes.cloudWatchEvents | eventTypes.cloudWatchLogs | eventTypes.dynamoDB | eventTypes.eventBridge | eventTypes.kinesis | eventTypes.lambdaUrl | eventTypes.s3 | eventTypes.sns | eventTypes.sqs | eventTypes.stepFunctions | undefined;
/**

@@ -34,0 +35,0 @@ * parseEventSourceARN parses the triggering event to determine the event source's

@@ -92,2 +92,13 @@ "use strict";

}
function extractStateMachineARN(event) {
// Extract Payload if available (Legacy lambda parsing)
if (typeof event.Payload === "object") {
event = event.Payload;
}
// Extract _datadog if available (JSONata v1 parsing)
if (typeof event._datadog === "object") {
event = event._datadog;
}
return event.StateMachine.Id;
}
var eventTypes;

@@ -108,2 +119,3 @@ (function (eventTypes) {

eventTypes["sqs"] = "sqs";
eventTypes["stepFunctions"] = "states";
})(eventTypes = exports.eventTypes || (exports.eventTypes = {}));

@@ -134,3 +146,3 @@ var eventSubTypes;

* api-gateway | application-load-balancer | cloudwatch-logs |
* cloudwatch-events | cloudfront | dynamodb | kinesis | s3 | sns | sqs
* cloudwatch-events | cloudfront | dynamodb | kinesis | s3 | sns | sqs | states
*/

@@ -176,2 +188,5 @@ function parseEventSource(event) {

}
if (eventType.isStepFunctionsEvent(event)) {
return eventTypes.stepFunctions;
}
}

@@ -235,2 +250,5 @@ exports.parseEventSource = parseEventSource;

}
if (source === "states") {
eventSourceARN = extractStateMachineARN(event);
}
return eventSourceARN;

@@ -255,2 +273,5 @@ }

}
if (event.resource) {
httpTags["http.route"] = event.resource;
}
return httpTags;

@@ -266,2 +287,7 @@ }

}
if (event.routeKey) {
// "GET /my/endpoint" => "/my/endpoint"
var array = event.routeKey.split(" ");
httpTags["http.route"] = array[array.length - 1];
}
return httpTags;

@@ -268,0 +294,0 @@ }

@@ -19,2 +19,3 @@ import { APIGatewayEvent, APIGatewayProxyEventV2, AppSyncResolverEvent, ALBEvent, CloudWatchLogsEvent, ScheduledEvent, CloudFrontRequestEvent, DynamoDBStreamEvent, KinesisStreamEvent, S3Event, SNSEvent, SQSEvent, EventBridgeEvent } from "aws-lambda";

export declare function isLambdaUrlEvent(event: any): boolean;
export declare function isStepFunctionsEvent(event: any): boolean;
//# sourceMappingURL=event-type-guards.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isLambdaUrlEvent = exports.isEventBridgeEvent = exports.isAppSyncResolverEvent = exports.isEBSQSEvent = exports.isSNSSQSEvent = exports.isSQSEvent = exports.isSNSEvent = exports.isS3Event = exports.isKinesisStreamEvent = exports.isDynamoDBStreamEvent = exports.isCloudFrontRequestEvent = exports.isCloudWatchEvent = exports.isCloudWatchLogsEvent = exports.isALBEvent = exports.isAPIGatewayWebsocketEvent = exports.isAPIGatewayEventV2 = exports.isAPIGatewayEvent = void 0;
exports.isStepFunctionsEvent = exports.isLambdaUrlEvent = exports.isEventBridgeEvent = exports.isAppSyncResolverEvent = exports.isEBSQSEvent = exports.isSNSSQSEvent = exports.isSQSEvent = exports.isSNSEvent = exports.isS3Event = exports.isKinesisStreamEvent = exports.isDynamoDBStreamEvent = exports.isCloudFrontRequestEvent = exports.isCloudWatchEvent = exports.isCloudWatchLogsEvent = exports.isALBEvent = exports.isAPIGatewayWebsocketEvent = exports.isAPIGatewayEventV2 = exports.isAPIGatewayEvent = void 0;
var constants_1 = require("../trace/constants");

@@ -98,2 +98,14 @@ function isAPIGatewayEvent(event) {

exports.isLambdaUrlEvent = isLambdaUrlEvent;
function isStepFunctionsEvent(event) {
// Extract Payload if available (Legacy lambda parsing)
if (typeof event.Payload === "object") {
event = event.Payload;
}
// Extract _datadog if available (JSONata v1 parsing)
if (typeof event._datadog === "object") {
event = event._datadog;
}
return (typeof event.Execution === "object" && typeof event.State === "object" && typeof event.StateMachine === "object");
}
exports.isStepFunctionsEvent = isStepFunctionsEvent;
//# sourceMappingURL=event-type-guards.js.map
{
"name": "datadog-lambda-js",
"version": "9.115.0",
"version": "9.116.0",
"description": "Lambda client library that supports hybrid tracing in node js",

@@ -31,3 +31,3 @@ "main": "dist/index.js",

"@types/shimmer": "^1.0.1",
"dd-trace": "^4.44.0",
"dd-trace": "^4.48.0",
"jest": "^27.0.1",

@@ -34,0 +34,0 @@ "mock-fs": "4.14.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc