dd-trace 5.134.0 → 5.135.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 (168) hide show
  1. package/LICENSE-3rdparty.csv +0 -1
  2. package/ci/cypress/support.js +15 -1
  3. package/ci/diagnose.js +4 -4
  4. package/ci/test-annotations.d.ts +5 -0
  5. package/ci/test-annotations.js +5 -0
  6. package/ci/test-optimization-validation/approval-artifacts.js +2 -2
  7. package/ci/test-optimization-validation/approval.js +2 -2
  8. package/ci/test-optimization-validation/artifact-id.js +2 -3
  9. package/ci/test-optimization-validation/ci-package-scripts.js +1 -1
  10. package/ci/test-optimization-validation/cli.js +1 -1
  11. package/ci/test-optimization-validation/command-runner.js +2 -3
  12. package/ci/test-optimization-validation/executable.js +1 -1
  13. package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
  14. package/ci/test-optimization-validation/literal-environment.js +2 -2
  15. package/ci/test-optimization-validation/manifest-scaffold.js +1 -1
  16. package/ci/test-optimization-validation/offline-fixtures.js +1 -1
  17. package/ci/test-optimization-validation/redaction.js +3 -3
  18. package/ci/test-optimization-validation/runner-contract.js +10 -10
  19. package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -1
  20. package/ci/vitest-no-worker-init-annotations.mjs +4 -0
  21. package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
  22. package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
  23. package/ci/vitest-no-worker-init-setup.mjs +34 -12
  24. package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
  25. package/ext/exporters.js +1 -0
  26. package/index.d.ts +19 -0
  27. package/loader-hook.mjs +53 -0
  28. package/openfeature/exposure-hook.d.ts +66 -0
  29. package/openfeature/exposure-hook.js +5 -0
  30. package/package.json +11 -9
  31. package/packages/datadog-core/src/storage.js +1 -1
  32. package/packages/datadog-esbuild/index.js +70 -7
  33. package/packages/datadog-instrumentations/src/cucumber.js +53 -19
  34. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  35. package/packages/datadog-instrumentations/src/graphql.js +9 -3
  36. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  37. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  38. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  39. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -1
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +8 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
  50. package/packages/datadog-instrumentations/src/jest.js +265 -82
  51. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  52. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  53. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  54. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  55. package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
  56. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  57. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  58. package/packages/datadog-instrumentations/src/pg.js +2 -1
  59. package/packages/datadog-instrumentations/src/playwright.js +81 -28
  60. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  61. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  62. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
  63. package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
  64. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  65. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  66. package/packages/datadog-instrumentations/src/vitest.js +10 -8
  67. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  68. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +274 -44
  69. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  70. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  71. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  72. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  73. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  74. package/packages/datadog-plugin-cypress/src/support.js +1217 -439
  75. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  76. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  77. package/packages/datadog-plugin-jest/src/index.js +25 -3
  78. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  79. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  80. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  81. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  82. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  83. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  84. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  85. package/packages/dd-trace/src/agent/info.js +2 -1
  86. package/packages/dd-trace/src/aiguard/sdk.js +0 -11
  87. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
  88. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  89. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
  90. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
  91. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  92. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  93. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  94. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  95. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
  96. package/packages/dd-trace/src/config/defaults.js +4 -3
  97. package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -0
  98. package/packages/dd-trace/src/config/index.js +95 -39
  99. package/packages/dd-trace/src/config/parsers.js +9 -1
  100. package/packages/dd-trace/src/config/supported-configurations.json +16 -0
  101. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  102. package/packages/dd-trace/src/encode/0.4.js +2 -2
  103. package/packages/dd-trace/src/esm-module-load.js +58 -0
  104. package/packages/dd-trace/src/exporter.js +25 -6
  105. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  106. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  107. package/packages/dd-trace/src/exporters/common/request.js +4 -4
  108. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  109. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  110. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  111. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  112. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  113. package/packages/dd-trace/src/llmobs/index.js +13 -2
  114. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  115. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  116. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
  117. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  118. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  119. package/packages/dd-trace/src/llmobs/sdk.js +2 -1
  120. package/packages/dd-trace/src/llmobs/span_processor.js +210 -12
  121. package/packages/dd-trace/src/llmobs/tagger.js +3 -0
  122. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  123. package/packages/dd-trace/src/log/writer.js +7 -1
  124. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
  125. package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
  126. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  127. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  128. package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
  129. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  130. package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
  131. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  132. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  133. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  134. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  135. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  136. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  137. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  138. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  139. package/packages/dd-trace/src/opentracing/tracer.js +9 -13
  140. package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
  141. package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
  142. package/packages/dd-trace/src/plugins/index.js +3 -0
  143. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  144. package/packages/dd-trace/src/plugins/util/git.js +11 -5
  145. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
  146. package/packages/dd-trace/src/plugins/util/test.js +26 -6
  147. package/packages/dd-trace/src/plugins/util/web.js +16 -0
  148. package/packages/dd-trace/src/process-tags/index.js +1 -1
  149. package/packages/dd-trace/src/profiling/config.js +6 -3
  150. package/packages/dd-trace/src/proxy.js +15 -4
  151. package/packages/dd-trace/src/serverless.js +3 -2
  152. package/packages/dd-trace/src/span_processor.js +21 -9
  153. package/packages/dd-trace/src/span_stats.js +28 -2
  154. package/packages/dd-trace/src/startup-log.js +2 -1
  155. package/packages/dd-trace/src/tagger.js +7 -5
  156. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  157. package/packages/dd-trace/src/telemetry/index.js +3 -0
  158. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  159. package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
  160. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  161. package/packages/dd-trace/src/util.js +1 -1
  162. package/register.js +2 -1
  163. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  164. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  165. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  166. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  167. package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
  168. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -44,6 +44,12 @@ const webTagsCache = require('./web-tags-cache')
44
44
  /** @typedef {import('./opentracing/span')} DatadogSpan */
45
45
  /** @typedef {import('./opentracing/span_context')} DatadogSpanContext */
46
46
  /** @typedef {InstanceType<typeof import('@datadog/pprof').otelThreadCtx.ThreadContext>} ThreadContext */
47
+ /**
48
+ * @typedef {object} CachedContext
49
+ * @property {ThreadContext | undefined} context
50
+ * @property {ReturnType<DatadogSpanContext['getTags']> | undefined} webTags
51
+ * @property {number} endpointIndex
52
+ */
47
53
 
48
54
  // OTEP-4947 duplicates are last-wins, so appending a later endpoint value would
49
55
  // correctly overwrite an earlier one — but an out-of-process reader sampling the
@@ -67,9 +73,10 @@ const webTagsCache = require('./web-tags-cache')
67
73
  // a bag, on already-expired spans under manual-GC debug mode — and webTagsCache
68
74
  // already depends on it, holding bags the wall profiler dereferences much later.
69
75
  //
70
- // Entries are dropped as soon as the endpoint resolves, or die with the tag bag
71
- // if it never does.
76
+ // Waiters leave on span finish, ancestry changes, or endpoint resolution.
72
77
  const pendingEndpoints = new WeakMap()
78
+ const NOT_WAITING = -1
79
+ const AWAITING_OWN_ENDPOINT = -2
73
80
 
74
81
  // Positional attribute layout. The local root span ID stays at index 0 by
75
82
  // convention (mirrors libdatadog's libdd-otel-thread-ctx, where
@@ -122,14 +129,10 @@ function traceFlagsOf (spanContext) {
122
129
  //
123
130
  // Fields:
124
131
  // context: ThreadContext from @datadog/pprof.otelThreadCtx — built the first
125
- // time onEnter activates the span, and cleared on span finish, which
126
- // is how a pendingEndpoints waiter recognizes a record it must no
127
- // longer append to.
132
+ // time onEnter activates the span.
128
133
  // webTags: the web-server tag bag the record's endpoint comes from, or is
129
134
  // waiting on; undefined while the span has no web-server ancestry.
130
- // Distinguishes a stale announcement from a live one when a nearer
131
- // web-server span takes over.
132
- // awaitsOwnEndpoint: this is the request span, waiting on its own endpoint.
135
+ // endpointIndex: slot in pendingEndpoints, or NOT_WAITING / AWAITING_OWN_ENDPOINT.
133
136
  const CachedSym = Symbol('OtelThreadCtx.cached')
134
137
 
135
138
  let started = false
@@ -205,7 +208,7 @@ function getOrBuildContext (span) {
205
208
  attrs[THREAD_NAME_IDX] = THREAD_NAME
206
209
  attrs[THREAD_ID_IDX] = THREAD_ID
207
210
  if (cached === undefined) {
208
- cached = { context: undefined, webTags: undefined, awaitsOwnEndpoint: false }
211
+ cached = { context: undefined, webTags: undefined, endpointIndex: NOT_WAITING }
209
212
  span[CachedSym] = cached
210
213
  }
211
214
  // The flags are the one part of the record that can still change after
@@ -222,6 +225,11 @@ function getOrBuildContext (span) {
222
225
 
223
226
  // Enlist a record built without an endpoint, so the resolution announcement for
224
227
  // its request fills it in.
228
+ /**
229
+ * @param {DatadogSpan} span
230
+ * @param {CachedContext['webTags']} webTags
231
+ * @param {CachedContext} cached
232
+ */
225
233
  function awaitEndpoint (span, webTags, cached) {
226
234
  // No web-server span in this span's ancestry, so no endpoint is coming. Should
227
235
  // one appear later, webTagsCache announces that separately — see
@@ -229,17 +237,36 @@ function awaitEndpoint (span, webTags, cached) {
229
237
  if (webTags === undefined) return
230
238
  // The request span waits on its own announcement; only descendants need the shared list.
231
239
  if (webTags === span.context().getTags()) {
232
- cached.awaitsOwnEndpoint = true
240
+ cached.endpointIndex = AWAITING_OWN_ENDPOINT
233
241
  return
234
242
  }
235
243
  const waiting = pendingEndpoints.get(webTags)
236
244
  if (waiting === undefined) {
245
+ cached.endpointIndex = 0
237
246
  pendingEndpoints.set(webTags, [cached])
238
247
  } else {
248
+ cached.endpointIndex = waiting.length
239
249
  waiting.push(cached)
240
250
  }
241
251
  }
242
252
 
253
+ /** @param {CachedContext} cached */
254
+ function removePendingEndpoint (cached) {
255
+ const index = cached.endpointIndex
256
+ if (index < 0) return
257
+ const waiting = pendingEndpoints.get(cached.webTags)
258
+ const last = waiting.pop()
259
+ if (last !== cached) {
260
+ waiting[index] = last
261
+ last.endpointIndex = index
262
+ }
263
+ cached.endpointIndex = NOT_WAITING
264
+ }
265
+
266
+ /**
267
+ * @param {ThreadContext} context
268
+ * @param {string} endpoint
269
+ */
243
270
  function appendEndpoint (context, endpoint) {
244
271
  // Append in place. The record buffer is shared across every async-context
245
272
  // frame holding this context, so the endpoint becomes visible everywhere at
@@ -264,6 +291,7 @@ function onEnter () {
264
291
  context.enter()
265
292
  }
266
293
 
294
+ /** @param {DatadogSpan} span */
267
295
  function onSpanFinished (span) {
268
296
  if (!started) return
269
297
  const cached = span[CachedSym]
@@ -271,6 +299,7 @@ function onSpanFinished (span) {
271
299
  span[CachedSym] = undefined
272
300
  const context = cached.context
273
301
  if (context === undefined) return
302
+ removePendingEndpoint(cached)
274
303
  // The span is over, so its record must stop presenting itself as an active
275
304
  // thread context to an out-of-process reader. Invalidating the record covers
276
305
  // every async-context frame still holding this same context reference —
@@ -280,9 +309,6 @@ function onSpanFinished (span) {
280
309
  // overwrite the record, and in ACF mode there is no `before` hook either, so
281
310
  // they would keep exposing the finished span's IDs.
282
311
  context.invalidate()
283
- // Marks the record dead for any pendingEndpoints waiter still holding this
284
- // entry, which must not append to an invalidated record.
285
- cached.context = undefined
286
312
  // Also detach from the current frame when it is the holder, so the record
287
313
  // becomes unreachable and collectable instead of lingering as an invalid one
288
314
  // for the rest of the frame's life.
@@ -302,26 +328,26 @@ function onSpanFinished (span) {
302
328
  // The endpoint of a request has settled: fill in every record built while it was
303
329
  // still unresolved. `span` is the web-server span, so its tag bag is the key its
304
330
  // descendants enlisted under.
331
+ /** @param {DatadogSpan} span */
305
332
  function onEndpointResolved (span) {
306
333
  if (!started) return
307
334
  const webTags = span.context().getTags()
308
335
  const own = span[CachedSym]
309
- const ownWaits = own !== undefined && own.awaitsOwnEndpoint
336
+ const ownWaits = own !== undefined && own.endpointIndex === AWAITING_OWN_ENDPOINT
310
337
  const waiting = pendingEndpoints.get(webTags)
311
338
  if (!ownWaits && waiting === undefined) return
312
339
  const endpoint = finalEndpoint(webTags)
313
340
  // webTagsCache only announces settled endpoints, so this is belt and braces.
314
341
  if (endpoint === undefined) return
315
342
  if (ownWaits) {
316
- own.awaitsOwnEndpoint = false
317
- if (own.context !== undefined && own.webTags === webTags) appendEndpoint(own.context, endpoint)
343
+ own.endpointIndex = NOT_WAITING
344
+ appendEndpoint(own.context, endpoint)
318
345
  }
319
346
  if (waiting === undefined) return
320
347
  pendingEndpoints.delete(webTags)
321
348
  for (const cached of waiting) {
322
- // A record whose span has since been attributed to a nearer web-server span
323
- // enlisted again under that bag, and this one is no longer its endpoint.
324
- if (cached.context !== undefined && cached.webTags === webTags) appendEndpoint(cached.context, endpoint)
349
+ cached.endpointIndex = NOT_WAITING
350
+ appendEndpoint(cached.context, endpoint)
325
351
  }
326
352
  }
327
353
 
@@ -330,14 +356,14 @@ function onEndpointResolved (span) {
330
356
  // built without any web-server ancestry its first endpoint, or a nearer
331
357
  // web-server span superseded the one this record is showing. Give the record
332
358
  // the new request's endpoint if it has settled, or wait for its announcement.
359
+ /** @param {DatadogSpan} span */
333
360
  function onWebTagsResolved (span) {
334
361
  if (!started) return
335
362
  const cached = span[CachedSym]
336
363
  if (cached === undefined || cached.context === undefined) return
337
364
  const webTags = webTagsCache.getCachedWebTags(span)
338
365
  if (webTags === cached.webTags) return
339
- // Recorded so that an announcement for the bag this record was previously
340
- // waiting on no longer applies to it.
366
+ removePendingEndpoint(cached)
341
367
  cached.webTags = webTags
342
368
  const endpoint = finalEndpoint(webTags)
343
369
  if (endpoint === undefined) {
@@ -223,7 +223,7 @@ module.exports = class CiPlugin extends Plugin {
223
223
  this.libraryConfig = undefined
224
224
  this.itrCorrelationId = undefined
225
225
  this.skippableSuitesCoverage = undefined
226
- log.error('Library configuration could not be fetched. %s', err.message)
226
+ log.error('Library configuration could not be fetched', err)
227
227
  this._addRequestErrorTag(DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS, err)
228
228
  } else {
229
229
  this.libraryConfig = effectiveLibraryConfig
@@ -263,7 +263,7 @@ module.exports = class CiPlugin extends Plugin {
263
263
  },
264
264
  (err, skippableSuites, itrCorrelationId, skippableSuitesCoverage) => {
265
265
  if (err) {
266
- log.error('Skippable suites could not be fetched. %s', err.message)
266
+ log.error('Skippable suites could not be fetched', err)
267
267
  this._addRequestErrorTag(DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS, err)
268
268
  } else {
269
269
  this.itrCorrelationId = itrCorrelationId
@@ -378,7 +378,7 @@ module.exports = class CiPlugin extends Plugin {
378
378
  }
379
379
  this.tracer._exporter.getKnownTests(this.testConfiguration, (err, knownTests) => {
380
380
  if (err) {
381
- log.error('Known tests could not be fetched. %s', err.message)
381
+ log.error('Known tests could not be fetched', err)
382
382
  this._addRequestErrorTag(DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS, err)
383
383
  if (this.libraryConfig) {
384
384
  this.libraryConfig = Object.freeze({
@@ -402,7 +402,7 @@ module.exports = class CiPlugin extends Plugin {
402
402
  }
403
403
  this.tracer._exporter.getTestManagementTests(this.testConfiguration, (err, testManagementTests) => {
404
404
  if (err) {
405
- log.error('Test management tests could not be fetched. %s', err.message)
405
+ log.error('Test management tests could not be fetched', err)
406
406
  this._addRequestErrorTag(DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS, err)
407
407
  if (this.libraryConfig) {
408
408
  this.libraryConfig = Object.freeze({
@@ -41,6 +41,7 @@ const plugins = {
41
41
  get '@redis/client' () { return require('../../../datadog-plugin-redis/src') },
42
42
  get '@smithy/core' () { return require('../../../datadog-plugin-aws-sdk/src') },
43
43
  get '@smithy/smithy-client' () { return require('../../../datadog-plugin-aws-sdk/src') },
44
+ get '@typesafe-ai/sdk' () { return require('../../../datadog-plugin-typesafe/src') },
44
45
  get '@vitest/runner' () { return require('../../../datadog-plugin-vitest/src') },
45
46
  get '@wdio/jasmine-framework' () { return require('../../../datadog-plugin-mocha/src') },
46
47
  get '@wdio/local-runner' () { return require('../../../datadog-plugin-mocha/src') },
@@ -71,6 +72,7 @@ const plugins = {
71
72
  get fs () { return require('../../../datadog-plugin-fs/src') },
72
73
  get 'global:fetch' () { return require('../../../datadog-plugin-fetch/src') },
73
74
  get graphql () { return require('../../../datadog-plugin-graphql/src') },
75
+ get 'graphql-jit' () { return require('../../../datadog-plugin-graphql/src') },
74
76
  get grpc () { return require('../../../datadog-plugin-grpc/src') },
75
77
  get hapi () { return require('../../../datadog-plugin-hapi/src') },
76
78
  get hono () { return require('../../../datadog-plugin-hono/src') },
@@ -128,6 +130,7 @@ const plugins = {
128
130
  get playwright () { return require('../../../datadog-plugin-playwright/src') },
129
131
  get postgres () { return require('../../../datadog-plugin-postgres/src') },
130
132
  get protobufjs () { return require('../../../datadog-plugin-protobufjs/src') },
133
+ get 'react-router' () { return require('../../../datadog-plugin-react-router/src') },
131
134
  get redis () { return require('../../../datadog-plugin-redis/src') },
132
135
  get restify () { return require('../../../datadog-plugin-restify/src') },
133
136
  get rhea () { return require('../../../datadog-plugin-rhea/src') },
@@ -203,7 +203,7 @@ class TracingPlugin extends Plugin {
203
203
  * @param {import('../tracer')} [options.tracer] - The tracer.
204
204
  * @param {object} [options.config] - The config for the span.
205
205
  *
206
- * @param {boolean} enterOrCtx - Whether to enter the span context into the storage.
206
+ * @param {boolean | object} enterOrCtx - Whether to enter the span context, or the context to populate with stores.
207
207
  */
208
208
  startSpan (name, options = {}, enterOrCtx = true) {
209
209
  // TODO: modularize this code to a helper function
@@ -88,7 +88,11 @@ function sanitizedExec (
88
88
  exitCode: err.status || err.errno,
89
89
  })
90
90
  }
91
- log.error('Git plugin error executing command', err)
91
+ if (executionOptions?.expectedFailure) {
92
+ log.debug('Git plugin error executing command', err)
93
+ } else {
94
+ log.error('Git plugin error executing command', err)
95
+ }
92
96
  if (executionOptions?.throwOnError) throw err
93
97
  return ''
94
98
  }
@@ -226,7 +230,7 @@ function getLatestCommits () {
226
230
  distributionMetric(TELEMETRY_GIT_COMMAND_MS, { command: 'get_local_commits' }, Date.now() - startTime)
227
231
  return result
228
232
  } catch (err) {
229
- log.error('Get latest commits failed: %s', err.message)
233
+ log.error('Get latest commits failed', err)
230
234
  incrementCountMetric(
231
235
  TELEMETRY_GIT_COMMAND_ERRORS,
232
236
  { command: 'get_local_commits', errorType: err.status }
@@ -262,7 +266,9 @@ function getGitRemoteName () {
262
266
  ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'],
263
267
  { name: TELEMETRY_GIT_COMMAND, tags: { command: 'get_remote_name' } },
264
268
  { name: TELEMETRY_GIT_COMMAND_MS, tags: { command: 'get_remote_name' } },
265
- { name: TELEMETRY_GIT_COMMAND_ERRORS, tags: { command: 'get_remote_name' } }
269
+ { name: TELEMETRY_GIT_COMMAND_ERRORS, tags: { command: 'get_remote_name' } },
270
+ true,
271
+ { expectedFailure: true } // Detached HEADs and branches without an upstream use the remote-list fallback.
266
272
  )
267
273
 
268
274
  if (upstreamRemote) {
@@ -391,7 +397,7 @@ function getCommitsRevList (commitsToExclude, commitsToInclude) {
391
397
  .split('\n')
392
398
  .filter(Boolean)
393
399
  } catch (err) {
394
- log.error('Get commits to upload failed: %s', err.message)
400
+ log.error('Get commits to upload failed', err)
395
401
  incrementCountMetric(
396
402
  TELEMETRY_GIT_COMMAND_ERRORS,
397
403
  { command: 'get_objects', errorType: err.code, exitCode: err.status || err.errno } // err.status might be null
@@ -435,7 +441,7 @@ function generatePackFilesForCommits (commitsToUpload) {
435
441
  try {
436
442
  result = execGitPackObjects(temporaryPath)
437
443
  } catch (err) {
438
- log.error('Git plugin error executing git pack-objects command', err)
444
+ log.debug('Git plugin error executing git pack-objects command, trying the working directory', err)
439
445
  incrementCountMetric(
440
446
  TELEMETRY_GIT_COMMAND_ERRORS,
441
447
  { command: 'pack_objects', exitCode: err.status || err.errno, errorType: err.code }
@@ -27,7 +27,7 @@ const KNOWN_METHODS = new Set([
27
27
 
28
28
  // Datadog HTTP meta keys replaced by OTel names — omitted when rebuilding meta.
29
29
  const DD_HTTP_META_KEYS = new Set([
30
- 'http.method', 'http.status_code', 'http.useragent', 'http.client_ip', 'http.endpoint', 'http.url', 'out.host',
30
+ 'http.method', 'http.status_code', 'http.useragent', 'http.client_ip', 'http.url', 'out.host',
31
31
  ])
32
32
  const NETWORK_DESTINATION_PORT = 'network.destination.port'
33
33
 
@@ -155,7 +155,7 @@ function defaultPortForUrl (url) {
155
155
  * `span_format`) when `DD_TRACE_OTEL_SEMANTICS_ENABLED` is set, so every HTTP
156
156
  * integration is covered from one place. No-op for non-HTTP spans. The span
157
157
  * keeps the Datadog tag names throughout its lifetime — only the serialized
158
- * output is renamed — so runtime consumers (peer.service, AppSec, trace stats)
158
+ * output is renamed — so runtime consumers (peer.service, AppSec)
159
159
  * are unaffected.
160
160
  *
161
161
  * @param {FormattedHttpSpan} formattedSpan
@@ -219,8 +219,6 @@ function applyHttpOtelSemantics (formattedSpan) {
219
219
  const clientIp = meta['http.client_ip']
220
220
  if (clientIp !== undefined) newMeta[CLIENT_ADDRESS] = clientIp
221
221
 
222
- // http.endpoint is Datadog-only (omitted above); it has no OTel equivalent.
223
-
224
222
  if (kind === 'server') {
225
223
  // FIXME: some server frameworks (e.g. Next.js — `packages/datadog-plugin-next`)
226
224
  // never populate `http.url`, so the OTel `url.*` / `server.*` attributes below
@@ -310,6 +310,8 @@ const DI_DEBUG_ERROR_LINE_SUFFIX = 'line'
310
310
 
311
311
  // Test Management tags
312
312
  const TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX = 'test.test_management.is_attempt_to_fix'
313
+ const TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION = 'test.test_management.prevent_failure_suppression'
314
+ const TEST_MANAGEMENT_NO_AUTO_RETRY = 'test.test_management.no_auto_retry'
313
315
  const TEST_MANAGEMENT_IS_DISABLED = 'test.test_management.is_test_disabled'
314
316
  const TEST_MANAGEMENT_IS_QUARANTINED = 'test.test_management.is_quarantined'
315
317
  const TEST_MANAGEMENT_ENABLED = 'test.test_management.enabled'
@@ -591,6 +593,8 @@ module.exports = {
591
593
  DD_TEST_IS_USER_PROVIDED_SERVICE,
592
594
  TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX,
593
595
  TEST_MANAGEMENT_IS_DISABLED,
596
+ TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION,
597
+ TEST_MANAGEMENT_NO_AUTO_RETRY,
594
598
  TEST_MANAGEMENT_IS_QUARANTINED,
595
599
  TEST_MANAGEMENT_ENABLED,
596
600
  TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED,
@@ -2343,14 +2347,17 @@ function collectDynamicNameFromTraceSpan (span, newTestsWithDynamicNames) {
2343
2347
 
2344
2348
  function collectAttemptToFixExecutionFromTraceSpan (span, attemptToFixExecutions) {
2345
2349
  const meta = span.meta
2346
- if (meta?.[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] !== 'true') return
2350
+ if (meta?.[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] !== 'true' ||
2351
+ meta[TEST_MANAGEMENT_NO_AUTO_RETRY] === 'true') return
2347
2352
 
2348
2353
  recordAttemptToFixExecution(attemptToFixExecutions, {
2349
2354
  testSuite: meta[TEST_SUITE],
2350
2355
  testName: meta[TEST_NAME],
2351
2356
  status: meta[TEST_STATUS],
2352
- isDisabled: meta[TEST_MANAGEMENT_IS_DISABLED] === 'true',
2353
- isQuarantined: meta[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
2357
+ isDisabled: meta[TEST_MANAGEMENT_IS_DISABLED] === 'true' &&
2358
+ meta[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] !== 'true',
2359
+ isQuarantined: meta[TEST_MANAGEMENT_IS_QUARANTINED] === 'true' &&
2360
+ meta[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] !== 'true',
2354
2361
  })
2355
2362
  }
2356
2363
 
@@ -2368,9 +2375,12 @@ function collectTestManagementExecutionFromTraceSpan (span, executions) {
2368
2375
  testSuite: meta[TEST_SUITE],
2369
2376
  testName: meta[TEST_NAME],
2370
2377
  status: meta[TEST_STATUS],
2371
- isAttemptToFix: meta[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] === 'true',
2372
- isDisabled: meta[TEST_MANAGEMENT_IS_DISABLED] === 'true',
2373
- isQuarantined: meta[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
2378
+ isAttemptToFix: meta[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] === 'true' &&
2379
+ meta[TEST_MANAGEMENT_NO_AUTO_RETRY] !== 'true',
2380
+ isDisabled: meta[TEST_MANAGEMENT_IS_DISABLED] === 'true' &&
2381
+ meta[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] !== 'true',
2382
+ isQuarantined: meta[TEST_MANAGEMENT_IS_QUARANTINED] === 'true' &&
2383
+ meta[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] !== 'true',
2374
2384
  }, executions)
2375
2385
  }
2376
2386
 
@@ -2381,6 +2391,7 @@ function collectTestManagementExecutionFromTraceSpan (span, executions) {
2381
2391
  * @param {string} data - JSON-serialized traces from a worker
2382
2392
  * @param {{
2383
2393
  * newTestsWithDynamicNames?: Set<string>,
2394
+ * testAnnotations?: Map<string, { mustFail: boolean, noAutoRetry: boolean }>,
2384
2395
  * attemptToFixExecutions?: AttemptToFixExecutions,
2385
2396
  * testManagementExecutions?: TestManagementExecutions
2386
2397
  * }} summaries
@@ -2390,12 +2401,21 @@ function collectTestOptimizationSummariesFromTraces (data, summaries) {
2390
2401
  newTestsWithDynamicNames,
2391
2402
  attemptToFixExecutions,
2392
2403
  testManagementExecutions: executions = testManagementExecutions,
2404
+ testAnnotations,
2393
2405
  } = summaries
2394
2406
 
2395
2407
  try {
2396
2408
  const traces = JSON.parse(data)
2397
2409
  for (const trace of traces) {
2398
2410
  for (const span of trace) {
2411
+ if (testAnnotations && span.type === 'test' &&
2412
+ (span.meta?.[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] === 'true' ||
2413
+ span.meta?.[TEST_MANAGEMENT_NO_AUTO_RETRY] === 'true')) {
2414
+ testAnnotations.set(`${span.meta[TEST_SUITE]} › ${span.meta[TEST_NAME]}`, {
2415
+ mustFail: span.meta[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] === 'true',
2416
+ noAutoRetry: span.meta[TEST_MANAGEMENT_NO_AUTO_RETRY] === 'true',
2417
+ })
2418
+ }
2399
2419
  if (newTestsWithDynamicNames) {
2400
2420
  collectDynamicNameFromTraceSpan(span, newTestsWithDynamicNames)
2401
2421
  }
@@ -204,6 +204,22 @@ const web = {
204
204
  return context ? context.span : null
205
205
  },
206
206
 
207
+ /** @param {import('../../opentracing/span') | undefined} span */
208
+ rootFromSpan (span) {
209
+ if (!span) return
210
+
211
+ const started = span.context()._trace.started
212
+ while (span) {
213
+ const context = span.context()
214
+ if (context.getTag(SPAN_KIND) === SERVER && typeof context.getTag(HTTP_URL) === 'string') return span
215
+
216
+ const parentId = context._parentId
217
+ if (!parentId) return
218
+ span = started.find(parent => parent.context()._spanId === parentId)
219
+ }
220
+ return span
221
+ },
222
+
207
223
  // Return the active span.
208
224
  active (req) {
209
225
  const context = contexts.get(req)
@@ -15,7 +15,7 @@ const ENTRYPOINT_PATH = require.main?.filename || ''
15
15
  /**
16
16
  * Sanitize a process tag value
17
17
  *
18
- * @param {string} value
18
+ * @param {unknown} value
19
19
  */
20
20
  function sanitize (value) {
21
21
  return String(value)
@@ -78,7 +78,6 @@ function createProfilers (config, { asyncContextFrameEnabled, flushInterval, tag
78
78
  const profilers = []
79
79
  for (const name of selectProfilerTypes(config)) {
80
80
  switch (name) {
81
- case 'cpu':
82
81
  case 'wall':
83
82
  profilers.push(new WallProfiler(config, { asyncContextFrameEnabled, flushInterval }))
84
83
  break
@@ -112,7 +111,12 @@ function selectProfilerTypes ({
112
111
  // snapshots the space profile won't include memory taken by profiles created
113
112
  // before it in the sequence. That memory is ultimately transient and will be
114
113
  // released when all profiles are subsequently encoded.
115
- const profilers = new Set(DD_PROFILING_PROFILERS)
114
+ // 'cpu' is an alias of 'wall'. Normalizing it here keeps the settings below from adding a second
115
+ // wall profiler next to the alias.
116
+ const profilers = new Set()
117
+ for (const name of DD_PROFILING_PROFILERS) {
118
+ profilers.add(name === 'cpu' ? 'wall' : name)
119
+ }
116
120
 
117
121
  let spaceExplicitlyEnabled = false
118
122
  // Add/remove space depending on the value of DD_PROFILING_HEAP_ENABLED
@@ -133,7 +137,6 @@ function selectProfilerTypes ({
133
137
  profilers.add('wall')
134
138
  } else {
135
139
  profilers.delete('wall')
136
- profilers.delete('cpu') // remove alias too
137
140
  }
138
141
  }
139
142
 
@@ -117,6 +117,7 @@ function defineLazily (obj, property, getClass, ...args) {
117
117
  }
118
118
 
119
119
  class Tracer extends NoopProxy {
120
+ #aiguardConfigurationErrorLogged = false
120
121
  #openfeatureState = OPENFEATURE_STATE_NOOP
121
122
 
122
123
  /** @type {boolean} */
@@ -196,7 +197,10 @@ class Tracer extends NoopProxy {
196
197
  require('./heap_snapshots').start(config)
197
198
  }
198
199
 
199
- telemetry.start(config, this._pluginManager)
200
+ const telemetryLogOptions = config.isCiVisibility && config.telemetry.DD_INSTRUMENTATION_TELEMETRY_ENABLED
201
+ ? require('./ci-visibility/telemetry-logs')
202
+ : undefined
203
+ telemetry.start(config, this._pluginManager, telemetryLogOptions)
200
204
 
201
205
  if (config.dogstatsd && !config.DD_AGENTLESS_ENABLED && !isOfflineTestOptimizationValidation()) {
202
206
  // Custom Metrics
@@ -261,7 +265,7 @@ class Tracer extends NoopProxy {
261
265
 
262
266
  // Experimental: mirror the active trace ID, span ID and endpoint into
263
267
  // an OTEP-4947 thread-local context record an out-of-process eBPF
264
- // reader can consume.
268
+ // reader can consume. On by default when appsec is enabled.
265
269
  if (config.DD_TRACE_OTEL_CTX_ENABLED) {
266
270
  try {
267
271
  require('./otel-thread-ctx').start()
@@ -408,6 +412,13 @@ class Tracer extends NoopProxy {
408
412
  */
409
413
  #updateTracing (config) {
410
414
  if (config.DD_TRACE_ENABLED !== false) {
415
+ const aiguardEnabled = config.aiguard.DD_AI_GUARD_ENABLED === true &&
416
+ config.DD_API_KEY !== undefined &&
417
+ config.DD_APP_KEY !== undefined
418
+ if (config.aiguard.DD_AI_GUARD_ENABLED && !aiguardEnabled && !this.#aiguardConfigurationErrorLogged) {
419
+ log.error('AIGuard: missing api and/or app keys, use env DD_API_KEY and DD_APP_KEY')
420
+ this.#aiguardConfigurationErrorLogged = true
421
+ }
411
422
  if (config.appsec.DD_APPSEC_ENABLED) {
412
423
  this._modules.appsec.enable(config)
413
424
  }
@@ -424,12 +435,12 @@ class Tracer extends NoopProxy {
424
435
  lazyProxy(this, 'llmobs', () => require('./llmobs/sdk'), this._tracer, this._modules.llmobs, config,
425
436
  () => this.openfeature)
426
437
 
427
- if (config.aiguard.DD_AI_GUARD_ENABLED) {
438
+ if (aiguardEnabled) {
428
439
  lazyProxy(this, 'aiguard', () => require('./aiguard/sdk'), this._tracer, config)
429
440
  }
430
441
  this._tracingInitialized = true
431
442
  }
432
- if (config.aiguard.DD_AI_GUARD_ENABLED) {
443
+ if (aiguardEnabled) {
433
444
  this._modules.aiguard.enable(this._tracer, config)
434
445
  }
435
446
  if (config.iast.DD_IAST_ENABLED) {
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { getEnvironmentVariable, getValueFromEnvSources } = require('./config/helper')
4
4
 
5
+ const IS_AWS_LAMBDA = getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined
5
6
  const IS_AWS_LAMBDA_MICROVM = getEnvironmentVariable('AWS_LAMBDA_MICROVM_IMAGE_ARN') !== undefined
6
7
  // Standard Lambda, whose sandbox freezes between invocations. Excludes Lambda Lite (native-http),
7
8
  // Managed Instances (lambda-managed-instances) and MicroVMs.
@@ -46,11 +47,10 @@ function getIsFlexConsumptionAzureFunction () {
46
47
  }
47
48
 
48
49
  function isInServerlessEnvironment () {
49
- const inAWSLambda = getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined
50
50
  const isGCPFunction = getIsGCPFunction()
51
51
  const isAzureFunction = getIsAzureFunction()
52
52
 
53
- return IS_AWS_LAMBDA_MICROVM || inAWSLambda || isGCPFunction || isAzureFunction
53
+ return IS_AWS_LAMBDA_MICROVM || IS_AWS_LAMBDA || isGCPFunction || isAzureFunction
54
54
  }
55
55
 
56
56
  /**
@@ -112,6 +112,7 @@ module.exports = {
112
112
  enableGCPPubSubPushSubscription,
113
113
  getIsFlexConsumptionAzureFunction,
114
114
  initializeServerlessTelemetry,
115
+ IS_AWS_LAMBDA,
115
116
  IS_AWS_LAMBDA_MICROVM,
116
117
  IS_STANDARD_AWS_LAMBDA,
117
118
  // true only for a Node that bundles its own OpenSSL, whose CSPRNG keeps the snapshot's DRBG
@@ -1,7 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { channel } = require('dc-polyfill')
4
+
3
5
  const { AUTO_KEEP, AUTO_REJECT } = require('../../../ext/priority')
4
6
  const log = require('./log')
7
+ const { usesOtlpTraceExporter } = require('./exporter')
5
8
  const spanFormat = require('./span_format')
6
9
  const SpanSampler = require('./span_sampler')
7
10
  const GitMetadataTagger = require('./git_metadata_tagger')
@@ -10,6 +13,8 @@ const { applyHttpOtelSemantics } = require('./plugins/util/http-otel-semantics')
10
13
  const TraceState = require('./opentracing/propagation/tracestate')
11
14
  const { APM_TRACING_ENABLED_KEY, SDK_OTLP_EXPORT_KEY } = require('./constants')
12
15
 
16
+ const traceSampledCh = channel('dd-trace:trace:sampled')
17
+
13
18
  const startedSpans = new WeakSet()
14
19
  const finishedSpans = new WeakSet()
15
20
 
@@ -26,12 +31,12 @@ function serializeOtlpTraceState (context) {
26
31
  class SpanProcessor {
27
32
  #exportOtlpTraces
28
33
 
29
- constructor (exporter, prioritySampler, config, otlpStatsExporter, exportOtlpTraces) {
34
+ constructor (exporter, prioritySampler, config, otlpStatsExporter) {
30
35
  this._exporter = exporter
31
36
  this._prioritySampler = prioritySampler
32
37
  this._config = config
33
38
  this._killAll = false
34
- this.#exportOtlpTraces = exportOtlpTraces
39
+ this.#exportOtlpTraces = usesOtlpTraceExporter(config)
35
40
 
36
41
  if (config.stats?.DD_TRACE_STATS_COMPUTATION_ENABLED &&
37
42
  !config.appsec?.DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED) {
@@ -45,7 +50,6 @@ class SpanProcessor {
45
50
  this._processTags = config.DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED
46
51
  ? processTags.serialized
47
52
  : false
48
- this._nativeExport = config.OTEL_TRACES_EXPORTER !== 'otlp'
49
53
  }
50
54
 
51
55
  sample (span) {
@@ -83,9 +87,18 @@ class SpanProcessor {
83
87
  this.sample(span)
84
88
  this._gitMetadataTagger.tagGitMetadata(spanContext)
85
89
 
90
+ const discard = this.#isDiscarded(spanContext)
91
+ const willExport = !discard && trace.isRecording !== false
92
+
93
+ if (traceSampledCh.hasSubscribers) {
94
+ traceSampledCh.publish({
95
+ spans: finished,
96
+ willExport,
97
+ })
98
+ }
99
+
86
100
  let isFirstSpanInChunk = true
87
101
  const stampApmDisabled = this._config.apmTracingEnabled === false
88
- const discard = this.#isDiscarded(spanContext)
89
102
  const exportOtlpTraces = this.#exportOtlpTraces && !(spanContext._sampling.priority < AUTO_KEEP)
90
103
  let traceState
91
104
 
@@ -102,21 +115,20 @@ class SpanProcessor {
102
115
  formattedSpan.metrics[APM_TRACING_ENABLED_KEY] = 0
103
116
  }
104
117
  // Stamped after formatting so a span tag with the same key can't override it.
105
- if (isFirstSpanInChunk && this._nativeExport) {
118
+ if (isFirstSpanInChunk && !this.#exportOtlpTraces) {
106
119
  formattedSpan.meta[SDK_OTLP_EXPORT_KEY] = 'false'
107
120
  }
108
121
  isFirstSpanInChunk = false
109
- // Span stats read Datadog HTTP tag names from the formatted span, so
110
- // record them before the OTel rename — an export-only transform.
111
- this._stats?.onSpanFinished(formattedSpan)
112
122
  if (this._config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
113
123
  applyHttpOtelSemantics(formattedSpan)
114
124
  }
125
+ // Trace metrics must aggregate the same names and attributes the OTLP exporter emits.
126
+ this._stats?.onSpanFinished(formattedSpan)
115
127
  formatted.push(formattedSpan)
116
128
  }
117
129
  }
118
130
 
119
- if (!discard && formatted.length !== 0 && trace.isRecording !== false) {
131
+ if (willExport && formatted.length !== 0) {
120
132
  this._exporter.export(formatted)
121
133
  }
122
134