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 4.64.0 to 4.65.0

dist/runtime/errors.d.ts

2

dist/constants.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.datadogLambdaVersion = void 0;
exports.datadogLambdaVersion = "4.64.0";
exports.datadogLambdaVersion = "4.65.0";
//# sourceMappingURL=constants.js.map

@@ -18,6 +18,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -28,13 +32,11 @@ Object.defineProperty(exports, "__esModule", { value: true });

var utils_1 = require("./utils");
// We reuse the function loading logic already inside the lambda runtime.
// tslint:disable-next-line:no-var-requires
var load = require("/var/runtime/UserFunction").load;
var runtime_1 = require("./runtime");
if (process.env.DD_TRACE_DISABLED_PLUGINS === undefined) {
process.env.DD_TRACE_DISABLED_PLUGINS = "fs";
utils_1.logDebug("disabled the dd-trace plugin 'fs'");
(0, utils_1.logDebug)("disabled the dd-trace plugin 'fs'");
}
if (index_1.getEnvValue("DD_TRACE_ENABLED", "true").toLowerCase() === "true") {
if ((0, index_1.getEnvValue)("DD_TRACE_ENABLED", "true").toLowerCase() === "true") {
// Looks for the function local version of dd-trace first, before using
// the version provided by the layer
var path = require.resolve("dd-trace", { paths: __spreadArray(["/var/task/node_modules"], __read(module.paths)) });
var path = require.resolve("dd-trace", { paths: __spreadArray(["/var/task/node_modules"], __read(module.paths), false) });
// tslint:disable-next-line:no-var-requires

@@ -46,3 +48,3 @@ var tracer = require(path).init({

});
utils_1.logDebug("automatically initialized dd-trace");
(0, utils_1.logDebug)("automatically initialized dd-trace");
// Configure the tracer to ignore HTTP calls made from the Lambda Library to the Extension

@@ -53,16 +55,16 @@ tracer.use("http", {

}
var taskRootEnv = index_1.getEnvValue(index_1.lambdaTaskRootEnvVar, "");
var handlerEnv = index_1.getEnvValue(index_1.datadogHandlerEnvVar, "");
var extractorEnv = index_1.getEnvValue(index_1.traceExtractorEnvVar, "");
var taskRootEnv = (0, index_1.getEnvValue)(index_1.lambdaTaskRootEnvVar, "");
var handlerEnv = (0, index_1.getEnvValue)(index_1.datadogHandlerEnvVar, "");
var extractorEnv = (0, index_1.getEnvValue)(index_1.traceExtractorEnvVar, "");
var traceExtractor;
if (extractorEnv) {
try {
traceExtractor = load(taskRootEnv, extractorEnv);
utils_1.logDebug("loaded custom trace context extractor", { extractorEnv: extractorEnv });
traceExtractor = (0, runtime_1.load)(taskRootEnv, extractorEnv);
(0, utils_1.logDebug)("loaded custom trace context extractor", { extractorEnv: extractorEnv });
}
catch (error) {
utils_1.logError("an error occurred while loading the custom trace context extractor", { error: error, extractorEnv: extractorEnv });
(0, utils_1.logError)("an error occurred while loading the custom trace context extractor", { error: error, extractorEnv: extractorEnv });
}
}
exports.handler = index_1.datadog(load(taskRootEnv, handlerEnv), { traceExtractor: traceExtractor });
exports.handler = (0, index_1.datadog)((0, runtime_1.load)(taskRootEnv, handlerEnv), { traceExtractor: traceExtractor });
//# sourceMappingURL=handler.js.map

@@ -65,6 +65,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -75,4 +79,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

var trace_1 = require("./trace");
var trigger_1 = require("./trace/trigger");
var utils_1 = require("./utils");
var trigger_1 = require("./trace/trigger");
exports.apiKeyEnvVar = "DD_API_KEY";

@@ -130,7 +134,7 @@ exports.apiKeyKMSEnvVar = "DD_KMS_API_KEY";

}
utils_1.setLogLevel(finalConfig.debugLogging ? utils_1.LogLevel.DEBUG : utils_1.LogLevel.ERROR);
(0, utils_1.setLogLevel)(finalConfig.debugLogging ? utils_1.LogLevel.DEBUG : utils_1.LogLevel.ERROR);
if (finalConfig.logger) {
utils_1.setLogger(finalConfig.logger);
(0, utils_1.setLogger)(finalConfig.logger);
}
var promHandler = utils_1.promisifiedHandler(handler);
var promHandler = (0, utils_1.promisifiedHandler)(handler);
var wrappedFunc = function (event, context) { return __awaiter(_this, void 0, void 0, function () {

@@ -142,3 +146,3 @@ var err_1, result, localResult, error, didThrow, err_2, err_3;

case 0:
utils_1.setColdStart();
(0, utils_1.setColdStart)();
currentMetricsListener = metricsListener;

@@ -156,3 +160,3 @@ currentTraceListener = traceListener;

if (finalConfig.enhancedMetrics) {
metrics_1.incrementInvocationsMetric(metricsListener, context);
(0, metrics_1.incrementInvocationsMetric)(metricsListener, context);
}

@@ -162,3 +166,5 @@ return [3 /*break*/, 5];

err_1 = _a.sent();
utils_1.logDebug("Failed to start listeners", err_1);
if (err_1 instanceof Error) {
(0, utils_1.logDebug)("Failed to start listeners", err_1);
}
return [3 /*break*/, 5];

@@ -182,7 +188,7 @@ case 5:

if (traceListener.currentSpan && finalConfig.captureLambdaPayload) {
utils_1.tagObject(traceListener.currentSpan, "function.request", localEvent);
utils_1.tagObject(traceListener.currentSpan, "function.response", localResult);
(0, utils_1.tagObject)(traceListener.currentSpan, "function.request", localEvent);
(0, utils_1.tagObject)(traceListener.currentSpan, "function.response", localResult);
}
if (traceListener.triggerTags) {
statusCode = trigger_1.extractHTTPStatusCodeTag(traceListener.triggerTags, localResult);
statusCode = (0, trigger_1.extractHTTPStatusCodeTag)(traceListener.triggerTags, localResult);
if (statusCode) {

@@ -218,3 +224,3 @@ // Store the status tag in the listener to send to Xray on invocation completion

if (didThrow && finalConfig.enhancedMetrics) {
metrics_1.incrementErrorsMetric(metricsListener, context);
(0, metrics_1.incrementErrorsMetric)(metricsListener, context);
}

@@ -224,3 +230,5 @@ return [3 /*break*/, 13];

err_3 = _a.sent();
utils_1.logDebug("Failed to complete listeners", err_3);
if (err_3 instanceof Error) {
(0, utils_1.logDebug)("Failed to complete listeners", err_3);
}
return [3 /*break*/, 13];

@@ -253,8 +261,8 @@ case 13:

}
tags = __spreadArray(__spreadArray([], __read(tags)), [getRuntimeTag()]);
tags = __spreadArray(__spreadArray([], __read(tags), false), [getRuntimeTag()], false);
if (currentMetricsListener !== undefined) {
currentMetricsListener.sendDistributionMetricWithDate.apply(currentMetricsListener, __spreadArray([name, value, metricTime, false], __read(tags)));
currentMetricsListener.sendDistributionMetricWithDate.apply(currentMetricsListener, __spreadArray([name, value, metricTime, false], __read(tags), false));
}
else {
utils_1.logError("handler not initialized");
(0, utils_1.logError)("handler not initialized");
}

@@ -274,8 +282,8 @@ }

}
tags = __spreadArray(__spreadArray([], __read(tags)), [getRuntimeTag()]);
tags = __spreadArray(__spreadArray([], __read(tags), false), [getRuntimeTag()], false);
if (currentMetricsListener !== undefined) {
currentMetricsListener.sendDistributionMetric.apply(currentMetricsListener, __spreadArray([name, value, false], __read(tags)));
currentMetricsListener.sendDistributionMetric.apply(currentMetricsListener, __spreadArray([name, value, false], __read(tags), false));
}
else {
utils_1.logError("handler not initialized");
(0, utils_1.logError)("handler not initialized");
}

@@ -282,0 +290,0 @@ }

@@ -61,3 +61,3 @@ "use strict";

switch (_a.label) {
case 0: return [4 /*yield*/, utils_1.post(this.getUrl("api/v1/distribution_points"), { series: metrics })];
case 0: return [4 /*yield*/, (0, utils_1.post)(this.getUrl("api/v1/distribution_points"), { series: metrics })];
case 1:

@@ -69,5 +69,5 @@ result = _a.sent();

if (result.statusCode === FORBIDDEN_HTTP_STATUS_CODE) {
utils_1.logDebug("authorization failed when sending metrics, please check validity of API key");
(0, utils_1.logDebug)("authorization failed when sending metrics, please check validity of API key");
}
utils_1.logDebug("failed attempt to send metrics to Datadog. " + result.errorMessage + " ");
(0, utils_1.logDebug)("failed attempt to send metrics to Datadog. " + result.errorMessage + " ");
throw result.errorMessage;

@@ -81,3 +81,3 @@ }

var url = new url_1.URL(path, this.baseAPIURL);
utils_1.logDebug("sending metadata to api endpoint " + url.toString());
(0, utils_1.logDebug)("sending metadata to api endpoint " + url.toString());
url.search = querystring_1.default.stringify((_a = {}, _a[API_KEY_QUERY_PARAM] = this.apiKey, _a));

@@ -84,0 +84,0 @@ return url;

@@ -18,6 +18,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -49,3 +53,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

Batcher.prototype.toAPIMetrics = function () {
return __spreadArray([], __read(this.metrics.values())).map(function (metric) { return metric.toAPIMetrics(); }) // No flatMap support yet in node 10
return __spreadArray([], __read(this.metrics.values()), false).map(function (metric) { return metric.toAPIMetrics(); }) // No flatMap support yet in node 10
.reduce(function (prev, curr) { return prev.concat(curr); }, []);

@@ -58,3 +62,3 @@ };

name: metric.name,
tags: __spreadArray([], __read(metric.tags)).sort(),
tags: __spreadArray([], __read(metric.tags), false).sort(),
});

@@ -61,0 +65,0 @@ };

@@ -18,6 +18,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -47,3 +51,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

function getRuntimeTag() {
var processVersion = process_version_1.getProcessVersion();
var processVersion = (0, process_version_1.getProcessVersion)();
var processVersionTagString = null;

@@ -65,5 +69,5 @@ if (processVersion.startsWith("v12")) {

if (context.invokedFunctionArn) {
arnTags = arn_1.parseTagsFromARN(context.invokedFunctionArn, context.functionVersion);
arnTags = (0, arn_1.parseTagsFromARN)(context.invokedFunctionArn, context.functionVersion);
}
var tags = __spreadArray(__spreadArray([], __read(arnTags)), [cold_start_1.getColdStartTag(), "memorysize:" + context.memoryLimitInMB, getVersionTag()]);
var tags = __spreadArray(__spreadArray([], __read(arnTags), false), [(0, cold_start_1.getColdStartTag)(), "memorysize:" + context.memoryLimitInMB, getVersionTag()], false);
var runtimeTag = getRuntimeTag();

@@ -83,3 +87,3 @@ if (runtimeTag) {

// Always write enhanced metrics to standard out
listener.sendDistributionMetric.apply(listener, __spreadArray(["aws.lambda.enhanced." + metricName, 1, true], __read(getEnhancedMetricTags(context))));
listener.sendDistributionMetric.apply(listener, __spreadArray(["aws.lambda.enhanced." + metricName, 1, true], __read(getEnhancedMetricTags(context)), false));
}

@@ -86,0 +90,0 @@ function incrementInvocationsMetric(listener, context) {

@@ -60,11 +60,11 @@ "use strict";

if (!extensionExists) {
utils_1.logDebug("Agent isn't present in sandbox");
(0, utils_1.logDebug)("Agent isn't present in sandbox");
return [2 /*return*/, false];
}
url = new url_1.URL(HELLO_PATH, exports.AGENT_URL);
return [4 /*yield*/, utils_1.get(url, { timeout: AGENT_TIMEOUT_MS })];
return [4 /*yield*/, (0, utils_1.get)(url, { timeout: AGENT_TIMEOUT_MS })];
case 2:
result = _a.sent();
if (!result.success) {
utils_1.logDebug("Could not connect to agent. " + result.errorMessage);
(0, utils_1.logDebug)("Could not connect to agent. " + result.errorMessage);
return [2 /*return*/, false];

@@ -85,7 +85,7 @@ }

url = new url_1.URL(FLUSH_PATH, exports.AGENT_URL);
return [4 /*yield*/, utils_1.post(url, {}, { timeout: AGENT_TIMEOUT_MS })];
return [4 /*yield*/, (0, utils_1.post)(url, {}, { timeout: AGENT_TIMEOUT_MS })];
case 1:
result = _a.sent();
if (!result.success) {
utils_1.logError("Failed to flush extension. " + result.errorMessage);
(0, utils_1.logError)("Failed to flush extension. " + result.errorMessage);
return [2 /*return*/, false];

@@ -92,0 +92,0 @@ }

@@ -81,3 +81,3 @@ "use strict";

errorMsg = "optional dependency aws-sdk not installed. KMS key decryption will not work";
utils_1.logError(errorMsg);
(0, utils_1.logError)(errorMsg);
throw Error(errorMsg);

@@ -84,0 +84,0 @@ }

@@ -54,17 +54,21 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetricsListener = void 0;
var hot_shots_1 = require("hot-shots");
var util_1 = require("util");
var utils_1 = require("../utils");
var api_1 = require("./api");
var extension_1 = require("./extension");
var metric_log_1 = require("./metric-log");
var model_1 = require("./model");
var processor_1 = require("./processor");
var hot_shots_1 = require("hot-shots");
var extension_1 = require("./extension");
var metricsBatchSendIntervalMS = 10000; // 10 seconds

@@ -86,10 +90,10 @@ var MetricsListener = /** @class */ (function () {

_a = this;
return [4 /*yield*/, extension_1.isAgentRunning()];
return [4 /*yield*/, (0, extension_1.isAgentRunning)()];
case 1:
_a.isAgentRunning = _b.sent();
utils_1.logDebug("Extension present: " + this.isAgentRunning);
(0, utils_1.logDebug)("Extension present: " + this.isAgentRunning);
_b.label = 2;
case 2:
if (this.isAgentRunning) {
utils_1.logDebug("Using StatsD client");
(0, utils_1.logDebug)("Using StatsD client");
this.statsDClient = new hot_shots_1.StatsD({ host: "127.0.0.1", closingFlushInterval: 1 });

@@ -99,3 +103,3 @@ return [2 /*return*/];

if (this.config.logForwarding) {
utils_1.logDebug("logForwarding configured");
(0, utils_1.logDebug)("logForwarding configured");
return [2 /*return*/];

@@ -124,3 +128,3 @@ }

// first before we flush by yielding control of the event loop.
return [4 /*yield*/, util_1.promisify(setImmediate)()];
return [4 /*yield*/, (0, util_1.promisify)(setImmediate)()];
case 2:

@@ -137,3 +141,3 @@ // After the processor becomes available, it's possible there are some pending

if (!(this.statsDClient !== undefined)) return [3 /*break*/, 6];
utils_1.logDebug("Flushing statsD");
(0, utils_1.logDebug)("Flushing statsD");
// Make sure all stats are flushed to extension

@@ -159,3 +163,5 @@ return [4 /*yield*/, new Promise(function (resolve, reject) {

// to KMS key decryption failing.
utils_1.logError("failed to flush metrics", error_1);
if (error_1 instanceof Error) {
(0, utils_1.logError)("failed to flush metrics", error_1);
}
return [3 /*break*/, 8];

@@ -165,4 +171,4 @@ case 8:

if (!this.isAgentRunning) return [3 /*break*/, 10];
utils_1.logDebug("Flushing Extension");
return [4 /*yield*/, extension_1.flushExtension()];
(0, utils_1.logDebug)("Flushing Extension");
return [4 /*yield*/, (0, extension_1.flushExtension)()];
case 9:

@@ -174,3 +180,5 @@ _a.sent();

error_2 = _a.sent();
utils_1.logError("failed to flush extension", error_2);
if (error_2 instanceof Error) {
(0, utils_1.logError)("failed to flush extension", error_2);
}
return [3 /*break*/, 12];

@@ -195,6 +203,6 @@ case 12:

if (this.config.logForwarding || forceAsync) {
metric_log_1.writeMetricToStdout(name, value, metricTime, tags);
(0, metric_log_1.writeMetricToStdout)(name, value, metricTime, tags);
return;
}
var dist = new (model_1.Distribution.bind.apply(model_1.Distribution, __spreadArray([void 0, name, [{ timestamp: metricTime, value: value }]], __read(tags))))();
var dist = new (model_1.Distribution.bind.apply(model_1.Distribution, __spreadArray([void 0, name, [{ timestamp: metricTime, value: value }]], __read(tags), false)))();
if (this.currentProcessor !== undefined) {

@@ -207,3 +215,3 @@ // tslint:disable-next-line: no-floating-promises

else {
utils_1.logError("can't send metrics, datadog lambda handler not set up.");
(0, utils_1.logError)("can't send metrics, datadog lambda handler not set up.");
}

@@ -216,3 +224,3 @@ };

}
this.sendDistributionMetricWithDate.apply(this, __spreadArray([name, value, new Date(Date.now()), forceAsync], __read(tags)));
this.sendDistributionMetricWithDate.apply(this, __spreadArray([name, value, new Date(Date.now()), forceAsync], __read(tags), false));
};

@@ -253,3 +261,5 @@ MetricsListener.prototype.createProcessor = function (config, apiKey) {

error_3 = _a.sent();
utils_1.logError("couldn't decrypt kms api key", error_3);
if (error_3 instanceof Error) {
(0, utils_1.logError)("couldn't decrypt kms api key", error_3);
}
return [3 /*break*/, 4];

@@ -260,6 +270,6 @@ case 4: return [3 /*break*/, 6];

if (config.logForwarding) {
utils_1.logDebug(errorMessage);
(0, utils_1.logDebug)(errorMessage);
}
else {
utils_1.logError(errorMessage);
(0, utils_1.logError)(errorMessage);
}

@@ -266,0 +276,0 @@ _a.label = 6;

@@ -29,6 +29,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -68,3 +72,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var distribution = new Distribution(this.name, this.points);
Object.assign(distribution, __assign(__assign({}, this), { points: __spreadArray(__spreadArray([], __read(this.points)), __read(metric.points)) }));
Object.assign(distribution, __assign(__assign({}, this), { points: __spreadArray(__spreadArray([], __read(this.points), false), __read(metric.points), false) }));
return distribution;

@@ -71,0 +75,0 @@ };

@@ -145,3 +145,3 @@ "use strict";

};
return [4 /*yield*/, promise_retry_1.default(options, function (retry) { return _this.client.sendMetrics(finalMetrics).catch(retry); })];
return [4 /*yield*/, (0, promise_retry_1.default)(options, function (retry) { return _this.client.sendMetrics(finalMetrics).catch(retry); })];
case 8:

@@ -148,0 +148,0 @@ _c.sent();

@@ -1,3 +0,2 @@

import { Context } from "aws-lambda";
import { SQSEvent } from "aws-lambda";
import { Context, SQSEvent } from "aws-lambda";
import { SampleMode, Source } from "./constants";

@@ -36,2 +35,3 @@ import { TraceExtractor } from "./listener";

export declare function sendXraySubsegment(segment: string): void;
export declare function readTraceFromAppSyncEvent(event: any): TraceContext | undefined;
export declare function readTraceFromSQSEvent(event: SQSEvent): TraceContext | undefined;

@@ -38,0 +38,0 @@ export declare function readTraceFromLambdaContext(context: any): TraceContext | undefined;

@@ -30,3 +30,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.convertToAPMParentID = exports.convertToAPMTraceID = exports.convertToSampleMode = exports.convertTraceContext = exports.readStepFunctionContextFromEvent = exports.parseXrayTraceContextHeader = exports.readTraceContextFromXray = exports.readTraceFromEvent = exports.readTraceFromHTTPEvent = exports.readTraceFromLambdaContext = exports.readTraceFromSQSEvent = exports.sendXraySubsegment = exports.generateXraySubsegment = exports.addXrayMetadata = exports.addLambdaFunctionTagsToXray = exports.addStepFunctionContextToXray = exports.addTraceContextToXray = exports.extractTraceContext = void 0;
exports.convertToAPMParentID = exports.convertToAPMTraceID = exports.convertToSampleMode = exports.convertTraceContext = exports.readStepFunctionContextFromEvent = exports.parseXrayTraceContextHeader = exports.readTraceContextFromXray = exports.readTraceFromEvent = exports.readTraceFromHTTPEvent = exports.readTraceFromLambdaContext = exports.readTraceFromSQSEvent = exports.readTraceFromAppSyncEvent = exports.sendXraySubsegment = exports.generateXraySubsegment = exports.addXrayMetadata = exports.addLambdaFunctionTagsToXray = exports.addStepFunctionContextToXray = exports.addTraceContextToXray = exports.extractTraceContext = void 0;
var bignumber_js_1 = require("bignumber.js");

@@ -47,6 +47,8 @@ var crypto_1 = require("crypto");

trace = extractor(event, context);
utils_1.logDebug("extracted trace context from the custom extractor", { trace: trace });
(0, utils_1.logDebug)("extracted trace context from the custom extractor", { trace: trace });
}
catch (error) {
utils_1.logError("custom extractor function failed", error);
if (error instanceof Error) {
(0, utils_1.logError)("custom extractor function failed", error);
}
}

@@ -66,3 +68,5 @@ }

catch (error) {
utils_1.logError("couldn't add step function metadata to xray", error);
if (error instanceof Error) {
(0, utils_1.logError)("couldn't add step function metadata to xray", error);
}
}

@@ -73,7 +77,9 @@ }

addTraceContextToXray(trace);
utils_1.logDebug("added trace context to xray metadata", { trace: trace });
(0, utils_1.logDebug)("added trace context to xray metadata", { trace: trace });
}
catch (error) {
// This might fail if running in an environment where xray isn't set up, (like for local development).
utils_1.logError("couldn't add trace context to xray metadata", error);
if (error instanceof Error) {
(0, utils_1.logError)("couldn't add trace context to xray metadata", error);
}
}

@@ -114,3 +120,3 @@ return trace;

if (header === undefined) {
utils_1.logDebug("couldn't read xray trace header from env");
(0, utils_1.logDebug)("couldn't read xray trace header from env");
return;

@@ -120,8 +126,9 @@ }

if (context === undefined) {
utils_1.logDebug("couldn't parse xray trace header from env");
(0, utils_1.logDebug)("couldn't parse xray trace header from env");
return;
}
var time = Date.now();
// Convert from milliseconds to seconds
var time = Date.now() * 0.001;
return JSON.stringify({
id: crypto_1.randomBytes(8).toString("hex"),
id: (0, crypto_1.randomBytes)(8).toString("hex"),
trace_id: context.xrayTraceID,

@@ -144,3 +151,3 @@ parent_id: context.xrayParentID,

if (xrayDaemonEnv === undefined) {
utils_1.logDebug("X-Ray daemon env var not set, not sending sub-segment");
(0, utils_1.logDebug)("X-Ray daemon env var not set, not sending sub-segment");
return;

@@ -150,3 +157,3 @@ }

if (parts.length <= 1) {
utils_1.logDebug("X-Ray daemon env var has invalid format, not sending sub-segment");
(0, utils_1.logDebug)("X-Ray daemon env var has invalid format, not sending sub-segment");
return;

@@ -159,15 +166,22 @@ }

try {
client = dgram_1.createSocket("udp4");
client = (0, dgram_1.createSocket)("udp4");
// Send segment asynchronously to xray daemon
client.send(message, 0, message.length, port, address, function (error, bytes) {
client === null || client === void 0 ? void 0 : client.close();
utils_1.logDebug("Xray daemon received metadata payload", { error: error, bytes: bytes });
(0, utils_1.logDebug)("Xray daemon received metadata payload", { error: error, bytes: bytes });
});
}
catch (error) {
client === null || client === void 0 ? void 0 : client.close();
utils_1.logDebug("Error occurred submitting to xray daemon", error);
if (error instanceof Error) {
client === null || client === void 0 ? void 0 : client.close();
(0, utils_1.logDebug)("Error occurred submitting to xray daemon", error);
}
}
}
exports.sendXraySubsegment = sendXraySubsegment;
function readTraceFromAppSyncEvent(event) {
event.headers = event.request.headers;
return readTraceFromHTTPEvent(event);
}
exports.readTraceFromAppSyncEvent = readTraceFromAppSyncEvent;
function readTraceFromSQSEvent(event) {

@@ -199,7 +213,9 @@ if (event.Records[0].messageAttributes &&

};
utils_1.logDebug("extracted trace context from sqs event", { trace: trace, event: event });
(0, utils_1.logDebug)("extracted trace context from sqs event", { trace: trace, event: event });
return trace;
}
catch (err) {
utils_1.logError("Error parsing SQS message trace data", err);
if (err instanceof Error) {
(0, utils_1.logError)("Error parsing SQS message trace data", err);
}
return;

@@ -255,3 +271,3 @@ }

};
utils_1.logDebug("extracted trace context from lambda context", { trace: trace, context: context });
(0, utils_1.logDebug)("extracted trace context from lambda context", { trace: trace, context: context });
return trace;

@@ -296,3 +312,3 @@ }

};
utils_1.logDebug("extracted trace context from http event", { trace: trace, event: event });
(0, utils_1.logDebug)("extracted trace context from http event", { trace: trace, event: event });
return trace;

@@ -308,3 +324,6 @@ }

}
if (event_type_guards_1.isSQSEvent(event)) {
if ((0, event_type_guards_1.isAppSyncResolverEvent)(event)) {
return readTraceFromAppSyncEvent(event);
}
if ((0, event_type_guards_1.isSQSEvent)(event)) {
return readTraceFromSQSEvent(event);

@@ -318,3 +337,3 @@ }

if (header === undefined) {
utils_1.logDebug("couldn't read xray trace header from env");
(0, utils_1.logDebug)("couldn't read xray trace header from env");
return;

@@ -324,3 +343,3 @@ }

if (context === undefined) {
utils_1.logError("couldn't read xray trace context from env, variable had invalid format");
(0, utils_1.logError)("couldn't read xray trace context from env, variable had invalid format");
return undefined;

@@ -330,3 +349,3 @@ }

if (parentID === undefined) {
utils_1.logDebug("couldn't parse xray parent ID", context);
(0, utils_1.logDebug)("couldn't parse xray parent ID", context);
return;

@@ -336,3 +355,3 @@ }

if (traceID === undefined) {
utils_1.logDebug("couldn't parse xray trace ID", context);
(0, utils_1.logDebug)("couldn't parse xray trace ID", context);
return;

@@ -347,3 +366,3 @@ }

};
utils_1.logDebug("extracted trace context from xray context", { trace: trace, header: header });
(0, utils_1.logDebug)("extracted trace context from xray context", { trace: trace, header: header });
return trace;

@@ -354,3 +373,3 @@ }

// Example: Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1
utils_1.logDebug("Reading trace context from env var " + header);
(0, utils_1.logDebug)("Reading trace context from env var " + header);
var _a = __read(header.split(";"), 3), root = _a[0], parent = _a[1], sampled = _a[2];

@@ -357,0 +376,0 @@ if (parent === undefined || sampled === undefined) {

@@ -85,20 +85,20 @@ "use strict";

if (this.config.injectLogContext) {
patch_console_1.patchConsole(console, this.contextService);
utils_1.logDebug("Patched console output with trace context");
(0, patch_console_1.patchConsole)(console, this.contextService);
(0, utils_1.logDebug)("Patched console output with trace context");
}
else {
utils_1.logDebug("Didn't patch console output with trace context");
(0, utils_1.logDebug)("Didn't patch console output with trace context");
}
// If the DD tracer is initialized then it's doing http patching so we don't again here
if (this.config.autoPatchHTTP && !tracerInitialized) {
utils_1.logDebug("Patching HTTP libraries");
patch_http_1.patchHttp(this.contextService);
(0, utils_1.logDebug)("Patching HTTP libraries");
(0, patch_http_1.patchHttp)(this.contextService);
}
else {
utils_1.logDebug("Not patching HTTP libraries", { autoPatchHTTP: this.config.autoPatchHTTP, tracerInitialized: tracerInitialized });
(0, utils_1.logDebug)("Not patching HTTP libraries", { autoPatchHTTP: this.config.autoPatchHTTP, tracerInitialized: tracerInitialized });
}
this.context = context;
this.triggerTags = trigger_1.extractTriggerTags(event, context);
this.contextService.rootTraceContext = context_1.extractTraceContext(event, context, this.config.traceExtractor);
this.stepFunctionContext = context_1.readStepFunctionContextFromEvent(event);
this.triggerTags = (0, trigger_1.extractTriggerTags)(event, context);
this.contextService.rootTraceContext = (0, context_1.extractTraceContext)(event, context, this.config.traceExtractor);
this.stepFunctionContext = (0, context_1.readStepFunctionContextFromEvent)(event);
};

@@ -112,8 +112,8 @@ TraceListener.prototype.onCompleteInvocation = function () {

if (this.triggerTags) {
context_1.addLambdaFunctionTagsToXray(this.triggerTags);
(0, context_1.addLambdaFunctionTagsToXray)(this.triggerTags);
}
tracerInitialized = this.tracerWrapper.isTracerAvailable;
if (this.config.autoPatchHTTP && !tracerInitialized) {
utils_1.logDebug("Unpatching HTTP libraries");
patch_http_1.unpatchHttp();
(0, utils_1.logDebug)("Unpatching HTTP libraries");
(0, patch_http_1.unpatchHttp)();
}

@@ -132,6 +132,6 @@ return [2 /*return*/];

parentSpanContext = this.tracerWrapper.extract(rootTraceHeaders);
utils_1.logDebug("Attempting to find parent for the aws.lambda span");
(0, utils_1.logDebug)("Attempting to find parent for the aws.lambda span");
}
else {
utils_1.logDebug("Didn't attempt to find parent for aws.lambda span", {
(0, utils_1.logDebug)("Didn't attempt to find parent for aws.lambda span", {
mergeDatadogXrayTraces: this.config.mergeDatadogXrayTraces,

@@ -143,7 +143,7 @@ traceSource: this.contextService.traceSource,

if (this.context) {
utils_1.logDebug("Creating the aws.lambda span");
(0, utils_1.logDebug)("Creating the aws.lambda span");
var functionArn = ((_a = this.context.invokedFunctionArn) !== null && _a !== void 0 ? _a : "").toLowerCase();
var tk = functionArn.split(":");
options.tags = {
cold_start: cold_start_1.didFunctionColdStart(),
cold_start: (0, cold_start_1.didFunctionColdStart)(),
function_arn: tk.length > 7 ? tk.slice(0, 7).join(":") : functionArn,

@@ -166,3 +166,3 @@ function_version: tk.length > 7 ? tk[7] : "$LATEST",

if (this.stepFunctionContext) {
utils_1.logDebug("Applying step function context to the aws.lambda span");
(0, utils_1.logDebug)("Applying step function context to the aws.lambda span");
options.tags = __assign(__assign({}, options.tags), this.stepFunctionContext);

@@ -169,0 +169,0 @@ }

@@ -69,4 +69,4 @@ "use strict";

var prefix = "";
var oldLogLevel = log_1.getLogLevel();
log_1.setLogLevel(log_1.LogLevel.NONE);
var oldLogLevel = (0, log_1.getLogLevel)();
(0, log_1.setLogLevel)(log_1.LogLevel.NONE);
try {

@@ -85,3 +85,3 @@ var context = contextService.currentTraceContext;

if (typeof logContent !== "string") {
logContent = util_1.inspect(logContent);
logContent = (0, util_1.inspect)(logContent);
}

@@ -95,3 +95,3 @@ arguments[0] = prefix + " " + logContent;

}
log_1.setLogLevel(oldLogLevel);
(0, log_1.setLogLevel)(oldLogLevel);
isLogging = false;

@@ -98,0 +98,0 @@ return original.apply(this, arguments);

@@ -33,3 +33,3 @@ "use strict";

if (datadogContext) {
utils_1.logDebug("set trace context from dd-trace with parent " + datadogContext.parentID);
(0, utils_1.logDebug)("set trace context from dd-trace with parent " + datadogContext.parentID);
return datadogContext;

@@ -36,0 +36,0 @@ }

@@ -18,6 +18,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -36,3 +40,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

// and one in the user's code.
var path = require.resolve("dd-trace", { paths: __spreadArray(["/var/task/node_modules"], __read(module.paths)) });
var path = require.resolve("dd-trace", { paths: __spreadArray(["/var/task/node_modules"], __read(module.paths), false) });
this.tracer = require(path);

@@ -42,3 +46,5 @@ return;

catch (err) {
utils_1.logDebug("Couldn't require dd-trace from main", err);
if (err instanceof Object || err instanceof Error) {
(0, utils_1.logDebug)("Couldn't require dd-trace from main", err);
}
}

@@ -45,0 +51,0 @@ }

@@ -59,3 +59,3 @@ "use strict";

var buffer = Buffer.from(event.awslogs.data, "base64");
var decompressed = zlib_1.gunzipSync(buffer).toString();
var decompressed = (0, zlib_1.gunzipSync)(buffer).toString();
return JSON.parse(decompressed);

@@ -231,3 +231,3 @@ }

catch (error) {
utils_1.logError("failed to extract " + eventSource + " arn from the event", { error: error });
(0, utils_1.logError)("failed to extract " + eventSource + " arn from the event", { error: error });
}

@@ -243,3 +243,3 @@ if (eventSourceARN) {

catch (error) {
utils_1.logError("failed to extract http tags from " + eventSource + " event");
(0, utils_1.logError)("failed to extract http tags from " + eventSource + " event");
}

@@ -246,0 +246,0 @@ }

@@ -1,2 +0,2 @@

import { APIGatewayEvent, APIGatewayProxyEventV2, ALBEvent, CloudWatchLogsEvent, ScheduledEvent, CloudFrontRequestEvent, DynamoDBStreamEvent, KinesisStreamEvent, S3Event, SNSEvent, SQSEvent } from "aws-lambda";
import { APIGatewayEvent, APIGatewayProxyEventV2, AppSyncResolverEvent, ALBEvent, CloudWatchLogsEvent, ScheduledEvent, CloudFrontRequestEvent, DynamoDBStreamEvent, KinesisStreamEvent, S3Event, SNSEvent, SQSEvent } from "aws-lambda";
export declare function isAPIGatewayEvent(event: any): event is APIGatewayEvent;

@@ -13,2 +13,3 @@ export declare function isAPIGatewayEventV2(event: any): event is APIGatewayProxyEventV2;

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

@@ -50,2 +50,6 @@ function isAPIGatewayEvent(event) {

exports.isSQSEvent = isSQSEvent;
function isAppSyncResolverEvent(event) {
return event.info !== undefined && event.info.selectionSetGraphQL !== undefined;
}
exports.isAppSyncResolverEvent = isAppSyncResolverEvent;
//# sourceMappingURL=event-type-guards.js.map

@@ -59,4 +59,6 @@ "use strict";

error_1 = _a.sent();
// Swallow the error and continue processing.
log_1.logError("Pre-lambda hook threw error", error_1);
if (error_1 instanceof Error) {
// Swallow the error and continue processing.
(0, log_1.logError)("Pre-lambda hook threw error", error_1);
}
return [3 /*break*/, 3];

@@ -71,3 +73,5 @@ case 3:

catch (error) {
log_1.logError("Failed to apply wrap to handler function", error);
if (error instanceof Error) {
(0, log_1.logError)("Failed to apply wrap to handler function", error);
}
}

@@ -83,3 +87,5 @@ _a.label = 4;

error_2 = _a.sent();
handlerError = error_2;
if (error_2 instanceof Error) {
handlerError = error_2;
}
throw error_2;

@@ -100,4 +106,6 @@ case 7:

error_3 = _a.sent();
// Swallow the error and continue processing.
log_1.logError("Post-lambda hook threw error", error_3);
if (error_3 instanceof Error) {
// Swallow the error and continue processing.
(0, log_1.logError)("Post-lambda hook threw error", error_3);
}
return [3 /*break*/, 13];

@@ -104,0 +112,0 @@ case 13: return [7 /*endfinally*/];

@@ -62,3 +62,3 @@ "use strict";

if (error !== undefined) {
var errorInfo = serialize_error_1.serializeError(error);
var errorInfo = (0, serialize_error_1.serializeError)(error);
output = __assign(__assign({}, output), errorInfo);

@@ -65,0 +65,0 @@ }

@@ -24,3 +24,3 @@ "use strict";

var buffer = Buffer.from(bodyJSON);
log_1.logDebug("sending payload with body " + bodyJSON);
(0, log_1.logDebug)("sending payload with body " + bodyJSON);
var requestOptions = __assign({ headers: { "content-type": "application/json" }, host: url.host, hostname: url.hostname, method: "POST", path: "" + url.pathname + url.search, port: url.port, protocol: url.protocol }, options);

@@ -27,0 +27,0 @@ return sendRequest(url, requestOptions, buffer);

{
"name": "datadog-lambda-js",
"version": "4.64.0",
"version": "4.65.0",
"description": "Lambda client library that supports hybrid tracing in node js",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -100,3 +100,3 @@ # datadog-lambda-js

If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), you must set `DD_SITE`. Possible values are `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com` and `ddog-gov.com`. The default is `datadoghq.com`.
If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), you must set `DD_SITE`. Possible values are `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com`, `us5.datadoghq.com`, and `ddog-gov.com`. The default is `datadoghq.com`.

@@ -103,0 +103,0 @@ ### DD_LOG_LEVEL

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

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

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