datadog-lambda-js
Advanced tools
Comparing version 7.95.0 to 7.96.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.STREAM_RESPONSE = exports.HANDLER_STREAMING = exports.datadogLambdaVersion = void 0; | ||
exports.datadogLambdaVersion = "7.95.0"; | ||
exports.datadogLambdaVersion = "7.96.0"; | ||
// Response streaming functions | ||
@@ -6,0 +6,0 @@ exports.HANDLER_STREAMING = Symbol.for("aws.lambda.runtime.handler.streaming"); |
@@ -48,2 +48,3 @@ import { Context, EventBridgeEvent, KinesisStreamEvent, SNSEvent, SQSEvent } from "aws-lambda"; | ||
export declare function readTraceFromSNSSQSEvent(event: SQSEvent): TraceContext | undefined; | ||
export declare function readTraceFromEBSQSEvent(event: SQSEvent): TraceContext | undefined; | ||
export declare function readTraceFromKinesisEvent(event: KinesisStreamEvent): TraceContext | undefined; | ||
@@ -50,0 +51,0 @@ export declare function readTraceFromEventbridgeEvent(event: EventBridgeEvent<any, any>): TraceContext | undefined; |
@@ -66,3 +66,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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 = exports.deterministicMd5HashToBigIntString = exports.deterministicMd5HashInBinary = exports.hexToBinary = exports.readTraceFromStepFunctionsContext = 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.readTraceFromEBSQSEvent = exports.readTraceFromSNSSQSEvent = exports.readTraceFromSQSEvent = exports.readTraceFromAppSyncEvent = exports.sendXraySubsegment = exports.generateXraySubsegment = exports.addXrayMetadata = exports.addLambdaFunctionTagsToXray = exports.addStepFunctionContextToXray = exports.addTraceContextToXray = exports.extractTraceContext = exports.deterministicMd5HashToBigIntString = exports.deterministicMd5HashInBinary = exports.hexToBinary = exports.readTraceFromStepFunctionsContext = void 0; | ||
var bignumber_js_1 = require("bignumber.js"); | ||
@@ -328,2 +328,22 @@ var crypto_1 = require("crypto"); | ||
exports.readTraceFromSNSSQSEvent = readTraceFromSNSSQSEvent; | ||
function readTraceFromEBSQSEvent(event) { | ||
var _a, _b, _c; | ||
if ((_b = (_a = event === null || event === void 0 ? void 0 : event.Records) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.body) { | ||
try { | ||
var parsedBody = JSON.parse(event.Records[0].body); | ||
if ((_c = parsedBody === null || parsedBody === void 0 ? void 0 : parsedBody.detail) === null || _c === void 0 ? void 0 : _c._datadog) { | ||
var trace = exportTraceData(parsedBody.detail._datadog); | ||
(0, utils_1.logDebug)("extracted trace context from EventBridge SQS event", { trace: trace, event: event }); | ||
return trace; | ||
} | ||
} | ||
catch (err) { | ||
if (err instanceof Error) { | ||
(0, utils_1.logDebug)("Error parsing EventBridge SQS message trace data", err); | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
exports.readTraceFromEBSQSEvent = readTraceFromEBSQSEvent; | ||
function readTraceFromKinesisEvent(event) { | ||
@@ -490,2 +510,5 @@ var _a, _b, _c; | ||
} | ||
if ((0, event_type_guards_1.isEBSQSEvent)(event)) { | ||
return readTraceFromEBSQSEvent(event); | ||
} | ||
if ((0, event_type_guards_1.isAppSyncResolverEvent)(event)) { | ||
@@ -492,0 +515,0 @@ return readTraceFromAppSyncEvent(event); |
@@ -1,2 +0,2 @@ | ||
import { Context, SNSMessage } from "aws-lambda"; | ||
import { Context, EventBridgeEvent } from "aws-lambda"; | ||
import { SpanContext, TracerWrapper } from "./tracer-wrapper"; | ||
@@ -18,8 +18,7 @@ import { SpanWrapper } from "./span-wrapper"; | ||
createInferredSpanForSns(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForSqsSns(event: SNSMessage, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForSqs(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForKinesis(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForS3(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForEventBridge(event: any, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
createInferredSpanForEventBridge(event: EventBridgeEvent<any, any>, context: Context | undefined, parentSpanContext: SpanContext | undefined): SpanWrapper; | ||
} | ||
//# sourceMappingURL=span-inferrer.d.ts.map |
@@ -263,6 +263,16 @@ "use strict"; | ||
SpanInferrer.prototype.createInferredSpanForSns = function (event, context, parentSpanContext) { | ||
var _a; | ||
var options = {}; | ||
var Records = event.Records; | ||
var referenceRecord = Records[0]; | ||
var EventSubscriptionArn = referenceRecord.EventSubscriptionArn, _a = referenceRecord.Sns, TopicArn = _a.TopicArn, Timestamp = _a.Timestamp, Type = _a.Type, Subject = _a.Subject, MessageId = _a.MessageId; | ||
var referenceRecord; | ||
var eventSubscriptionArn = ""; | ||
if (event.Records) { | ||
// Full SNS Event into Lambda | ||
var Records = event.Records; | ||
(_a = Records[0], referenceRecord = _a.Sns, eventSubscriptionArn = _a.EventSubscriptionArn); | ||
} | ||
else { | ||
// SNS message wrapping an SQS message | ||
referenceRecord = event; | ||
} | ||
var TopicArn = referenceRecord.TopicArn, Timestamp = referenceRecord.Timestamp, Type = referenceRecord.Type, Subject = referenceRecord.Subject, MessageId = referenceRecord.MessageId; | ||
var topicName = (TopicArn === null || TopicArn === void 0 ? void 0 : TopicArn.split(":").pop()) || ""; | ||
@@ -288,36 +298,7 @@ var resourceName = topicName; | ||
topic_arn: TopicArn, | ||
event_subscription_arn: EventSubscriptionArn, | ||
}; | ||
if (parentSpanContext) { | ||
options.childOf = parentSpanContext; | ||
// EventSubscriptionARN not available for direct integrations to SQS from SNS. | ||
if (eventSubscriptionArn !== "") { | ||
options.tags.event_subscription_arn = eventSubscriptionArn; | ||
} | ||
options.startTime = Date.parse(Timestamp); | ||
var spanWrapperOptions = { | ||
isAsync: true, | ||
}; | ||
return new span_wrapper_1.SpanWrapper(this.traceWrapper.startSpan("aws.sns", options), spanWrapperOptions); | ||
}; | ||
SpanInferrer.prototype.createInferredSpanForSqsSns = function (event, context, parentSpanContext) { | ||
var options = {}; | ||
var TopicArn = event.TopicArn, Timestamp = event.Timestamp, Type = event.Type, Subject = event.Subject, MessageId = event.MessageId; | ||
var topicName = (TopicArn === null || TopicArn === void 0 ? void 0 : TopicArn.split(":").pop()) || ""; | ||
var resourceName = topicName; | ||
var serviceName = SpanInferrer.determineServiceName(topicName, "lambda_sns", "sns"); | ||
options.tags = { | ||
operation_name: "aws.sns", | ||
resource_names: resourceName, | ||
"span.type": "sns", | ||
"resource.name": resourceName, | ||
"peer.service": this.service, | ||
service: serviceName, | ||
_inferred_span: { | ||
tag_source: "self", | ||
synchronicity: "async", | ||
}, | ||
type: Type, | ||
subject: Subject, | ||
message_id: MessageId, | ||
topicname: topicName, | ||
topic_arn: TopicArn, | ||
}; | ||
if (parentSpanContext) { | ||
@@ -333,6 +314,7 @@ options.childOf = parentSpanContext; | ||
SpanInferrer.prototype.createInferredSpanForSqs = function (event, context, parentSpanContext) { | ||
var _a; | ||
var options = {}; | ||
var Records = event.Records; | ||
var referenceRecord = Records[0]; | ||
var _a = referenceRecord.attributes, SentTimestamp = _a.SentTimestamp, ApproximateReceiveCount = _a.ApproximateReceiveCount, SenderId = _a.SenderId, eventSourceARN = referenceRecord.eventSourceARN, receiptHandle = referenceRecord.receiptHandle, body = referenceRecord.body; | ||
var _b = referenceRecord.attributes, SentTimestamp = _b.SentTimestamp, ApproximateReceiveCount = _b.ApproximateReceiveCount, SenderId = _b.SenderId, eventSourceARN = referenceRecord.eventSourceARN, receiptHandle = referenceRecord.receiptHandle, body = referenceRecord.body; | ||
var queueName = (eventSourceARN === null || eventSourceARN === void 0 ? void 0 : eventSourceARN.split(":").pop()) || ""; | ||
@@ -365,10 +347,14 @@ var resourceName = queueName; | ||
// create further upstream sns span and finish/attach it here | ||
var upstreamSnsSpan = null; | ||
var upstreamSpan = null; | ||
try { | ||
var upstreamSnsMessage = void 0; | ||
upstreamSnsMessage = JSON.parse(body); | ||
if (upstreamSnsMessage && upstreamSnsMessage.TopicArn && upstreamSnsMessage.Timestamp) { | ||
upstreamSnsSpan = this.createInferredSpanForSqsSns(upstreamSnsMessage, context, parentSpanContext); | ||
upstreamSnsSpan.finish(Number(SentTimestamp)); | ||
var upstreamMessage = void 0; | ||
upstreamMessage = JSON.parse(body); | ||
if (upstreamMessage && upstreamMessage.TopicArn && upstreamMessage.Timestamp) { | ||
upstreamSpan = this.createInferredSpanForSns(upstreamMessage, context, parentSpanContext); | ||
upstreamSpan.finish(Number(SentTimestamp)); | ||
} | ||
else if ((_a = upstreamMessage === null || upstreamMessage === void 0 ? void 0 : upstreamMessage.detail) === null || _a === void 0 ? void 0 : _a._datadog) { | ||
upstreamSpan = this.createInferredSpanForEventBridge(upstreamMessage, context, parentSpanContext); | ||
upstreamSpan.finish(Number(SentTimestamp)); | ||
} | ||
} | ||
@@ -378,3 +364,3 @@ catch (e) { | ||
} | ||
options.childOf = upstreamSnsSpan ? upstreamSnsSpan.span : parentSpanContext; | ||
options.childOf = upstreamSpan ? upstreamSpan.span : parentSpanContext; | ||
options.startTime = Number(SentTimestamp); | ||
@@ -381,0 +367,0 @@ var spanWrapperOptions = { |
@@ -15,2 +15,3 @@ import { APIGatewayEvent, APIGatewayProxyEventV2, AppSyncResolverEvent, ALBEvent, CloudWatchLogsEvent, ScheduledEvent, CloudFrontRequestEvent, DynamoDBStreamEvent, KinesisStreamEvent, S3Event, SNSEvent, SQSEvent, EventBridgeEvent } from "aws-lambda"; | ||
export declare function isSNSSQSEvent(event: any): event is SQSEvent; | ||
export declare function isEBSQSEvent(event: any): event is SQSEvent; | ||
export declare function isAppSyncResolverEvent(event: any): event is AppSyncResolverEvent<any>; | ||
@@ -17,0 +18,0 @@ export declare function isEventBridgeEvent(event: any): event is EventBridgeEvent<any, any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLambdaUrlEvent = exports.isEventBridgeEvent = exports.isAppSyncResolverEvent = exports.isSNSSQSEvent = exports.isSQSEvent = exports.isSNSEvent = exports.isS3Event = exports.isKinesisStreamEvent = exports.isDynamoDBStreamEvent = exports.isCloudFrontRequestEvent = exports.isCloudWatchEvent = exports.isCloudWatchLogsEvent = exports.isALBEvent = exports.isAPIGatewayWebsocketEvent = exports.isAPIGatewayEventV2 = exports.isAPIGatewayEvent = void 0; | ||
exports.isLambdaUrlEvent = exports.isEventBridgeEvent = exports.isAppSyncResolverEvent = exports.isEBSQSEvent = exports.isSNSSQSEvent = exports.isSQSEvent = exports.isSNSEvent = exports.isS3Event = exports.isKinesisStreamEvent = exports.isDynamoDBStreamEvent = exports.isCloudFrontRequestEvent = exports.isCloudWatchEvent = exports.isCloudWatchLogsEvent = exports.isALBEvent = exports.isAPIGatewayWebsocketEvent = exports.isAPIGatewayEventV2 = exports.isAPIGatewayEvent = void 0; | ||
var constants_1 = require("../trace/constants"); | ||
@@ -72,2 +72,15 @@ function isAPIGatewayEvent(event) { | ||
exports.isSNSSQSEvent = isSNSSQSEvent; | ||
function isEBSQSEvent(event) { | ||
if (Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].eventSource === "aws:sqs") { | ||
try { | ||
var body = JSON.parse(event.Records[0].body); | ||
return body["detail-type"] !== undefined; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.isEBSQSEvent = isEBSQSEvent; | ||
function isAppSyncResolverEvent(event) { | ||
@@ -74,0 +87,0 @@ return event.info !== undefined && event.info.selectionSetGraphQL !== undefined; |
{ | ||
"name": "datadog-lambda-js", | ||
"version": "7.95.0", | ||
"version": "7.96.0", | ||
"description": "Lambda client library that supports hybrid tracing in node js", | ||
@@ -29,3 +29,3 @@ "main": "dist/index.js", | ||
"@types/shimmer": "^1.0.1", | ||
"dd-trace": "^3.29.1", | ||
"dd-trace": "^3.32.1", | ||
"jest": "^27.0.1", | ||
@@ -32,0 +32,0 @@ "mock-fs": "4.14.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
449699
6285