dd-trace 5.136.0 → 5.138.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/index.d.ts +56 -0
- package/initialize.mjs +5 -3
- package/package.json +36 -32
- package/packages/datadog-esbuild/index.js +8 -15
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +88 -122
- package/packages/datadog-instrumentations/src/aws-lambda.js +9 -0
- 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/hooks.js +0 -1
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +12 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +5 -3
- 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 +32 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +43 -0
- package/packages/datadog-instrumentations/src/next.js +184 -20
- package/packages/datadog-instrumentations/src/path-to-regexp.js +11 -11
- package/packages/datadog-instrumentations/src/router.js +52 -13
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1 -1
- 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/context/events.js +167 -0
- package/packages/datadog-plugin-aws-lambda/src/context/extractor.js +153 -0
- package/packages/datadog-plugin-aws-lambda/src/context/http.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/context/span-context.js +26 -0
- package/packages/datadog-plugin-aws-lambda/src/context/step-functions.js +142 -0
- package/packages/datadog-plugin-aws-lambda/src/context/types.d.ts +17 -0
- package/packages/datadog-plugin-aws-lambda/src/context/xray.js +67 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +52 -4
- 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-azure-functions/src/index.js +68 -12
- 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-fetch/src/index.js +7 -0
- 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 +14 -1
- package/packages/datadog-plugin-http/src/server.js +18 -4
- 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/client.js +7 -9
- package/packages/dd-trace/src/aiguard/evaluation.js +7 -2
- 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/aiguard/messages/utils.js +2 -2
- package/packages/dd-trace/src/aiguard/sdk.js +7 -2
- package/packages/dd-trace/src/appsec/api_security/normalized-route.js +273 -167
- package/packages/dd-trace/src/appsec/blocking/index.js +17 -1
- package/packages/dd-trace/src/appsec/channels.js +8 -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/iast/taint-tracking/plugin.js +21 -14
- package/packages/dd-trace/src/appsec/index.js +9 -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 +64 -3
- 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 +47 -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/carrier.js +7 -1
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +4 -2
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +31 -19
- package/packages/dd-trace/src/config/generated-config-types.d.ts +14 -5
- package/packages/dd-trace/src/config/index.js +73 -27
- package/packages/dd-trace/src/config/parsers.js +60 -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 +41 -13
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/http.js +57 -0
- package/packages/dd-trace/src/datastreams/index.js +24 -0
- package/packages/dd-trace/src/datastreams/pathway.js +142 -28
- package/packages/dd-trace/src/datastreams/processor.js +27 -7
- 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/lambda/handler-paths.js +1 -1
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +86 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +182 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +3 -0
- package/packages/dd-trace/src/llmobs/tagger.js +9 -0
- package/packages/dd-trace/src/noop/span.js +0 -4
- 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/openfeature/flagging_provider.js +17 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +16 -1
- package/packages/dd-trace/src/opentelemetry/trace/index.js +5 -4
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -6
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +42 -26
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +4 -4
- package/packages/dd-trace/src/plugin_manager.js +2 -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/inferred_proxy.js +3 -5
- package/packages/dd-trace/src/plugins/util/test.js +28 -1
- package/packages/dd-trace/src/plugins/util/url.js +9 -6
- 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/packages/dd-trace/src/register-loader.js +43 -0
- package/register.js +10 -44
- package/register.mjs +27 -0
- 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,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
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const fs = require('node:fs')
|
|
4
|
+
const path = require('node:path')
|
|
5
|
+
|
|
6
|
+
const { getEnvironmentVariable } = require('../../dd-trace/src/config/helper')
|
|
7
|
+
const log = require('../../dd-trace/src/log')
|
|
3
8
|
const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
|
|
4
9
|
const web = require('../../dd-trace/src/plugins/util/web')
|
|
5
10
|
const { getIsAzureContainerApp } = require('../../dd-trace/src/serverless')
|
|
@@ -24,6 +29,9 @@ class AzureFunctionsPlugin extends TracingPlugin {
|
|
|
24
29
|
static type = 'serverless'
|
|
25
30
|
static prefix = 'tracing:datadog:azure:functions:invoke'
|
|
26
31
|
|
|
32
|
+
/** @type {string | undefined} */
|
|
33
|
+
#routePrefix
|
|
34
|
+
|
|
27
35
|
bindStart (ctx) {
|
|
28
36
|
const meta = getMetaForTrigger(ctx)
|
|
29
37
|
const triggerType = triggerMap[ctx.methodName]
|
|
@@ -34,7 +42,8 @@ class AzureFunctionsPlugin extends TracingPlugin {
|
|
|
34
42
|
|
|
35
43
|
if (isHttpTrigger) {
|
|
36
44
|
const { httpRequest } = ctx
|
|
37
|
-
const
|
|
45
|
+
const url = new URL(httpRequest.url)
|
|
46
|
+
const path = url.pathname
|
|
38
47
|
const req = {
|
|
39
48
|
method: httpRequest.method,
|
|
40
49
|
headers: Object.fromEntries(httpRequest.headers),
|
|
@@ -42,21 +51,40 @@ class AzureFunctionsPlugin extends TracingPlugin {
|
|
|
42
51
|
}
|
|
43
52
|
// Patch the request to create web context
|
|
44
53
|
const webContext = web.patch(req)
|
|
45
|
-
|
|
46
|
-
webContext.tracer = this.tracer
|
|
47
|
-
webContext.paths = [path]
|
|
54
|
+
const operationName = this.operationName()
|
|
48
55
|
// Creates a standard span and an inferred proxy span if headers are present
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if (this.config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
|
|
57
|
+
req.headers.host = url.host
|
|
58
|
+
req.url = path + getTraceQuery(url)
|
|
59
|
+
req.socket = { encrypted: url.protocol === 'https:' }
|
|
60
|
+
span = web.startSpan(
|
|
61
|
+
this.tracer,
|
|
62
|
+
this.config,
|
|
63
|
+
req,
|
|
64
|
+
undefined,
|
|
65
|
+
operationName,
|
|
66
|
+
ctx
|
|
67
|
+
)
|
|
68
|
+
const route = ctx.invocationContext.options.trigger.route?.trim() || ctx.functionName
|
|
69
|
+
const prefix = this.#routePrefix ??= getRoutePrefix()
|
|
70
|
+
web.setRoute(req, prefix + (route.startsWith('/') ? route : `/${route}`))
|
|
71
|
+
} else {
|
|
72
|
+
webContext.config = this.config
|
|
73
|
+
webContext.tracer = this.tracer
|
|
74
|
+
webContext.paths = [path]
|
|
75
|
+
span = web.startServerlessSpanWithInferredProxy(
|
|
76
|
+
this.tracer,
|
|
77
|
+
this.config,
|
|
78
|
+
operationName,
|
|
79
|
+
req,
|
|
80
|
+
ctx
|
|
81
|
+
)
|
|
82
|
+
webContext.span = span
|
|
83
|
+
}
|
|
84
|
+
|
|
56
85
|
span._integrationName = 'azure-functions'
|
|
57
86
|
span.context().setTag('component', 'azure-functions')
|
|
58
87
|
span.addTags(meta)
|
|
59
|
-
webContext.span = span
|
|
60
88
|
webContext.azureFunctionCtx = ctx
|
|
61
89
|
ctx.webContext = webContext
|
|
62
90
|
} else {
|
|
@@ -101,6 +129,34 @@ class AzureFunctionsPlugin extends TracingPlugin {
|
|
|
101
129
|
}
|
|
102
130
|
}
|
|
103
131
|
|
|
132
|
+
function getRoutePrefix () {
|
|
133
|
+
let prefix = getEnvironmentVariable('AzureFunctionsJobHost__extensions__http__routePrefix')
|
|
134
|
+
if (prefix === undefined) {
|
|
135
|
+
try {
|
|
136
|
+
const root = getEnvironmentVariable('AzureWebJobsScriptRoot') || process.cwd()
|
|
137
|
+
const contents = fs.readFileSync(path.join(root, 'host.json'), 'utf8')
|
|
138
|
+
prefix = JSON.parse(contents.replace(/^\uFEFF/, '')).extensions?.http?.routePrefix ?? 'api'
|
|
139
|
+
} catch (error) {
|
|
140
|
+
log.debug('Cannot determine Azure Functions route prefix: %s', error.code || error.name)
|
|
141
|
+
return ''
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return typeof prefix === 'string' && prefix ? `/${prefix}` : ''
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {URL} url
|
|
149
|
+
*/
|
|
150
|
+
function getTraceQuery (url) {
|
|
151
|
+
const search = url.search
|
|
152
|
+
if (search) {
|
|
153
|
+
for (const name of url.searchParams.keys()) {
|
|
154
|
+
if (name.toLowerCase() === 'code') return ''
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return search
|
|
158
|
+
}
|
|
159
|
+
|
|
104
160
|
function getMetaForTrigger ({ functionName, methodName, invocationContext }) {
|
|
105
161
|
const prefix = getIsAzureContainerApp() ? 'aca' : 'aas'
|
|
106
162
|
|
|
@@ -100,7 +100,10 @@ const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
|
|
|
100
100
|
const { RESOURCE_NAME } = require('../../../ext/tags')
|
|
101
101
|
const getConfig = require('../../dd-trace/src/config')
|
|
102
102
|
const { getRepositoryRoot } = require('../../dd-trace/src/plugins/util/git')
|
|
103
|
-
const {
|
|
103
|
+
const {
|
|
104
|
+
getUserProviderGitMetadata,
|
|
105
|
+
validateGitCommitSha,
|
|
106
|
+
} = require('../../dd-trace/src/plugins/util/user-provided-git')
|
|
104
107
|
const { getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
|
|
105
108
|
const {
|
|
106
109
|
SCREENSHOT_UPLOAD_RESULT_ERROR,
|
|
@@ -372,7 +375,8 @@ function getModifiedFiles (testEnvironmentMetadata, gitRoot) {
|
|
|
372
375
|
[GIT_PULL_REQUEST_BASE_BRANCH_SHA]: pullRequestBaseBranchSha,
|
|
373
376
|
[GIT_COMMIT_HEAD_SHA]: commitHeadSha,
|
|
374
377
|
} = diffMetadata
|
|
375
|
-
const
|
|
378
|
+
const commitSha = testEnvironmentMetadata[GIT_COMMIT_SHA]
|
|
379
|
+
const targetCommit = commitHeadSha || (isCustomCheckout && validateGitCommitSha(commitSha) ? commitSha : undefined)
|
|
376
380
|
|
|
377
381
|
const baseBranchSha = pullRequestBaseBranchSha || getPullRequestBaseBranch(pullRequestBaseBranch, gitRoot)
|
|
378
382
|
|
|
@@ -522,6 +526,12 @@ function reconcileNativeRetries (native, baseline, configured, actual) {
|
|
|
522
526
|
|
|
523
527
|
class CypressPlugin {
|
|
524
528
|
#pendingTestSuiteSpans = new Map()
|
|
529
|
+
// Cypress 16.3.0+ runs every after:spec handler, including user handlers that forward to the
|
|
530
|
+
// legacy helper after the plugin's own handler, so each spec execution is finalized once.
|
|
531
|
+
#specFinalizations = new WeakMap()
|
|
532
|
+
// Cypress 16.3.0+ also runs user after:screenshot handlers after the plugin's, so a renamed screenshot
|
|
533
|
+
// reaches after:spec under a new path. Its capture time still identifies the uploaded screenshot.
|
|
534
|
+
#uploadedScreenshotCaptures = new Set()
|
|
525
535
|
|
|
526
536
|
_isInit = false
|
|
527
537
|
testEnvironmentMetadata = getTestEnvironmentMetadata(TEST_FRAMEWORK_NAME)
|
|
@@ -600,7 +610,8 @@ class CypressPlugin {
|
|
|
600
610
|
|
|
601
611
|
this.testConfiguration = {
|
|
602
612
|
repositoryUrl,
|
|
603
|
-
sha,
|
|
613
|
+
// The `git.commit.sha` tag reports malformed values as provided, but they must not select backend data.
|
|
614
|
+
sha: validateGitCommitSha(sha) ? sha : undefined,
|
|
604
615
|
gitRoot: this.repositoryRoot,
|
|
605
616
|
osVersion,
|
|
606
617
|
osPlatform,
|
|
@@ -670,6 +681,7 @@ class CypressPlugin {
|
|
|
670
681
|
this.attemptToFixExecutions = new Map()
|
|
671
682
|
this.loggedAttemptToFixTests = new Set()
|
|
672
683
|
this.uploadedScreenshotPaths = new Set()
|
|
684
|
+
this.#uploadedScreenshotCaptures = new Set()
|
|
673
685
|
this.uploadedVideoPaths = new Set()
|
|
674
686
|
this.pendingVideoUploads = []
|
|
675
687
|
this.screenshotUploadPromisesByTraceId = new Map()
|
|
@@ -1719,6 +1731,17 @@ class CypressPlugin {
|
|
|
1719
1731
|
}
|
|
1720
1732
|
|
|
1721
1733
|
afterSpec (spec, results, error, finishTime) {
|
|
1734
|
+
// Cypress passes the same results object to every chained handler for one spec execution,
|
|
1735
|
+
// while each execution, including an interactive rerun, receives a new one.
|
|
1736
|
+
if (results && this.#specFinalizations.has(results)) {
|
|
1737
|
+
return this.#specFinalizations.get(results)
|
|
1738
|
+
}
|
|
1739
|
+
const finalization = this.#afterSpec(spec, results, error, finishTime)
|
|
1740
|
+
if (results) this.#specFinalizations.set(results, finalization)
|
|
1741
|
+
return finalization
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
#afterSpec (spec, results, error, finishTime) {
|
|
1722
1745
|
const { tests, stats, screenshots, video, error: resultError } = results || {}
|
|
1723
1746
|
const cypressTests = tests || []
|
|
1724
1747
|
if (cypressTests.length > 0 || stats?.tests > 0) this.hasTestsReported = true
|
|
@@ -2113,10 +2136,13 @@ class CypressPlugin {
|
|
|
2113
2136
|
|
|
2114
2137
|
for (const screenshot of screenshots) {
|
|
2115
2138
|
const filePath = getScreenshotFilePath(screenshot)
|
|
2116
|
-
|
|
2139
|
+
const takenAt = screenshot !== null && typeof screenshot === 'object' ? screenshot.takenAt : undefined
|
|
2140
|
+
const captureKey = takenAt ? `${traceId}:${takenAt}` : undefined
|
|
2141
|
+
if (!filePath || this.uploadedScreenshotPaths.has(filePath) || this.#uploadedScreenshotCaptures.has(captureKey)) {
|
|
2117
2142
|
continue
|
|
2118
2143
|
}
|
|
2119
2144
|
this.uploadedScreenshotPaths.add(filePath)
|
|
2145
|
+
if (captureKey) this.#uploadedScreenshotCaptures.add(captureKey)
|
|
2120
2146
|
// Stable per-artifact key (trace + filename) so an upload retry overwrites the
|
|
2121
2147
|
// same stored object instead of duplicating; the Cypress filename encodes the
|
|
2122
2148
|
// test name and attempt, so it is unique within the trace.
|