dd-trace 5.136.0 → 5.137.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 (141) 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/package.json +33 -30
  8. package/packages/datadog-esbuild/index.js +8 -15
  9. package/packages/datadog-esbuild/src/log.js +2 -29
  10. package/packages/datadog-instrumentations/src/ai.js +6 -1
  11. package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
  12. package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +23 -1
  13. package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
  14. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +9 -6
  15. package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
  16. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +6 -0
  17. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
  18. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
  19. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
  20. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +21 -0
  21. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +30 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +6 -0
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
  25. package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
  26. package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
  27. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
  28. package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
  29. package/packages/datadog-instrumentations/src/next.js +184 -20
  30. package/packages/datadog-instrumentations/src/router.js +35 -12
  31. package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
  32. package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
  33. package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
  34. package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
  35. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
  36. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
  37. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
  38. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
  39. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
  40. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +30 -4
  41. package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
  42. package/packages/datadog-plugin-express/src/code_origin.js +2 -2
  43. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  44. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -0
  45. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -0
  46. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +7 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
  48. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  49. package/packages/datadog-plugin-http/src/client.js +2 -1
  50. package/packages/datadog-plugin-http2/src/client.js +2 -1
  51. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
  52. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
  53. package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
  54. package/packages/datadog-plugin-postgres/src/index.js +118 -41
  55. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
  56. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
  57. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
  58. package/packages/datadog-plugin-vitest/src/index.js +3 -2
  59. package/packages/datadog-plugin-ws/src/close.js +3 -5
  60. package/packages/datadog-plugin-ws/src/producer.js +1 -4
  61. package/packages/datadog-plugin-ws/src/receiver.js +3 -5
  62. package/packages/datadog-plugin-ws/src/server.js +44 -13
  63. package/packages/datadog-vite/index.js +537 -0
  64. package/packages/datadog-vite/src/log.js +5 -0
  65. package/packages/datadog-webpack/src/log.js +2 -29
  66. package/packages/dd-trace/src/aiguard/index.js +1 -1
  67. package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
  68. package/packages/dd-trace/src/appsec/blocking/index.js +17 -1
  69. package/packages/dd-trace/src/appsec/channels.js +7 -0
  70. package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
  71. package/packages/dd-trace/src/appsec/graphql.js +10 -13
  72. package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
  73. package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
  74. package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
  75. package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
  76. package/packages/dd-trace/src/appsec/index.js +6 -0
  77. package/packages/dd-trace/src/appsec/lambda.js +17 -17
  78. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
  79. package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
  80. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
  81. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
  82. package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
  83. package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
  84. package/packages/dd-trace/src/appsec/recommended.json +70 -3
  85. package/packages/dd-trace/src/appsec/reporter.js +9 -0
  86. package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
  87. package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
  88. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  89. package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
  90. package/packages/dd-trace/src/appsec/waf/index.js +65 -6
  91. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
  92. package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
  93. package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -2
  94. package/packages/dd-trace/src/config/index.js +46 -26
  95. package/packages/dd-trace/src/config/parsers.js +35 -0
  96. package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
  97. package/packages/dd-trace/src/config/remote_config.js +2 -1
  98. package/packages/dd-trace/src/config/supported-configurations.json +14 -6
  99. package/packages/dd-trace/src/datastreams/fnv.js +27 -0
  100. package/packages/dd-trace/src/datastreams/pathway.js +113 -28
  101. package/packages/dd-trace/src/datastreams/processor.js +5 -4
  102. package/packages/dd-trace/src/debugger/config.js +1 -1
  103. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
  104. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  105. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  106. package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
  107. package/packages/dd-trace/src/debugger/index.js +2 -2
  108. package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
  109. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +4 -1
  110. package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
  111. package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
  112. package/packages/dd-trace/src/git_metadata.js +2 -1
  113. package/packages/dd-trace/src/index.js +6 -3
  114. package/packages/dd-trace/src/lambda/facade.js +6 -5
  115. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
  116. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
  117. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +3 -0
  118. package/packages/dd-trace/src/openfeature/configuration_source.js +20 -0
  119. package/packages/dd-trace/src/plugins/ci_plugin.js +104 -9
  120. package/packages/dd-trace/src/plugins/index.js +2 -0
  121. package/packages/dd-trace/src/plugins/util/ci.js +34 -0
  122. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +9 -14
  123. package/packages/dd-trace/src/plugins/util/test.js +28 -1
  124. package/packages/dd-trace/src/plugins/util/url.js +8 -5
  125. package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -4
  126. package/packages/dd-trace/src/process-tags/index.js +1 -1
  127. package/packages/dd-trace/src/profiler.js +74 -12
  128. package/packages/dd-trace/src/profiling/profiler.js +30 -2
  129. package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
  130. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  131. package/packages/dd-trace/src/profiling/remote-config.js +354 -0
  132. package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
  133. package/packages/dd-trace/src/propagation-hash/index.js +7 -0
  134. package/packages/dd-trace/src/proxy.js +13 -1
  135. package/vendor/dist/@opentelemetry/core/LICENSE +11 -0
  136. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  137. package/vite.d.ts +7 -0
  138. package/vite.js +3 -0
  139. package/lambda.d.ts +0 -39
  140. package/lambda.js +0 -3
  141. package/packages/datadog-plugin-cypress/src/support.js +0 -1348
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { normalizeService } = require('../config/normalize-service')
3
4
  const { createSiteUrl } = require('../exporters/common/url')
4
5
  const log = require('../log')
5
6
  const { warnRemoteConfigFlagSelection, withFlagSelection } = require('./flag-selection')
@@ -11,6 +12,8 @@ const AGENTLESS_START_MESSAGE = 'Feature Flags: starting agentless configuration
11
12
  const REMOTE_CONFIG_DISABLED_WARNING = 'Feature Flags: configuration source is remote_config but Remote ' +
12
13
  'Configuration is disabled; flag evaluations will return their default values. Set ' +
13
14
  'DD_REMOTE_CONFIGURATION_ENABLED=true or DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=agentless'
15
+ const USAGE_SERVICE_REJECTED_MESSAGE =
16
+ 'Feature Flags: service %s has no normalized name; DD-Service header not sent'
14
17
  const MISSING_API_KEY_MESSAGE = 'DD_API_KEY is required for the default Datadog Feature Flagging endpoint; ' +
15
18
  'set DD_API_KEY, set DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL, or set ' +
16
19
  'DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=remote_config to load flags through the Datadog Agent'
@@ -73,6 +76,7 @@ function create (config, applyConfiguration) {
73
76
  requestTimeoutMs: requestTimeoutSeconds * 1000,
74
77
  apiKey: hasCustomEndpoint ? undefined : config.DD_API_KEY,
75
78
  env: config.env,
79
+ service: usageService(config.service),
76
80
  }, applyConfiguration)
77
81
  }
78
82
 
@@ -115,6 +119,22 @@ function endpoint (config, configuredBaseUrl) {
115
119
  return url
116
120
  }
117
121
 
122
+ /**
123
+ * Selects the DD-Service value: the tracer service, normalized with the same function as the inferred service. For
124
+ * example, `My Service` becomes `my_service`.
125
+ *
126
+ * If nothing is left of the normalized name, no value is sent. The normalized name has only ASCII characters, so
127
+ * Node.js cannot throw on the header. The tracer service itself does not change. The CDN alone decides which values it
128
+ * uses.
129
+ *
130
+ * @param {string | undefined} service - Tracer service name.
131
+ */
132
+ function usageService (service) {
133
+ const name = normalizeService(service)
134
+ if (service && !name) log.debug(USAGE_SERVICE_REJECTED_MESSAGE, service)
135
+ return name || undefined
136
+ }
137
+
118
138
  /**
119
139
  * Drops everything but the origin; a custom base URL may embed a signed token in its path.
120
140
  *
@@ -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,
@@ -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) {
@@ -39,10 +39,15 @@ function getProtocol (req) {
39
39
  return req.socket?.encrypted ? 'https' : 'http'
40
40
  }
41
41
 
42
+ /**
43
+ * @typedef {object} NormalizedUrlConfig
44
+ * @property {boolean | RegExp} queryStringObfuscation
45
+ */
46
+
42
47
  /**
43
48
  * Obfuscate query string
44
49
  *
45
- * @param {object} config
50
+ * @param {NormalizedUrlConfig} config
46
51
  * @param {string} url
47
52
  */
48
53
  function obfuscateQs (config, url) {
@@ -115,16 +120,14 @@ function getQsObfuscator (config) {
115
120
  * Callers gate this behind `DD_TRACE_OTEL_SEMANTICS_ENABLED`, so the default
116
121
  * (flag off) hot path stays a plain tag assignment.
117
122
  *
118
- * @param {{ queryStringObfuscation?: boolean | string }} config
123
+ * @param {NormalizedUrlConfig} config
119
124
  * @param {string} base `scheme://host[:port]`
120
125
  * @param {string} [pathname] raw request path, may include `?query`
121
126
  * @param {string} strippedUrl `base` + query-stripped path (used when there is no query)
122
127
  */
123
128
  function buildClientHttpUrl (config, base, pathname, strippedUrl) {
124
129
  if (pathname?.includes('?')) {
125
- // `config.queryStringObfuscation` is the raw config value here (client plugins
126
- // don't normalize it the way the server does), so compile it first.
127
- return obfuscateQs({ queryStringObfuscation: getQsObfuscator(config) }, `${base}${pathname}`)
130
+ return obfuscateQs(config, `${base}${pathname}`)
128
131
  }
129
132
  return strippedUrl
130
133
  }
@@ -18,7 +18,7 @@ const {
18
18
  GIT_COMMIT_HEAD_SHA,
19
19
  } = require('./tags')
20
20
 
21
- const { normalizeRef } = require('./ci')
21
+ const { normalizeCommitSha, normalizeRef } = require('./ci')
22
22
  const { filterSensitiveInfoFromRepository, isScpStyleRepositoryUrl } = require('./url')
23
23
 
24
24
  function removeEmptyValues (tagsAndValues) {
@@ -73,7 +73,7 @@ function getUserProviderGitMetadata () {
73
73
 
74
74
  // Key value pairs are grouped in pairs of two
75
75
  return removeEmptyValues([
76
- GIT_COMMIT_SHA, DD_GIT_COMMIT_SHA,
76
+ GIT_COMMIT_SHA, normalizeCommitSha(DD_GIT_COMMIT_SHA),
77
77
  GIT_BRANCH, branch,
78
78
  GIT_REPOSITORY_URL, filterSensitiveInfoFromRepository(DD_GIT_REPOSITORY_URL),
79
79
  GIT_TAG, tag,
@@ -85,8 +85,8 @@ function getUserProviderGitMetadata () {
85
85
  GIT_COMMIT_AUTHOR_EMAIL, DD_GIT_COMMIT_AUTHOR_EMAIL,
86
86
  GIT_COMMIT_AUTHOR_DATE, DD_GIT_COMMIT_AUTHOR_DATE,
87
87
  GIT_PULL_REQUEST_BASE_BRANCH, DD_GIT_PULL_REQUEST_BASE_BRANCH,
88
- GIT_PULL_REQUEST_BASE_BRANCH_SHA, DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA,
89
- GIT_COMMIT_HEAD_SHA, DD_GIT_COMMIT_HEAD_SHA,
88
+ GIT_PULL_REQUEST_BASE_BRANCH_SHA, normalizeCommitSha(DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA),
89
+ GIT_COMMIT_HEAD_SHA, normalizeCommitSha(DD_GIT_COMMIT_HEAD_SHA),
90
90
  ])
91
91
  }
92
92
 
@@ -72,7 +72,7 @@ function buildProcessTags (config) {
72
72
  // Singleton with constant defaults so pre-init reads don't blow up
73
73
  const processTags = module.exports = {
74
74
  /**
75
- * @param {import('../config/config-base')} config
75
+ * @param {import('../config/config-base')} [config]
76
76
  */
77
77
  initialize (config) {
78
78
  // check if one of the properties added during build exist and if so return