dd-trace 6.22.0 → 6.24.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 (194) 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 -5
  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 +35 -5
  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 +23 -20
  31. package/packages/datadog-core/src/storage.js +1 -1
  32. package/packages/datadog-esbuild/index.js +70 -7
  33. package/packages/datadog-instrumentations/index.js +2 -1
  34. package/packages/datadog-instrumentations/src/cucumber.js +64 -21
  35. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  36. package/packages/datadog-instrumentations/src/graphql.js +9 -3
  37. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  38. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +27 -8
  39. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  40. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  41. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -1
  42. package/packages/datadog-instrumentations/src/helpers/register.js +9 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +10 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/jest.js +12 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/vitest.js +8 -0
  50. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  51. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
  52. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  53. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +13 -0
  54. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
  55. package/packages/datadog-instrumentations/src/jest.js +332 -137
  56. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  57. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  58. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  59. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  60. package/packages/datadog-instrumentations/src/mocha/utils.js +92 -13
  61. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  62. package/packages/datadog-instrumentations/src/nova-sonic/session.js +25 -16
  63. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  64. package/packages/datadog-instrumentations/src/pg.js +2 -1
  65. package/packages/datadog-instrumentations/src/playwright.js +81 -26
  66. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  67. package/packages/datadog-instrumentations/src/stripe.js +23 -12
  68. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  69. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -47
  70. package/packages/datadog-instrumentations/src/vitest-main.js +33 -3
  71. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  72. package/packages/datadog-instrumentations/src/vitest-util.js +5 -2
  73. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  74. package/packages/datadog-instrumentations/src/vitest.js +16 -6
  75. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  76. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +277 -44
  77. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  78. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  79. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  80. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  81. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  82. package/packages/datadog-plugin-cypress/src/support.js +1217 -437
  83. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  84. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  85. package/packages/datadog-plugin-jest/src/index.js +25 -3
  86. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  87. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  88. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  89. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  90. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  91. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  92. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  93. package/packages/dd-trace/src/agent/info.js +2 -1
  94. package/packages/dd-trace/src/aiguard/evaluation.js +143 -1
  95. package/packages/dd-trace/src/aiguard/sdk.js +0 -11
  96. package/packages/dd-trace/src/appsec/iast/path-line.js +2 -1
  97. package/packages/dd-trace/src/appsec/stack_trace.js +3 -2
  98. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +3 -2
  99. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
  100. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  101. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
  102. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
  103. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  104. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  105. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  106. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  107. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
  108. package/packages/dd-trace/src/config/defaults.js +4 -3
  109. package/packages/dd-trace/src/config/generated-config-types.d.ts +6 -0
  110. package/packages/dd-trace/src/config/index.js +140 -39
  111. package/packages/dd-trace/src/config/parsers.js +9 -1
  112. package/packages/dd-trace/src/config/supported-configurations.json +25 -0
  113. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +6 -5
  114. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -5
  115. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +4 -6
  116. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  117. package/packages/dd-trace/src/debugger/unsupported-runtime.js +16 -0
  118. package/packages/dd-trace/src/encode/0.4.js +2 -2
  119. package/packages/dd-trace/src/esm-module-load.js +58 -0
  120. package/packages/dd-trace/src/exporter.js +25 -6
  121. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  122. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  123. package/packages/dd-trace/src/exporters/common/request.js +4 -4
  124. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  125. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  126. package/packages/dd-trace/src/llmobs/agent-manifest.js +19 -2
  127. package/packages/dd-trace/src/llmobs/constants/tags.js +4 -0
  128. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  129. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  130. package/packages/dd-trace/src/llmobs/index.js +13 -2
  131. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  132. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  133. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
  134. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +5 -0
  135. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +9 -1
  136. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  137. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  138. package/packages/dd-trace/src/llmobs/sdk.js +17 -5
  139. package/packages/dd-trace/src/llmobs/span_processor.js +222 -12
  140. package/packages/dd-trace/src/llmobs/tagger.js +21 -8
  141. package/packages/dd-trace/src/llmobs/util.js +10 -4
  142. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  143. package/packages/dd-trace/src/log/writer.js +7 -1
  144. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
  145. package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
  146. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  147. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  148. package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
  149. package/packages/dd-trace/src/openfeature/index.js +6 -0
  150. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  151. package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
  152. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  153. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  154. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  155. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  156. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  157. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  158. package/packages/dd-trace/src/openfeature/writers/util.js +4 -4
  159. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  160. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +18 -1
  161. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  162. package/packages/dd-trace/src/opentracing/tracer.js +9 -13
  163. package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
  164. package/packages/dd-trace/src/plugin_manager.js +1 -2
  165. package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
  166. package/packages/dd-trace/src/plugins/index.js +3 -0
  167. package/packages/dd-trace/src/plugins/tracing.js +1 -2
  168. package/packages/dd-trace/src/plugins/util/git.js +102 -40
  169. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
  170. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -1
  171. package/packages/dd-trace/src/plugins/util/test.js +28 -6
  172. package/packages/dd-trace/src/plugins/util/web.js +106 -20
  173. package/packages/dd-trace/src/process-tags/index.js +1 -1
  174. package/packages/dd-trace/src/profiling/config.js +6 -3
  175. package/packages/dd-trace/src/proxy.js +15 -4
  176. package/packages/dd-trace/src/serverless.js +3 -2
  177. package/packages/dd-trace/src/span_processor.js +21 -9
  178. package/packages/dd-trace/src/span_stats.js +32 -3
  179. package/packages/dd-trace/src/startup-log.js +2 -1
  180. package/packages/dd-trace/src/tagger.js +7 -5
  181. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  182. package/packages/dd-trace/src/telemetry/index.js +3 -0
  183. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  184. package/packages/dd-trace/src/telemetry/logs/log-collector.js +2 -1
  185. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  186. package/packages/dd-trace/src/util.js +9 -5
  187. package/register.js +2 -1
  188. package/vendor/dist/@apm-js-collab/code-transformer/index.js +8 -8
  189. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  190. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  191. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  192. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  193. package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
  194. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -0,0 +1,25 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Snapshot scalar split features in canonical key order for stable aggregation.
5
+ * A prefix selects one provider destination; hook-only metadata must not reach intake.
6
+ * @param {unknown} source
7
+ * @param {string} [prefix]
8
+ * @returns {Record<string, string | number | boolean> | undefined}
9
+ */
10
+ function snapshotFeatures (source, prefix = '') {
11
+ if (source === null || typeof source !== 'object' || Array.isArray(source)) return
12
+ let features
13
+ for (const key of Object.keys(source).sort()) {
14
+ if (!key.startsWith(prefix) || key.length === prefix.length) continue
15
+ const descriptor = Object.getOwnPropertyDescriptor(source, key)
16
+ const value = descriptor?.value
17
+ if (typeof value !== 'string' && typeof value !== 'boolean' &&
18
+ !(typeof value === 'number' && Number.isFinite(value))) continue
19
+ features ??= Object.create(null)
20
+ features[key.slice(prefix.length)] = value
21
+ }
22
+ return features
23
+ }
24
+
25
+ module.exports = { snapshotFeatures }
@@ -31,14 +31,14 @@ const deliveryStrategies = new WeakMap()
31
31
  let missingRouteWarningLogged = false
32
32
 
33
33
  /**
34
- * Logs the unavailable exposure-delivery warning once.
34
+ * Logs the unavailable event-delivery warning once.
35
35
  *
36
36
  */
37
- function warnExposureDeliveryUnavailable () {
37
+ function warnEventDeliveryUnavailable () {
38
38
  if (missingRouteWarningLogged) return
39
39
  missingRouteWarningLogged = true
40
40
  logger.warn(
41
- 'Feature Flags exposure delivery is disabled because no compatible local EVP route or direct intake ' +
41
+ 'Feature Flags event delivery is disabled because no compatible local EVP route or direct intake ' +
42
42
  'credentials are available.'
43
43
  )
44
44
  }
@@ -169,7 +169,7 @@ function setAgentlessStrategy (config, setWriterEnabledValue) {
169
169
  if (error) {
170
170
  logger.debug('FFE Writer disabled - error getting local receiver info: %s', error.message)
171
171
  }
172
- warnExposureDeliveryUnavailable()
172
+ warnEventDeliveryUnavailable()
173
173
  markUnavailable()
174
174
  })
175
175
  }
@@ -12,10 +12,10 @@ const { nowUnixNano } = require('./time')
12
12
  * @param {(error: Error | null) => void} [done]
13
13
  * @param {Error | null} [error]
14
14
  */
15
- function callDone (done, error) {
15
+ function callDone (done, error = null) {
16
16
  if (!done) return
17
17
  try {
18
- done(error ?? null)
18
+ done(error)
19
19
  } catch (callbackError) {
20
20
  log.error('Error completing OTLP metrics lifecycle callback:', callbackError)
21
21
  }
@@ -95,6 +95,11 @@ const DD_ERROR_META_KEYS = new Set(['error.message'])
95
95
  class OtlpTraceTransformer extends OtlpTransformerBase {
96
96
  #otelTraceSemanticsEnabled
97
97
 
98
+ // Span meta entries with the same key and value as a resource attribute are already carried by
99
+ // the resource (e.g. DD_TAGS), so they are not repeated as span attributes.
100
+ /** @type {import('@opentelemetry/api').Attributes} */
101
+ #resourceAttributes
102
+
98
103
  /**
99
104
  * Creates a new OtlpTraceTransformer instance.
100
105
  *
@@ -104,6 +109,16 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
104
109
  constructor (resourceAttributes, otelTraceSemanticsEnabled) {
105
110
  super(resourceAttributes, 'http/json', 'traces')
106
111
  this.#otelTraceSemanticsEnabled = otelTraceSemanticsEnabled
112
+ this.#resourceAttributes = resourceAttributes
113
+ }
114
+
115
+ /**
116
+ * @override
117
+ * @param {import('@opentelemetry/api').Attributes} resourceAttributes - Resource attributes
118
+ */
119
+ updateResourceAttributes (resourceAttributes) {
120
+ super.updateResourceAttributes(resourceAttributes)
121
+ this.#resourceAttributes = resourceAttributes
107
122
  }
108
123
 
109
124
  /**
@@ -216,11 +231,13 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
216
231
  }
217
232
  }
218
233
 
219
- // Add meta string tags, skipping keys that map to dedicated OTLP fields
234
+ // Add meta string tags, skipping keys that map to dedicated OTLP fields and tags the
235
+ // resource already carries with the same value (e.g. global tags from DD_TAGS)
220
236
  if (span.meta) {
221
237
  for (const [key, value] of Object.entries(span.meta)) {
222
238
  if (EXCLUDED_META_KEYS.has(key)) continue
223
239
  if (this.#otelTraceSemanticsEnabled && DD_ERROR_META_KEYS.has(key)) continue
240
+ if (this.#resourceAttributes[key] === value) continue
224
241
  attributes.push({ key, value: { stringValue: value } })
225
242
  }
226
243
  }
@@ -84,7 +84,11 @@ class TracerProvider {
84
84
  return Promise.reject(new Error('Not started'))
85
85
  }
86
86
 
87
- exporter._writer?.flush()
87
+ if (typeof exporter.flush === 'function') {
88
+ exporter.flush()
89
+ } else {
90
+ exporter._writer?.flush()
91
+ }
88
92
  return this.#activeProcessor.forceFlush()
89
93
  }
90
94
 
@@ -4,6 +4,7 @@ const os = require('os')
4
4
  const SpanProcessor = require('../span_processor')
5
5
  const PrioritySampler = require('../priority_sampler')
6
6
  const formats = require('../../../../ext/formats')
7
+ const exporters = require('../../../../ext/exporters')
7
8
  const log = require('../log')
8
9
  const runtimeMetrics = require('../runtime_metrics')
9
10
  const getExporter = require('../exporter')
@@ -31,21 +32,17 @@ class DatadogTracer {
31
32
  this._debug = config.debug
32
33
  this._prioritySampler = prioritySampler ?? new PrioritySampler(config.env, config.sampler)
33
34
 
34
- // OTEL_TRACES_EXPORTER=otlp should not replace the Test Optimization
35
- // exporter when the tracer is running in Test Optimization mode. Test spans
36
- // (test_session/test_module/ test_suite/test) belong on the citestcycle
37
- // endpoint, not on an OTLP traces endpoint — otherwise users with OTEL_*
38
- // vars set in their environment (e.g. for a separate telemetry integration)
39
- // silently lose all test spans. The same applies to the Electron exporter:
40
- // spans must reach the Electron SDK's IPC bridge, not an OTLP endpoint,
41
- // even when OTEL_* vars are set for unrelated telemetry.
42
- const exportOtlpTraces = config.OTEL_TRACES_EXPORTER === 'otlp' && !config.isCiVisibility &&
43
- config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER !== 'electron'
35
+ const exportOtlpTraces = getExporter.usesOtlpTraceExporter(config)
44
36
  if (exportOtlpTraces) {
45
37
  const { createOtlpTraceExporter } = require('../opentelemetry/trace')
46
38
  this._exporter = createOtlpTraceExporter(config)
47
39
  } else {
48
- const Exporter = getExporter(config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER)
40
+ let exporterName = config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER
41
+ if (config.llmobs?.DD_LLMOBS_ENABLED && !config.isCiVisibility &&
42
+ (!exporterName || exporterName === exporters.AGENT || exporterName === exporters.AGENTLESS)) {
43
+ exporterName = exporters.LLMOBS
44
+ }
45
+ const Exporter = getExporter(exporterName)
49
46
  this._exporter = new Exporter(config, this._prioritySampler)
50
47
  }
51
48
 
@@ -58,8 +55,7 @@ class DatadogTracer {
58
55
  this._exporter,
59
56
  this._prioritySampler,
60
57
  config,
61
- otlpStatsExporter,
62
- exportOtlpTraces
58
+ otlpStatsExporter
63
59
  )
64
60
  this._url = this._exporter._url
65
61
  this._enableGetRumData = config.rum.DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED
@@ -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) {
@@ -102,8 +102,7 @@ module.exports = class PluginManager {
102
102
  loadPlugin (name) {
103
103
  const Plugin = pluginClasses[name]
104
104
 
105
- if (!Plugin) return
106
- if (!this._tracerConfig) return // TODO: don't wait for tracer to be initialized
105
+ if (!Plugin || !this._tracerConfig) return // TODO: don't wait for tracer to be initialized
107
106
 
108
107
  // Check if this is a Test Optimization plugin and Test Optimization is not enabled
109
108
  if (TEST_OPTIMIZATION_PLUGINS.has(name) && !this._tracerConfig.isCiVisibility) {
@@ -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
@@ -267,7 +267,6 @@ class TracingPlugin extends Plugin {
267
267
  analyticsSampler.sample(span, config.measured)
268
268
 
269
269
  // TODO: Remove this after migration to TracingChannel is done.
270
- // eslint-disable-next-line unicorn/no-unnecessary-boolean-comparison -- Context objects use the other branch.
271
270
  if (enterOrCtx === true) {
272
271
  legacyStorage.enterWith({ ...store, span })
273
272
  } else if (enterOrCtx) {