dd-trace 6.25.0 → 6.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/package.json +33 -30
- package/packages/datadog-esbuild/index.js +8 -15
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +6 -1
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +23 -1
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +9 -6
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +21 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
- package/packages/datadog-instrumentations/src/next.js +184 -20
- package/packages/datadog-instrumentations/src/router.js +35 -12
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +30 -4
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +7 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +2 -1
- package/packages/datadog-plugin-http2/src/client.js +2 -1
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- package/packages/dd-trace/src/appsec/blocking/index.js +17 -1
- package/packages/dd-trace/src/appsec/channels.js +7 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +10 -13
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/index.js +6 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
- package/packages/dd-trace/src/appsec/recommended.json +70 -3
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -2
- package/packages/dd-trace/src/config/index.js +46 -26
- package/packages/dd-trace/src/config/parsers.js +35 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +14 -6
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/pathway.js +113 -28
- package/packages/dd-trace/src/datastreams/processor.js +5 -4
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +4 -1
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/git_metadata.js +2 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +6 -5
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +3 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +20 -0
- package/packages/dd-trace/src/plugins/ci_plugin.js +104 -9
- package/packages/dd-trace/src/plugins/index.js +2 -0
- package/packages/dd-trace/src/plugins/util/ci.js +34 -0
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +9 -14
- package/packages/dd-trace/src/plugins/util/test.js +28 -1
- package/packages/dd-trace/src/plugins/util/url.js +8 -5
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -4
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +13 -1
- package/vendor/dist/@opentelemetry/core/LICENSE +11 -0
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vite.d.ts +7 -0
- package/vite.js +3 -0
- package/lambda.d.ts +0 -39
- package/lambda.js +0 -3
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Ported from datadog-lambda-js at da9fc3c0c9dca00893f70c9a1bd5ac1254af3b01.
|
|
4
|
+
|
|
5
|
+
const API_GATEWAY_EVENT_V2 = '2.0'
|
|
6
|
+
|
|
7
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
8
|
+
function isAPIGatewayEvent (event) {
|
|
9
|
+
return event.requestContext?.stage !== undefined && event.httpMethod !== undefined && event.resource !== undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
13
|
+
function isAPIGatewayEventV2 (event) {
|
|
14
|
+
return (
|
|
15
|
+
event.requestContext !== undefined &&
|
|
16
|
+
event.version === API_GATEWAY_EVENT_V2 &&
|
|
17
|
+
event.rawQueryString !== undefined &&
|
|
18
|
+
!event.requestContext.domainName.includes('lambda-url')
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
23
|
+
function isAPIGatewayWebsocketEvent (event) {
|
|
24
|
+
return event.requestContext !== undefined && event.requestContext.messageDirection !== undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
28
|
+
function isALBEvent (event) {
|
|
29
|
+
return event.requestContext !== undefined && event.requestContext.elb !== undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
33
|
+
function isCloudWatchLogsEvent (event) {
|
|
34
|
+
return event.awslogs !== undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
38
|
+
function isCloudWatchEvent (event) {
|
|
39
|
+
return event.source !== undefined && event.source === 'aws.events'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
43
|
+
function isCloudFrontRequestEvent (event) {
|
|
44
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].cf !== undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
48
|
+
function isDynamoDBStreamEvent (event) {
|
|
49
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].dynamodb !== undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
53
|
+
function isKinesisStreamEvent (event) {
|
|
54
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].kinesis !== undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
58
|
+
function isS3Event (event) {
|
|
59
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].s3 !== undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
63
|
+
function isSNSEvent (event) {
|
|
64
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].Sns !== undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
68
|
+
function isSQSEvent (event) {
|
|
69
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].eventSource === 'aws:sqs'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
73
|
+
function isSNSSQSEvent (event) {
|
|
74
|
+
if (isSQSEvent(event)) {
|
|
75
|
+
try {
|
|
76
|
+
const body = JSON.parse(event.Records[0].body)
|
|
77
|
+
if (body.Type === 'Notification' && body.TopicArn) {
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
88
|
+
function isEventBridgeSQSEvent (event) {
|
|
89
|
+
if (isSQSEvent(event)) {
|
|
90
|
+
try {
|
|
91
|
+
const body = JSON.parse(event.Records[0].body)
|
|
92
|
+
return body['detail-type'] !== undefined
|
|
93
|
+
} catch {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
101
|
+
function isAppSyncResolverEvent (event) {
|
|
102
|
+
return event.info !== undefined && event.info.selectionSetGraphQL !== undefined
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
106
|
+
function isEventBridgeEvent (event) {
|
|
107
|
+
return event['detail-type'] !== undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
111
|
+
function isLambdaUrlEvent (event) {
|
|
112
|
+
return event?.requestContext?.domainName?.includes('lambda-url')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Preserve the pinned shim's null/object semantics, including malformed-envelope throws.
|
|
116
|
+
/* eslint-disable eslint-rules/eslint-safe-typeof-object */
|
|
117
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
118
|
+
function isStepFunctionsEvent (event) {
|
|
119
|
+
// Extract Payload if available (Legacy lambda parsing)
|
|
120
|
+
if (typeof event.Payload === 'object') {
|
|
121
|
+
event = event.Payload
|
|
122
|
+
}
|
|
123
|
+
// Extract _datadog if available (JSONata v1 parsing)
|
|
124
|
+
if (typeof event._datadog === 'object') {
|
|
125
|
+
event = event._datadog
|
|
126
|
+
}
|
|
127
|
+
return (
|
|
128
|
+
typeof event.Execution === 'object' && typeof event.State === 'object' && typeof event.StateMachine === 'object'
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* eslint-enable eslint-rules/eslint-safe-typeof-object */
|
|
133
|
+
|
|
134
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
135
|
+
function isMSKEvent (event) {
|
|
136
|
+
return (
|
|
137
|
+
event?.eventSource === 'aws:kafka' &&
|
|
138
|
+
event.records !== null &&
|
|
139
|
+
typeof event.records === 'object' &&
|
|
140
|
+
!Array.isArray(event.records)
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
145
|
+
function isDurableExecutionEvent (event) {
|
|
146
|
+
return typeof event.DurableExecutionArn === 'string'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
isAPIGatewayEvent,
|
|
151
|
+
isAPIGatewayEventV2,
|
|
152
|
+
isAPIGatewayWebsocketEvent,
|
|
153
|
+
isALBEvent,
|
|
154
|
+
isCloudWatchLogsEvent,
|
|
155
|
+
isCloudWatchEvent,
|
|
156
|
+
isCloudFrontRequestEvent,
|
|
157
|
+
isDynamoDBStreamEvent,
|
|
158
|
+
isKinesisStreamEvent,
|
|
159
|
+
isS3Event,
|
|
160
|
+
isSNSEvent,
|
|
161
|
+
isSQSEvent,
|
|
162
|
+
isSNSSQSEvent,
|
|
163
|
+
isEventBridgeSQSEvent,
|
|
164
|
+
isAppSyncResolverEvent,
|
|
165
|
+
isEventBridgeEvent,
|
|
166
|
+
isLambdaUrlEvent,
|
|
167
|
+
isStepFunctionsEvent,
|
|
168
|
+
isMSKEvent,
|
|
169
|
+
isDurableExecutionEvent,
|
|
170
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Ported from datadog-lambda-js at da9fc3c0c9dca00893f70c9a1bd5ac1254af3b01.
|
|
4
|
+
|
|
5
|
+
const { gunzipSync } = require('node:zlib')
|
|
6
|
+
|
|
7
|
+
const log = require('../../dd-trace/src/log')
|
|
8
|
+
const eventType = require('./event-type-guards')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string | undefined} eventSource
|
|
12
|
+
*/
|
|
13
|
+
function isHTTPTriggerEvent (eventSource) {
|
|
14
|
+
return (
|
|
15
|
+
eventSource === 'api-gateway' ||
|
|
16
|
+
eventSource === 'application-load-balancer' ||
|
|
17
|
+
eventSource === 'lambda-function-url'
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} region
|
|
23
|
+
*/
|
|
24
|
+
function getAWSPartitionByRegion (region) {
|
|
25
|
+
if (region.startsWith('us-gov-')) {
|
|
26
|
+
return 'aws-us-gov'
|
|
27
|
+
} else if (region.startsWith('cn-')) {
|
|
28
|
+
return 'aws-cn'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return 'aws'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {Record<string, unknown>} event
|
|
36
|
+
*/
|
|
37
|
+
function extractCloudWatchLogsEventDecodedLogs (event) {
|
|
38
|
+
const buffer = Buffer.from(event.awslogs.data, 'base64')
|
|
39
|
+
const decompressed = gunzipSync(buffer).toString()
|
|
40
|
+
return JSON.parse(decompressed)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Preserve the pinned shim's envelope order and null behavior.
|
|
44
|
+
/* eslint-disable eslint-rules/eslint-safe-typeof-object */
|
|
45
|
+
/**
|
|
46
|
+
* @param {Record<string, unknown>} event
|
|
47
|
+
*/
|
|
48
|
+
function extractStateMachineARN (event) {
|
|
49
|
+
// Extract Payload if available (Legacy lambda parsing)
|
|
50
|
+
if (typeof event.Payload === 'object') {
|
|
51
|
+
event = event.Payload
|
|
52
|
+
}
|
|
53
|
+
// Extract _datadog if available (JSONata v1 parsing)
|
|
54
|
+
if (typeof event._datadog === 'object') {
|
|
55
|
+
event = event._datadog
|
|
56
|
+
}
|
|
57
|
+
return event.StateMachine.Id
|
|
58
|
+
}
|
|
59
|
+
/* eslint-enable eslint-rules/eslint-safe-typeof-object */
|
|
60
|
+
|
|
61
|
+
const eventTypes = {
|
|
62
|
+
apiGateway: 'api-gateway',
|
|
63
|
+
applicationLoadBalancer: 'application-load-balancer',
|
|
64
|
+
cloudFront: 'cloudfront',
|
|
65
|
+
cloudWatchEvents: 'cloudwatch-events',
|
|
66
|
+
cloudWatchLogs: 'cloudwatch-logs',
|
|
67
|
+
cloudWatch: 'cloudwatch',
|
|
68
|
+
dynamoDB: 'dynamodb',
|
|
69
|
+
eventBridge: 'eventbridge',
|
|
70
|
+
kinesis: 'kinesis',
|
|
71
|
+
lambdaUrl: 'lambda-function-url',
|
|
72
|
+
s3: 's3',
|
|
73
|
+
sns: 'sns',
|
|
74
|
+
sqs: 'sqs',
|
|
75
|
+
stepFunctions: 'states',
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const eventSubTypes = {
|
|
79
|
+
apiGatewayV1: 'api-gateway-rest-api',
|
|
80
|
+
apiGatewayV2: 'api-gateway-http-api',
|
|
81
|
+
apiGatewayWebsocket: 'api-gateway-websocket',
|
|
82
|
+
unknown: 'unknown-sub-type',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {Record<string, unknown>} event
|
|
87
|
+
*/
|
|
88
|
+
function parseEventSourceSubtype (event) {
|
|
89
|
+
if (eventType.isAPIGatewayEvent(event)) {
|
|
90
|
+
return eventSubTypes.apiGatewayV1
|
|
91
|
+
}
|
|
92
|
+
if (eventType.isAPIGatewayEventV2(event)) {
|
|
93
|
+
return eventSubTypes.apiGatewayV2
|
|
94
|
+
}
|
|
95
|
+
if (eventType.isAPIGatewayWebsocketEvent(event)) {
|
|
96
|
+
return eventSubTypes.apiGatewayWebsocket
|
|
97
|
+
}
|
|
98
|
+
return eventSubTypes.unknown
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* parseEventSource parses the triggering event to determine the source
|
|
103
|
+
* Possible Returns:
|
|
104
|
+
* api-gateway | application-load-balancer | cloudwatch-logs |
|
|
105
|
+
* cloudwatch-events | cloudfront | dynamodb | kinesis | s3 | sns | sqs | states
|
|
106
|
+
*
|
|
107
|
+
* @param {Record<string, unknown>} event
|
|
108
|
+
*/
|
|
109
|
+
function parseEventSource (event) {
|
|
110
|
+
if (eventType.isLambdaUrlEvent(event)) {
|
|
111
|
+
return eventTypes.lambdaUrl
|
|
112
|
+
}
|
|
113
|
+
if (
|
|
114
|
+
eventType.isAPIGatewayEvent(event) ||
|
|
115
|
+
eventType.isAPIGatewayEventV2(event) ||
|
|
116
|
+
eventType.isAPIGatewayWebsocketEvent(event)
|
|
117
|
+
) {
|
|
118
|
+
return eventTypes.apiGateway
|
|
119
|
+
}
|
|
120
|
+
if (eventType.isALBEvent(event)) {
|
|
121
|
+
return eventTypes.applicationLoadBalancer
|
|
122
|
+
}
|
|
123
|
+
if (eventType.isCloudWatchLogsEvent(event)) {
|
|
124
|
+
return eventTypes.cloudWatchLogs
|
|
125
|
+
}
|
|
126
|
+
if (eventType.isCloudWatchEvent(event)) {
|
|
127
|
+
return eventTypes.cloudWatchEvents
|
|
128
|
+
}
|
|
129
|
+
if (eventType.isCloudFrontRequestEvent(event)) {
|
|
130
|
+
return eventTypes.cloudFront
|
|
131
|
+
}
|
|
132
|
+
if (eventType.isDynamoDBStreamEvent(event)) {
|
|
133
|
+
return eventTypes.dynamoDB
|
|
134
|
+
}
|
|
135
|
+
if (eventType.isKinesisStreamEvent(event)) {
|
|
136
|
+
return eventTypes.kinesis
|
|
137
|
+
}
|
|
138
|
+
if (eventType.isS3Event(event)) {
|
|
139
|
+
return eventTypes.s3
|
|
140
|
+
}
|
|
141
|
+
if (eventType.isSNSEvent(event)) {
|
|
142
|
+
return eventTypes.sns
|
|
143
|
+
}
|
|
144
|
+
if (eventType.isSQSEvent(event)) {
|
|
145
|
+
return eventTypes.sqs
|
|
146
|
+
}
|
|
147
|
+
if (eventType.isEventBridgeEvent(event)) {
|
|
148
|
+
return eventTypes.eventBridge
|
|
149
|
+
}
|
|
150
|
+
if (eventType.isStepFunctionsEvent(event)) {
|
|
151
|
+
return eventTypes.stepFunctions
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* parseEventSourceARN parses the triggering event to determine the event source's
|
|
157
|
+
* ARN if available. Otherwise we stitch together the ARN
|
|
158
|
+
*
|
|
159
|
+
* @param {string | undefined} source
|
|
160
|
+
* @param {Record<string, unknown>} event
|
|
161
|
+
* @param {{ invokedFunctionArn: string }} context
|
|
162
|
+
*/
|
|
163
|
+
function parseEventSourceARN (source, event, context) {
|
|
164
|
+
const splitFunctionArn = context.invokedFunctionArn.split(':')
|
|
165
|
+
const region = splitFunctionArn[3]
|
|
166
|
+
const accountId = splitFunctionArn[4]
|
|
167
|
+
const awsARN = getAWSPartitionByRegion(region)
|
|
168
|
+
switch (source) {
|
|
169
|
+
case 's3': {
|
|
170
|
+
return event.Records[0].s3.bucket.arn
|
|
171
|
+
}
|
|
172
|
+
case 'sns': {
|
|
173
|
+
return event.Records[0].Sns.TopicArn
|
|
174
|
+
}
|
|
175
|
+
case 'sqs': {
|
|
176
|
+
return event.Records[0].eventSourceARN
|
|
177
|
+
}
|
|
178
|
+
case 'cloudfront': {
|
|
179
|
+
const distributionId = event.Records[0].cf.config.distributionId
|
|
180
|
+
return `arn:${awsARN}:cloudfront::${accountId}:distribution/${distributionId}`
|
|
181
|
+
}
|
|
182
|
+
case 'api-gateway': {
|
|
183
|
+
const requestContext = event.requestContext
|
|
184
|
+
return `arn:${awsARN}:apigateway:${region}::/restapis/${requestContext.apiId}` +
|
|
185
|
+
`/stages/${requestContext.stage}`
|
|
186
|
+
}
|
|
187
|
+
case 'application-load-balancer': {
|
|
188
|
+
return event.requestContext.elb.targetGroupArn
|
|
189
|
+
}
|
|
190
|
+
case 'cloudwatch-logs': {
|
|
191
|
+
const logs = extractCloudWatchLogsEventDecodedLogs(event)
|
|
192
|
+
return `arn:${awsARN}:logs:${region}:${accountId}:log-group:${logs.logGroup}`
|
|
193
|
+
}
|
|
194
|
+
case 'cloudwatch-events': {
|
|
195
|
+
return event.resources[0]
|
|
196
|
+
}
|
|
197
|
+
case 'dynamodb': {
|
|
198
|
+
return event.Records[0].eventSourceARN
|
|
199
|
+
}
|
|
200
|
+
case 'kinesis': {
|
|
201
|
+
return event.Records[0].eventSourceARN
|
|
202
|
+
}
|
|
203
|
+
case 'eventbridge': {
|
|
204
|
+
return event.source
|
|
205
|
+
}
|
|
206
|
+
case 'states': {
|
|
207
|
+
return extractStateMachineARN(event)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* extractHTTPTags extracts HTTP facet tags from the triggering event
|
|
214
|
+
*
|
|
215
|
+
* @param {Record<string, unknown>} event
|
|
216
|
+
*/
|
|
217
|
+
function extractHTTPTags (event) {
|
|
218
|
+
const httpTags = {}
|
|
219
|
+
if (eventType.isAPIGatewayEvent(event)) {
|
|
220
|
+
const requestContext = event.requestContext
|
|
221
|
+
const path = requestContext.path
|
|
222
|
+
if (requestContext.domainName) {
|
|
223
|
+
httpTags['http.url'] = `https://${requestContext.domainName}${path ?? ''}`
|
|
224
|
+
}
|
|
225
|
+
httpTags['http.url_details.path'] = path
|
|
226
|
+
httpTags['http.method'] = requestContext.httpMethod
|
|
227
|
+
if (event.headers?.Referer) {
|
|
228
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
229
|
+
}
|
|
230
|
+
if (event.resource) {
|
|
231
|
+
httpTags['http.route'] = event.resource
|
|
232
|
+
}
|
|
233
|
+
return httpTags
|
|
234
|
+
}
|
|
235
|
+
if (eventType.isAPIGatewayEventV2(event)) {
|
|
236
|
+
const requestContext = event.requestContext
|
|
237
|
+
const path = requestContext.http.path
|
|
238
|
+
httpTags['http.url'] = `https://${requestContext.domainName}${path ?? ''}`
|
|
239
|
+
httpTags['http.url_details.path'] = path
|
|
240
|
+
httpTags['http.method'] = requestContext.http.method
|
|
241
|
+
if (event.headers?.Referer) {
|
|
242
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
243
|
+
}
|
|
244
|
+
if (event.routeKey) {
|
|
245
|
+
// "GET /my/endpoint" => "/my/endpoint"
|
|
246
|
+
const array = event.routeKey.split(' ')
|
|
247
|
+
httpTags['http.route'] = array.at(-1)
|
|
248
|
+
}
|
|
249
|
+
return httpTags
|
|
250
|
+
}
|
|
251
|
+
if (eventType.isALBEvent(event)) {
|
|
252
|
+
httpTags['http.url_details.path'] = event.path
|
|
253
|
+
httpTags['http.method'] = event.httpMethod
|
|
254
|
+
if (event.headers && event.headers.Referer) {
|
|
255
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
256
|
+
}
|
|
257
|
+
return httpTags
|
|
258
|
+
}
|
|
259
|
+
if (eventType.isLambdaUrlEvent(event)) {
|
|
260
|
+
const requestContext = event.requestContext
|
|
261
|
+
const path = requestContext.http.path
|
|
262
|
+
if (requestContext.domainName) {
|
|
263
|
+
httpTags['http.url'] = `https://${requestContext.domainName}${path ?? ''}`
|
|
264
|
+
}
|
|
265
|
+
httpTags['http.url_details.path'] = path
|
|
266
|
+
httpTags['http.method'] = requestContext.http.method
|
|
267
|
+
if (event.headers?.Referer) {
|
|
268
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
269
|
+
}
|
|
270
|
+
return httpTags
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* extractTriggerTags parses the trigger event object for tags to be added to the span metadata
|
|
276
|
+
*
|
|
277
|
+
* @param {Record<string, unknown>} event
|
|
278
|
+
* @param {{ invokedFunctionArn: string }} context
|
|
279
|
+
* @param {string | undefined} eventSource
|
|
280
|
+
*/
|
|
281
|
+
function extractTriggerTags (event, context, eventSource) {
|
|
282
|
+
let triggerTags = {}
|
|
283
|
+
if (eventSource) {
|
|
284
|
+
triggerTags['function_trigger.event_source'] = eventSource
|
|
285
|
+
let eventSourceARN
|
|
286
|
+
try {
|
|
287
|
+
eventSourceARN = parseEventSourceARN(eventSource, event, context)
|
|
288
|
+
} catch (error) {
|
|
289
|
+
log.debug('failed to extract %s arn from the event: %s', eventSource, error)
|
|
290
|
+
}
|
|
291
|
+
if (eventSourceARN) {
|
|
292
|
+
triggerTags['function_trigger.event_source_arn'] = eventSourceARN
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (isHTTPTriggerEvent(eventSource)) {
|
|
296
|
+
try {
|
|
297
|
+
triggerTags = { ...triggerTags, ...extractHTTPTags(event) }
|
|
298
|
+
} catch {
|
|
299
|
+
log.debug('failed to extract http tags from %s event', eventSource)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return triggerTags
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* extractHTTPStatusCode extracts a status code from the response if the Lambda was triggered
|
|
307
|
+
* by API Gateway, ALB, or Lambda Function URL
|
|
308
|
+
*
|
|
309
|
+
* @param {Record<string, string> | undefined} triggerTags
|
|
310
|
+
* @param {{ statusCode?: string | number } | null | undefined} result
|
|
311
|
+
* @param {boolean} isResponseStreamFunction
|
|
312
|
+
*/
|
|
313
|
+
function extractHTTPStatusCodeTag (triggerTags, result, isResponseStreamFunction) {
|
|
314
|
+
const eventSource = triggerTags?.['function_trigger.event_source']
|
|
315
|
+
if (!isHTTPTriggerEvent(eventSource)) {
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
const resultStatusCode = result?.statusCode
|
|
319
|
+
// Return a 502 status if no response is found in
|
|
320
|
+
// any buffered function. Streaming functions returning
|
|
321
|
+
// undefined results will be marked as 200.
|
|
322
|
+
if (result === undefined && !isResponseStreamFunction) {
|
|
323
|
+
return '502'
|
|
324
|
+
} else if (resultStatusCode) {
|
|
325
|
+
return resultStatusCode.toString()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return '200'
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
module.exports = {
|
|
332
|
+
eventTypes,
|
|
333
|
+
eventSubTypes,
|
|
334
|
+
parseEventSourceSubtype,
|
|
335
|
+
parseEventSource,
|
|
336
|
+
parseEventSourceARN,
|
|
337
|
+
extractTriggerTags,
|
|
338
|
+
extractHTTPStatusCodeTag,
|
|
339
|
+
}
|
|
@@ -5,6 +5,10 @@ const log = require('../../../dd-trace/src/log')
|
|
|
5
5
|
const { DYNAMODB_PTR_KIND, SPAN_POINTER_DIRECTION } = require('../../../dd-trace/src/constants')
|
|
6
6
|
const { extractPrimaryKeys, generatePointerHash } = require('../util')
|
|
7
7
|
|
|
8
|
+
// Requests may name the table by ARN, which cross-account access requires:
|
|
9
|
+
// arn:<partition>:dynamodb:<region>:<account>:table/<name>
|
|
10
|
+
const TABLE_ARN = /^arn:[^:]+:dynamodb:[^:]+:[^:]+:table\/[^/]+$/
|
|
11
|
+
|
|
8
12
|
class DynamoDb extends BaseAwsSdkPlugin {
|
|
9
13
|
static id = 'dynamodb'
|
|
10
14
|
static peerServicePrecursors = ['tablename']
|
|
@@ -31,6 +35,9 @@ class DynamoDb extends BaseAwsSdkPlugin {
|
|
|
31
35
|
tags['resource.name'] = `${operation} ${tableName}`
|
|
32
36
|
tags['aws.dynamodb.table_name'] = tableName
|
|
33
37
|
tags.tablename = tableName
|
|
38
|
+
if (TABLE_ARN.test(tableName)) {
|
|
39
|
+
tags['aws.table.arn'] = tableName
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
// TODO: DynamoDB.DocumentClient does batches on multiple tables
|
|
@@ -7,6 +7,18 @@ function recordDataAsString (data) {
|
|
|
7
7
|
return Buffer.isBuffer(data) ? data.toString('utf8') : Buffer.from(data).toString('utf8')
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the stream a request addresses. Requests may identify it by `StreamARN` alone
|
|
12
|
+
* (`arn:aws:kinesis:<region>:<account>:stream/<name>`); the name is then its last path segment,
|
|
13
|
+
* as dd-trace-go derives it.
|
|
14
|
+
*
|
|
15
|
+
* @param {{ StreamName?: string, StreamARN?: string }} params
|
|
16
|
+
* @returns {string | undefined}
|
|
17
|
+
*/
|
|
18
|
+
function getStreamName ({ StreamName, StreamARN }) {
|
|
19
|
+
return StreamName || StreamARN?.slice(StreamARN.lastIndexOf('/') + 1)
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
// Caps the promise-path iterator→stream cache so abandoned shard iterators
|
|
11
23
|
// (AWS expires them after 5 minutes) can't grow it without bound. Polling loops
|
|
12
24
|
// delete on consume, so their working set is ~the active shard count.
|
|
@@ -100,7 +112,7 @@ class Kinesis extends BaseAwsSdkPlugin {
|
|
|
100
112
|
*/
|
|
101
113
|
#trackShardStream (request, response) {
|
|
102
114
|
if (request.operation === 'getShardIterator') {
|
|
103
|
-
this.#rememberShardStream(response?.ShardIterator, request.params
|
|
115
|
+
if (request.params) this.#rememberShardStream(response?.ShardIterator, getStreamName(request.params))
|
|
104
116
|
} else if (request.operation === 'getRecords') {
|
|
105
117
|
this.#advanceShardStream(request.params?.ShardIterator, response?.NextShardIterator)
|
|
106
118
|
}
|
|
@@ -134,22 +146,32 @@ class Kinesis extends BaseAwsSdkPlugin {
|
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
generateTags (params, operation, response) {
|
|
137
|
-
if (!params
|
|
149
|
+
if (!params) return
|
|
150
|
+
|
|
151
|
+
const streamName = getStreamName(params)
|
|
152
|
+
if (!streamName) return
|
|
138
153
|
|
|
139
|
-
|
|
140
|
-
'resource.name': `${operation} ${
|
|
141
|
-
'aws.kinesis.stream_name':
|
|
154
|
+
const tags = {
|
|
155
|
+
'resource.name': `${operation} ${streamName}`,
|
|
156
|
+
'aws.kinesis.stream_name': streamName,
|
|
142
157
|
'messaging.system': 'aws_kinesis',
|
|
143
|
-
streamname:
|
|
158
|
+
streamname: streamName,
|
|
144
159
|
}
|
|
160
|
+
|
|
161
|
+
if (params.StreamARN) {
|
|
162
|
+
tags['aws.stream.arn'] = params.StreamARN
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return tags
|
|
145
166
|
}
|
|
146
167
|
|
|
147
168
|
storeStreamName (params, operation, store) {
|
|
148
169
|
if (!operation) return store
|
|
149
170
|
if (operation !== 'getShardIterator' && operation !== 'listShards') return store
|
|
150
|
-
if (!params
|
|
171
|
+
if (!params) return store
|
|
151
172
|
|
|
152
|
-
const streamName = params
|
|
173
|
+
const streamName = getStreamName(params)
|
|
174
|
+
if (!streamName) return store
|
|
153
175
|
return { ...store, streamName }
|
|
154
176
|
}
|
|
155
177
|
|
|
@@ -227,11 +249,11 @@ class Kinesis extends BaseAwsSdkPlugin {
|
|
|
227
249
|
let stream
|
|
228
250
|
switch (operation) {
|
|
229
251
|
case 'putRecord':
|
|
230
|
-
stream = params
|
|
252
|
+
stream = getStreamName(params) ?? ''
|
|
231
253
|
this.injectToMessage(span, params, stream, true)
|
|
232
254
|
break
|
|
233
255
|
case 'putRecords':
|
|
234
|
-
stream = params
|
|
256
|
+
stream = getStreamName(params) ?? ''
|
|
235
257
|
for (let i = 0; i < params.Records.length; i++) {
|
|
236
258
|
this.injectToMessage(
|
|
237
259
|
span,
|
|
@@ -9,11 +9,20 @@ class Lambda extends BaseAwsSdkPlugin {
|
|
|
9
9
|
generateTags (params, operation, response) {
|
|
10
10
|
if (!params?.FunctionName) return
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const tags = {
|
|
13
13
|
'resource.name': `${operation} ${params.FunctionName}`,
|
|
14
14
|
functionname: params.FunctionName,
|
|
15
15
|
'aws.lambda': params.FunctionName,
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
// Like dd-trace-java, only a full ARN (arn:<partition>:lambda:<region>:<account>:function:<name>[:<qualifier>]),
|
|
19
|
+
// which cross-account and cross-Region invocations require, identifies the function; names and partial ARNs
|
|
20
|
+
// lack its account or Region.
|
|
21
|
+
if (params.FunctionName.startsWith('arn:')) {
|
|
22
|
+
tags['aws.function.arn'] = params.FunctionName
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return tags
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
requestInject (span, request) {
|
|
@@ -33,6 +33,9 @@ class Stepfunctions extends BaseAwsSdkPlugin {
|
|
|
33
33
|
if (operation === 'startExecution' || operation === 'startSyncExecution') {
|
|
34
34
|
tags.statemachinearn = params.stateMachineArn
|
|
35
35
|
}
|
|
36
|
+
if (params.stateMachineArn) {
|
|
37
|
+
tags['aws.step_functions.state_machine.arn'] = params.stateMachineArn
|
|
38
|
+
}
|
|
36
39
|
return tags
|
|
37
40
|
}
|
|
38
41
|
|