datadog-lambda-js
Advanced tools
Comparing version 3.43.0 to 3.44.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.datadogLambdaVersion = void 0; | ||
exports.datadogLambdaVersion = "3.43.0"; | ||
exports.datadogLambdaVersion = "3.44.0"; | ||
//# sourceMappingURL=constants.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
var index_1 = require("./index"); | ||
var utils_1 = require("./utils"); | ||
// We reuse the function loading logic already inside the lambda runtime. | ||
@@ -22,3 +23,13 @@ // tslint:disable-next-line:no-var-requires | ||
var handlerEnv = index_1.getEnvValue(index_1.datadogHandlerEnvVar, ""); | ||
exports.handler = index_1.datadog(load(taskRootEnv, handlerEnv)); | ||
var extractorEnv = index_1.getEnvValue(index_1.traceExtractorEnvVar, ""); | ||
var traceExtractor; | ||
if (extractorEnv) { | ||
try { | ||
traceExtractor = load(taskRootEnv, extractorEnv); | ||
} | ||
catch (error) { | ||
utils_1.logError("an error occured while loading the extractor", error); | ||
} | ||
} | ||
exports.handler = index_1.datadog(load(taskRootEnv, handlerEnv), { traceExtractor: traceExtractor }); | ||
//# sourceMappingURL=handler.js.map |
@@ -16,2 +16,3 @@ import { Handler } from "aws-lambda"; | ||
export declare const mergeXrayTracesEnvVar = "DD_MERGE_XRAY_TRACES"; | ||
export declare const traceExtractorEnvVar = "DD_TRACE_EXTRACTOR"; | ||
export declare const defaultSiteURL = "datadoghq.com"; | ||
@@ -18,0 +19,0 @@ interface GlobalConfig { |
@@ -70,3 +70,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEnvValue = exports.getTraceHeaders = exports.sendDistributionMetric = exports.sendDistributionMetricWithDate = exports.datadog = exports.defaultConfig = exports.defaultSiteURL = exports.mergeXrayTracesEnvVar = exports.lambdaTaskRootEnvVar = exports.datadogHandlerEnvVar = exports.enhancedMetricsEnvVar = exports.logInjectionEnvVar = exports.logForwardingEnvVar = exports.logLevelEnvVar = exports.siteURLEnvVar = exports.apiKeyKMSEnvVar = exports.apiKeyEnvVar = void 0; | ||
exports.getEnvValue = exports.getTraceHeaders = exports.sendDistributionMetric = exports.sendDistributionMetricWithDate = exports.datadog = exports.defaultConfig = exports.defaultSiteURL = exports.traceExtractorEnvVar = exports.mergeXrayTracesEnvVar = exports.lambdaTaskRootEnvVar = exports.datadogHandlerEnvVar = exports.enhancedMetricsEnvVar = exports.logInjectionEnvVar = exports.logForwardingEnvVar = exports.logLevelEnvVar = exports.siteURLEnvVar = exports.apiKeyKMSEnvVar = exports.apiKeyEnvVar = void 0; | ||
var metrics_1 = require("./metrics"); | ||
@@ -85,2 +85,3 @@ var trace_1 = require("./trace"); | ||
exports.mergeXrayTracesEnvVar = "DD_MERGE_XRAY_TRACES"; | ||
exports.traceExtractorEnvVar = "DD_TRACE_EXTRACTOR"; | ||
exports.defaultSiteURL = "datadoghq.com"; | ||
@@ -87,0 +88,0 @@ exports.defaultConfig = { |
@@ -26,3 +26,3 @@ "use strict"; | ||
exports.awsXrayDaemonAddressEnvVar = "AWS_XRAY_DAEMON_ADDRESS"; | ||
exports.ddtraceVersion = "0.29.2"; | ||
exports.ddtraceVersion = "0.30.5"; | ||
//# sourceMappingURL=constants.js.map |
@@ -0,3 +1,5 @@ | ||
import { Context } from "aws-lambda"; | ||
import { SQSEvent } from "aws-lambda"; | ||
import { SampleMode, Source } from "./constants"; | ||
import { TraceExtractor } from "./listener"; | ||
export interface XRayTraceHeader { | ||
@@ -25,3 +27,3 @@ traceID: string; | ||
*/ | ||
export declare function extractTraceContext(event: any): TraceContext | undefined; | ||
export declare function extractTraceContext(event: any, context: Context, extractor?: TraceExtractor): TraceContext | undefined; | ||
export declare function addTraceContextToXray(traceContext: TraceContext): void; | ||
@@ -33,2 +35,3 @@ export declare function addStepFunctionContextToXray(context: StepFunctionContext): void; | ||
export declare function readTraceFromSQSEvent(event: SQSEvent): TraceContext | undefined; | ||
export declare function readTraceFromLambdaContext(context: any): TraceContext | undefined; | ||
export declare function readTraceFromHTTPEvent(event: any): TraceContext | undefined; | ||
@@ -35,0 +38,0 @@ export declare function readTraceFromEvent(event: 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.readTraceFromSQSEvent = exports.sendXraySubsegment = exports.generateXraySubsegment = exports.addXrayMetadata = 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.sendXraySubsegment = exports.generateXraySubsegment = exports.addXrayMetadata = exports.addStepFunctionContextToXray = exports.addTraceContextToXray = exports.extractTraceContext = void 0; | ||
var bignumber_js_1 = require("bignumber.js"); | ||
@@ -44,4 +44,18 @@ var crypto_1 = require("crypto"); | ||
*/ | ||
function extractTraceContext(event) { | ||
var trace = readTraceFromEvent(event); | ||
function extractTraceContext(event, context, extractor) { | ||
var trace; | ||
if (extractor) { | ||
try { | ||
trace = extractor(event, context); | ||
} | ||
catch (error) { | ||
utils_1.logError("extractor function failed", { error: error }); | ||
} | ||
} | ||
if (!trace) { | ||
trace = readTraceFromEvent(event); | ||
} | ||
if (!trace) { | ||
trace = readTraceFromLambdaContext(context); | ||
} | ||
var stepFuncContext = readStepFunctionContextFromEvent(event); | ||
@@ -183,2 +197,32 @@ if (stepFuncContext) { | ||
exports.readTraceFromSQSEvent = readTraceFromSQSEvent; | ||
function readTraceFromLambdaContext(context) { | ||
var _a, _b; | ||
if (!context || typeof context !== "object") { | ||
return; | ||
} | ||
var traceData = (_b = (_a = context.clientContext) === null || _a === void 0 ? void 0 : _a.custom) === null || _b === void 0 ? void 0 : _b._datadog; | ||
if (!traceData || typeof traceData !== "object") { | ||
return; | ||
} | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
if (typeof traceID !== "string") { | ||
return; | ||
} | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
if (typeof parentID !== "string") { | ||
return; | ||
} | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
return { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
} | ||
exports.readTraceFromLambdaContext = readTraceFromLambdaContext; | ||
function readTraceFromHTTPEvent(event) { | ||
@@ -185,0 +229,0 @@ var e_1, _a; |
@@ -1,3 +0,3 @@ | ||
export { TraceConfig, TraceListener } from "./listener"; | ||
export { TraceConfig, TraceListener, TraceExtractor } from "./listener"; | ||
export { TraceHeaders } from "./trace-context-service"; | ||
//# sourceMappingURL=index.d.ts.map |
import { Context } from "aws-lambda"; | ||
import { TraceContext } from "./context"; | ||
export declare type TraceExtractor = (event: any, context: Context) => TraceContext; | ||
export interface TraceConfig { | ||
@@ -17,2 +19,6 @@ /** | ||
mergeDatadogXrayTraces: boolean; | ||
/** | ||
* Custom trace extractor function | ||
*/ | ||
traceExtractor?: TraceExtractor; | ||
} | ||
@@ -19,0 +25,0 @@ export declare class TraceListener { |
@@ -92,3 +92,3 @@ "use strict"; | ||
this.context = context; | ||
this.contextService.rootTraceContext = context_1.extractTraceContext(event); | ||
this.contextService.rootTraceContext = context_1.extractTraceContext(event, context, this.config.traceExtractor); | ||
this.stepFunctionContext = context_1.readStepFunctionContextFromEvent(event); | ||
@@ -95,0 +95,0 @@ }; |
{ | ||
"name": "datadog-lambda-js", | ||
"version": "3.43.0", | ||
"version": "3.44.0", | ||
"description": "Lambda client library that supports hybrid tracing in node js", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.70", | ||
"@types/aws-lambda": "^8.10.71", | ||
"@types/aws-sdk": "^2.7.0", | ||
@@ -26,9 +26,9 @@ "@types/jest": "^26.0.20", | ||
"@types/nock": "^11.1.0", | ||
"@types/node": "^14.14.20", | ||
"@types/node": "^14.14.22", | ||
"@types/promise-retry": "^1.1.3", | ||
"@types/shimmer": "^1.0.1", | ||
"dd-trace": "0.29.2", | ||
"dd-trace": "0.30.5", | ||
"jest": "^26.6.3", | ||
"mock-fs": "4.13.0", | ||
"nock": "13.0.5", | ||
"nock": "13.0.6", | ||
"prettier": "^2.2.1", | ||
@@ -44,3 +44,3 @@ "ts-jest": "^26.4.4", | ||
"promise-retry": "^2.0.1", | ||
"serialize-error": "^8.0.0", | ||
"serialize-error": "^8.0.1", | ||
"shimmer": "^1.2.1" | ||
@@ -47,0 +47,0 @@ }, |
@@ -82,3 +82,3 @@ # datadog-lambda-js | ||
If `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`. | ||
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`. | ||
@@ -85,0 +85,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
240059
3377
Updatedserialize-error@^8.0.1