datadog-lambda-js
Advanced tools
Comparing version 6.84.0 to 6.85.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.datadogLambdaVersion = void 0; | ||
exports.datadogLambdaVersion = "6.84.0"; | ||
exports.datadogLambdaVersion = "6.85.0"; | ||
//# sourceMappingURL=constants.js.map |
@@ -20,2 +20,4 @@ import { Handler } from "aws-lambda"; | ||
export declare const defaultSiteURL = "datadoghq.com"; | ||
export declare const encodeAuthorizerContextEnvVar = "DD_ENCODE_AUTHORIZER_CONTEXT"; | ||
export declare const decodeAuthorizerContextEnvVar = "DD_DECODE_AUTHORIZER_CONTEXT"; | ||
interface GlobalConfig { | ||
@@ -22,0 +24,0 @@ /** |
@@ -75,3 +75,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.traceManagedServicesEnvVar = exports.captureLambdaPayloadEnvVar = exports.apiKeyKMSEnvVar = exports.apiKeyEnvVar = void 0; | ||
exports.getEnvValue = exports.getTraceHeaders = exports.sendDistributionMetric = exports.sendDistributionMetricWithDate = exports.datadog = exports.defaultConfig = exports.decodeAuthorizerContextEnvVar = exports.encodeAuthorizerContextEnvVar = exports.defaultSiteURL = exports.traceExtractorEnvVar = exports.mergeXrayTracesEnvVar = exports.lambdaTaskRootEnvVar = exports.datadogHandlerEnvVar = exports.enhancedMetricsEnvVar = exports.logInjectionEnvVar = exports.logForwardingEnvVar = exports.logLevelEnvVar = exports.siteURLEnvVar = exports.traceManagedServicesEnvVar = exports.captureLambdaPayloadEnvVar = exports.apiKeyKMSEnvVar = exports.apiKeyEnvVar = void 0; | ||
var metrics_1 = require("./metrics"); | ||
@@ -94,2 +94,4 @@ var trace_1 = require("./trace"); | ||
exports.defaultSiteURL = "datadoghq.com"; | ||
exports.encodeAuthorizerContextEnvVar = "DD_ENCODE_AUTHORIZER_CONTEXT"; | ||
exports.decodeAuthorizerContextEnvVar = "DD_DECODE_AUTHORIZER_CONTEXT"; | ||
exports.defaultConfig = { | ||
@@ -102,2 +104,4 @@ apiKey: "", | ||
debugLogging: false, | ||
encodeAuthorizerContext: true, | ||
decodeAuthorizerContext: true, | ||
enhancedMetrics: true, | ||
@@ -209,3 +213,3 @@ forceWrap: false, | ||
_a.sent(); | ||
return [4 /*yield*/, traceListener.onCompleteInvocation(error)]; | ||
return [4 /*yield*/, traceListener.onCompleteInvocation(error, result, event)]; | ||
case 11: | ||
@@ -330,2 +334,10 @@ _a.sent(); | ||
} | ||
if (userConfig === undefined || userConfig.encodeAuthorizerContext === undefined) { | ||
var result = getEnvValue(exports.encodeAuthorizerContextEnvVar, "true").toLowerCase(); | ||
config.encodeAuthorizerContext = result === "true"; | ||
} | ||
if (userConfig === undefined || userConfig.decodeAuthorizerContext === undefined) { | ||
var result = getEnvValue(exports.decodeAuthorizerContextEnvVar, "true").toLowerCase(); | ||
config.decodeAuthorizerContext = result === "true"; | ||
} | ||
return config; | ||
@@ -332,0 +344,0 @@ } |
@@ -40,2 +40,3 @@ "use strict"; | ||
RuntimeTagValues["Node16"] = "nodejs16.x"; | ||
RuntimeTagValues["Node18"] = "nodejs18.x"; | ||
})(RuntimeTagValues || (RuntimeTagValues = {})); | ||
@@ -63,2 +64,5 @@ function getVersionTag() { | ||
} | ||
if (processVersion.startsWith("v18")) { | ||
processVersionTagString = RuntimeTagValues.Node18; | ||
} | ||
if (!processVersionTagString) { | ||
@@ -65,0 +69,0 @@ return null; |
@@ -24,2 +24,4 @@ export declare enum SampleMode { | ||
export declare const apiGatewayEventV2 = "2.0"; | ||
export declare const parentSpanFinishTimeHeader = "x-datadog-parent-span-finish-time"; | ||
export declare const authorizingRequestIdHeader = "x-datadog-authorizing-requestid"; | ||
//# sourceMappingURL=constants.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.apiGatewayEventV2 = exports.ddtraceVersion = exports.awsXrayDaemonAddressEnvVar = exports.xrayTraceEnvVar = exports.xraySubsegmentNamespace = exports.xrayLambdaFunctionTagsKey = exports.xrayBaggageSubsegmentKey = exports.xraySubsegmentKey = exports.xraySubsegmentName = exports.samplingPriorityHeader = exports.parentIDHeader = exports.traceIDHeader = exports.Source = exports.SampleMode = void 0; | ||
exports.authorizingRequestIdHeader = exports.parentSpanFinishTimeHeader = exports.apiGatewayEventV2 = exports.ddtraceVersion = exports.awsXrayDaemonAddressEnvVar = exports.xrayTraceEnvVar = exports.xraySubsegmentNamespace = exports.xrayLambdaFunctionTagsKey = exports.xrayBaggageSubsegmentKey = exports.xraySubsegmentKey = exports.xraySubsegmentName = exports.samplingPriorityHeader = exports.parentIDHeader = exports.traceIDHeader = exports.Source = exports.SampleMode = void 0; | ||
var SampleMode; | ||
@@ -29,2 +29,4 @@ (function (SampleMode) { | ||
exports.apiGatewayEventV2 = "2.0"; | ||
exports.parentSpanFinishTimeHeader = "x-datadog-parent-span-finish-time"; | ||
exports.authorizingRequestIdHeader = "x-datadog-authorizing-requestid"; | ||
//# sourceMappingURL=constants.js.map |
import { Context, EventBridgeEvent, KinesisStreamEvent, SNSEvent, SQSEvent } from "aws-lambda"; | ||
import { SampleMode, Source } from "./constants"; | ||
import { TraceExtractor } from "./listener"; | ||
import { eventSubTypes } from "./trigger"; | ||
export interface XRayTraceHeader { | ||
@@ -26,3 +27,3 @@ traceID: string; | ||
*/ | ||
export declare function extractTraceContext(event: any, context: Context, extractor?: TraceExtractor): TraceContext | undefined; | ||
export declare function extractTraceContext(event: any, context: Context, extractor?: TraceExtractor, decodeAuthorizerContext?: boolean): TraceContext | undefined; | ||
export declare function addTraceContextToXray(traceContext: TraceContext): void; | ||
@@ -43,4 +44,5 @@ export declare function addStepFunctionContextToXray(context: StepFunctionContext): void; | ||
export declare function readTraceFromLambdaContext(context: any): TraceContext | undefined; | ||
export declare function readTraceFromHTTPEvent(event: any): TraceContext | undefined; | ||
export declare function readTraceFromEvent(event: any): TraceContext | undefined; | ||
export declare function getInjectedAuthorizerData(event: any, eventSourceSubType: eventSubTypes): any; | ||
export declare function readTraceFromHTTPEvent(event: any, decodeAuthorizerContext?: boolean): TraceContext | undefined; | ||
export declare function readTraceFromEvent(event: any, decodeAuthorizerContext?: boolean): TraceContext | undefined; | ||
export declare function readTraceContextFromXray(): TraceContext | undefined; | ||
@@ -47,0 +49,0 @@ export declare function readStepFunctionContextFromEvent(event: any): StepFunctionContext | undefined; |
@@ -30,3 +30,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertToAPMParentID = exports.convertToAPMTraceID = exports.convertToSampleMode = exports.readStepFunctionContextFromEvent = exports.readTraceContextFromXray = exports.readTraceFromEvent = exports.readTraceFromHTTPEvent = exports.readTraceFromLambdaContext = exports.readTraceFromSNSEvent = exports.readTraceFromEventbridgeEvent = exports.readTraceFromKinesisEvent = exports.readTraceFromSNSSQSEvent = exports.readTraceFromSQSEvent = exports.readTraceFromAppSyncEvent = exports.sendXraySubsegment = exports.generateXraySubsegment = exports.addXrayMetadata = exports.addLambdaFunctionTagsToXray = exports.addStepFunctionContextToXray = exports.addTraceContextToXray = exports.extractTraceContext = void 0; | ||
exports.convertToAPMParentID = exports.convertToAPMTraceID = exports.convertToSampleMode = exports.readStepFunctionContextFromEvent = exports.readTraceContextFromXray = exports.readTraceFromEvent = exports.readTraceFromHTTPEvent = exports.getInjectedAuthorizerData = exports.readTraceFromLambdaContext = exports.readTraceFromSNSEvent = exports.readTraceFromEventbridgeEvent = exports.readTraceFromKinesisEvent = exports.readTraceFromSNSSQSEvent = 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"); | ||
@@ -38,2 +38,4 @@ var crypto_1 = require("crypto"); | ||
var constants_1 = require("./constants"); | ||
var trigger_1 = require("./trigger"); | ||
var constants_2 = require("./constants"); | ||
/** | ||
@@ -43,3 +45,4 @@ * Reads the trace context from either an incoming lambda event, or the current xray segment. | ||
*/ | ||
function extractTraceContext(event, context, extractor) { | ||
function extractTraceContext(event, context, extractor, decodeAuthorizerContext) { | ||
if (decodeAuthorizerContext === void 0) { decodeAuthorizerContext = true; } | ||
var trace; | ||
@@ -58,3 +61,3 @@ if (extractor) { | ||
if (!trace) { | ||
trace = readTraceFromEvent(event); | ||
trace = readTraceFromEvent(event, decodeAuthorizerContext); | ||
} | ||
@@ -184,3 +187,3 @@ if (!trace) { | ||
event.headers = event.request.headers; | ||
return readTraceFromHTTPEvent(event); | ||
return readTraceFromHTTPEvent(event, false); | ||
} | ||
@@ -193,16 +196,3 @@ exports.readTraceFromAppSyncEvent = readTraceFromAppSyncEvent; | ||
try { | ||
var traceData = JSON.parse(traceHeaders); | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof traceID !== "string" || typeof parentID !== "string" || typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(JSON.parse(traceHeaders)); | ||
(0, utils_1.logDebug)("extracted trace context from sqs event", { trace: trace, event: event }); | ||
@@ -237,15 +227,3 @@ return trace; | ||
} | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof traceID !== "string" || typeof parentID !== "string" || typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(traceData); | ||
(0, utils_1.logDebug)("extracted trace context from SNS SQS event", { trace: trace, event: event }); | ||
@@ -270,16 +248,3 @@ return trace; | ||
if (parsedBody && parsedBody._datadog) { | ||
var traceData = parsedBody._datadog; | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof traceID !== "string" || typeof parentID !== "string" || typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(parsedBody._datadog); | ||
(0, utils_1.logDebug)("extracted trace context from Kinesis event", { trace: trace }); | ||
@@ -302,16 +267,3 @@ return trace; | ||
try { | ||
var traceData = event.detail._datadog; | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof traceID !== "string" || typeof parentID !== "string" || typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(event.detail._datadog); | ||
(0, utils_1.logDebug)("extracted trace context from Eventbridge event", { trace: trace, event: event }); | ||
@@ -341,15 +293,3 @@ return trace; | ||
} | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof traceID !== "string" || typeof parentID !== "string" || typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(traceData); | ||
(0, utils_1.logDebug)("extracted trace context from SNS event", { trace: trace, event: event }); | ||
@@ -392,21 +332,3 @@ return trace; | ||
} | ||
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); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(traceData); | ||
(0, utils_1.logDebug)("extracted trace context from lambda context", { trace: trace, context: context }); | ||
@@ -416,4 +338,37 @@ return trace; | ||
exports.readTraceFromLambdaContext = readTraceFromLambdaContext; | ||
function readTraceFromHTTPEvent(event) { | ||
function getInjectedAuthorizerData(event, eventSourceSubType) { | ||
var _a; | ||
var authorizerHeaders = (_a = event === null || event === void 0 ? void 0 : event.requestContext) === null || _a === void 0 ? void 0 : _a.authorizer; | ||
if (!authorizerHeaders) | ||
return null; | ||
var rawDatadogData = eventSourceSubType === trigger_1.eventSubTypes.apiGatewayV2 ? authorizerHeaders.lambda._datadog : authorizerHeaders._datadog; | ||
if (!rawDatadogData) | ||
return null; | ||
var injectedData = JSON.parse(Buffer.from(rawDatadogData, "base64").toString()); | ||
// use the injected requestId to tell if it's the authorizing invocation (not cached) | ||
if (authorizerHeaders.integrationLatency > 0 || | ||
event.requestContext.requestId === injectedData[constants_2.authorizingRequestIdHeader]) { | ||
return injectedData; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
exports.getInjectedAuthorizerData = getInjectedAuthorizerData; | ||
function readTraceFromHTTPEvent(event, decodeAuthorizerContext) { | ||
var e_1, _a; | ||
if (decodeAuthorizerContext === void 0) { decodeAuthorizerContext = true; } | ||
if (decodeAuthorizerContext) { | ||
// need to set the trace context if using authorizer lambda in authorizing (non-cached) cases | ||
try { | ||
var eventSourceSubType = (0, trigger_1.parseEventSourceSubType)(event); | ||
var injectedAuthorizerData = getInjectedAuthorizerData(event, eventSourceSubType); | ||
if (injectedAuthorizerData !== null) { | ||
return exportTraceData(injectedAuthorizerData); | ||
} | ||
} | ||
catch (error) { | ||
(0, utils_1.logDebug)("unable to extract trace context from authorizer event.", { error: error }); | ||
} | ||
} | ||
var headers = event.headers; | ||
@@ -434,21 +389,3 @@ var lowerCaseHeaders = {}; | ||
} | ||
var traceID = lowerCaseHeaders[constants_1.traceIDHeader]; | ||
if (typeof traceID !== "string") { | ||
return; | ||
} | ||
var parentID = lowerCaseHeaders[constants_1.parentIDHeader]; | ||
if (typeof parentID !== "string") { | ||
return; | ||
} | ||
var sampledHeader = lowerCaseHeaders[constants_1.samplingPriorityHeader]; | ||
if (typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
var trace = { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
var trace = exportTraceData(lowerCaseHeaders); | ||
(0, utils_1.logDebug)("extracted trace context from http event", { trace: trace, event: event }); | ||
@@ -458,3 +395,4 @@ return trace; | ||
exports.readTraceFromHTTPEvent = readTraceFromHTTPEvent; | ||
function readTraceFromEvent(event) { | ||
function readTraceFromEvent(event, decodeAuthorizerContext) { | ||
if (decodeAuthorizerContext === void 0) { decodeAuthorizerContext = true; } | ||
if (!event || typeof event !== "object") { | ||
@@ -464,3 +402,3 @@ return; | ||
if (event.headers !== null && typeof event.headers === "object") { | ||
return readTraceFromHTTPEvent(event); | ||
return readTraceFromHTTPEvent(event, decodeAuthorizerContext); | ||
} | ||
@@ -624,2 +562,17 @@ if ((0, event_type_guards_1.isSNSEvent)(event)) { | ||
exports.convertToAPMParentID = convertToAPMParentID; | ||
function exportTraceData(traceData) { | ||
var traceID = traceData[constants_1.traceIDHeader]; | ||
var parentID = traceData[constants_1.parentIDHeader]; | ||
var sampledHeader = traceData[constants_1.samplingPriorityHeader]; | ||
if (typeof traceID !== "string" || typeof parentID !== "string" || typeof sampledHeader !== "string") { | ||
return; | ||
} | ||
var sampleMode = parseInt(sampledHeader, 10); | ||
return { | ||
parentID: parentID, | ||
sampleMode: sampleMode, | ||
source: constants_1.Source.Event, | ||
traceID: traceID, | ||
}; | ||
} | ||
//# sourceMappingURL=context.js.map |
@@ -19,2 +19,10 @@ import { Context } from "aws-lambda"; | ||
/** | ||
* Whether to encode trace context in authorizer metadata | ||
*/ | ||
encodeAuthorizerContext: boolean; | ||
/** | ||
* Whether to decode trace context in authorizer metadata | ||
*/ | ||
decodeAuthorizerContext: boolean; | ||
/** | ||
* Whether to automatically patch console.log with Datadog's tracing ids. | ||
@@ -58,5 +66,6 @@ */ | ||
onEndingInvocation(event: any, result: any, shouldTagPayload?: boolean): boolean; | ||
onCompleteInvocation(error?: any): Promise<void>; | ||
injectAuthorizerSpan(result: any, requestId: string, finishTime: number): any; | ||
onCompleteInvocation(error?: any, result?: any, event?: any): Promise<void>; | ||
onWrap<T = (...args: any[]) => any>(func: T): T; | ||
} | ||
//# sourceMappingURL=listener.d.ts.map |
@@ -95,3 +95,3 @@ "use strict"; | ||
} | ||
var rootTraceHeaders = this.contextService.extractHeadersFromContext(event, context, this.config.traceExtractor); | ||
var rootTraceHeaders = this.contextService.extractHeadersFromContext(event, context, this.config.traceExtractor, this.config.decodeAuthorizerContext); | ||
// The aws.lambda span needs to have a parented to the Datadog trace context from the | ||
@@ -111,3 +111,3 @@ // incoming event if available or the X-Ray trace context if hybrid tracing is enabled | ||
if (this.config.createInferredSpan) { | ||
this.inferredSpan = this.inferrer.createInferredSpan(event, context, parentSpanContext); | ||
this.inferredSpan = this.inferrer.createInferredSpan(event, context, parentSpanContext, this.config.encodeAuthorizerContext); | ||
} | ||
@@ -157,7 +157,20 @@ this.lambdaSpanParentContext = ((_b = this.inferredSpan) === null || _b === void 0 ? void 0 : _b.span) || parentSpanContext; | ||
}; | ||
TraceListener.prototype.onCompleteInvocation = function (error) { | ||
TraceListener.prototype.injectAuthorizerSpan = function (result, requestId, finishTime) { | ||
var _a; | ||
var _b, _c; | ||
if (!result.context) { | ||
result.context = {}; | ||
} | ||
var injectedHeaders = __assign(__assign({}, this.tracerWrapper.injectSpan(((_b = this.inferredSpan) === null || _b === void 0 ? void 0 : _b.span) || ((_c = this.wrappedCurrentSpan) === null || _c === void 0 ? void 0 : _c.span))), (_a = {}, _a[constants_2.parentSpanFinishTimeHeader] = finishTime * 1e6, _a)); | ||
if (requestId) { | ||
// undefined in token-type authorizer | ||
injectedHeaders[constants_2.authorizingRequestIdHeader] = requestId; | ||
} | ||
result.context._datadog = Buffer.from(JSON.stringify(injectedHeaders)).toString("base64"); | ||
}; | ||
TraceListener.prototype.onCompleteInvocation = function (error, result, event) { | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tracerInitialized, finishTime; | ||
return __generator(this, function (_b) { | ||
return __generator(this, function (_d) { | ||
// Create a new dummy Datadog subsegment for function trigger tags so we | ||
@@ -173,2 +186,3 @@ // can attach them to X-Ray spans when hybrid tracing is used | ||
} | ||
finishTime = (_a = this.wrappedCurrentSpan) === null || _a === void 0 ? void 0 : _a.endTime(); | ||
if (this.inferredSpan) { | ||
@@ -180,5 +194,14 @@ (0, utils_1.logDebug)("Finishing inferred span"); | ||
} | ||
finishTime = this.inferredSpan.isAsync() ? (_a = this.wrappedCurrentSpan) === null || _a === void 0 ? void 0 : _a.startTime() : Date.now(); | ||
if (this.inferredSpan.isAsync()) { | ||
finishTime = ((_b = this.wrappedCurrentSpan) === null || _b === void 0 ? void 0 : _b.startTime()) || Date.now(); | ||
} | ||
else { | ||
finishTime = Date.now(); | ||
} | ||
this.inferredSpan.finish(finishTime); | ||
} | ||
if (this.config.encodeAuthorizerContext && (result === null || result === void 0 ? void 0 : result.principalId) && (result === null || result === void 0 ? void 0 : result.policyDocument)) { | ||
// We're in an authorizer, pass on the trace context, requestId and finishTime to make the authorizer span | ||
this.injectAuthorizerSpan(result, (_c = event === null || event === void 0 ? void 0 : event.requestContext) === null || _c === void 0 ? void 0 : _c.requestId, finishTime || Date.now()); | ||
} | ||
return [2 /*return*/]; | ||
@@ -185,0 +208,0 @@ }); |
@@ -148,3 +148,3 @@ "use strict"; | ||
if (isIntegrationTest()) { | ||
_logHttpRequest(requestOpts); | ||
_logHttpRequest(requestOpts, traceHeaders); | ||
} | ||
@@ -165,6 +165,6 @@ return requestOpts; | ||
*/ | ||
function _logHttpRequest(options) { | ||
var headerMessage = "Headers: []"; | ||
if (options.headers) { | ||
var headerStrings = Object.entries(options.headers).map(function (_a) { | ||
function _logHttpRequest(options, traceHeaders) { | ||
var headerMessage = "TraceHeaders: []"; | ||
if (traceHeaders) { | ||
var headerStrings = Object.entries(traceHeaders).map(function (_a) { | ||
var _b = __read(_a, 2), name = _b[0], value = _b[1]; | ||
@@ -174,3 +174,3 @@ return "".concat(name, ":").concat(value); | ||
headerStrings.sort(); | ||
headerMessage = "Headers: ".concat(JSON.stringify(headerStrings)); | ||
headerMessage = "TraceHeaders: ".concat(JSON.stringify(headerStrings)); | ||
} | ||
@@ -177,0 +177,0 @@ var url = "".concat(options.protocol, "//").concat(options.host || options.hostname).concat(options.path); |
@@ -7,5 +7,5 @@ import { Context, SNSMessage } from "aws-lambda"; | ||
constructor(traceWrapper: TracerWrapper); | ||
createInferredSpan(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): any; | ||
createInferredSpan(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined, decodeAuthorizerContext?: boolean): any; | ||
isApiGatewayAsync(event: any): string; | ||
createInferredSpanForApiGateway(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForApiGateway(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined, decodeAuthorizerContext?: boolean): SpanWrapper; | ||
createInferredSpanForLambdaUrl(event: any, context: Context | undefined): any; | ||
@@ -12,0 +12,0 @@ createInferredSpanForDynamoDBStreamEvent(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
@@ -22,2 +33,5 @@ var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
var span_wrapper_1 = require("./span-wrapper"); | ||
var constants_1 = require("./constants"); | ||
var utils_1 = require("../utils"); | ||
var context_1 = require("./context"); | ||
var SpanInferrer = /** @class */ (function () { | ||
@@ -27,26 +41,27 @@ function SpanInferrer(traceWrapper) { | ||
} | ||
SpanInferrer.prototype.createInferredSpan = function (event, context, parentSpanContext) { | ||
SpanInferrer.prototype.createInferredSpan = function (event, context, parentSpanContext, decodeAuthorizerContext) { | ||
if (decodeAuthorizerContext === void 0) { decodeAuthorizerContext = true; } | ||
var eventSource = (0, trigger_1.parseEventSource)(event); | ||
if (eventSource === trigger_1.eventSources.lambdaUrl) { | ||
if (eventSource === trigger_1.eventTypes.lambdaUrl) { | ||
return this.createInferredSpanForLambdaUrl(event, context); | ||
} | ||
if (eventSource === trigger_1.eventSources.apiGateway) { | ||
return this.createInferredSpanForApiGateway(event, context, parentSpanContext); | ||
if (eventSource === trigger_1.eventTypes.apiGateway) { | ||
return this.createInferredSpanForApiGateway(event, context, parentSpanContext, decodeAuthorizerContext); | ||
} | ||
if (eventSource === trigger_1.eventSources.sns) { | ||
if (eventSource === trigger_1.eventTypes.sns) { | ||
return this.createInferredSpanForSns(event, context, parentSpanContext); | ||
} | ||
if (eventSource === trigger_1.eventSources.dynamoDB) { | ||
if (eventSource === trigger_1.eventTypes.dynamoDB) { | ||
return this.createInferredSpanForDynamoDBStreamEvent(event, context, parentSpanContext); | ||
} | ||
if (eventSource === trigger_1.eventSources.sqs) { | ||
if (eventSource === trigger_1.eventTypes.sqs) { | ||
return this.createInferredSpanForSqs(event, context, parentSpanContext); | ||
} | ||
if (eventSource === trigger_1.eventSources.kinesis) { | ||
if (eventSource === trigger_1.eventTypes.kinesis) { | ||
return this.createInferredSpanForKinesis(event, context, parentSpanContext); | ||
} | ||
if (eventSource === trigger_1.eventSources.s3) { | ||
if (eventSource === trigger_1.eventTypes.s3) { | ||
return this.createInferredSpanForS3(event, context, parentSpanContext); | ||
} | ||
if (eventSource === trigger_1.eventSources.eventBridge) { | ||
if (eventSource === trigger_1.eventTypes.eventBridge) { | ||
return this.createInferredSpanForEventBridge(event, context, parentSpanContext); | ||
@@ -61,3 +76,4 @@ } | ||
}; | ||
SpanInferrer.prototype.createInferredSpanForApiGateway = function (event, context, parentSpanContext) { | ||
SpanInferrer.prototype.createInferredSpanForApiGateway = function (event, context, parentSpanContext, decodeAuthorizerContext) { | ||
if (decodeAuthorizerContext === void 0) { decodeAuthorizerContext = true; } | ||
var options = {}; | ||
@@ -103,6 +119,42 @@ var domain = event.requestContext.domainName; | ||
} | ||
if (parentSpanContext) { | ||
options.childOf = parentSpanContext; | ||
var upstreamAuthorizerSpan; | ||
var eventSourceSubType = (0, trigger_1.parseEventSourceSubType)(event); | ||
if (decodeAuthorizerContext) { | ||
try { | ||
var parsedUpstreamContext = (0, context_1.getInjectedAuthorizerData)(event, eventSourceSubType); | ||
if (parsedUpstreamContext) { | ||
var upstreamSpanOptions = {}; | ||
var startTime = parsedUpstreamContext[constants_1.parentSpanFinishTimeHeader] / 1e6; | ||
// getting an approximated endTime | ||
if (eventSourceSubType === trigger_1.eventSubTypes.apiGatewayV2) { | ||
options.startTime = startTime; // not inserting authorizer span | ||
options.tags.operation_name = "aws.httpapi"; | ||
} | ||
else { | ||
upstreamSpanOptions = { | ||
startTime: startTime, | ||
childOf: parentSpanContext, | ||
tags: __assign({ operation_name: "aws.apigateway.authorizer" }, options.tags), | ||
}; | ||
upstreamAuthorizerSpan = new span_wrapper_1.SpanWrapper(this.traceWrapper.startSpan("aws.apigateway.authorizer", upstreamSpanOptions), { isAsync: false }); | ||
var endTime = event.requestContext.requestTimeEpoch + event.requestContext.authorizer.integrationLatency; | ||
upstreamAuthorizerSpan.finish(endTime); | ||
options.startTime = endTime; // For the main function's inferred span | ||
} | ||
} | ||
} | ||
catch (error) { | ||
(0, utils_1.logDebug)("Error decoding authorizer span", error); | ||
} | ||
} | ||
options.startTime = event.requestContext.timeEpoch; | ||
if (!options.startTime) { | ||
if (eventSourceSubType === trigger_1.eventSubTypes.apiGatewayV1 || | ||
eventSourceSubType === trigger_1.eventSubTypes.apiGatewayWebsocket) { | ||
options.startTime = event.requestContext.requestTimeEpoch; | ||
} | ||
else { | ||
options.startTime = event.requestContext.timeEpoch; | ||
} | ||
} | ||
options.childOf = upstreamAuthorizerSpan ? upstreamAuthorizerSpan.span : parentSpanContext; | ||
var spanWrapperOptions = { | ||
@@ -109,0 +161,0 @@ isAsync: this.isApiGatewayAsync(event) === "async", |
@@ -16,3 +16,9 @@ "use strict"; | ||
SpanWrapper.prototype.endTime = function () { | ||
return this.span._endTime; | ||
if (this.span._endTime) { | ||
return this.span._endTime; | ||
} | ||
if (this.span._duration && this.span._startTime) { | ||
return this.span._startTime + this.span._duration; | ||
} | ||
throw new Error("_endTime not defined"); | ||
}; | ||
@@ -19,0 +25,0 @@ SpanWrapper.prototype.finish = function (timestamp) { |
@@ -21,3 +21,3 @@ import { Context } from "aws-lambda"; | ||
constructor(tracerWrapper: TracerWrapper); | ||
extractHeadersFromContext(event: any, context: Context, extractor?: TraceExtractor): Partial<TraceHeaders> | undefined; | ||
extractHeadersFromContext(event: any, context: Context, extractor?: TraceExtractor, decodeAuthorizerContext?: boolean): Partial<TraceHeaders> | undefined; | ||
get currentTraceContext(): TraceContext | undefined; | ||
@@ -24,0 +24,0 @@ get currentTraceHeaders(): Partial<TraceHeaders>; |
@@ -25,4 +25,5 @@ "use strict"; | ||
} | ||
TraceContextService.prototype.extractHeadersFromContext = function (event, context, extractor) { | ||
this.rootTraceContext = (0, context_1.extractTraceContext)(event, context, extractor); | ||
TraceContextService.prototype.extractHeadersFromContext = function (event, context, extractor, decodeAuthorizerContext) { | ||
if (decodeAuthorizerContext === void 0) { decodeAuthorizerContext = true; } | ||
this.rootTraceContext = (0, context_1.extractTraceContext)(event, context, extractor, decodeAuthorizerContext); | ||
return this.currentTraceHeaders; | ||
@@ -29,0 +30,0 @@ }; |
@@ -34,3 +34,4 @@ import { TraceContext } from "./context"; | ||
traceContext(): TraceContext | undefined; | ||
injectSpan(span: SpanContext): any; | ||
} | ||
//# sourceMappingURL=tracer-wrapper.d.ts.map |
@@ -101,2 +101,7 @@ "use strict"; | ||
}; | ||
TracerWrapper.prototype.injectSpan = function (span) { | ||
var dest = {}; | ||
this.tracer.inject(span, "text_map", dest); | ||
return dest; | ||
}; | ||
return TracerWrapper; | ||
@@ -103,0 +108,0 @@ }()); |
import { Context } from "aws-lambda"; | ||
export declare enum eventSources { | ||
export declare enum eventTypes { | ||
apiGateway = "api-gateway", | ||
@@ -17,2 +17,9 @@ applicationLoadBalancer = "application-load-balancer", | ||
} | ||
export declare enum eventSubTypes { | ||
apiGatewayV1 = "api-gateway-rest-api", | ||
apiGatewayV2 = "api-gateway-http-api", | ||
apiGatewayWebsocket = "api-gateway-websocket", | ||
unknown = "unknown-sub-type" | ||
} | ||
export declare function parseEventSourceSubType(event: any): eventSubTypes; | ||
/** | ||
@@ -24,3 +31,3 @@ * parseEventSource parses the triggering event to determine the source | ||
*/ | ||
export declare function parseEventSource(event: any): eventSources.apiGateway | eventSources.applicationLoadBalancer | eventSources.cloudFront | eventSources.cloudWatchEvents | eventSources.cloudWatchLogs | eventSources.dynamoDB | eventSources.eventBridge | eventSources.kinesis | eventSources.lambdaUrl | eventSources.s3 | eventSources.sns | eventSources.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 | undefined; | ||
/** | ||
@@ -27,0 +34,0 @@ * parseEventSourceARN parses the triggering event to determine the event source's |
@@ -37,3 +37,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extractHTTPStatusCodeTag = exports.extractTriggerTags = exports.parseEventSourceARN = exports.parseEventSource = exports.eventSources = void 0; | ||
exports.extractHTTPStatusCodeTag = exports.extractTriggerTags = exports.parseEventSourceARN = exports.parseEventSource = exports.parseEventSourceSubType = exports.eventSubTypes = exports.eventTypes = void 0; | ||
var eventType = __importStar(require("../utils/event-type-guards")); | ||
@@ -93,18 +93,38 @@ var utils_1 = require("../utils"); | ||
} | ||
var eventSources; | ||
(function (eventSources) { | ||
eventSources["apiGateway"] = "api-gateway"; | ||
eventSources["applicationLoadBalancer"] = "application-load-balancer"; | ||
eventSources["cloudFront"] = "cloudfront"; | ||
eventSources["cloudWatchEvents"] = "cloudwatch-events"; | ||
eventSources["cloudWatchLogs"] = "cloudwatch-logs"; | ||
eventSources["cloudWatch"] = "cloudwatch"; | ||
eventSources["dynamoDB"] = "dynamodb"; | ||
eventSources["eventBridge"] = "eventbridge"; | ||
eventSources["kinesis"] = "kinesis"; | ||
eventSources["lambdaUrl"] = "lambda-function-url"; | ||
eventSources["s3"] = "s3"; | ||
eventSources["sns"] = "sns"; | ||
eventSources["sqs"] = "sqs"; | ||
})(eventSources = exports.eventSources || (exports.eventSources = {})); | ||
var eventTypes; | ||
(function (eventTypes) { | ||
eventTypes["apiGateway"] = "api-gateway"; | ||
eventTypes["applicationLoadBalancer"] = "application-load-balancer"; | ||
eventTypes["cloudFront"] = "cloudfront"; | ||
eventTypes["cloudWatchEvents"] = "cloudwatch-events"; | ||
eventTypes["cloudWatchLogs"] = "cloudwatch-logs"; | ||
eventTypes["cloudWatch"] = "cloudwatch"; | ||
eventTypes["dynamoDB"] = "dynamodb"; | ||
eventTypes["eventBridge"] = "eventbridge"; | ||
eventTypes["kinesis"] = "kinesis"; | ||
eventTypes["lambdaUrl"] = "lambda-function-url"; | ||
eventTypes["s3"] = "s3"; | ||
eventTypes["sns"] = "sns"; | ||
eventTypes["sqs"] = "sqs"; | ||
})(eventTypes = exports.eventTypes || (exports.eventTypes = {})); | ||
var eventSubTypes; | ||
(function (eventSubTypes) { | ||
eventSubTypes["apiGatewayV1"] = "api-gateway-rest-api"; | ||
eventSubTypes["apiGatewayV2"] = "api-gateway-http-api"; | ||
eventSubTypes["apiGatewayWebsocket"] = "api-gateway-websocket"; | ||
eventSubTypes["unknown"] = "unknown-sub-type"; | ||
})(eventSubTypes = exports.eventSubTypes || (exports.eventSubTypes = {})); | ||
function parseEventSourceSubType(event) { | ||
if (eventType.isAPIGatewayEvent(event)) { | ||
return eventSubTypes.apiGatewayV1; | ||
} | ||
if (eventType.isAPIGatewayEventV2(event)) { | ||
return eventSubTypes.apiGatewayV2; | ||
} | ||
if (eventType.isAPIGatewayWebsocketEvent(event)) { | ||
return eventSubTypes.apiGatewayWebsocket; | ||
} | ||
return eventSubTypes.unknown; | ||
} | ||
exports.parseEventSourceSubType = parseEventSourceSubType; | ||
/** | ||
@@ -118,3 +138,3 @@ * parseEventSource parses the triggering event to determine the source | ||
if (eventType.isLambdaUrlEvent(event)) { | ||
return eventSources.lambdaUrl; | ||
return eventTypes.lambdaUrl; | ||
} | ||
@@ -124,33 +144,33 @@ if (eventType.isAPIGatewayEvent(event) || | ||
eventType.isAPIGatewayWebsocketEvent(event)) { | ||
return eventSources.apiGateway; | ||
return eventTypes.apiGateway; | ||
} | ||
if (eventType.isALBEvent(event)) { | ||
return eventSources.applicationLoadBalancer; | ||
return eventTypes.applicationLoadBalancer; | ||
} | ||
if (eventType.isCloudWatchLogsEvent(event)) { | ||
return eventSources.cloudWatchLogs; | ||
return eventTypes.cloudWatchLogs; | ||
} | ||
if (eventType.isCloudWatchEvent(event)) { | ||
return eventSources.cloudWatchEvents; | ||
return eventTypes.cloudWatchEvents; | ||
} | ||
if (eventType.isCloudFrontRequestEvent(event)) { | ||
return eventSources.cloudFront; | ||
return eventTypes.cloudFront; | ||
} | ||
if (eventType.isDynamoDBStreamEvent(event)) { | ||
return eventSources.dynamoDB; | ||
return eventTypes.dynamoDB; | ||
} | ||
if (eventType.isKinesisStreamEvent(event)) { | ||
return eventSources.kinesis; | ||
return eventTypes.kinesis; | ||
} | ||
if (eventType.isS3Event(event)) { | ||
return eventSources.s3; | ||
return eventTypes.s3; | ||
} | ||
if (eventType.isSNSEvent(event)) { | ||
return eventSources.sns; | ||
return eventTypes.sns; | ||
} | ||
if (eventType.isSQSEvent(event)) { | ||
return eventSources.sqs; | ||
return eventTypes.sqs; | ||
} | ||
if (eventType.isEventBridgeEvent(event)) { | ||
return eventSources.eventBridge; | ||
return eventTypes.eventBridge; | ||
} | ||
@@ -280,3 +300,3 @@ } | ||
catch (error) { | ||
(0, utils_1.logError)("failed to extract ".concat(eventSource, " arn from the event"), { error: error }); | ||
(0, utils_1.logDebug)("failed to extract ".concat(eventSource, " arn from the event"), { error: error }); | ||
} | ||
@@ -292,3 +312,3 @@ if (eventSourceARN) { | ||
catch (error) { | ||
(0, utils_1.logError)("failed to extract http tags from ".concat(eventSource, " event")); | ||
(0, utils_1.logDebug)("failed to extract http tags from ".concat(eventSource, " event")); | ||
} | ||
@@ -295,0 +315,0 @@ } |
{ | ||
"name": "datadog-lambda-js", | ||
"version": "6.84.0", | ||
"version": "6.85.0", | ||
"description": "Lambda client library that supports hybrid tracing in node js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,3 +9,3 @@ # datadog-lambda-js | ||
Datadog Lambda Library for Node.js (12.x, 14.x and 16.x) enables enhanced Lambda metrics, distributed tracing, and custom metric submission from AWS Lambda functions. | ||
Datadog Lambda Library for Node.js (12.x, 14.x, 16.x, and 18.x) enables enhanced Lambda metrics, distributed tracing, and custom metric submission from AWS Lambda functions. | ||
@@ -12,0 +12,0 @@ ## Installation |
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
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
393849
154
5585