dd-trace 6.25.0 → 6.27.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.
Files changed (190) hide show
  1. package/README.md +3 -0
  2. package/ci/cypress/support.js +2 -1
  3. package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
  4. package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
  5. package/ci/vitest-no-worker-init-setup.mjs +729 -724
  6. package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
  7. package/index.d.ts +58 -1
  8. package/initialize.mjs +5 -3
  9. package/package.json +36 -32
  10. package/packages/datadog-esbuild/index.js +8 -15
  11. package/packages/datadog-esbuild/src/log.js +2 -29
  12. package/packages/datadog-instrumentations/src/ai.js +88 -122
  13. package/packages/datadog-instrumentations/src/aws-lambda.js +9 -0
  14. package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
  15. package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +23 -1
  16. package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +9 -6
  18. package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
  19. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  20. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -3
  21. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +6 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +12 -1
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +2 -0
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +5 -3
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +21 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +30 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +6 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
  32. package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
  33. package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
  34. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +32 -2
  35. package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +43 -0
  36. package/packages/datadog-instrumentations/src/next.js +184 -20
  37. package/packages/datadog-instrumentations/src/path-to-regexp.js +11 -11
  38. package/packages/datadog-instrumentations/src/router.js +52 -13
  39. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1 -1
  40. package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
  41. package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
  42. package/packages/datadog-plugin-aws-lambda/src/context/events.js +167 -0
  43. package/packages/datadog-plugin-aws-lambda/src/context/extractor.js +153 -0
  44. package/packages/datadog-plugin-aws-lambda/src/context/http.js +50 -0
  45. package/packages/datadog-plugin-aws-lambda/src/context/span-context.js +26 -0
  46. package/packages/datadog-plugin-aws-lambda/src/context/step-functions.js +142 -0
  47. package/packages/datadog-plugin-aws-lambda/src/context/types.d.ts +17 -0
  48. package/packages/datadog-plugin-aws-lambda/src/context/xray.js +67 -0
  49. package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
  50. package/packages/datadog-plugin-aws-lambda/src/index.js +52 -4
  51. package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
  52. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
  53. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
  54. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
  55. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
  56. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
  57. package/packages/datadog-plugin-azure-functions/src/index.js +68 -12
  58. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +30 -4
  59. package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
  60. package/packages/datadog-plugin-express/src/code_origin.js +2 -2
  61. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  62. package/packages/datadog-plugin-fetch/src/index.js +7 -0
  63. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -0
  64. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -0
  65. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +7 -0
  66. package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
  67. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  68. package/packages/datadog-plugin-http/src/client.js +14 -1
  69. package/packages/datadog-plugin-http/src/server.js +18 -4
  70. package/packages/datadog-plugin-http2/src/client.js +2 -1
  71. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
  72. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
  73. package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
  74. package/packages/datadog-plugin-postgres/src/index.js +118 -41
  75. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
  76. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
  77. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
  78. package/packages/datadog-plugin-vitest/src/index.js +3 -2
  79. package/packages/datadog-plugin-ws/src/close.js +3 -5
  80. package/packages/datadog-plugin-ws/src/producer.js +1 -4
  81. package/packages/datadog-plugin-ws/src/receiver.js +3 -5
  82. package/packages/datadog-plugin-ws/src/server.js +44 -13
  83. package/packages/datadog-vite/index.js +537 -0
  84. package/packages/datadog-vite/src/log.js +5 -0
  85. package/packages/datadog-webpack/src/log.js +2 -29
  86. package/packages/dd-trace/src/aiguard/client.js +7 -9
  87. package/packages/dd-trace/src/aiguard/evaluation.js +7 -2
  88. package/packages/dd-trace/src/aiguard/index.js +1 -1
  89. package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
  90. package/packages/dd-trace/src/aiguard/messages/utils.js +2 -2
  91. package/packages/dd-trace/src/aiguard/sdk.js +7 -2
  92. package/packages/dd-trace/src/appsec/api_security/normalized-route.js +273 -167
  93. package/packages/dd-trace/src/appsec/blocking/index.js +17 -1
  94. package/packages/dd-trace/src/appsec/channels.js +8 -0
  95. package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
  96. package/packages/dd-trace/src/appsec/graphql.js +10 -13
  97. package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
  98. package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
  99. package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
  100. package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
  101. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +21 -14
  102. package/packages/dd-trace/src/appsec/index.js +9 -0
  103. package/packages/dd-trace/src/appsec/lambda.js +17 -17
  104. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
  105. package/packages/dd-trace/src/appsec/rasp/index.js +64 -3
  106. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
  107. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
  108. package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
  109. package/packages/dd-trace/src/appsec/rasp/utils.js +47 -3
  110. package/packages/dd-trace/src/appsec/recommended.json +70 -3
  111. package/packages/dd-trace/src/appsec/reporter.js +9 -0
  112. package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
  113. package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
  114. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  115. package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
  116. package/packages/dd-trace/src/appsec/waf/index.js +65 -6
  117. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
  118. package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
  119. package/packages/dd-trace/src/carrier.js +7 -1
  120. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +4 -2
  121. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +31 -19
  122. package/packages/dd-trace/src/config/generated-config-types.d.ts +14 -5
  123. package/packages/dd-trace/src/config/index.js +73 -27
  124. package/packages/dd-trace/src/config/parsers.js +60 -0
  125. package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
  126. package/packages/dd-trace/src/config/remote_config.js +2 -1
  127. package/packages/dd-trace/src/config/supported-configurations.json +41 -13
  128. package/packages/dd-trace/src/datastreams/fnv.js +27 -0
  129. package/packages/dd-trace/src/datastreams/http.js +57 -0
  130. package/packages/dd-trace/src/datastreams/index.js +24 -0
  131. package/packages/dd-trace/src/datastreams/pathway.js +142 -28
  132. package/packages/dd-trace/src/datastreams/processor.js +27 -7
  133. package/packages/dd-trace/src/debugger/config.js +1 -1
  134. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
  135. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  136. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  137. package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
  138. package/packages/dd-trace/src/debugger/index.js +2 -2
  139. package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
  140. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +4 -1
  141. package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
  142. package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
  143. package/packages/dd-trace/src/git_metadata.js +2 -1
  144. package/packages/dd-trace/src/index.js +6 -3
  145. package/packages/dd-trace/src/lambda/facade.js +6 -5
  146. package/packages/dd-trace/src/lambda/handler-paths.js +1 -1
  147. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  148. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +86 -3
  149. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +182 -1
  150. package/packages/dd-trace/src/llmobs/span_processor.js +3 -0
  151. package/packages/dd-trace/src/llmobs/tagger.js +9 -0
  152. package/packages/dd-trace/src/noop/span.js +0 -4
  153. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +3 -0
  154. package/packages/dd-trace/src/openfeature/configuration_source.js +20 -0
  155. package/packages/dd-trace/src/openfeature/flagging_provider.js +17 -0
  156. package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +2 -1
  157. package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +2 -1
  158. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +16 -1
  159. package/packages/dd-trace/src/opentelemetry/trace/index.js +5 -4
  160. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -6
  161. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +42 -26
  162. package/packages/dd-trace/src/opentracing/propagation/text_map.js +4 -4
  163. package/packages/dd-trace/src/plugin_manager.js +2 -0
  164. package/packages/dd-trace/src/plugins/ci_plugin.js +104 -9
  165. package/packages/dd-trace/src/plugins/index.js +2 -0
  166. package/packages/dd-trace/src/plugins/util/ci.js +34 -0
  167. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +9 -14
  168. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +3 -5
  169. package/packages/dd-trace/src/plugins/util/test.js +28 -1
  170. package/packages/dd-trace/src/plugins/util/url.js +9 -6
  171. package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -4
  172. package/packages/dd-trace/src/process-tags/index.js +1 -1
  173. package/packages/dd-trace/src/profiler.js +74 -12
  174. package/packages/dd-trace/src/profiling/profiler.js +30 -2
  175. package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
  176. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  177. package/packages/dd-trace/src/profiling/remote-config.js +354 -0
  178. package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
  179. package/packages/dd-trace/src/propagation-hash/index.js +7 -0
  180. package/packages/dd-trace/src/proxy.js +13 -1
  181. package/packages/dd-trace/src/register-loader.js +43 -0
  182. package/register.js +10 -44
  183. package/register.mjs +27 -0
  184. package/vendor/dist/@opentelemetry/core/LICENSE +11 -0
  185. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  186. package/vite.d.ts +7 -0
  187. package/vite.js +3 -0
  188. package/lambda.d.ts +0 -39
  189. package/lambda.js +0 -3
  190. package/packages/datadog-plugin-cypress/src/support.js +0 -1348
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const OtlpTransformerBase = require('../otlp/otlp_transformer_base')
4
+ const { isInt64 } = require('../otlp/otlp_transformer_base')
4
5
  const { getProtobufTypes } = require('../otlp/protobuf_loader')
5
6
  const { AUTO_KEEP } = require('../../../../../ext/priority')
6
7
  const { VERSION } = require('../../../../../version')
@@ -8,7 +9,7 @@ const { SAMPLING_PRIORITY_KEY } = require('../../constants')
8
9
  const id = require('../../id')
9
10
  const { eventTimeNano } = require('../../encode/tags-processors')
10
11
 
11
- const { protoSpanKind } = getProtobufTypes()
12
+ const { protoSpanKind, protoTraceService } = getProtobufTypes()
12
13
  const SPAN_KIND_UNSPECIFIED = protoSpanKind.values.SPAN_KIND_UNSPECIFIED
13
14
  const SPAN_KIND_INTERNAL = protoSpanKind.values.SPAN_KIND_INTERNAL
14
15
  const SPAN_KIND_SERVER = protoSpanKind.values.SPAN_KIND_SERVER
@@ -81,18 +82,19 @@ const EXCLUDED_META_KEYS = new Set([
81
82
  const DD_ERROR_META_KEYS = new Set(['error.message'])
82
83
 
83
84
  /**
84
- * OtlpTraceTransformer transforms DD-formatted spans to OTLP trace JSON format.
85
+ * OtlpTraceTransformer transforms DD-formatted spans to OTLP trace format.
85
86
  *
86
87
  * This implementation follows the OTLP trace data model:
87
88
  * https://github.com/open-telemetry/opentelemetry-proto/blob/v1.7.0/opentelemetry/proto/trace/v1/trace.proto
88
89
  *
89
90
  * It receives DD-formatted spans (from span_format.js) and produces
90
- * an ExportTraceServiceRequest serialized as JSON (http/json protocol only).
91
+ * an ExportTraceServiceRequest serialized as JSON (http/json) or protobuf (http/protobuf).
91
92
  *
92
93
  * @class OtlpTraceTransformer
93
94
  * @augments OtlpTransformerBase
94
95
  */
95
96
  class OtlpTraceTransformer extends OtlpTransformerBase {
97
+ #isJson
96
98
  #otelTraceSemanticsEnabled
97
99
 
98
100
  // Span meta entries with the same key and value as a resource attribute are already carried by
@@ -104,10 +106,12 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
104
106
  * Creates a new OtlpTraceTransformer instance.
105
107
  *
106
108
  * @param {import('@opentelemetry/api').Attributes} resourceAttributes - Resource attributes
109
+ * @param {string} protocol - OTLP protocol (http/protobuf or http/json)
107
110
  * @param {boolean} [otelTraceSemanticsEnabled] - When true, do not emit Datadog-only attributes as span attributes
108
111
  */
109
- constructor (resourceAttributes, otelTraceSemanticsEnabled) {
110
- super(resourceAttributes, 'http/json', 'traces')
112
+ constructor (resourceAttributes, protocol, otelTraceSemanticsEnabled) {
113
+ super(resourceAttributes, protocol, 'traces')
114
+ this.#isJson = this.protocol === 'http/json'
111
115
  this.#otelTraceSemanticsEnabled = otelTraceSemanticsEnabled
112
116
  this.#resourceAttributes = resourceAttributes
113
117
  }
@@ -122,10 +126,10 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
122
126
  }
123
127
 
124
128
  /**
125
- * Transforms DD-formatted spans to OTLP JSON format.
129
+ * Transforms DD-formatted spans to OTLP format based on the configured protocol.
126
130
  *
127
131
  * @param {DDFormattedSpan[]} spans - Array of DD-formatted spans to transform
128
- * @returns {Buffer} JSON-encoded trace data
132
+ * @returns {Buffer} JSON- or protobuf-encoded trace data
129
133
  */
130
134
  transformSpans (spans) {
131
135
  const traceData = {
@@ -134,7 +138,9 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
134
138
  scopeSpans: this.#transformScopeSpans(spans),
135
139
  }],
136
140
  }
137
- return this.serializeToJson(traceData)
141
+ return this.#isJson
142
+ ? this.serializeToJson(traceData)
143
+ : this.serializeToProtobuf(protoTraceService, traceData)
138
144
  }
139
145
 
140
146
  /**
@@ -182,9 +188,9 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
182
188
  const samplingPriority = span.metrics?.[SAMPLING_PRIORITY_KEY]
183
189
 
184
190
  return {
185
- traceId: span.trace_id.toTraceIdHex(traceIdHigh).padStart(32, '0'),
186
- spanId: this.#spanIdToHex(span.span_id),
187
- parentSpanId: parentId && !parentId.equals(ZERO_ID) ? this.#spanIdToHex(parentId) : undefined,
191
+ traceId: this.#encodeId(span.trace_id.toTraceIdHex(traceIdHigh).padStart(32, '0')),
192
+ spanId: this.#encodeSpanId(span.span_id),
193
+ parentSpanId: parentId && !parentId.equals(ZERO_ID) ? this.#encodeSpanId(parentId) : undefined,
188
194
  traceState: span.trace_state,
189
195
  name: span.resource,
190
196
  kind: this.#mapSpanKind(span.meta?.['span.kind']),
@@ -245,7 +251,7 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
245
251
  // Add metrics as numeric attributes
246
252
  if (span.metrics) {
247
253
  for (const [key, value] of Object.entries(span.metrics)) {
248
- if (Number.isInteger(value)) {
254
+ if (isInt64(value)) {
249
255
  attributes.push({ key, value: { intValue: value } })
250
256
  } else {
251
257
  attributes.push({ key, value: { doubleValue: value } })
@@ -253,14 +259,14 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
253
259
  }
254
260
  }
255
261
 
256
- // TODO: meta_struct values are logically raw bytes. The OTLP http/json spec encodes the bytesValue
257
- // field as base64, but when http/protobuf or gRPC support is added the payload should be sent as
258
- // raw bytes directly (no JSON.stringify + base64). The backend decoding side will need to be
259
- // updated in parallel to accept the unencoded bytes.
262
+ // meta_struct values carry their JSON serialization so receivers decode the same bytes for every
263
+ // protocol; only http/json additionally base64-encodes bytesValue, per the proto JSON mapping.
264
+ // TODO: meta_struct values are logically raw bytes. Sending them without JSON.stringify requires
265
+ // the backend decoding side to accept the unencoded bytes first.
260
266
  if (span.meta_struct) {
261
267
  for (const [key, value] of Object.entries(span.meta_struct)) {
262
268
  const bytes = Buffer.from(JSON.stringify(value))
263
- attributes.push({ key, value: { bytesValue: bytes.toString('base64') } })
269
+ attributes.push({ key, value: { bytesValue: this.#isJson ? bytes.toString('base64') : bytes } })
264
270
  }
265
271
  }
266
272
 
@@ -352,8 +358,8 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
352
358
  */
353
359
  #transformLink (link) {
354
360
  return {
355
- traceId: this.#hexToBytes(link.trace_id, 16),
356
- spanId: this.#hexToBytes(link.span_id, 8),
361
+ traceId: this.#encodeHexId(link.trace_id, 16),
362
+ spanId: this.#encodeHexId(link.span_id, 8),
357
363
  traceState: link.tracestate || '',
358
364
  attributes: this.transformAttributes(link.attributes ?? {}),
359
365
  droppedAttributesCount: 0,
@@ -362,22 +368,32 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
362
368
  }
363
369
 
364
370
  /** @param {Identifier} identifier */
365
- #spanIdToHex (identifier) {
366
- return identifier.toString(16).slice(-16)
371
+ #encodeSpanId (identifier) {
372
+ return this.#encodeId(identifier.toString(16).slice(-16))
367
373
  }
368
374
 
369
375
  /**
370
- * Normalizes a hex string to the specified byte length.
376
+ * Normalizes a hex string to the specified byte length, then encodes it for the wire.
371
377
  * Pads with leading zeros if the hex string is shorter than expected.
372
- * Per the OTLP http/json spec, trace-ids and span-ids must be hex-encoded strings.
373
378
  *
374
379
  * @param {string | undefined} hexString - Hex string to normalize
375
380
  * @param {number} targetLength - Target byte length
376
381
  */
377
- #hexToBytes (hexString, targetLength) {
378
- if (!hexString) return '0'.repeat(targetLength * 2)
382
+ #encodeHexId (hexString, targetLength) {
383
+ if (!hexString) return this.#encodeId('0'.repeat(targetLength * 2))
379
384
  const cleanHex = hexString.startsWith('0x') ? hexString.slice(2) : hexString
380
- return cleanHex.padStart(targetLength * 2, '0')
385
+ return this.#encodeId(cleanHex.padStart(targetLength * 2, '0'))
386
+ }
387
+
388
+ /**
389
+ * Encodes a trace or span ID. OTLP http/json requires hex-encoded strings instead of the
390
+ * base64 the proto JSON mapping would use for bytes; http/protobuf carries the raw bytes.
391
+ *
392
+ * @param {string} hex - Hex-encoded ID
393
+ * @returns {string | Buffer}
394
+ */
395
+ #encodeId (hex) {
396
+ return this.#isJson ? hex : Buffer.from(hex, 'hex')
381
397
  }
382
398
  }
383
399
 
@@ -333,8 +333,8 @@ class TextMapPropagator {
333
333
  this.#b3InjectIsSingleHeader = true
334
334
  this.#extractB3Context = extractB3SingleContext
335
335
  } else {
336
- const envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE')
337
- // eslint-disable-next-line eslint-rules/eslint-env-aliases
336
+ const envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE') ??
337
+ getValidatedConfiguredEnvName('OTEL_PROPAGATORS')
338
338
  this.#extractB3Context = envName === 'OTEL_PROPAGATORS'
339
339
  ? extractB3SingleContext
340
340
  : extractB3MultiContext
@@ -355,13 +355,13 @@ class TextMapPropagator {
355
355
 
356
356
  let envName
357
357
  if (origin === 'calculated' && !experimentalEnabled && sharedOrigin !== 'remote_config') {
358
- envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE')
358
+ envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE') ??
359
+ getValidatedConfiguredEnvName('OTEL_PROPAGATORS')
359
360
  } else if (origin === 'env_var' ||
360
361
  origin === 'local_stable_config' ||
361
362
  origin === 'fleet_stable_config') {
362
363
  envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE_INJECT')
363
364
  }
364
- // eslint-disable-next-line eslint-rules/eslint-env-aliases
365
365
  this.#b3InjectIsSingleHeader = envName === 'OTEL_PROPAGATORS'
366
366
  this.#b3InjectOrigin = origin
367
367
  this.#b3ExperimentalEnabled = experimentalEnabled
@@ -190,6 +190,7 @@ module.exports = class PluginManager {
190
190
  codeOriginForSpans,
191
191
  dbmPropagationMode,
192
192
  dsmEnabled,
193
+ DD_DATA_STREAMS_HTTP_ENABLED,
193
194
  DD_TRACE_HTTP_CLIENT_ERROR_STATUSES,
194
195
  DD_TRACE_HTTP_SERVER_ERROR_STATUSES,
195
196
  clientIpEnabled,
@@ -219,6 +220,7 @@ module.exports = class PluginManager {
219
220
  codeOriginForSpans,
220
221
  dbmPropagationMode,
221
222
  dsmEnabled,
223
+ DD_DATA_STREAMS_HTTP_ENABLED,
222
224
  DD_TRACE_MEMCACHED_COMMAND_ENABLED,
223
225
  DD_TRACE_OTEL_SEMANTICS_ENABLED,
224
226
  site,
@@ -52,7 +52,7 @@ const REPOSITORY_METADATA_KEYS = [
52
52
 
53
53
  const Plugin = require('./plugin')
54
54
  const { getRepositoryRoot } = require('./util/git')
55
- const { getUserProviderGitMetadata } = require('./util/user-provided-git')
55
+ const { getUserProviderGitMetadata, validateGitCommitSha } = require('./util/user-provided-git')
56
56
  const {
57
57
  getTestEnvironmentMetadata,
58
58
  getTestLevelsMetadataTags,
@@ -86,6 +86,7 @@ const {
86
86
  TEST_SUITE_EXECUTION_ID,
87
87
  getTestSuiteExecutionKey,
88
88
  getFileAndLineNumberFromError,
89
+ getNonDependencyStackFramesFromError,
89
90
  DI_ERROR_DEBUG_INFO_CAPTURED,
90
91
  DI_DEBUG_ERROR_PREFIX,
91
92
  DI_DEBUG_ERROR_SNAPSHOT_ID_SUFFIX,
@@ -115,9 +116,19 @@ const {
115
116
 
116
117
  const legacyStorage = storage('legacy')
117
118
  const DI_OPERATION_TIMEOUT_MS = 2000
119
+ const DI_STACK_FRAMES_TO_COMPARE = 2
120
+ const DI_CALLER_FRAME_LINE_TOLERANCE = 2
118
121
  const DI_LOGGER_THREAD_ID = threadId === 0 ? `pid:${process.pid}` : `pid:${process.pid};tid:${threadId}`
119
122
  const DI_LOGGER_THREAD_NAME = threadId === 0 ? 'MainThread' : `WorkerThread:${threadId}`
120
123
 
124
+ const DI_SNAPSHOT_DEPENDENCY_FOLDERS = [
125
+ 'node_modules',
126
+ 'node:',
127
+ '.pnpm',
128
+ '.yarn',
129
+ '.pnp',
130
+ ]
131
+
121
132
  const FRAMEWORK_TO_TRIMMED_COMMAND = {
122
133
  vitest: 'vitest run',
123
134
  mocha: 'mocha',
@@ -200,6 +211,32 @@ function disableTestImpactAnalysis (libraryConfig) {
200
211
  })
201
212
  }
202
213
 
214
+ function normalizeSnapshotFileName (fileName) {
215
+ return fileName.startsWith('file://') ? fileName.slice('file://'.length) : fileName
216
+ }
217
+
218
+ function getNonDependencySnapshotStackFrames (snapshot, repositoryRoot) {
219
+ if (!snapshot.stack) {
220
+ return []
221
+ }
222
+
223
+ const frames = []
224
+ for (const frame of snapshot.stack) {
225
+ if (!frame || typeof frame.fileName !== 'string' || !Number.isInteger(frame.lineNumber)) {
226
+ continue
227
+ }
228
+
229
+ const file = normalizeSnapshotFileName(frame.fileName)
230
+ if (!file.includes(repositoryRoot) || DI_SNAPSHOT_DEPENDENCY_FOLDERS.some(pattern => file.includes(pattern))) {
231
+ continue
232
+ }
233
+
234
+ frames.push({ file, line: frame.lineNumber })
235
+ }
236
+
237
+ return frames
238
+ }
239
+
203
240
  module.exports = class CiPlugin extends Plugin {
204
241
  constructor (...args) {
205
242
  super(...args)
@@ -207,6 +244,8 @@ module.exports = class CiPlugin extends Plugin {
207
244
  this.fileLineToProbeId = new Map()
208
245
  this.diBreakpointHitPromise = undefined
209
246
  this.diBreakpointHitResolvers = []
247
+ this.diBreakpointHitSpans = []
248
+ this.testErrorStackFrames = []
210
249
  this.rootDir = process.cwd() // fallback in case :session:start events are not emitted
211
250
  this._testSuiteSpansByTestSuite = new Map()
212
251
  this._pendingWorkerTracesByTestSuite = new Map()
@@ -444,8 +483,9 @@ module.exports = class CiPlugin extends Plugin {
444
483
  [GIT_PULL_REQUEST_BASE_BRANCH_SHA]: pullRequestBaseBranchSha,
445
484
  [GIT_COMMIT_HEAD_SHA]: commitHeadSha,
446
485
  } = diffMetadata
486
+ const commitSha = this.testEnvironmentMetadata[GIT_COMMIT_SHA]
447
487
  const targetCommit = commitHeadSha ||
448
- (isCustomCheckout ? this.testEnvironmentMetadata[GIT_COMMIT_SHA] : undefined)
488
+ (isCustomCheckout && validateGitCommitSha(commitSha) ? commitSha : undefined)
449
489
 
450
490
  const baseBranchSha = pullRequestBaseBranchSha ||
451
491
  getPullRequestBaseBranch(pullRequestBaseBranch, this.repositoryRoot)
@@ -855,7 +895,8 @@ module.exports = class CiPlugin extends Plugin {
855
895
 
856
896
  this.testConfiguration = {
857
897
  repositoryUrl,
858
- sha,
898
+ // The `git.commit.sha` tag reports malformed values as provided, but they must not select backend data.
899
+ sha: validateGitCommitSha(sha) ? sha : undefined,
859
900
  gitRoot: this.repositoryRoot,
860
901
  osVersion,
861
902
  osPlatform,
@@ -954,34 +995,44 @@ module.exports = class CiPlugin extends Plugin {
954
995
  }
955
996
 
956
997
  onDiBreakpointHit ({ snapshot }) {
998
+ if (this.filterDiBreakpointHitByStack && !this.#isExpectedDiBreakpointHit(snapshot)) {
999
+ log.debug('Ignoring Dynamic Instrumentation snapshot because it does not match the failed test stack')
1000
+ return
1001
+ }
1002
+
957
1003
  for (const resolve of this.diBreakpointHitResolvers) {
958
1004
  resolve()
959
1005
  }
960
1006
  this.diBreakpointHitResolvers.length = 0
961
1007
 
962
- if (!this.activeTestSpan || this.activeTestSpan.context()._isFinished) {
1008
+ while (this.diBreakpointHitSpans[0]?.context()._isFinished) {
1009
+ this.diBreakpointHitSpans.shift()
1010
+ }
1011
+ const testSpan = this.diBreakpointHitSpans.shift() || this.activeTestSpan
1012
+
1013
+ if (!testSpan || testSpan.context()._isFinished) {
963
1014
  // This is unexpected and is caused by a race condition.
964
1015
  log.warn('Breakpoint snapshot could not be attached to the active test span')
965
1016
  return
966
1017
  }
967
1018
 
968
1019
  const stackIndex = this.testErrorStackIndex
1020
+ const activeTestSpanContext = testSpan.context()
969
1021
 
970
- this.activeTestSpan.setTag(DI_ERROR_DEBUG_INFO_CAPTURED, 'true')
971
- this.activeTestSpan.setTag(
1022
+ testSpan.setTag(DI_ERROR_DEBUG_INFO_CAPTURED, 'true')
1023
+ testSpan.setTag(
972
1024
  `${DI_DEBUG_ERROR_PREFIX}.${stackIndex}.${DI_DEBUG_ERROR_SNAPSHOT_ID_SUFFIX}`,
973
1025
  snapshot.id
974
1026
  )
975
- this.activeTestSpan.setTag(
1027
+ testSpan.setTag(
976
1028
  `${DI_DEBUG_ERROR_PREFIX}.${stackIndex}.${DI_DEBUG_ERROR_FILE_SUFFIX}`,
977
1029
  snapshot.probe.location.file
978
1030
  )
979
- this.activeTestSpan.setTag(
1031
+ testSpan.setTag(
980
1032
  `${DI_DEBUG_ERROR_PREFIX}.${stackIndex}.${DI_DEBUG_ERROR_LINE_SUFFIX}`,
981
1033
  Number(snapshot.probe.location.lines[0])
982
1034
  )
983
1035
 
984
- const activeTestSpanContext = this.activeTestSpan.context()
985
1036
  const topStackFrame = snapshot.stack?.[0]
986
1037
 
987
1038
  this.tracer._exporter.exportDiLogs(this.testEnvironmentMetadata, {
@@ -1001,6 +1052,39 @@ module.exports = class CiPlugin extends Plugin {
1001
1052
  })
1002
1053
  }
1003
1054
 
1055
+ #isExpectedDiBreakpointHit (snapshot) {
1056
+ const failureFrames = this.testErrorStackFrames
1057
+ if (failureFrames.length < DI_STACK_FRAMES_TO_COMPARE) {
1058
+ return true
1059
+ }
1060
+
1061
+ const snapshotFrames = getNonDependencySnapshotStackFrames(snapshot, this.repositoryRoot)
1062
+ if (snapshotFrames.length < DI_STACK_FRAMES_TO_COMPARE) {
1063
+ return true
1064
+ }
1065
+
1066
+ for (let i = 0; i < DI_STACK_FRAMES_TO_COMPARE; i++) {
1067
+ const expectedFrame = failureFrames[i]
1068
+ const snapshotFrame = snapshotFrames[i]
1069
+
1070
+ if (expectedFrame.file !== snapshotFrame.file) {
1071
+ return false
1072
+ }
1073
+
1074
+ if (i === 0 && expectedFrame.line !== snapshotFrame.line) {
1075
+ return false
1076
+ }
1077
+
1078
+ // Vite can report a slightly shifted caller line in debugger snapshots compared to error stacks.
1079
+ // Keep the probe frame exact and only tolerate a small caller-frame offset.
1080
+ if (i > 0 && Math.abs(expectedFrame.line - snapshotFrame.line) > DI_CALLER_FRAME_LINE_TOLERANCE) {
1081
+ return false
1082
+ }
1083
+ }
1084
+
1085
+ return true
1086
+ }
1087
+
1004
1088
  /**
1005
1089
  * Wait for a Dynamic Instrumentation operation without blocking test framework progress forever.
1006
1090
  *
@@ -1019,6 +1103,16 @@ module.exports = class CiPlugin extends Plugin {
1019
1103
  resolve()
1020
1104
  }
1021
1105
  this.diBreakpointHitResolvers.length = 0
1106
+ this.diBreakpointHitSpans.length = 0
1107
+ }
1108
+
1109
+ /**
1110
+ * Queue the test span expected to receive the next Dynamic Instrumentation breakpoint hit.
1111
+ *
1112
+ * @param {import('../../../datadog-core/src/opentracing/span')} span
1113
+ */
1114
+ queueDiBreakpointHitSpan (span) {
1115
+ this.diBreakpointHitSpans.push(span)
1022
1116
  }
1023
1117
 
1024
1118
  /**
@@ -1134,6 +1228,7 @@ module.exports = class CiPlugin extends Plugin {
1134
1228
  log.debug('Adding breakpoint for Dynamic Instrumentation')
1135
1229
 
1136
1230
  this.testErrorStackIndex = stackIndex
1231
+ this.testErrorStackFrames = getNonDependencyStackFramesFromError(err, this.repositoryRoot)
1137
1232
  const activeProbeKey = `${file}:${line}`
1138
1233
 
1139
1234
  if (this.fileLineToProbeId.has(activeProbeKey)) {
@@ -8,7 +8,9 @@ const plugins = {
8
8
  get '@azure/cosmos' () { return require('../../../datadog-plugin-azure-cosmos/src') },
9
9
  get '@azure/event-hubs' () { return require('../../../datadog-plugin-azure-event-hubs/src') },
10
10
  get '@azure/functions' () { return require('../../../datadog-plugin-azure-functions/src') },
11
+ get '@modelcontextprotocol/client' () { return require('../../../datadog-plugin-modelcontextprotocol-sdk/src') },
11
12
  get '@modelcontextprotocol/sdk' () { return require('../../../datadog-plugin-modelcontextprotocol-sdk/src') },
13
+ get '@modelcontextprotocol/server' () { return require('../../../datadog-plugin-modelcontextprotocol-sdk/src') },
12
14
  get '@aws/durable-execution-sdk-js' () { return require('../../../datadog-plugin-aws-durable-execution-sdk-js/src') },
13
15
  get '@supabase/auth-js' () { return require('../../../datadog-plugin-supabase/src') },
14
16
  get '@supabase/functions-js' () { return require('../../../datadog-plugin-supabase/src') },
@@ -38,6 +38,16 @@ const {
38
38
  } = require('./tags')
39
39
  const { filterSensitiveInfoFromRepository } = require('./url')
40
40
 
41
+ // `user-provided-git` requires this module, so its SHA validator cannot be reused here.
42
+ const COMMIT_SHA_REGEX = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
43
+ const COMMIT_SHA_TAGS = [
44
+ GIT_COMMIT_SHA,
45
+ GIT_COMMIT_HEAD_SHA,
46
+ GIT_PULL_REQUEST_BASE_BRANCH_SHA,
47
+ GIT_PULL_REQUEST_BASE_BRANCH_HEAD_SHA,
48
+ CI_GIT_MERGE_COMMIT_SHA,
49
+ ]
50
+
41
51
  // Receives a string with the form 'John Doe <john.doe@gmail.com>'
42
52
  // and returns { name: 'John Doe', email: 'john.doe@gmail.com' }
43
53
  function parseEmailAndName (emailAndName) {
@@ -82,6 +92,16 @@ function normalizeRef (ref) {
82
92
  return ref.replaceAll(/origin\/|refs\/heads\/|refs\/tags\/|tags\//g, '')
83
93
  }
84
94
 
95
+ /**
96
+ * Lowercases a commit SHA. Values that are not a SHA in any case stay unchanged so validation still rejects them.
97
+ *
98
+ * @param {string | undefined} sha
99
+ */
100
+ function normalizeCommitSha (sha) {
101
+ const lowerCaseSha = sha?.toLowerCase()
102
+ return COMMIT_SHA_REGEX.test(lowerCaseSha || '') ? lowerCaseSha : sha
103
+ }
104
+
85
105
  function resolveTilde (filePath) {
86
106
  if (!filePath || typeof filePath !== 'string') {
87
107
  return ''
@@ -286,6 +306,7 @@ function getJobIDFromDiagFile () {
286
306
 
287
307
  module.exports = {
288
308
  normalizeRef,
309
+ normalizeCommitSha,
289
310
  expandGlobPattern,
290
311
  getJobIDFromDiagFile,
291
312
  getCIMetadata () {
@@ -374,6 +395,7 @@ module.exports = {
374
395
  CI_MERGE_REQUEST_IID,
375
396
  CI_MERGE_REQUEST_TARGET_BRANCH_SHA,
376
397
  CI_MERGE_REQUEST_DIFF_BASE_SHA,
398
+ CI_MERGE_REQUEST_SOURCE_BRANCH_SHA,
377
399
  CI_MERGE_REQUEST_EVENT_TYPE,
378
400
  } = env
379
401
 
@@ -409,6 +431,7 @@ module.exports = {
409
431
  [CI_JOB_ID]: GITLAB_CI_JOB_ID,
410
432
  [GIT_PULL_REQUEST_BASE_BRANCH_SHA]: CI_MERGE_REQUEST_DIFF_BASE_SHA,
411
433
  [GIT_PULL_REQUEST_BASE_BRANCH_HEAD_SHA]: CI_MERGE_REQUEST_TARGET_BRANCH_SHA,
434
+ [GIT_COMMIT_HEAD_SHA]: CI_MERGE_REQUEST_SOURCE_BRANCH_SHA,
412
435
  }
413
436
  if (CI_MERGE_REQUEST_IID &&
414
437
  (CI_MERGE_REQUEST_EVENT_TYPE === 'merged_result' || CI_MERGE_REQUEST_EVENT_TYPE === 'merge_train')) {
@@ -573,6 +596,13 @@ module.exports = {
573
596
  [GIT_TAG]: APPVEYOR_REPO_TAG_NAME,
574
597
  [GIT_BRANCH]: APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH || APPVEYOR_REPO_BRANCH,
575
598
  }
599
+
600
+ // A PR build of a commit other than the PR head commit is testing the merge result.
601
+ const headSha = APPVEYOR_PULL_REQUEST_HEAD_COMMIT?.toLowerCase()
602
+ if (/^\d+$/.test(APPVEYOR_PULL_REQUEST_NUMBER || '') && COMMIT_SHA_REGEX.test(headSha || '') &&
603
+ APPVEYOR_REPO_COMMIT && headSha !== APPVEYOR_REPO_COMMIT.toLowerCase()) {
604
+ tags[CI_GIT_MERGE_COMMIT_SHA] = APPVEYOR_REPO_COMMIT
605
+ }
576
606
  }
577
607
  }
578
608
 
@@ -611,6 +641,7 @@ module.exports = {
611
641
  [CI_PIPELINE_NAME]: BUILD_DEFINITIONNAME,
612
642
  [CI_PIPELINE_NUMBER]: BUILD_BUILDID,
613
643
  [GIT_COMMIT_SHA]: SYSTEM_PULLREQUEST_SOURCECOMMITID || BUILD_SOURCEVERSION,
644
+ [GIT_COMMIT_HEAD_SHA]: SYSTEM_PULLREQUEST_SOURCECOMMITID,
614
645
  [CI_WORKSPACE_PATH]: BUILD_SOURCESDIRECTORY,
615
646
  [GIT_REPOSITORY_URL]: SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI || BUILD_REPOSITORY_URI,
616
647
  [refKey]: ref,
@@ -950,6 +981,9 @@ module.exports = {
950
981
  normalizeTag(tags, GIT_TAG, normalizeRef)
951
982
  normalizeTag(tags, GIT_PULL_REQUEST_BASE_BRANCH, normalizeRef)
952
983
  normalizeTag(tags, PR_NUMBER, normalizeNumber)
984
+ for (const tag of COMMIT_SHA_TAGS) {
985
+ normalizeTag(tags, tag, normalizeCommitSha)
986
+ }
953
987
 
954
988
  return removeEmptyValues(tags)
955
989
  },
@@ -85,41 +85,37 @@ function stripIpv6Brackets (host) {
85
85
  */
86
86
 
87
87
  /**
88
- * Decompose a server request URL into the OpenTelemetry `url.*` / `server.*`
89
- * parts. Structural fields (scheme, address, path) are read from the raw URL;
90
- * the port is explicit or inferred from the scheme. The query comes from the
91
- * already-obfuscated URL so configured query-string obfuscation is preserved.
88
+ * Decompose an already-obfuscated server request URL into OpenTelemetry `url.*` / `server.*` parts.
92
89
  *
93
- * @param {string} rawUrl full request URL (`scheme://host[:port]/path?query`)
94
- * @param {string} obfuscatedUrl same URL with its query string obfuscated
90
+ * @param {string} url full request URL (`scheme://host[:port]/path?query`)
95
91
  * @returns {ServerUrlParts}
96
92
  */
97
- function decomposeServerUrl (rawUrl, obfuscatedUrl) {
93
+ function decomposeServerUrl (url) {
98
94
  let scheme
99
95
  let address
100
96
  let port
101
97
  let path
102
98
 
103
99
  try {
104
- const parsed = new URL(rawUrl)
100
+ const parsed = new URL(url)
105
101
  scheme = parsed.protocol.length > 1 ? parsed.protocol.slice(0, -1) : undefined
106
102
  // `extractURL` builds `http://undefined/...` when the Host header is absent; skip that.
107
103
  const hostname = parsed.hostname
108
104
  if (hostname && hostname !== 'undefined') {
109
105
  address = stripIpv6Brackets(hostname)
110
- port = parsed.port ? Number.parseInt(parsed.port, 10) : defaultPortForUrl(rawUrl)
106
+ port = parsed.port ? Number.parseInt(parsed.port, 10) : defaultPortForUrl(url)
111
107
  if (port === 0) port = undefined
112
108
  }
113
109
  path = parsed.pathname || '/'
114
110
  } catch {
115
111
  // Malformed or relative URL: fall back to a best-effort path only.
116
- path = extractPathFromUrl(rawUrl)
112
+ path = extractPathFromUrl(url)
117
113
  }
118
114
 
119
115
  let query
120
- const queryIndex = obfuscatedUrl.indexOf('?')
116
+ const queryIndex = url.indexOf('?')
121
117
  if (queryIndex !== -1) {
122
- const rawQuery = obfuscatedUrl.slice(queryIndex + 1)
118
+ const rawQuery = url.slice(queryIndex + 1)
123
119
  if (rawQuery) query = rawQuery
124
120
  }
125
121
 
@@ -256,7 +252,7 @@ function applyHttpOtelSemantics (formattedSpan) {
256
252
  if (kind === 'server') {
257
253
  if (url !== undefined) {
258
254
  // The query in `http.url` is already obfuscated per config, so it is preserved.
259
- const { scheme, address, port, path, query } = decomposeServerUrl(url, url)
255
+ const { scheme, address, port, path, query } = decomposeServerUrl(url)
260
256
  if (path !== undefined) newMeta[URL_PATH] = path
261
257
  if (scheme !== undefined) newMeta[URL_SCHEME] = toHttpScheme(scheme)
262
258
  if (query !== undefined) newMeta[URL_QUERY] = query
@@ -294,7 +290,6 @@ module.exports = {
294
290
  HTTP_STATUS_ERROR,
295
291
  INSTRUMENTATION_HTTP_RESOURCE,
296
292
  NETWORK_PEER_ADDRESS, // imported by web.js (set from req.socket, not at serialization)
297
- decomposeServerUrl, // exercised directly by the helper spec
298
293
  isInstrumentationOwnedResource,
299
294
  otelHttpResourceName,
300
295
  setInstrumentationHttpResource,
@@ -143,16 +143,14 @@ function extractInferredProxyContext (headers) {
143
143
  return null
144
144
  }
145
145
 
146
+ const requestPath = headers[PROXY_HEADER_PATH]
147
+
146
148
  return {
147
149
  requestTime: headers[PROXY_HEADER_START_TIME_MS]
148
150
  ? Number.parseInt(headers[PROXY_HEADER_START_TIME_MS], 10)
149
151
  : Date.now(),
150
152
  method: headers[PROXY_HEADER_HTTPMETHOD],
151
- path: headers[PROXY_HEADER_PATH]
152
- ? (headers[PROXY_HEADER_PATH].startsWith('/')
153
- ? headers[PROXY_HEADER_PATH]
154
- : '/' + headers[PROXY_HEADER_PATH])
155
- : headers[PROXY_HEADER_PATH],
153
+ path: requestPath && !requestPath.startsWith('/') ? '/' + requestPath : requestPath,
156
154
  stage: headers[PROXY_HEADER_STAGE],
157
155
  domainName: headers[PROXY_HEADER_DOMAIN],
158
156
  proxySystemName: headers[PROXY_HEADER_SYSTEM],
@@ -591,6 +591,7 @@ module.exports = {
591
591
  TEST_RETRY_REASON_TYPES,
592
592
  getNumFromKnownTests,
593
593
  getFileAndLineNumberFromError,
594
+ getNonDependencyStackFramesFromError,
594
595
  DI_ERROR_DEBUG_INFO_CAPTURED,
595
596
  DI_DEBUG_ERROR_PREFIX,
596
597
  DI_DEBUG_ERROR_SNAPSHOT_ID_SUFFIX,
@@ -665,7 +666,10 @@ function removeInvalidMetadata (metadata) {
665
666
  }
666
667
  if ((tag === GIT_COMMIT_SHA || tag === CI_GIT_MERGE_COMMIT_SHA) && !validateGitCommitSha(metadata[tag])) {
667
668
  log.error('Git commit SHA must be a full-length git SHA: %s.', metadata[tag])
668
- return filteredTags
669
+ // A malformed commit SHA is reported as provided; consumers validate it before using it for Git or requests.
670
+ if (tag === CI_GIT_MERGE_COMMIT_SHA || !metadata[tag]) {
671
+ return filteredTags
672
+ }
669
673
  }
670
674
  if (tag === CI_PIPELINE_URL && !validateUrl(metadata[CI_PIPELINE_URL])) {
671
675
  return filteredTags
@@ -1909,6 +1913,29 @@ function getFileAndLineNumberFromError (error, repositoryRoot) {
1909
1913
  return []
1910
1914
  }
1911
1915
 
1916
+ function getNonDependencyStackFramesFromError (error, repositoryRoot) {
1917
+ if (!error?.stack) {
1918
+ return []
1919
+ }
1920
+
1921
+ const stackLines = error.stack.split('\n')
1922
+ const frames = stackLines.filter(line => line.includes('at ') && line.includes(repositoryRoot))
1923
+ const locations = []
1924
+
1925
+ for (const frame of frames) {
1926
+ if (DEPENDENCY_FOLDERS.some(pattern => frame.includes(pattern))) {
1927
+ continue
1928
+ }
1929
+
1930
+ const location = parseStackFrameLocation(frame, repositoryRoot)
1931
+ if (location) {
1932
+ locations.push(location)
1933
+ }
1934
+ }
1935
+
1936
+ return locations
1937
+ }
1938
+
1912
1939
  function getFormattedError (error, repositoryRoot) {
1913
1940
  const newError = new Error(error.message)
1914
1941
  if (error.stack) {