dd-trace 5.135.0 → 5.136.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/ci/init.js +2 -22
  2. package/ext/exporters.js +0 -1
  3. package/index.d.ts +105 -5
  4. package/initialize.mjs +5 -2
  5. package/lambda.d.ts +39 -0
  6. package/lambda.js +3 -0
  7. package/package.json +11 -9
  8. package/packages/datadog-esbuild/index.js +8 -55
  9. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  10. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  11. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  12. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  13. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  14. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  15. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  16. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  18. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  21. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -1
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  33. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  34. package/packages/datadog-instrumentations/src/next.js +19 -6
  35. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  36. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  37. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  38. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  39. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  40. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  41. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  42. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  43. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  44. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  45. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
  46. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  49. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  50. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  51. package/packages/datadog-plugin-http/src/client.js +32 -9
  52. package/packages/datadog-plugin-http2/src/client.js +38 -13
  53. package/packages/datadog-plugin-next/src/index.js +112 -14
  54. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  55. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  56. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  57. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  58. package/packages/datadog-plugin-undici/src/index.js +22 -7
  59. package/packages/datadog-turbopack/index.js +4 -28
  60. package/packages/datadog-turbopack/src/loader.js +14 -452
  61. package/packages/datadog-webpack/index.js +3 -55
  62. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  63. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  64. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  65. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  66. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  67. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  68. package/packages/dd-trace/src/before-exit.js +32 -0
  69. package/packages/dd-trace/src/bootstrap.js +5 -3
  70. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  71. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  73. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  75. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  77. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  78. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  79. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  80. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  81. package/packages/dd-trace/src/config/defaults.js +5 -0
  82. package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
  83. package/packages/dd-trace/src/config/index.js +17 -5
  84. package/packages/dd-trace/src/config/parsers.js +9 -0
  85. package/packages/dd-trace/src/config/supported-configurations.json +158 -4
  86. package/packages/dd-trace/src/constants.js +1 -0
  87. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  88. package/packages/dd-trace/src/exporter.js +0 -11
  89. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  90. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  91. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  92. package/packages/dd-trace/src/id.js +1 -1
  93. package/packages/dd-trace/src/lambda/facade.js +74 -0
  94. package/packages/dd-trace/src/lambda/handler.js +3 -41
  95. package/packages/dd-trace/src/lambda/index.js +38 -15
  96. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  97. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  98. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  99. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  100. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  101. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  102. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  103. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  104. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  105. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  106. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  107. package/packages/dd-trace/src/log/channels.js +4 -0
  108. package/packages/dd-trace/src/log/writer.js +6 -1
  109. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
  110. package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
  111. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  112. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  113. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  114. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  115. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  117. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  118. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  119. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  120. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  121. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  122. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  123. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  124. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  125. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  126. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  127. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  128. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  129. package/packages/dd-trace/src/plugin_manager.js +34 -7
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
  131. package/packages/dd-trace/src/plugins/index.js +6 -0
  132. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  133. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  134. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  135. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  136. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  137. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
  138. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  139. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  140. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +64 -39
  142. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  143. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  144. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  145. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  146. package/packages/dd-trace/src/proxy.js +33 -53
  147. package/packages/dd-trace/src/span_processor.js +20 -0
  148. package/packages/dd-trace/src/startup-log.js +8 -6
  149. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  150. package/packages/dd-trace/src/tracer.js +0 -2
  151. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  152. package/register.js +2 -1
  153. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  154. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  155. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  156. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  157. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  158. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  160. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  161. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  162. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  163. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  164. package/vendor/dist/esquery/LICENSE +2 -0
  165. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  166. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  167. package/vendor/dist/jest-docblock/LICENSE +16 -0
  168. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  169. package/vendor/dist/limiter/LICENSE +2 -0
  170. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  171. package/vendor/dist/lru-cache/LICENSE +13 -0
  172. package/vendor/dist/meriyah/LICENSE +13 -0
  173. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  174. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  175. package/vendor/dist/pprof-format/LICENSE +13 -0
  176. package/vendor/dist/pprof-format/index.js +1 -1
  177. package/vendor/dist/protobufjs/LICENSE +219 -0
  178. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  179. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  180. package/vendor/dist/retry/LICENSE +2 -0
  181. package/vendor/dist/rfdc/LICENSE +2 -0
  182. package/vendor/dist/semifies/LICENSE +3 -1
  183. package/vendor/dist/shell-quote/LICENSE +3 -1
  184. package/vendor/dist/source-map/LICENSE +1 -0
  185. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  186. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  187. package/vendor/dist/ttl-set/LICENSE +28 -0
  188. package/ci/diagnose.js +0 -2215
  189. package/ci/runbook.md +0 -299
  190. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  191. package/ci/test-optimization-validation/approval.js +0 -386
  192. package/ci/test-optimization-validation/artifact-id.js +0 -18
  193. package/ci/test-optimization-validation/blocker-category.js +0 -24
  194. package/ci/test-optimization-validation/bounded-json.js +0 -120
  195. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  196. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  197. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  198. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  199. package/ci/test-optimization-validation/cli.js +0 -954
  200. package/ci/test-optimization-validation/command-blocker.js +0 -377
  201. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  202. package/ci/test-optimization-validation/command-runner.js +0 -649
  203. package/ci/test-optimization-validation/environment.js +0 -88
  204. package/ci/test-optimization-validation/executable-approval.js +0 -47
  205. package/ci/test-optimization-validation/executable.js +0 -244
  206. package/ci/test-optimization-validation/execution-lock.js +0 -70
  207. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  208. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  209. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  210. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  211. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  212. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  213. package/ci/test-optimization-validation/generated-files.js +0 -425
  214. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  215. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  216. package/ci/test-optimization-validation/literal-environment.js +0 -56
  217. package/ci/test-optimization-validation/literal-glob.js +0 -52
  218. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  219. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  220. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  221. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  222. package/ci/test-optimization-validation/offline-output.js +0 -406
  223. package/ci/test-optimization-validation/package-check.js +0 -97
  224. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  225. package/ci/test-optimization-validation/plan-writer.js +0 -541
  226. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  227. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  228. package/ci/test-optimization-validation/redaction.js +0 -319
  229. package/ci/test-optimization-validation/report-writer.js +0 -666
  230. package/ci/test-optimization-validation/result-semantics.js +0 -103
  231. package/ci/test-optimization-validation/runner-command.js +0 -264
  232. package/ci/test-optimization-validation/runner-contract.js +0 -695
  233. package/ci/test-optimization-validation/safe-files.js +0 -202
  234. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  235. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  236. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  237. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  238. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  239. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  240. package/ci/test-optimization-validation/source-text.js +0 -84
  241. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  242. package/ci/test-optimization-validation/test-output.js +0 -120
  243. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  244. package/ci/validate-test-optimization.js +0 -3
  245. package/packages/datadog-esbuild/src/resolver.js +0 -284
  246. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  247. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  248. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  249. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  250. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -15,7 +15,14 @@ const urlFilter = require('./urlfilter')
15
15
  const { createInferredProxySpan, finishInferredProxySpan } = require('./inferred_proxy')
16
16
  const { getServerStatusValidator } = require('./status-validator')
17
17
  const { extractURL, obfuscateQs, getQsObfuscator, calculateHttpEndpoint } = require('./url')
18
- const { NETWORK_PEER_ADDRESS } = require('./http-otel-semantics')
18
+ const {
19
+ HTTP_STATUS_ERROR,
20
+ INSTRUMENTATION_HTTP_RESOURCE,
21
+ isInstrumentationOwnedResource,
22
+ NETWORK_PEER_ADDRESS,
23
+ otelHttpResourceName,
24
+ setInstrumentationHttpResource,
25
+ } = require('./http-otel-semantics')
19
26
 
20
27
  const WEB = types.WEB
21
28
  const SERVER = kinds.SERVER
@@ -144,9 +151,27 @@ const web = {
144
151
  setRoute (req, path) {
145
152
  const context = contexts.get(req)
146
153
 
147
- if (!context) return
154
+ if (!context?.span) return
155
+
156
+ if (!path || !context.config?.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
157
+ context.paths = [path]
158
+ return
159
+ }
148
160
 
161
+ const spanContext = context.span.context()
162
+ const currentRoute = spanContext.getTag(HTTP_ROUTE)
163
+ const publishedRoute = context.paths.length > 1 ? context.paths.join('') : context.paths[0]
149
164
  context.paths = [path]
165
+ // Publish before finish because downstream requests can trigger sampling inside the handler.
166
+ // Replace only values this context owns, so an upstream route still wins.
167
+ let route = currentRoute
168
+ if (currentRoute === undefined || currentRoute === publishedRoute) {
169
+ route = path
170
+ context.span.setTag(HTTP_ROUTE, path)
171
+ }
172
+ if (ownsResource(spanContext)) {
173
+ setInstrumentationHttpResource(context.span, otelHttpResourceName(req.method, route))
174
+ }
150
175
  },
151
176
 
152
177
  // Remove the current route segment.
@@ -268,10 +293,16 @@ const web = {
268
293
 
269
294
  if (!spanHasExistingError && !isValidStatusCode) {
270
295
  span.setTag(ERROR, error || true)
296
+ if (context.config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
297
+ span.setTag(HTTP_STATUS_ERROR, String(statusCode))
298
+ }
271
299
  }
272
300
 
273
301
  if (inferredProxySpan && !inferredSpanHasExistingError && !isValidStatusCode) {
274
302
  inferredProxySpan.setTag(ERROR, error || true)
303
+ if (context.config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
304
+ inferredProxySpan.setTag(HTTP_STATUS_ERROR, String(statusCode))
305
+ }
275
306
  }
276
307
  },
277
308
 
@@ -302,8 +333,7 @@ const web = {
302
333
  if (context.finished && !req.stream) return
303
334
 
304
335
  // `addRequestTags` is idempotent: in the normal HTTP path it ran during
305
- // `web.startSpan`. Serverless callers (e.g. Azure Functions) skip
306
- // `web.startSpan` and rely on this call to do the request-side work.
336
+ // `web.startSpan`, and this call applies any framework config installed afterwards.
307
337
  addRequestTags(context, spanType)
308
338
  // Configured-header tagging runs at finish time. Framework plugins
309
339
  // (connect, express, ...) install their own config via `setFramework`
@@ -509,6 +539,10 @@ function addRequestTags (context, spanType) {
509
539
  // other HTTP attributes, which are renamed centrally in span_format) it is set
510
540
  // here directly when OTel semantics are enabled.
511
541
  if (config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
542
+ // Claim the resource before propagation can sample it.
543
+ if (ownsResource(spanContext)) {
544
+ setInstrumentationHttpResource(span, otelHttpResourceName(req.method))
545
+ }
512
546
  const peerAddress = req.socket?.remoteAddress
513
547
  if (peerAddress) span.setTag(NETWORK_PEER_ADDRESS, peerAddress)
514
548
  }
@@ -581,18 +615,39 @@ function applyRouteOrEndpointTag (context) {
581
615
  span.setTag(HTTP_ENDPOINT, endpoint)
582
616
  }
583
617
 
618
+ /**
619
+ * @param {import('../../opentracing/span_context')} spanContext
620
+ */
621
+ function ownsResource (spanContext) {
622
+ return isInstrumentationOwnedResource(
623
+ spanContext.getTag(RESOURCE_NAME),
624
+ spanContext.getTag(INSTRUMENTATION_HTTP_RESOURCE)
625
+ )
626
+ }
627
+
584
628
  function addResourceTag (context) {
585
- const { req, span } = context
629
+ const { req, span, config } = context
586
630
  const spanContext = span.context()
631
+ const currentResource = spanContext.getTag(RESOURCE_NAME)
587
632
 
588
- if (spanContext.getTag(RESOURCE_NAME)) return
633
+ if (!config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
634
+ if (currentResource) return
635
+
636
+ let resource = req.method
637
+ const route = spanContext.getTag(HTTP_ROUTE)
638
+
639
+ if (route) resource += ` ${route}`
640
+ span.setTag(RESOURCE_NAME, resource)
641
+ return
642
+ }
589
643
 
590
- let resource = req.method
591
- const route = spanContext.getTag(HTTP_ROUTE)
644
+ const instrumentationResource = spanContext.getTag(INSTRUMENTATION_HTTP_RESOURCE)
645
+ if (currentResource && !isInstrumentationOwnedResource(currentResource, instrumentationResource)) return
592
646
 
593
- if (route) resource += ` ${route}`
647
+ const resource = otelHttpResourceName(req.method, spanContext.getTag(HTTP_ROUTE))
648
+ if (currentResource === resource && instrumentationResource === resource) return
594
649
 
595
- span.setTag(RESOURCE_NAME, resource)
650
+ setInstrumentationHttpResource(span, resource)
596
651
  }
597
652
 
598
653
  function addRequestHeaders (context) {
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { HTTP_METHOD, HTTP_ROUTE, RESOURCE_NAME, SPAN_TYPE } = require('../../../../ext/tags')
4
4
  const { WEB } = require('../../../../ext/types')
5
+ const { INSTRUMENTATION_HTTP_RESOURCE, otelHttpResourceName } = require('../plugins/util/http-otel-semantics')
5
6
 
6
7
  function isWebServerSpan (tags) {
7
8
  return tags[SPAN_TYPE] === WEB
@@ -18,10 +19,9 @@ function endpointNameFromTags (tags) {
18
19
  }
19
20
 
20
21
  // The endpoint name a web-server span's tag bag yields changes over the span's
21
- // lifetime: plugins set `http.method` when the request arrives and only add
22
- // `http.route` (and often `resource.name`) once framework routing has resolved
23
- // the URL. Returns the endpoint name once its value looks stable, or undefined
24
- // while it is still an interim placeholder.
22
+ // lifetime: plugins set `http.method` when the request arrives and refine
23
+ // `http.route` and `resource.name` as nested framework routes resolve.
24
+ // Returns the current endpoint, or undefined for a method-only placeholder.
25
25
  //
26
26
  // Consumers that read the tag bag lazily (the wall profiler resolves endpoint
27
27
  // labels at serialization time) see the settled value for free and only need
@@ -44,7 +44,8 @@ function finalEndpoint (tags) {
44
44
  // the string building inside endpointNameFromTags.
45
45
  if (tags[RESOURCE_NAME] == null && tags[HTTP_ROUTE] == null) return
46
46
  const endpoint = endpointNameFromTags(tags)
47
- if (!endpoint || endpoint === tags[HTTP_METHOD]) return
47
+ if (!endpoint || endpoint === tags[HTTP_METHOD] ||
48
+ (endpoint === tags[INSTRUMENTATION_HTTP_RESOURCE] && endpoint === otelHttpResourceName(tags[HTTP_METHOD]))) return
48
49
  return endpoint
49
50
  }
50
51
 
@@ -5,11 +5,10 @@ const uuid = require('../../../vendor/dist/crypto-randomuuid')
5
5
  const NoopProxy = require('./noop/proxy')
6
6
  const DatadogTracer = require('./tracer')
7
7
  const getConfig = require('./config')
8
- const { getEnvironmentVariable } = require('./config/helper')
9
8
  const { reseed } = require('./id')
10
9
  const runtimeMetrics = require('./runtime_metrics')
11
10
  const log = require('./log')
12
- const { setStartupLogPluginManager, startupLog } = require('./startup-log')
11
+ const { setStartupLogConfig, setStartupLogPluginManager, startupLog } = require('./startup-log')
13
12
  const telemetry = require('./telemetry')
14
13
  const nomenclature = require('./service-naming')
15
14
  const PluginManager = require('./plugin_manager')
@@ -23,7 +22,6 @@ const {
23
22
  } = require('./serverless')
24
23
  const { flushServerlessTelemetry, registerTelemetryFlusher } = require('./flush')
25
24
  const processTags = require('./process-tags')
26
- const { isTrue } = require('./util')
27
25
  const {
28
26
  setBaggageItem,
29
27
  getBaggageItem,
@@ -32,20 +30,6 @@ const {
32
30
  removeAllBaggageItems,
33
31
  } = require('./baggage')
34
32
 
35
- const VALIDATION_MANIFEST_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MANIFEST_FILE'
36
- const VALIDATION_MODE_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MODE'
37
- const VALIDATION_OUTPUT_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_OUTPUT_DIR'
38
- const ORDINARY_TRACING_DISABLED_MESSAGE =
39
- 'Ordinary dd-trace application tracing initialization is disabled during offline Test Optimization validation. ' +
40
- 'The CI test process must initialize through dd-trace/ci/init.'
41
- const OFFLINE_VALIDATION_EXPORTERS = new Set([
42
- 'ci_validation',
43
- 'cucumber_worker',
44
- 'jest_worker',
45
- 'mocha_worker',
46
- 'playwright_worker',
47
- 'vitest_worker',
48
- ])
49
33
  const OPENFEATURE_STATE_NOOP = 0
50
34
  const OPENFEATURE_STATE_LAZY = 1
51
35
  const OPENFEATURE_STATE_ACTIVE = 2
@@ -123,6 +107,9 @@ class Tracer extends NoopProxy {
123
107
  /** @type {boolean} */
124
108
  #configPublished = false
125
109
 
110
+ /** @type {boolean} */
111
+ #iastUnavailable = false
112
+
126
113
  constructor () {
127
114
  super()
128
115
 
@@ -166,11 +153,6 @@ class Tracer extends NoopProxy {
166
153
 
167
154
  this._initialized = true
168
155
 
169
- if (isOfflineTestOptimizationValidation() && !isOfflineValidationExporter(options)) {
170
- process.stderr.write(`${ORDINARY_TRACING_DISABLED_MESSAGE}\n`)
171
- return this
172
- }
173
-
174
156
  try {
175
157
  const config = getConfig(options) // TODO: support dynamic code config
176
158
 
@@ -202,7 +184,7 @@ class Tracer extends NoopProxy {
202
184
  : undefined
203
185
  telemetry.start(config, this._pluginManager, telemetryLogOptions)
204
186
 
205
- if (config.dogstatsd && !config.DD_AGENTLESS_ENABLED && !isOfflineTestOptimizationValidation()) {
187
+ if (config.dogstatsd && !config.DD_AGENTLESS_ENABLED) {
206
188
  // Custom Metrics
207
189
  lazyProxy(this, 'dogstatsd', () => require('./dogstatsd').CustomMetrics, config)
208
190
  }
@@ -277,14 +259,16 @@ class Tracer extends NoopProxy {
277
259
  // OTel logs/metrics pipelines must be initialized BEFORE runtimeMetrics.start so that
278
260
  // when the OTLP runtime metrics module calls metrics.getMeterProvider(), it gets the
279
261
  // real provider, otherwise instruments register on the noop provider and never export.
262
+ let logs
263
+ let metrics
280
264
  if (config.DD_LOGS_OTEL_ENABLED) {
281
265
  const { initializeOpenTelemetryLogs } = require('./opentelemetry/logs')
282
- initializeOpenTelemetryLogs(config)
266
+ logs = initializeOpenTelemetryLogs(config)
283
267
  }
284
268
 
285
269
  if (config.DD_METRICS_OTEL_ENABLED) {
286
270
  const { initializeOpenTelemetryMetrics } = require('./opentelemetry/metrics')
287
- initializeOpenTelemetryMetrics(config)
271
+ metrics = initializeOpenTelemetryMetrics(config)
288
272
  }
289
273
 
290
274
  if (config.runtimeMetrics.enabled) {
@@ -294,9 +278,12 @@ class Tracer extends NoopProxy {
294
278
  registerTelemetryFlusher(done => runtimeMetrics.flush(done), { afterTrace: true })
295
279
  }
296
280
 
297
- this.#updateTracing(config)
281
+ const tracing = this.#updateTracing(config)
282
+ setStartupLogConfig(config, { ...tracing, logs, metrics })
283
+ setStartupLogPluginManager(this._pluginManager)
284
+ startupLog()
298
285
 
299
- if (config.iast.DD_IAST_ENABLED) {
286
+ if (config.iast.DD_IAST_ENABLED && !this.#iastUnavailable) {
300
287
  this._modules.rewriter.enable(config)
301
288
  }
302
289
 
@@ -409,8 +396,11 @@ class Tracer extends NoopProxy {
409
396
 
410
397
  /**
411
398
  * @param {import('./config/config-base')} config - Tracer configuration
399
+ * @returns {import('./opentelemetry/startup-config').Pipelines | undefined}
412
400
  */
413
401
  #updateTracing (config) {
402
+ /** @type {import('./opentelemetry/startup-config').Pipelines | undefined} */
403
+ let startupPipelines
414
404
  if (config.DD_TRACE_ENABLED !== false) {
415
405
  const aiguardEnabled = config.aiguard.DD_AI_GUARD_ENABLED === true &&
416
406
  config.DD_API_KEY !== undefined &&
@@ -430,10 +420,13 @@ class Tracer extends NoopProxy {
430
420
  ? require('./standalone').configure(config)
431
421
  : undefined
432
422
  this._tracer = new DatadogTracer(config, prioritySampler)
423
+ startupPipelines = this._tracer.getStartupConfig()
433
424
  this.dataStreamsCheckpointer = this._tracer.dataStreamsCheckpointer
434
- lazyProxy(this, 'appsec', () => require('./appsec/sdk'), this._tracer, config)
435
- lazyProxy(this, 'llmobs', () => require('./llmobs/sdk'), this._tracer, this._modules.llmobs, config,
436
- () => this.openfeature)
425
+ if (!config.isCiVisibility) {
426
+ lazyProxy(this, 'appsec', () => require('./appsec/sdk'), this._tracer, config)
427
+ lazyProxy(this, 'llmobs', () => require('./llmobs/sdk'), this._tracer, this._modules.llmobs, config,
428
+ () => this.openfeature)
429
+ }
437
430
 
438
431
  if (aiguardEnabled) {
439
432
  lazyProxy(this, 'aiguard', () => require('./aiguard/sdk'), this._tracer, config)
@@ -443,8 +436,15 @@ class Tracer extends NoopProxy {
443
436
  if (aiguardEnabled) {
444
437
  this._modules.aiguard.enable(this._tracer, config)
445
438
  }
446
- if (config.iast.DD_IAST_ENABLED) {
447
- this._modules.iast.enable(config, this._tracer)
439
+ if (config.iast.DD_IAST_ENABLED && !this.#iastUnavailable) {
440
+ // IAST loads optional native addons that can be missing (e.g. installs without optional
441
+ // dependencies). Disable it for the process lifetime instead of aborting tracer setup.
442
+ try {
443
+ this._modules.iast.enable(config, this._tracer)
444
+ } catch (error) {
445
+ this.#iastUnavailable = true
446
+ log.error('[IAST] Unable to start IAST, it stays disabled', error)
447
+ }
448
448
  }
449
449
  // This needs to be after the IAST module is enabled
450
450
  } else if (this._tracingInitialized) {
@@ -460,11 +460,10 @@ class Tracer extends NoopProxy {
460
460
  this._tracer.configure(config)
461
461
  this._pluginManager.configure(config)
462
462
  dynamicInstrumentation?.configure(config)
463
- setStartupLogPluginManager(this._pluginManager)
464
- startupLog()
465
463
  }
466
464
 
467
465
  initializeServerlessTelemetry(this._serverlessTelemetry)
466
+ return startupPipelines
468
467
  }
469
468
 
470
469
  /**
@@ -539,25 +538,6 @@ class Tracer extends NoopProxy {
539
538
  }
540
539
  }
541
540
 
542
- /**
543
- * Checks the private filesystem-only Test Optimization validation mode.
544
- *
545
- */
546
- function isOfflineTestOptimizationValidation () {
547
- return isTrue(getEnvironmentVariable(VALIDATION_MODE_ENV)) &&
548
- Boolean(getEnvironmentVariable(VALIDATION_MANIFEST_ENV)) &&
549
- Boolean(getEnvironmentVariable(VALIDATION_OUTPUT_ENV))
550
- }
551
-
552
- /**
553
- * Checks whether initialization selected a filesystem-only Test Optimization exporter.
554
- *
555
- * @param {import('../../../index').TracerOptions} [options] tracer initialization options
556
- */
557
- function isOfflineValidationExporter (options) {
558
- return OFFLINE_VALIDATION_EXPORTERS.has(options?.experimental?.exporter)
559
- }
560
-
561
541
  /**
562
542
  * Discards Node's buffered UUID entropy, so the identity subscribers draw from bytes generated
563
543
  * after the clone resumed.
@@ -31,6 +31,12 @@ function serializeOtlpTraceState (context) {
31
31
  class SpanProcessor {
32
32
  #exportOtlpTraces
33
33
 
34
+ /**
35
+ * @readonly
36
+ * @type {import('./opentelemetry/startup-config').InitializedExporter | undefined}
37
+ */
38
+ #spanMetricsStartupConfig
39
+
34
40
  constructor (exporter, prioritySampler, config, otlpStatsExporter) {
35
41
  this._exporter = exporter
36
42
  this._prioritySampler = prioritySampler
@@ -42,6 +48,12 @@ class SpanProcessor {
42
48
  !config.appsec?.DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED) {
43
49
  const { SpanStatsProcessor } = require('./span_stats')
44
50
  this._stats = new SpanStatsProcessor(config, otlpStatsExporter)
51
+ if (otlpStatsExporter) {
52
+ this.#spanMetricsStartupConfig = {
53
+ protocol: otlpStatsExporter.protocol,
54
+ resourceAttributes: otlpStatsExporter.getStartupResourceAttributes(),
55
+ }
56
+ }
45
57
  }
46
58
 
47
59
  this._spanSampler = new SpanSampler(config.sampler)
@@ -52,6 +64,14 @@ class SpanProcessor {
52
64
  : false
53
65
  }
54
66
 
67
+ /**
68
+ * Returns the OTLP span-metrics configuration accepted during initialization, if active.
69
+ * @returns {import('./opentelemetry/startup-config').InitializedExporter | undefined}
70
+ */
71
+ getSpanMetricsStartupConfig () {
72
+ return this.#spanMetricsStartupConfig
73
+ }
74
+
55
75
  sample (span) {
56
76
  const spanContext = span.context()
57
77
  this._prioritySampler.sample(spanContext)
@@ -3,11 +3,12 @@
3
3
  const os = require('os')
4
4
  const { inspect } = require('util')
5
5
  const tracerVersion = require('../../../package.json').version
6
- const { usesOtlpTraceExporter } = require('./exporter')
7
6
  const { warn } = require('./log/writer')
7
+ const startupConfig = require('./opentelemetry/startup-config')
8
8
 
9
9
  const errors = {}
10
10
  let config
11
+ let otelConfig
11
12
  let pluginManager
12
13
  /** @type {import('./sampling_rule')[]} */
13
14
  let samplingRules = []
@@ -101,6 +102,7 @@ function configInfo () {
101
102
  agent_url: url,
102
103
  debug: !!config.debug,
103
104
  sample_rate: config.sampler.sampleRate,
105
+ sample_rate_limit: config.sampler.rateLimit,
104
106
  sampling_rules: samplingRules,
105
107
  tags: config.tags,
106
108
  log_injection_enabled: !!config.logInjection,
@@ -108,9 +110,7 @@ function configInfo () {
108
110
  profiling_enabled: profilingEnabled === 'true' || profilingEnabled === 'auto',
109
111
  appsec_enabled: config.appsec.DD_APPSEC_ENABLED,
110
112
  data_streams_enabled: !!config.dsmEnabled,
111
- otlp_traces_export_enabled: usesOtlpTraceExporter(config),
112
- otlp_metrics_export_enabled: !!config.DD_METRICS_OTEL_ENABLED,
113
- otlp_logs_export_enabled: !!config.DD_LOGS_OTEL_ENABLED,
113
+ ...otelConfig,
114
114
  }
115
115
  if (config.tags?.version) startupLog.dd_version = config.tags.version
116
116
  return startupLog
@@ -127,10 +127,12 @@ function tracerInfo () {
127
127
  }
128
128
 
129
129
  /**
130
- * @param {import('./config')} aConfig
130
+ * @param {ReturnType<import('./config')>} aConfig
131
+ * @param {import('./opentelemetry/startup-config').Pipelines} [pipelines]
131
132
  */
132
- function setStartupLogConfig (aConfig) {
133
+ function setStartupLogConfig (aConfig, pipelines) {
133
134
  config = aConfig
135
+ otelConfig ??= startupConfig(config, samplingRules, pipelines)
134
136
  }
135
137
 
136
138
  /**
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { TELEMETRY_DISTRIBUTION_RELATIVE_ACCURACY } = require('../constants')
3
4
  const { sendData } = require('./send-data')
4
5
 
5
6
  let LogCollapsingLowestDenseDDSketch
@@ -42,7 +43,7 @@ function createSketch () {
42
43
  if (LogCollapsingLowestDenseDDSketch === undefined) {
43
44
  ({ LogCollapsingLowestDenseDDSketch } = require('../../../../vendor/dist/@datadog/sketches-js'))
44
45
  }
45
- return new LogCollapsingLowestDenseDDSketch()
46
+ return new LogCollapsingLowestDenseDDSketch({ relativeAccuracy: TELEMETRY_DISTRIBUTION_RELATIVE_ACCURACY })
46
47
  }
47
48
 
48
49
  class Metric {
@@ -11,7 +11,6 @@ const shimmer = require('../../datadog-shimmer')
11
11
  const Tracer = require('./opentracing/tracer')
12
12
  const Scope = require('./scope')
13
13
  const { isError } = require('./util')
14
- const { setStartupLogConfig } = require('./startup-log')
15
14
  const { DataStreamsCheckpointer, DataStreamsManager, DataStreamsProcessor } = require('./datastreams')
16
15
  const { IS_SERVERLESS } = require('./serverless')
17
16
  const { flushServerlessTelemetry } = require('./flush')
@@ -33,7 +32,6 @@ class DatadogTracer extends Tracer {
33
32
  this._dataStreamsManager = new DataStreamsManager(this._dataStreamsProcessor)
34
33
  this.dataStreamsCheckpointer = new DataStreamsCheckpointer(this)
35
34
  this._scope = new Scope()
36
- setStartupLogConfig(config)
37
35
  flushStartupLogs(log)
38
36
  // Curated frameworks (e.g. Next.js) silently no-op when loaded first and their users enable
39
37
  // no logging (#5430 / #5432), so surface those unconditionally.
@@ -21,10 +21,8 @@
21
21
  // exactly once, regardless of subscription order or how many other
22
22
  // consumers are attached.
23
23
  //
24
- // `endpointResolvedCh` is the same idea one field over: published once per
25
- // web-server span at the moment its endpoint name settles (see finalEndpoint in
26
- // profiling/webspan-utils.js), i.e. when routing tags stop being interim
27
- // placeholders. Consumers that must materialize the endpoint eagerly rather
24
+ // `endpointResolvedCh` publishes when a web-server endpoint becomes available
25
+ // or changes as routing resolves. Consumers that must materialize it eagerly rather
28
26
  // than read the tag bag at leisure need that moment; owning it here means the
29
27
  // one `dd-trace:span:tags:update` subscription this module already holds serves
30
28
  // them too, instead of each consumer adding its own subscriber to that hot
@@ -45,8 +43,7 @@ const { finalEndpoint, isWebServerSpan, getStartedSpans } = require('./profiling
45
43
  // resolved: true once the parent-chain walk has run.
46
44
  // webTags: the resolved tag bag, or undefined when the walk came up
47
45
  // empty (no web-server span found in the started-spans chain).
48
- // endpointFinal: true once this span is a web-server span whose endpoint name
49
- // has settled and endpointResolvedCh has been published for it.
46
+ // endpoint: the last published endpoint name for this web-server span.
50
47
  const CachedSym = Symbol('WebTagsCache')
51
48
 
52
49
  const tagsUpdateCh = dc.channel('dd-trace:span:tags:update')
@@ -91,6 +88,7 @@ function getCachedWebTags (span) {
91
88
  }
92
89
  cached.webTags = webTags
93
90
  cached.resolved = true
91
+ if (webTags === tags && endpointResolvedCh.hasSubscribers) cached.endpoint = finalEndpoint(tags)
94
92
  return webTags
95
93
  }
96
94
 
@@ -121,12 +119,13 @@ function onTagsUpdate (span) {
121
119
  // when nobody is listening, keeping this the same early return it used to be
122
120
  // for consumers that only care about web-tag discovery.
123
121
  if (
124
- !endpointResolvedCh.hasSubscribers || cached.endpointFinal || cached.webTags !== tags ||
125
- finalEndpoint(tags) === undefined
122
+ !endpointResolvedCh.hasSubscribers || cached.webTags !== tags
126
123
  ) {
127
124
  return
128
125
  }
129
- cached.endpointFinal = true
126
+ const endpoint = finalEndpoint(tags)
127
+ if (endpoint === undefined || endpoint === cached.endpoint) return
128
+ cached.endpoint = endpoint
130
129
  endpointResolvedCh.publish(span)
131
130
  }
132
131
 
package/register.js CHANGED
@@ -26,7 +26,8 @@ if (shouldRegisterSyncLoaderHooks()) {
26
26
  }
27
27
  }
28
28
 
29
- if (!isSyncLoaderRegistered) {
29
+ // `module.register` is removed in Node.js 27+ (nodejs/node#67090).
30
+ if (!isSyncLoaderRegistered && register) {
30
31
  const { getLoaderRegisterOptions } = require('./packages/dd-trace/src/esm-module-load')
31
32
  register('./loader-hook.mjs', parentURL, getLoaderRegisterOptions())
32
33
  }