dd-trace 5.135.0 → 5.136.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 (250) hide show
  1. package/ci/init.js +2 -22
  2. package/ext/exporters.js +0 -1
  3. package/index.d.ts +105 -5
  4. package/initialize.mjs +5 -2
  5. package/lambda.d.ts +39 -0
  6. package/lambda.js +3 -0
  7. package/package.json +11 -9
  8. package/packages/datadog-esbuild/index.js +8 -55
  9. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  10. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  11. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  12. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  13. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  14. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  15. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  16. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  18. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  21. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -1
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  33. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  34. package/packages/datadog-instrumentations/src/next.js +19 -6
  35. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  36. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  37. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  38. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  39. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  40. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  41. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  42. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  43. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  44. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  45. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
  46. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  49. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  50. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  51. package/packages/datadog-plugin-http/src/client.js +32 -9
  52. package/packages/datadog-plugin-http2/src/client.js +38 -13
  53. package/packages/datadog-plugin-next/src/index.js +112 -14
  54. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  55. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  56. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  57. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  58. package/packages/datadog-plugin-undici/src/index.js +22 -7
  59. package/packages/datadog-turbopack/index.js +4 -28
  60. package/packages/datadog-turbopack/src/loader.js +14 -452
  61. package/packages/datadog-webpack/index.js +3 -55
  62. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  63. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  64. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  65. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  66. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  67. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  68. package/packages/dd-trace/src/before-exit.js +32 -0
  69. package/packages/dd-trace/src/bootstrap.js +5 -3
  70. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  71. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  73. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  75. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  77. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  78. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  79. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  80. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  81. package/packages/dd-trace/src/config/defaults.js +5 -0
  82. package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
  83. package/packages/dd-trace/src/config/index.js +17 -5
  84. package/packages/dd-trace/src/config/parsers.js +9 -0
  85. package/packages/dd-trace/src/config/supported-configurations.json +158 -4
  86. package/packages/dd-trace/src/constants.js +1 -0
  87. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  88. package/packages/dd-trace/src/exporter.js +0 -11
  89. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  90. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  91. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  92. package/packages/dd-trace/src/id.js +1 -1
  93. package/packages/dd-trace/src/lambda/facade.js +74 -0
  94. package/packages/dd-trace/src/lambda/handler.js +3 -41
  95. package/packages/dd-trace/src/lambda/index.js +38 -15
  96. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  97. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  98. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  99. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  100. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  101. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  102. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  103. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  104. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  105. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  106. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  107. package/packages/dd-trace/src/log/channels.js +4 -0
  108. package/packages/dd-trace/src/log/writer.js +6 -1
  109. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
  110. package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
  111. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  112. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  113. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  114. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  115. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  117. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  118. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  119. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  120. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  121. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  122. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  123. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  124. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  125. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  126. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  127. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  128. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  129. package/packages/dd-trace/src/plugin_manager.js +34 -7
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
  131. package/packages/dd-trace/src/plugins/index.js +6 -0
  132. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  133. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  134. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  135. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  136. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  137. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
  138. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  139. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  140. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +64 -39
  142. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  143. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  144. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  145. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  146. package/packages/dd-trace/src/proxy.js +33 -53
  147. package/packages/dd-trace/src/span_processor.js +20 -0
  148. package/packages/dd-trace/src/startup-log.js +8 -6
  149. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  150. package/packages/dd-trace/src/tracer.js +0 -2
  151. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  152. package/register.js +2 -1
  153. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  154. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  155. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  156. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  157. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  158. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  160. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  161. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  162. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  163. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  164. package/vendor/dist/esquery/LICENSE +2 -0
  165. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  166. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  167. package/vendor/dist/jest-docblock/LICENSE +16 -0
  168. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  169. package/vendor/dist/limiter/LICENSE +2 -0
  170. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  171. package/vendor/dist/lru-cache/LICENSE +13 -0
  172. package/vendor/dist/meriyah/LICENSE +13 -0
  173. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  174. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  175. package/vendor/dist/pprof-format/LICENSE +13 -0
  176. package/vendor/dist/pprof-format/index.js +1 -1
  177. package/vendor/dist/protobufjs/LICENSE +219 -0
  178. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  179. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  180. package/vendor/dist/retry/LICENSE +2 -0
  181. package/vendor/dist/rfdc/LICENSE +2 -0
  182. package/vendor/dist/semifies/LICENSE +3 -1
  183. package/vendor/dist/shell-quote/LICENSE +3 -1
  184. package/vendor/dist/source-map/LICENSE +1 -0
  185. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  186. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  187. package/vendor/dist/ttl-set/LICENSE +28 -0
  188. package/ci/diagnose.js +0 -2215
  189. package/ci/runbook.md +0 -299
  190. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  191. package/ci/test-optimization-validation/approval.js +0 -386
  192. package/ci/test-optimization-validation/artifact-id.js +0 -18
  193. package/ci/test-optimization-validation/blocker-category.js +0 -24
  194. package/ci/test-optimization-validation/bounded-json.js +0 -120
  195. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  196. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  197. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  198. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  199. package/ci/test-optimization-validation/cli.js +0 -954
  200. package/ci/test-optimization-validation/command-blocker.js +0 -377
  201. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  202. package/ci/test-optimization-validation/command-runner.js +0 -649
  203. package/ci/test-optimization-validation/environment.js +0 -88
  204. package/ci/test-optimization-validation/executable-approval.js +0 -47
  205. package/ci/test-optimization-validation/executable.js +0 -244
  206. package/ci/test-optimization-validation/execution-lock.js +0 -70
  207. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  208. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  209. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  210. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  211. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  212. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  213. package/ci/test-optimization-validation/generated-files.js +0 -425
  214. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  215. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  216. package/ci/test-optimization-validation/literal-environment.js +0 -56
  217. package/ci/test-optimization-validation/literal-glob.js +0 -52
  218. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  219. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  220. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  221. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  222. package/ci/test-optimization-validation/offline-output.js +0 -406
  223. package/ci/test-optimization-validation/package-check.js +0 -97
  224. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  225. package/ci/test-optimization-validation/plan-writer.js +0 -541
  226. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  227. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  228. package/ci/test-optimization-validation/redaction.js +0 -319
  229. package/ci/test-optimization-validation/report-writer.js +0 -666
  230. package/ci/test-optimization-validation/result-semantics.js +0 -103
  231. package/ci/test-optimization-validation/runner-command.js +0 -264
  232. package/ci/test-optimization-validation/runner-contract.js +0 -695
  233. package/ci/test-optimization-validation/safe-files.js +0 -202
  234. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  235. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  236. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  237. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  238. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  239. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  240. package/ci/test-optimization-validation/source-text.js +0 -84
  241. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  242. package/ci/test-optimization-validation/test-output.js +0 -120
  243. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  244. package/ci/validate-test-optimization.js +0 -3
  245. package/packages/datadog-esbuild/src/resolver.js +0 -284
  246. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  247. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  248. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  249. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  250. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -17,6 +17,8 @@ const USER_AGENT_ORIGINAL = 'user_agent.original'
17
17
  const CLIENT_ADDRESS = 'client.address'
18
18
  const NETWORK_PEER_ADDRESS = 'network.peer.address'
19
19
  const HTTP_REQUEST_METHOD_ORIGINAL = 'http.request.method_original'
20
+ const INSTRUMENTATION_HTTP_RESOURCE = '_dd.otel.instrumentation_http_resource'
21
+ const HTTP_STATUS_ERROR = '_dd.otel.status_error'
20
22
 
21
23
  // Known HTTP methods (RFC 9110 + PATCH RFC 5789 + QUERY httpbis draft). A verb
22
24
  // outside this set is reported as `_OTHER` with the raw value preserved on
@@ -25,12 +27,48 @@ const KNOWN_METHODS = new Set([
25
27
  'CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'QUERY', 'TRACE',
26
28
  ])
27
29
 
30
+ /**
31
+ * The OTel HTTP span name: `{method} {target}`, or the bare method with no target. An unknown
32
+ * verb uses the literal `HTTP`, never the URL path.
33
+ *
34
+ * @param {string} method
35
+ * @param {string} [route]
36
+ */
37
+ function otelHttpResourceName (method, route) {
38
+ const normalizedMethod = KNOWN_METHODS.has(method) ? method : 'HTTP'
39
+ if (typeof route === 'string' && route.length > 0) return `${normalizedMethod} ${route}`
40
+ return normalizedMethod
41
+ }
42
+
43
+ /**
44
+ * Record the generated resource so later passes do not overwrite an application change.
45
+ *
46
+ * @param {import('../../opentracing/span')} span
47
+ * @param {string} resource
48
+ */
49
+ function setInstrumentationHttpResource (span, resource) {
50
+ span.context().setTag(INSTRUMENTATION_HTTP_RESOURCE, resource)
51
+ span.setTag('resource.name', resource)
52
+ }
53
+
28
54
  // Datadog HTTP meta keys replaced by OTel names — omitted when rebuilding meta.
55
+ // `http.endpoint` stays: it has no OTel equivalent and ASM plus endpoint aggregation read it.
29
56
  const DD_HTTP_META_KEYS = new Set([
30
57
  'http.method', 'http.status_code', 'http.useragent', 'http.client_ip', 'http.url', 'out.host',
58
+ INSTRUMENTATION_HTTP_RESOURCE, HTTP_STATUS_ERROR,
31
59
  ])
32
60
  const NETWORK_DESTINATION_PORT = 'network.destination.port'
33
61
 
62
+ /**
63
+ * Treat a resource that differs from the recorded instrumentation value as application-owned.
64
+ *
65
+ * @param {string | undefined} currentResource
66
+ * @param {string | undefined} instrumentationResource
67
+ */
68
+ function isInstrumentationOwnedResource (currentResource, instrumentationResource) {
69
+ return !currentResource || currentResource === instrumentationResource
70
+ }
71
+
34
72
  // IPv6 literals arrive bracketed (URL.hostname / out.host = `[::1]`); OTel
35
73
  // `server.address` is the bare address.
36
74
  function stripIpv6Brackets (host) {
@@ -48,9 +86,9 @@ function stripIpv6Brackets (host) {
48
86
 
49
87
  /**
50
88
  * Decompose a server request URL into the OpenTelemetry `url.*` / `server.*`
51
- * parts. Structural fields (scheme, address, port, path) are read from the raw
52
- * URL; the query is taken from the already-obfuscated URL so the configured
53
- * query-string obfuscation is preserved.
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.
54
92
  *
55
93
  * @param {string} rawUrl full request URL (`scheme://host[:port]/path?query`)
56
94
  * @param {string} obfuscatedUrl same URL with its query string obfuscated
@@ -69,10 +107,8 @@ function decomposeServerUrl (rawUrl, obfuscatedUrl) {
69
107
  const hostname = parsed.hostname
70
108
  if (hostname && hostname !== 'undefined') {
71
109
  address = stripIpv6Brackets(hostname)
72
- }
73
- if (parsed.port) {
74
- const parsedPort = Number.parseInt(parsed.port, 10)
75
- if (parsedPort > 0) port = parsedPort
110
+ port = parsed.port ? Number.parseInt(parsed.port, 10) : defaultPortForUrl(rawUrl)
111
+ if (port === 0) port = undefined
76
112
  }
77
113
  path = parsed.pathname || '/'
78
114
  } catch {
@@ -100,8 +136,8 @@ function toHttpScheme (scheme) {
100
136
 
101
137
  /**
102
138
  * Redact any userinfo embedded in a URL's authority, since `url.full` must not
103
- * leak credentials: `user:pass@host` -> `REDACTED:REDACTED@host`, `user@host` ->
104
- * `REDACTED@host`. Returns the URL unchanged when no userinfo is present.
139
+ * leak credentials. Any userinfo becomes `REDACTED:REDACTED@host`, matching OpenTelemetry HTTP
140
+ * instrumentation. Returns the URL unchanged when no userinfo is present.
105
141
  *
106
142
  * @param {string} url
107
143
  */
@@ -124,17 +160,13 @@ function redactUrlCredentials (url) {
124
160
  const at = url.lastIndexOf('@', authorityEnd - 1)
125
161
  if (at < authorityStart) return url
126
162
 
127
- const redacted = url.slice(authorityStart, at).includes(':') ? 'REDACTED:REDACTED' : 'REDACTED'
128
- return url.slice(0, authorityStart) + redacted + url.slice(at)
163
+ return url.slice(0, authorityStart) + 'REDACTED:REDACTED' + url.slice(at)
129
164
  }
130
165
 
131
166
  /**
132
- * The scheme's default port, used as the `server.port` fallback for client spans
133
- * (the attribute is required for clients but the explicit port is absent for
134
- * default-port requests).
167
+ * Return the required client `server.port` when the URL omits its default port.
135
168
  *
136
169
  * @param {string} [url]
137
- * @returns {number | undefined}
138
170
  */
139
171
  function defaultPortForUrl (url) {
140
172
  if (url === undefined) return
@@ -165,7 +197,19 @@ function applyHttpOtelSemantics (formattedSpan) {
165
197
  const metrics = formattedSpan.metrics
166
198
  const method = meta['http.method']
167
199
  const url = meta['http.url']
168
- if (method === undefined && url === undefined) return
200
+ // Hooks can remove the method and URL; the resource marker still identifies HTTP spans whose
201
+ // remaining tags need renaming.
202
+ if (method === undefined && url === undefined && meta[INSTRUMENTATION_HTTP_RESOURCE] === undefined) {
203
+ // Rebuild to remove an orphaned internal marker without demoting `meta` to V8 dictionary mode.
204
+ if (Object.hasOwn(meta, HTTP_STATUS_ERROR)) {
205
+ const cleanMeta = {}
206
+ for (const key of Object.keys(meta)) {
207
+ if (key !== HTTP_STATUS_ERROR) cleanMeta[key] = meta[key]
208
+ }
209
+ formattedSpan.meta = cleanMeta
210
+ }
211
+ return
212
+ }
169
213
 
170
214
  // Rebuild meta/metrics as fresh objects that omit the renamed Datadog HTTP
171
215
  // keys. Deleting them in place demotes the formatted span to V8 dictionary
@@ -175,6 +219,7 @@ function applyHttpOtelSemantics (formattedSpan) {
175
219
  for (const key of Object.keys(meta)) {
176
220
  if (!DD_HTTP_META_KEYS.has(key)) newMeta[key] = meta[key]
177
221
  }
222
+
178
223
  const newMetrics = {}
179
224
  for (const key of Object.keys(metrics)) {
180
225
  if (key !== NETWORK_DESTINATION_PORT) newMetrics[key] = metrics[key]
@@ -186,29 +231,18 @@ function applyHttpOtelSemantics (formattedSpan) {
186
231
  if (KNOWN_METHODS.has(method)) {
187
232
  newMeta[HTTP_REQUEST_METHOD] = method
188
233
  } else {
189
- // Unknown verb: bucket to `_OTHER`, preserve the raw value, and use the
190
- // literal "HTTP" in the span name (the spec forbids the URL path there).
191
- // Known-method names are already `{method} {route}`.
192
234
  newMeta[HTTP_REQUEST_METHOD] = '_OTHER'
193
235
  newMeta[HTTP_REQUEST_METHOD_ORIGINAL] = method
194
- const resource = formattedSpan.resource
195
- if (typeof resource === 'string') {
196
- if (resource === method) {
197
- formattedSpan.resource = 'HTTP'
198
- } else if (resource.startsWith(`${method} `)) {
199
- formattedSpan.resource = `HTTP${resource.slice(method.length)}`
200
- }
201
- }
236
+ }
237
+ // Comparing against the recorded value keeps a manual resource shaped like "GET /custom".
238
+ if (isInstrumentationOwnedResource(formattedSpan.resource, meta[INSTRUMENTATION_HTTP_RESOURCE])) {
239
+ formattedSpan.resource = otelHttpResourceName(method, kind === 'server' ? meta['http.route'] : undefined)
202
240
  }
203
241
  }
204
242
 
205
243
  const status = meta['http.status_code']
206
244
  let statusCode
207
245
  if (status !== undefined) {
208
- // OTel types http.response.status_code as an int, so emit it as a numeric
209
- // metric (the OTLP exporter serializes meta as stringValue but metrics as
210
- // intValue) — mirroring how server.port is handled below. Guard against a
211
- // non-numeric status, which would otherwise write a NaN metric.
212
246
  statusCode = Number.parseInt(status, 10)
213
247
  if (Number.isFinite(statusCode)) newMetrics[HTTP_RESPONSE_STATUS_CODE] = statusCode
214
248
  }
@@ -220,11 +254,6 @@ function applyHttpOtelSemantics (formattedSpan) {
220
254
  if (clientIp !== undefined) newMeta[CLIENT_ADDRESS] = clientIp
221
255
 
222
256
  if (kind === 'server') {
223
- // FIXME: some server frameworks (e.g. Next.js — `packages/datadog-plugin-next`)
224
- // never populate `http.url`, so the OTel `url.*` / `server.*` attributes below
225
- // can't be derived and are omitted for those spans. This needs a fix; the
226
- // short-term option is to set `http.url` in those integrations so they emit
227
- // the full server attribute set.
228
257
  if (url !== undefined) {
229
258
  // The query in `http.url` is already obfuscated per config, so it is preserved.
230
259
  const { scheme, address, port, path, query } = decomposeServerUrl(url, url)
@@ -236,7 +265,6 @@ function applyHttpOtelSemantics (formattedSpan) {
236
265
  }
237
266
  } else {
238
267
  if (url !== undefined) {
239
- // url.full must not carry embedded credentials.
240
268
  newMeta[URL_FULL] = redactUrlCredentials(url)
241
269
  }
242
270
  const outHost = meta['out.host']
@@ -251,15 +279,11 @@ function applyHttpOtelSemantics (formattedSpan) {
251
279
  }
252
280
  }
253
281
 
254
- // OTel error semantics for an error response (no-clobber on an exception-derived
255
- // type): server spans are errors on 5xx only (4xx MUST be left unset per the
256
- // spec); client spans on any status >= 400.
257
- if (status !== undefined && newMeta[ERROR_TYPE] === undefined) {
258
- const isError = statusCode >= (kind === 'server' ? 500 : 400)
259
- if (isError) {
260
- newMeta[ERROR_TYPE] = status
261
- formattedSpan.error = 1
262
- }
282
+ // Configured validators, not a fixed status range, decide whether status caused the error.
283
+ // Match the recorded status so a hook replacement is not blamed, and keep exception-derived types.
284
+ const statusCausedError = status !== undefined && meta[HTTP_STATUS_ERROR] === status
285
+ if (formattedSpan.error && newMeta[ERROR_TYPE] === undefined && statusCausedError && Number.isFinite(statusCode)) {
286
+ newMeta[ERROR_TYPE] = status
263
287
  }
264
288
 
265
289
  formattedSpan.meta = newMeta
@@ -267,7 +291,12 @@ function applyHttpOtelSemantics (formattedSpan) {
267
291
  }
268
292
 
269
293
  module.exports = {
294
+ HTTP_STATUS_ERROR,
295
+ INSTRUMENTATION_HTTP_RESOURCE,
270
296
  NETWORK_PEER_ADDRESS, // imported by web.js (set from req.socket, not at serialization)
271
297
  decomposeServerUrl, // exercised directly by the helper spec
298
+ isInstrumentationOwnedResource,
299
+ otelHttpResourceName,
300
+ setInstrumentationHttpResource,
272
301
  applyHttpOtelSemantics,
273
302
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  const log = require('../../log')
4
4
  const tags = require('../../../../../ext/tags')
5
+ const { INSTRUMENTATION_HTTP_RESOURCE, otelHttpResourceName } = require('./http-otel-semantics')
5
6
 
6
7
  const RESOURCE_NAME = tags.RESOURCE_NAME
7
8
  const SPAN_TYPE = tags.SPAN_TYPE
@@ -62,6 +63,9 @@ function createInferredProxySpan (headers, childOf, tracer, reqCtx, traceCtx, co
62
63
  }
63
64
 
64
65
  const proxySpanInfo = supportedProxies[proxyContext.proxySystemName]
66
+ const resourcePath = proxyContext.resourcePath || proxyContext.path
67
+ const otelSemantics = config.DD_TRACE_OTEL_SEMANTICS_ENABLED
68
+ let resourceName = `${proxyContext.method} ${resourcePath}`
65
69
 
66
70
  log.debug('Successfully extracted inferred span info %s for proxy:', proxyContext, proxyContext.proxySystemName)
67
71
 
@@ -79,6 +83,11 @@ function createInferredProxySpan (headers, childOf, tracer, reqCtx, traceCtx, co
79
83
  if (proxyContext.accountId) meta.account_id = proxyContext.accountId
80
84
  if (proxyContext.apiId) meta.apiid = proxyContext.apiId
81
85
  if (proxyContext.awsUser) meta.aws_user = proxyContext.awsUser
86
+ if (otelSemantics) {
87
+ resourceName = otelHttpResourceName(proxyContext.method, proxyContext.resourcePath)
88
+ meta[RESOURCE_NAME] = resourceName
89
+ meta[INSTRUMENTATION_HTTP_RESOURCE] = resourceName
90
+ }
82
91
 
83
92
  const span = startSpanHelper(tracer, proxySpanInfo.spanName, {
84
93
  childOf,
@@ -93,14 +102,13 @@ function createInferredProxySpan (headers, childOf, tracer, reqCtx, traceCtx, co
93
102
 
94
103
  log.debug('Successfully created inferred proxy span.')
95
104
 
96
- setInferredProxySpanTags(span, proxyContext)
105
+ setInferredProxySpanTags(span, proxyContext, resourceName)
97
106
 
98
107
  return childOf
99
108
  }
100
109
 
101
- function setInferredProxySpanTags (span, proxyContext) {
102
- const resourcePath = proxyContext.resourcePath || proxyContext.path
103
- span.setTag(RESOURCE_NAME, `${proxyContext.method} ${resourcePath}`)
110
+ function setInferredProxySpanTags (span, proxyContext, resourceName) {
111
+ span.setTag(RESOURCE_NAME, resourceName)
104
112
  span.setTag('_dd.inferred_span', 1)
105
113
 
106
114
  // Set dd_resource_key as API Gateway ARN if we have the required components
@@ -8,7 +8,6 @@ const MAX_HTTP_STATUS_CODE = 599
8
8
 
9
9
  const SERVER_ERROR_STATUSES = 'DD_TRACE_HTTP_SERVER_ERROR_STATUSES'
10
10
  const CLIENT_ERROR_STATUSES = 'DD_TRACE_HTTP_CLIENT_ERROR_STATUSES'
11
-
12
11
  /** @typedef {(code: number) => boolean} StatusValidator */
13
12
 
14
13
  /** @type {StatusValidator} */
@@ -21,30 +20,47 @@ function isNotClientErrorCode (code) {
21
20
  return code < 400 || code >= 500
22
21
  }
23
22
 
23
+ // OTel treats client 5xx responses and unrecognized codes above 599 as errors.
24
+ /** @type {StatusValidator} */
25
+ function isNotOtelClientErrorCode (code) {
26
+ return code < 400
27
+ }
28
+
24
29
  /**
25
- * @param {{ validateStatus?: unknown, DD_TRACE_HTTP_SERVER_ERROR_STATUSES?: unknown }} config
30
+ * @param {{
31
+ * validateStatus?: unknown,
32
+ * DD_TRACE_HTTP_SERVER_ERROR_STATUSES?: unknown,
33
+ * DD_TRACE_HTTP_CLIENT_ERROR_STATUSES?: unknown,
34
+ * }} config
26
35
  * @returns {StatusValidator}
27
36
  */
28
37
  function getServerStatusValidator (config) {
29
- return getStatusValidator(config, SERVER_ERROR_STATUSES, '500-599', isNotServerErrorCode)
38
+ return getStatusValidator(config, SERVER_ERROR_STATUSES, isNotServerErrorCode)
30
39
  }
31
40
 
32
41
  /**
33
- * @param {{ validateStatus?: unknown, DD_TRACE_HTTP_CLIENT_ERROR_STATUSES?: unknown }} config
42
+ * @param {{
43
+ * validateStatus?: unknown,
44
+ * DD_TRACE_HTTP_CLIENT_ERROR_STATUSES?: unknown,
45
+ * DD_TRACE_OTEL_SEMANTICS_ENABLED?: unknown
46
+ * }} config
34
47
  * @returns {StatusValidator}
35
48
  */
36
49
  function getClientStatusValidator (config) {
37
- return getStatusValidator(config, CLIENT_ERROR_STATUSES, '400-499', isNotClientErrorCode)
50
+ if (config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
51
+ return getStatusValidator(config, CLIENT_ERROR_STATUSES, isNotOtelClientErrorCode)
52
+ }
53
+
54
+ return getStatusValidator(config, CLIENT_ERROR_STATUSES, isNotClientErrorCode)
38
55
  }
39
56
 
40
57
  /**
41
58
  * @param {Record<string, unknown>} config
42
59
  * @param {string} optionName - Name of the configuration holding the error status ranges.
43
- * @param {string} defaultRanges - Ranges covered by `defaultValidator`
44
60
  * @param {StatusValidator} defaultValidator
45
61
  * @returns {StatusValidator}
46
62
  */
47
- function getStatusValidator (config, optionName, defaultRanges, defaultValidator) {
63
+ function getStatusValidator (config, optionName, defaultValidator) {
48
64
  if (typeof config.validateStatus === 'function') {
49
65
  return /** @type {StatusValidator} */ (config.validateStatus)
50
66
  } else if (Object.hasOwn(config, 'validateStatus')) {
@@ -57,10 +73,7 @@ function getStatusValidator (config, optionName, defaultRanges, defaultValidator
57
73
  log.error('Expected `%s` to be a string.', optionName)
58
74
  return defaultValidator
59
75
  }
60
- if (ranges === defaultRanges) return defaultValidator
61
-
62
76
  const normalized = ranges.replaceAll(whitespacePattern, '')
63
- if (normalized === defaultRanges) return defaultValidator
64
77
  if (!statusCodeRangesPattern.test(normalized)) {
65
78
  log.error('`%s` must contain comma-separated status codes or ranges from 100 to 599.', optionName)
66
79
  return defaultValidator
@@ -3,6 +3,8 @@
3
3
  const GIT_COMMIT_SHA = 'git.commit.sha'
4
4
  const GIT_BRANCH = 'git.branch'
5
5
  const GIT_REPOSITORY_URL = 'git.repository_url'
6
+ const GIT_CHECKOUT_ROOT = 'git.checkout.root'
7
+ const GIT_CHECKOUT_IS_CUSTOM = 'git.checkout.is_custom'
6
8
  const GIT_TAG = 'git.tag'
7
9
  const GIT_COMMIT_MESSAGE = 'git.commit.message'
8
10
  const GIT_COMMIT_COMMITTER_DATE = 'git.commit.committer.date'
@@ -31,6 +33,7 @@ const CI_PIPELINE_NUMBER = 'ci.pipeline.number'
31
33
  const CI_PIPELINE_URL = 'ci.pipeline.url'
32
34
  const CI_PROVIDER_NAME = 'ci.provider.name'
33
35
  const CI_WORKSPACE_PATH = 'ci.workspace_path'
36
+ const CI_GIT_MERGE_COMMIT_SHA = 'ci.git.merge_commit_sha'
34
37
  const CI_JOB_URL = 'ci.job.url'
35
38
  const CI_JOB_NAME = 'ci.job.name'
36
39
  const CI_JOB_ID = 'ci.job.id'
@@ -46,6 +49,8 @@ module.exports = {
46
49
  GIT_COMMIT_SHA,
47
50
  GIT_BRANCH,
48
51
  GIT_REPOSITORY_URL,
52
+ GIT_CHECKOUT_ROOT,
53
+ GIT_CHECKOUT_IS_CUSTOM,
49
54
  GIT_TAG,
50
55
  GIT_COMMIT_MESSAGE,
51
56
  GIT_COMMIT_COMMITTER_DATE,
@@ -72,6 +77,7 @@ module.exports = {
72
77
  CI_PIPELINE_URL,
73
78
  CI_PROVIDER_NAME,
74
79
  CI_WORKSPACE_PATH,
80
+ CI_GIT_MERGE_COMMIT_SHA,
75
81
  CI_JOB_URL,
76
82
  CI_JOB_NAME,
77
83
  CI_JOB_ID,
@@ -30,6 +30,8 @@ const {
30
30
  GIT_BRANCH,
31
31
  GIT_COMMIT_SHA,
32
32
  GIT_REPOSITORY_URL,
33
+ GIT_CHECKOUT_ROOT,
34
+ GIT_CHECKOUT_IS_CUSTOM,
33
35
  GIT_TAG,
34
36
  GIT_COMMIT_AUTHOR_DATE,
35
37
  GIT_COMMIT_AUTHOR_EMAIL,
@@ -46,6 +48,7 @@ const {
46
48
  GIT_COMMIT_HEAD_COMMITTER_NAME,
47
49
  GIT_COMMIT_HEAD_MESSAGE,
48
50
  CI_WORKSPACE_PATH,
51
+ CI_GIT_MERGE_COMMIT_SHA,
49
52
  CI_PIPELINE_ID,
50
53
  CI_PIPELINE_NAME,
51
54
  CI_PIPELINE_DISPLAY_NAME,
@@ -75,6 +78,7 @@ const {
75
78
  getLocalBranches,
76
79
  getMergeBase,
77
80
  getCounts,
81
+ hasLocalGitObject,
78
82
  } = require('./git')
79
83
 
80
84
  /**
@@ -269,6 +273,9 @@ const TEST_LEVELS_METADATA_TAGS = [
269
273
  CI_PROVIDER_NAME,
270
274
  CI_STAGE_NAME,
271
275
  CI_WORKSPACE_PATH,
276
+ CI_GIT_MERGE_COMMIT_SHA,
277
+ GIT_CHECKOUT_ROOT,
278
+ GIT_CHECKOUT_IS_CUSTOM,
272
279
  GIT_BRANCH,
273
280
  GIT_COMMIT_AUTHOR_DATE,
274
281
  GIT_COMMIT_AUTHOR_EMAIL,
@@ -656,8 +663,8 @@ function removeInvalidMetadata (metadata) {
656
663
  log.error('Repository URL is not a valid repository URL: %s.', metadata[GIT_REPOSITORY_URL])
657
664
  return filteredTags
658
665
  }
659
- if (tag === GIT_COMMIT_SHA && !validateGitCommitSha(metadata[GIT_COMMIT_SHA])) {
660
- log.error('Git commit SHA must be a full-length git SHA: %s.', metadata[GIT_COMMIT_SHA])
666
+ if ((tag === GIT_COMMIT_SHA || tag === CI_GIT_MERGE_COMMIT_SHA) && !validateGitCommitSha(metadata[tag])) {
667
+ log.error('Git commit SHA must be a full-length git SHA: %s.', metadata[tag])
661
668
  return filteredTags
662
669
  }
663
670
  if (tag === CI_PIPELINE_URL && !validateUrl(metadata[CI_PIPELINE_URL])) {
@@ -736,15 +743,15 @@ function checkShaDiscrepancies (ciMetadata, userProvidedGitMetadata) {
736
743
  v1: ciRepositoryUrl,
737
744
  v2: gitRepositoryUrl,
738
745
  type: 'repository_discrepancy',
739
- expected: 'ci_provider',
740
- discrepant: 'git_client',
746
+ expected: 'git_client',
747
+ discrepant: 'ci_provider',
741
748
  },
742
749
  {
743
750
  v1: ciCommitSHA,
744
751
  v2: gitCommitSHA,
745
752
  type: 'commit_discrepancy',
746
- expected: 'ci_provider',
747
- discrepant: 'git_client',
753
+ expected: 'git_client',
754
+ discrepant: 'ci_provider',
748
755
  },
749
756
  ]
750
757
 
@@ -782,32 +789,36 @@ function getTestEnvironmentMetadata (testFramework, config, shouldSkipGitMetadat
782
789
  if (!shouldSkipGitMetadataExtraction) {
783
790
  checkShaDiscrepancies(ciMetadata, userProvidedGitMetadata)
784
791
 
785
- const {
786
- [GIT_COMMIT_SHA]: commitSHA,
787
- [GIT_BRANCH]: branch,
788
- [GIT_REPOSITORY_URL]: repositoryUrl,
789
- [GIT_TAG]: tag,
790
- [GIT_COMMIT_AUTHOR_NAME]: authorName,
791
- [GIT_COMMIT_AUTHOR_EMAIL]: authorEmail,
792
- [GIT_COMMIT_MESSAGE]: commitMessage,
793
- [CI_WORKSPACE_PATH]: ciWorkspacePath,
794
- [GIT_COMMIT_HEAD_SHA]: headCommitSha,
795
- } = ciMetadata
796
792
  gitMetadata = getGitMetadata({
797
- commitSHA,
798
- branch,
799
- repositoryUrl,
800
- tag,
801
- authorName,
802
- authorEmail,
803
- commitMessage,
804
- ciWorkspacePath,
805
- headCommitSha,
793
+ ciWorkspacePath: ciMetadata[CI_WORKSPACE_PATH],
794
+ headCommitSha: ciMetadata[GIT_COMMIT_HEAD_SHA],
806
795
  pullRequestBaseBranchSha: userProvidedGitMetadata[GIT_PULL_REQUEST_BASE_BRANCH_SHA] ||
807
796
  ciMetadata[GIT_PULL_REQUEST_BASE_BRANCH_SHA],
808
797
  })
809
798
  }
810
799
 
800
+ let providerMetadata = ciMetadata
801
+ if (gitMetadata[GIT_COMMIT_SHA]) {
802
+ providerMetadata = {}
803
+ // Preserve workflow and PR relationships separately from the selected checkout metadata.
804
+ for (const key of Object.keys(ciMetadata)) {
805
+ const isPullRequestMetadata = key.startsWith('git.commit.head.') || key.startsWith('git.pull_request.')
806
+ if (!key.startsWith('git.') || isPullRequestMetadata) {
807
+ providerMetadata[key] = ciMetadata[key]
808
+ }
809
+ }
810
+ const isMatchingDetachedCheckout = ciMetadata[CI_WORKSPACE_PATH] && gitMetadata[GIT_CHECKOUT_ROOT] &&
811
+ gitMetadata[GIT_CHECKOUT_IS_CUSTOM] !== 'true' && !gitMetadata[GIT_BRANCH] &&
812
+ (gitMetadata[GIT_COMMIT_SHA] === ciMetadata[GIT_COMMIT_SHA] ||
813
+ gitMetadata[GIT_COMMIT_SHA] === ciMetadata[CI_GIT_MERGE_COMMIT_SHA])
814
+ if (isMatchingDetachedCheckout) {
815
+ // A detached CI checkout can use a mirror remote; CI supplies its branch, tag and canonical repository identity.
816
+ for (const key of [GIT_BRANCH, GIT_TAG, GIT_REPOSITORY_URL]) {
817
+ if (ciMetadata[key]) providerMetadata[key] = ciMetadata[key]
818
+ }
819
+ }
820
+ }
821
+
811
822
  /** @type {TestEnvironmentMetadata} */
812
823
  const runtimeAndOSMetadata = getRuntimeAndOSMetadata()
813
824
 
@@ -815,10 +826,22 @@ function getTestEnvironmentMetadata (testFramework, config, shouldSkipGitMetadat
815
826
  [TEST_FRAMEWORK]: testFramework,
816
827
  [DD_TEST_IS_USER_PROVIDED_SERVICE]: (config && config.isServiceUserProvided) ? 'true' : 'false',
817
828
  ...gitMetadata,
818
- ...ciMetadata,
829
+ ...providerMetadata,
819
830
  ...userProvidedGitMetadata,
820
831
  ...runtimeAndOSMetadata,
821
832
  }
833
+ const explicitSha = userProvidedGitMetadata[GIT_COMMIT_SHA]
834
+ if (explicitSha && explicitSha !== (gitMetadata[GIT_COMMIT_SHA] || ciMetadata[GIT_COMMIT_SHA])) {
835
+ // The checkout's author, message and tag must not describe a different user-selected commit.
836
+ for (const key of Object.keys(metadata)) {
837
+ if ((key === GIT_TAG || (key.startsWith('git.commit.') && key !== GIT_COMMIT_SHA &&
838
+ !key.startsWith('git.commit.head.'))) &&
839
+ // eslint-disable-next-line prefer-object-has-own -- Cypress 6's plugin process runs on Node 12.
840
+ !Object.prototype.hasOwnProperty.call(userProvidedGitMetadata, key)) {
841
+ delete metadata[key]
842
+ }
843
+ }
844
+ }
822
845
  if (/^(true|1)$/i.test(getEnvironmentVariable('_DD_TEST_PARALLELIZATION_ENABLED'))) {
823
846
  metadata[TEST_PARALLELIZATION_ENABLED] = 'true'
824
847
  Object.assign(metadata, getTestParallelizationPlanMetadata())
@@ -1968,23 +1991,25 @@ function getLibraryCapabilitiesTags (testFramework, frameworkVersion, options =
1968
1991
  }
1969
1992
  }
1970
1993
 
1971
- function getPullRequestBaseBranch (pullRequestBaseBranch) {
1972
- const remoteName = getGitRemoteName()
1994
+ function getPullRequestBaseBranch (pullRequestBaseBranch, gitRoot) {
1995
+ const remoteName = getGitRemoteName(gitRoot)
1973
1996
 
1974
- const sourceBranch = getSourceBranch()
1997
+ const sourceBranch = getSourceBranch(gitRoot)
1975
1998
  // TODO: We will get the default branch name from the backend in the future.
1976
1999
  const POSSIBLE_DEFAULT_BRANCHES = ['main', 'master']
1977
2000
 
1978
2001
  const candidateBranches = []
1979
2002
  if (pullRequestBaseBranch) {
1980
- checkAndFetchBranch(pullRequestBaseBranch, remoteName)
1981
- candidateBranches.push(pullRequestBaseBranch)
2003
+ checkAndFetchBranch(pullRequestBaseBranch, remoteName, gitRoot)
2004
+ candidateBranches.push(hasLocalGitObject(pullRequestBaseBranch, gitRoot)
2005
+ ? pullRequestBaseBranch
2006
+ : `${remoteName}/${pullRequestBaseBranch}`)
1982
2007
  } else {
1983
2008
  for (const branch of POSSIBLE_BASE_BRANCHES) {
1984
- checkAndFetchBranch(branch, remoteName)
2009
+ checkAndFetchBranch(branch, remoteName, gitRoot)
1985
2010
  }
1986
2011
 
1987
- const localBranches = getLocalBranches(remoteName)
2012
+ const localBranches = getLocalBranches(remoteName, gitRoot)
1988
2013
  for (const branch of localBranches) {
1989
2014
  const shortBranchName = branch.replace(new RegExp(`^${remoteName}/`), '')
1990
2015
  if (branch !== sourceBranch && BASE_LIKE_BRANCH_FILTER.test(shortBranchName)) {
@@ -1994,19 +2019,19 @@ function getPullRequestBaseBranch (pullRequestBaseBranch) {
1994
2019
  }
1995
2020
 
1996
2021
  if (candidateBranches.length === 1) {
1997
- return getMergeBase(candidateBranches[0], sourceBranch)
2022
+ return getMergeBase(candidateBranches[0], sourceBranch, gitRoot)
1998
2023
  }
1999
2024
 
2000
2025
  const metrics = {}
2001
2026
  let hasMetrics = false
2002
2027
  for (const candidate of candidateBranches) {
2003
2028
  // Find common ancestor
2004
- const baseSha = getMergeBase(candidate, sourceBranch)
2029
+ const baseSha = getMergeBase(candidate, sourceBranch, gitRoot)
2005
2030
  if (!baseSha) {
2006
2031
  continue
2007
2032
  }
2008
2033
  // Count commits ahead/behind
2009
- const counts = getCounts(candidate, sourceBranch)
2034
+ const counts = getCounts(candidate, sourceBranch, gitRoot)
2010
2035
  if (!counts) {
2011
2036
  continue
2012
2037
  }
@@ -2042,11 +2067,11 @@ function getPullRequestBaseBranch (pullRequestBaseBranch) {
2042
2067
  return bestBranch ? metrics[bestBranch].baseSha : null
2043
2068
  }
2044
2069
 
2045
- function getPullRequestDiff (baseCommit, targetCommit) {
2070
+ function getPullRequestDiff (baseCommit, targetCommit, gitRoot) {
2046
2071
  if (!baseCommit) {
2047
2072
  return
2048
2073
  }
2049
- return getGitDiff(baseCommit, targetCommit)
2074
+ return getGitDiff(baseCommit, targetCommit, gitRoot)
2050
2075
  }
2051
2076
 
2052
2077
  function getModifiedFilesFromDiff (diff) {
@@ -16,6 +16,8 @@ const INT_ID_SEGMENT = /^(?=.*[0-9])[0-9._-]{3,}$/ // Mixed string with digits a
16
16
  const HEX_SEGMENT = /^(?=.*[0-9])[A-Fa-f0-9]{6,}$/ // Hexadecimal digits of size at least 6 with at least one decimal digit
17
17
  const HEX_ID_SEGMENT = /^(?=.*[0-9])[A-Fa-f0-9._-]{6,}$/ // Mixed string with hex digits and delimiters
18
18
  const SPECIAL_CHARACTER_SEGMENT = /[%&'()*+,:=@]/
19
+ const SCP_STYLE_REPOSITORY_URL = /^(?:[^@/:\s\\]+@)?(?:\[[^@\]/\s\\]+\]|[^@/:\s\\]+):.+$/
20
+ const REPOSITORY_URI_OR_DRIVE = /^(?:[a-z][a-z\d+.-]*:\/\/|[a-z]:[\\/])/i
19
21
 
20
22
  /**
21
23
  * Extract full URL from HTTP request
@@ -178,12 +180,17 @@ function calculateHttpEndpoint (url) {
178
180
  : '/'
179
181
  }
180
182
 
183
+ /** @param {string} repositoryUrl */
184
+ function isScpStyleRepositoryUrl (repositoryUrl) {
185
+ return !REPOSITORY_URI_OR_DRIVE.test(repositoryUrl) && SCP_STYLE_REPOSITORY_URL.test(repositoryUrl)
186
+ }
187
+
181
188
  function filterSensitiveInfoFromRepository (repositoryUrl) {
182
189
  if (!repositoryUrl) {
183
190
  return ''
184
191
  }
185
- if (repositoryUrl.startsWith('git@')) {
186
- return repositoryUrl
192
+ if (isScpStyleRepositoryUrl(repositoryUrl)) {
193
+ return repositoryUrl.startsWith('git@') ? repositoryUrl : repositoryUrl.replace(/^[^@/:]+@/, '')
187
194
  }
188
195
 
189
196
  // Remove the username from ssh URLs
@@ -208,5 +215,6 @@ module.exports = {
208
215
  buildClientHttpUrl,
209
216
  calculateHttpEndpoint,
210
217
  filterSensitiveInfoFromRepository,
218
+ isScpStyleRepositoryUrl,
211
219
  extractPathFromUrl, // used by http-otel-semantics decomposeServerUrl fallback (and tests)
212
220
  }
@@ -19,7 +19,7 @@ const {
19
19
  } = require('./tags')
20
20
 
21
21
  const { normalizeRef } = require('./ci')
22
- const { filterSensitiveInfoFromRepository } = require('./url')
22
+ const { filterSensitiveInfoFromRepository, isScpStyleRepositoryUrl } = require('./url')
23
23
 
24
24
  function removeEmptyValues (tagsAndValues) {
25
25
  const filteredTags = {}
@@ -36,7 +36,7 @@ function removeEmptyValues (tagsAndValues) {
36
36
  // https://github.com/jonschlinkert/is-git-url/blob/396965ffabf2f46656c8af4c47bef1d69f09292e/index.js#L9C15-L9C87
37
37
  // The `.git` suffix is optional in this version
38
38
  function validateGitRepositoryUrl (repoUrl) {
39
- return /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\/?|#[-\w.]+)$/.test(repoUrl)
39
+ return isScpStyleRepositoryUrl(repoUrl) || /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\/?|#[-\w.]+)$/.test(repoUrl)
40
40
  }
41
41
 
42
42
  function validateGitCommitSha (gitCommitSha) {