dd-trace 6.23.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 (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
@@ -18,12 +18,15 @@ const { isTrue } = require('../util')
18
18
  const telemetry = require('../telemetry')
19
19
  const telemetryMetrics = require('../telemetry/metrics')
20
20
  const {
21
+ getServerlessPlatform,
21
22
  getServerlessPlatformTags,
22
23
  IS_SERVERLESS,
24
+ IS_AWS_LAMBDA,
23
25
  getIsGCPFunction,
24
26
  getIsAzureFunction,
25
27
  } = require('../serverless')
26
28
  const { ORIGIN_KEY, DATADOG_MINI_AGENT_PATH } = require('../constants')
29
+ const { usesOtlpTraceExporter } = require('../exporter')
27
30
  const { appendRules } = require('../payload-tagging/config')
28
31
  const { createSiteUrl } = require('../exporters/common/url')
29
32
  const { getUnsupportedRuntime } = require('../debugger/unsupported-runtime')
@@ -428,10 +431,8 @@ class Config extends ConfigBase {
428
431
  setAndTrack(this, 'DD_METRICS_OTEL_ENABLED', false)
429
432
  }
430
433
 
431
- if (this.OTEL_TRACES_EXPORTER === 'otlp' && trackedConfigOrigins.has('protocolVersion')) {
432
- log.warn('DD_TRACE_AGENT_PROTOCOL_VERSION is set, disabling OTLP traces export')
433
- setAndTrack(this, 'OTEL_TRACES_EXPORTER', 'none')
434
- }
434
+ const agentlessTracingEnabled = this.DD_AGENTLESS_ENABLED ||
435
+ isTrue(getEnvironmentVariable('_DD_APM_TRACING_AGENTLESS_ENABLED'))
435
436
 
436
437
  if (this.telemetry.DD_TELEMETRY_HEARTBEAT_INTERVAL) {
437
438
  setAndTrack(this, 'telemetry.DD_TELEMETRY_HEARTBEAT_INTERVAL',
@@ -451,8 +452,15 @@ class Config extends ConfigBase {
451
452
  setAndTrack(this, 'DD_TRACE_RESOURCE_RENAMING_ENABLED', this.appsec.DD_APPSEC_ENABLED ?? false)
452
453
  }
453
454
 
454
- if (!trackedConfigOrigins.has('spanComputePeerService') && this.spanAttributeSchema !== 'v0') {
455
- setAndTrack(this, 'spanComputePeerService', true)
455
+ // Enable the thread context writer when appsec is enabled and only
456
+ // if DD_TRACE_OTEL_CTX_ENABLED is not explicitly set. The writer is started once
457
+ // at init, so appsec enabled later through remote config does not start it.
458
+ // Serverless functions and Vercel are left out: the eBPF reader cannot run there.
459
+ if (!trackedConfigOrigins.has('DD_TRACE_OTEL_CTX_ENABLED') &&
460
+ this.appsec.DD_APPSEC_ENABLED &&
461
+ !IS_SERVERLESS &&
462
+ !getServerlessPlatform().isVercel) {
463
+ setAndTrack(this, 'DD_TRACE_OTEL_CTX_ENABLED', true)
456
464
  }
457
465
 
458
466
  if (!this.apmTracingEnabled) {
@@ -479,7 +487,7 @@ class Config extends ConfigBase {
479
487
  setAndTrack(this, 'tracePropagationStyle.extract', this.tracePropagationStyle.extract)
480
488
  }
481
489
 
482
- if (getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') && !fs.existsSync(DATADOG_MINI_AGENT_PATH)) {
490
+ if (IS_AWS_LAMBDA && !fs.existsSync(DATADOG_MINI_AGENT_PATH)) {
483
491
  setAndTrack(this, 'flushInterval', 0)
484
492
  }
485
493
 
@@ -503,23 +511,6 @@ class Config extends ConfigBase {
503
511
  setAndTrack(this, 'runtimeMetrics.enabled', false)
504
512
  }
505
513
 
506
- const agentlessTracingEnabled = this.DD_AGENTLESS_ENABLED ||
507
- isTrue(getEnvironmentVariable('_DD_APM_TRACING_AGENTLESS_ENABLED'))
508
-
509
- // Apply the OTel sampler when the user opted into OTel traces or explicitly set the sampler.
510
- // OTEL_TRACES_SAMPLER has `default: parentbased_always_on` (per OTel spec), so opt-in users
511
- // that don't set the sampler still get parent-based sampling. Electron exporter spans go over
512
- // the Electron SDK's IPC bridge rather than OTLP (see opentracing/tracer.js), so an
513
- // OTEL_TRACES_EXPORTER=otlp set for an unrelated telemetry pipeline shouldn't also override
514
- // dd-trace's own sampling policy in that case.
515
- if (!trackedConfigOrigins.has('sampleRate') &&
516
- (trackedConfigOrigins.has('OTEL_TRACES_SAMPLER') ||
517
- (this.OTEL_TRACES_EXPORTER === 'otlp' &&
518
- this.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER !== 'electron'))) {
519
- setAndTrack(this, 'sampleRate',
520
- getFromOtelSamplerMap(this.OTEL_TRACES_SAMPLER, this.OTEL_TRACES_SAMPLER_ARG))
521
- }
522
-
523
514
  if (this.DD_SPAN_SAMPLING_RULES_FILE) {
524
515
  try {
525
516
  // TODO: Should we log a warning in case this is defined next to spanSamplingRules?
@@ -529,14 +520,6 @@ class Config extends ConfigBase {
529
520
  }
530
521
  }
531
522
 
532
- // All sampler options are tracked as individual values. No need to track the sampler object as a whole.
533
- this.sampler = {
534
- rules: this.samplingRules,
535
- rateLimit: this.rateLimit,
536
- sampleRate: this.sampleRate,
537
- spanSamplingRules: this.spanSamplingRules,
538
- }
539
-
540
523
  // For LLMObs, we want to auto enable it when other llmobs options are defined.
541
524
  if (!this.llmobs.DD_LLMOBS_ENABLED &&
542
525
  !trackedConfigOrigins.has('llmobs.DD_LLMOBS_ENABLED') &&
@@ -546,6 +529,14 @@ class Config extends ConfigBase {
546
529
  setAndTrack(this, 'llmobs.DD_LLMOBS_ENABLED', true)
547
530
  }
548
531
 
532
+ if (this.llmobs.DD_LLMOBS_ENABLED) {
533
+ // LLMObs payloads use APM structured metadata, which is only supported by protocol v0.4.
534
+ if (this.protocolVersion !== '0.4') {
535
+ log.warn('LLM Observability requires protocol version 0.4 - overriding choice of %s', this.protocolVersion)
536
+ }
537
+ setAndTrack(this, 'protocolVersion', '0.4')
538
+ }
539
+
549
540
  if (this.OTEL_RESOURCE_ATTRIBUTES) {
550
541
  for (const [key, value] of Object.entries(this.OTEL_RESOURCE_ATTRIBUTES)) {
551
542
  // Not replacing existing tags keeps the order of the tags as before.
@@ -688,10 +679,6 @@ class Config extends ConfigBase {
688
679
  setAndTrack(this, 'stats.DD_TRACE_STATS_COMPUTATION_ENABLED', false)
689
680
  // Enable hostname reporting
690
681
  setAndTrack(this, 'reportHostname', true)
691
- // Disable rate limiting - server-side sampling will be used
692
- setAndTrack(this, 'sampler.rateLimit', -1)
693
- // Clear sampling rules - server-side sampling handles this
694
- setAndTrack(this, 'sampler.rules', [])
695
682
  // Agentless intake only accepts 64-bit trace IDs; disable 128-bit generation
696
683
  if (!trackedConfigOrigins.has('traceId128BitGenerationEnabled')) {
697
684
  setAndTrack(this, 'traceId128BitGenerationEnabled', false)
@@ -711,6 +698,75 @@ class Config extends ConfigBase {
711
698
  }
712
699
  }
713
700
 
701
+ if (this.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
702
+ let warning
703
+
704
+ if (this.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER === exporters.ELECTRON) {
705
+ warning = 'DD_TRACE_EXPERIMENTAL_EXPORTER=electron is incompatible with DD_TRACE_OTEL_SEMANTICS_ENABLED. ' +
706
+ 'DD_TRACE_OTEL_SEMANTICS_ENABLED deactivated'
707
+ } else if (this.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER === exporters.AGENTLESS) {
708
+ warning = 'Agentless tracing is incompatible with DD_TRACE_OTEL_SEMANTICS_ENABLED. ' +
709
+ 'DD_TRACE_OTEL_SEMANTICS_ENABLED deactivated'
710
+ } else if (this.isCiVisibility) {
711
+ warning = 'Test Optimization is incompatible with DD_TRACE_OTEL_SEMANTICS_ENABLED. ' +
712
+ 'Deactivating DD_TRACE_OTEL_SEMANTICS_ENABLED'
713
+ } else if (this.OTEL_TRACES_EXPORTER === 'none') {
714
+ warning = 'DD_TRACE_OTEL_SEMANTICS_ENABLED is deactivated due to OTEL_TRACES_EXPORTER set to "none"'
715
+ }
716
+
717
+ if (warning) {
718
+ log.warn(warning)
719
+ setAndTrack(this, 'DD_TRACE_OTEL_SEMANTICS_ENABLED', false)
720
+ } else {
721
+ setAndTrack(this, 'OTEL_TRACES_EXPORTER', 'otlp')
722
+ }
723
+ }
724
+
725
+ if (this.OTEL_TRACES_EXPORTER === 'otlp' && trackedConfigOrigins.has('protocolVersion')) {
726
+ log.warn('DD_TRACE_AGENT_PROTOCOL_VERSION is set, disabling OTLP traces export')
727
+ setAndTrack(this, 'OTEL_TRACES_EXPORTER', 'none')
728
+ if (this.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
729
+ setAndTrack(this, 'DD_TRACE_OTEL_SEMANTICS_ENABLED', false)
730
+ }
731
+ }
732
+
733
+ if (this.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
734
+ if (this.spanAttributeSchema !== 'v0') {
735
+ log.warn('DD_TRACE_OTEL_SEMANTICS_ENABLED requires DD_TRACE_SPAN_ATTRIBUTE_SCHEMA to be "v0". Resetting')
736
+ }
737
+ if (this.spanComputePeerService) {
738
+ log.warn(
739
+ 'DD_TRACE_OTEL_SEMANTICS_ENABLED requires DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED to be false. Resetting'
740
+ )
741
+ }
742
+ setAndTrack(this, 'spanAttributeSchema', 'v0')
743
+ setAndTrack(this, 'spanComputePeerService', false)
744
+ } else if (!trackedConfigOrigins.has('spanComputePeerService') && this.spanAttributeSchema !== 'v0') {
745
+ setAndTrack(this, 'spanComputePeerService', true)
746
+ }
747
+
748
+ // An explicit OTel sampler also applies to native trace exporters.
749
+ if (!trackedConfigOrigins.has('sampleRate') &&
750
+ (trackedConfigOrigins.has('OTEL_TRACES_SAMPLER') || usesOtlpTraceExporter(this))) {
751
+ setAndTrack(this, 'sampleRate',
752
+ getFromOtelSamplerMap(this.OTEL_TRACES_SAMPLER, this.OTEL_TRACES_SAMPLER_ARG))
753
+ }
754
+
755
+ // All sampler options are tracked as individual values. No need to track the sampler object as a whole.
756
+ this.sampler = {
757
+ rules: this.samplingRules,
758
+ rateLimit: this.rateLimit,
759
+ sampleRate: this.sampleRate,
760
+ spanSamplingRules: this.spanSamplingRules,
761
+ }
762
+
763
+ if (agentlessTracingEnabled && !this.isCiVisibility) {
764
+ // Disable rate limiting - server-side sampling will be used
765
+ setAndTrack(this, 'sampler.rateLimit', -1)
766
+ // Clear sampling rules - server-side sampling handles this
767
+ setAndTrack(this, 'sampler.rules', [])
768
+ }
769
+
714
770
  // TODO: This could likely be moved to the base class and allow easier GRPC handling
715
771
  // Default OTLP endpoints follow the configured agent host so users who point DD at a custom
716
772
  // agent (DD_AGENT_HOST / DD_TRACE_AGENT_URL) also reach OTLP on that host. In agentless mode
@@ -742,7 +798,7 @@ class Config extends ConfigBase {
742
798
  assignOtlpHeaderApiKey('OTEL_EXPORTER_OTLP_TRACES_HEADERS')
743
799
  }
744
800
 
745
- const autoTraceMetrics = this.OTEL_TRACES_EXPORTER === 'otlp' && this.DD_METRICS_OTEL_ENABLED === true
801
+ const autoTraceMetrics = usesOtlpTraceExporter(this) && this.DD_METRICS_OTEL_ENABLED === true
746
802
  setAndTrack(this, 'OTEL_TRACES_SPAN_METRICS_ENABLED', this.OTEL_TRACES_SPAN_METRICS_ENABLED ?? autoTraceMetrics)
747
803
 
748
804
  if (this.OTEL_TRACES_SPAN_METRICS_ENABLED) {
@@ -856,7 +912,7 @@ function getFromOtelSamplerMap (otelTracesSampler, otelTracesSamplerArg) {
856
912
  function warnWrongOtelSettings () {
857
913
  // This mostly works for non-aliased environment variables only.
858
914
  // TODO: Adjust this to work across all sources.
859
- for (const [otelEnvVar, ddEnvVar, key] of [
915
+ for (const [otelEnvVar, ddEnvVar, key = otelEnvVar] of [
860
916
  // eslint-disable-next-line eslint-rules/eslint-env-aliases
861
917
  ['OTEL_LOG_LEVEL', 'DD_TRACE_LOG_LEVEL', 'logLevel'],
862
918
  // eslint-disable-next-line eslint-rules/eslint-env-aliases
@@ -873,7 +929,7 @@ function warnWrongOtelSettings () {
873
929
  ]) {
874
930
  // eslint-disable-next-line eslint-rules/eslint-process-env
875
931
  const envs = process.env
876
- const otelSource = trackedConfigOrigins.get(/** @type {ConfigPath} */ (key ?? otelEnvVar))
932
+ const otelSource = trackedConfigOrigins.get(/** @type {ConfigPath} */ (key))
877
933
  const otelEnvValue = envs[otelEnvVar]
878
934
  if (otelEnvValue) {
879
935
  if (envs[ddEnvVar]) {
@@ -334,7 +334,15 @@ const parsers = {
334
334
  // DD_TAGS is a special case. It may be a map of key-value pairs separated by spaces.
335
335
  raw = raw.replaceAll(/\s+/g, ',')
336
336
  }
337
- tagger.add(entries, raw, valueSeparator)
337
+ if (valueSeparator === '=' && raw.includes('%')) {
338
+ try {
339
+ tagger.add(entries, raw, valueSeparator, true)
340
+ } catch {
341
+ return
342
+ }
343
+ } else {
344
+ tagger.add(entries, raw, valueSeparator)
345
+ }
338
346
  return entries
339
347
  },
340
348
  JSON (raw) {
@@ -143,6 +143,7 @@
143
143
  {
144
144
  "implementation": "A",
145
145
  "type": "string",
146
+ "allowed": ".+",
146
147
  "default": null,
147
148
  "aliases": [
148
149
  "DATADOG_API_KEY"
@@ -497,6 +498,7 @@
497
498
  {
498
499
  "implementation": "A",
499
500
  "type": "string",
501
+ "allowed": ".+",
500
502
  "default": null,
501
503
  "sensitive": true
502
504
  }
@@ -4017,6 +4019,13 @@
4017
4019
  "default": "true"
4018
4020
  }
4019
4021
  ],
4022
+ "DD_TRACE_REACT_ROUTER_ENABLED": [
4023
+ {
4024
+ "implementation": "A",
4025
+ "type": "boolean",
4026
+ "default": "true"
4027
+ }
4028
+ ],
4020
4029
  "DD_TRACE_REDIS_CLIENT_ENABLED": [
4021
4030
  {
4022
4031
  "implementation": "A",
@@ -4229,6 +4238,13 @@
4229
4238
  "default": "true"
4230
4239
  }
4231
4240
  ],
4241
+ "DD_TRACE_TYPESAFE_ENABLED": [
4242
+ {
4243
+ "implementation": "A",
4244
+ "type": "boolean",
4245
+ "default": "true"
4246
+ }
4247
+ ],
4232
4248
  "DD_TRACE_UNDICI_ENABLED": [
4233
4249
  {
4234
4250
  "implementation": "A",
@@ -152,7 +152,7 @@ function installProbeSampler (guardrailMetrics, config) {
152
152
  if (elapsedNs > evaluationTimeoutNs) {
153
153
  return recordConditionError(probeIndex, probeId, now, describeTimeout(elapsedNs), true)
154
154
  }
155
- return matched === true && sample(probeIndex, probeId, now, nsBetweenSampling, isSnapshotProducingProbe)
155
+ return matched && sample(probeIndex, probeId, now, nsBetweenSampling, isSnapshotProducingProbe)
156
156
  },
157
157
 
158
158
  /**
@@ -235,7 +235,7 @@ function installProbeSampler (guardrailMetrics, config) {
235
235
  if (state.timedOut) {
236
236
  guardrailMetrics.eventSkipped(
237
237
  SKIPPED_REASON.EVALUATION_TIMEOUT,
238
- isSnapshotProducingProbe === true ? EVENT_TYPE.SNAPSHOT : EVENT_TYPE.LOG
238
+ isSnapshotProducingProbe ? EVENT_TYPE.SNAPSHOT : EVENT_TYPE.LOG
239
239
  )
240
240
  }
241
241
  return true
@@ -254,7 +254,7 @@ function installProbeSampler (guardrailMetrics, config) {
254
254
  * @param {boolean} isSnapshotProducingProbe - Whether this probe counts toward the global snapshot sample limit.
255
255
  */
256
256
  function sample (probeIndex, probeId, now, nsBetweenSampling, isSnapshotProducingProbe) {
257
- if (isSnapshotProducingProbe === true) {
257
+ if (isSnapshotProducingProbe) {
258
258
  const span = /** @type {ActiveSpan | null | undefined} */ (legacyStorage.getStore()?.span)
259
259
  const trace = span?.context()._trace
260
260
  // The span processor empties `started` once all spans of a trace have finished. A probe hit under such a trace
@@ -320,12 +320,12 @@ function installProbeSampler (guardrailMetrics, config) {
320
320
  if (lastCaptureNs !== undefined && now - lastCaptureNs < nsBetweenSampling) {
321
321
  guardrailMetrics.eventSkipped(
322
322
  SKIPPED_REASON.RATE_LIMIT_PROBE,
323
- isSnapshotProducingProbe === true ? EVENT_TYPE.SNAPSHOT : EVENT_TYPE.LOG
323
+ isSnapshotProducingProbe ? EVENT_TYPE.SNAPSHOT : EVENT_TYPE.LOG
324
324
  )
325
325
  return true
326
326
  }
327
327
 
328
- if (isSnapshotProducingProbe === true &&
328
+ if (isSnapshotProducingProbe &&
329
329
  now - globalSnapshotSamplingRateWindowStart <= oneSecondNs &&
330
330
  snapshotsSampledWithinTheLastSecond >= MAX_SNAPSHOTS_PER_SECOND_GLOBALLY) {
331
331
  guardrailMetrics.eventSkipped(SKIPPED_REASON.RATE_LIMIT_GLOBAL, EVENT_TYPE.SNAPSHOT)
@@ -346,7 +346,7 @@ function installProbeSampler (guardrailMetrics, config) {
346
346
  function commitSample (probeIndex, probeId, now, isSnapshotProducingProbe) {
347
347
  if (!storeSampledProbeIndex(probeIndex)) return false
348
348
 
349
- if (isSnapshotProducingProbe === true) {
349
+ if (isSnapshotProducingProbe) {
350
350
  if (now - globalSnapshotSamplingRateWindowStart > oneSecondNs) {
351
351
  snapshotsSampledWithinTheLastSecond = 1
352
352
  globalSnapshotSamplingRateWindowStart = now
@@ -694,7 +694,7 @@ class AgentEncoder {
694
694
  let count = 0
695
695
  for (const key of Object.keys(value)) {
696
696
  const entryValue = value[key]
697
- if (typeof entryValue === 'string' || typeof entryValue === 'number' ||
697
+ if (typeof entryValue === 'string' || typeof entryValue === 'number' || typeof entryValue === 'boolean' ||
698
698
  (entryValue !== null && typeof entryValue === 'object')) {
699
699
  this._encodeString(bytes, key)
700
700
  this.#encodeObjectAsByteArray(bytes, entryValue)
@@ -768,7 +768,7 @@ class AgentEncoder {
768
768
 
769
769
  let count = 0
770
770
  for (const item of value) {
771
- if (typeof item === 'string' || typeof item === 'number' ||
771
+ if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean' ||
772
772
  (item !== null && typeof item === 'object' && !circularReferencesDetector.has(item))) {
773
773
  this.#encodeObject(bytes, item, circularReferencesDetector)
774
774
  count++
@@ -0,0 +1,58 @@
1
+ 'use strict'
2
+
3
+ const { MessageChannel } = require('node:worker_threads')
4
+
5
+ const dc = require('dc-polyfill')
6
+
7
+ const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
8
+ const moduleLoadEndChannel = dc.channel('dd-trace:moduleLoadEnd')
9
+
10
+ // The loader reports a package once, possibly before dependency telemetry subscribes (the loader handles
11
+ // the whole graph before an app that starts the tracer itself runs), so late consumers replay these.
12
+ /** @type {string[]} */
13
+ const publishedFilenames = []
14
+
15
+ /**
16
+ * Publishes an ESM module load that the loader observed but did not wrap, so consumers such as
17
+ * dependency telemetry see packages without dd-trace instrumentation too.
18
+ *
19
+ * @param {string} filename Loaded module URL.
20
+ */
21
+ function publishModuleLoad (filename) {
22
+ publishedFilenames.push(filename)
23
+ const payload = { filename }
24
+ if (moduleLoadStartChannel.hasSubscribers) {
25
+ moduleLoadStartChannel.publish(payload)
26
+ }
27
+ // Consumers such as datadog-lambda-js cold start tracing pair every start with an end. The load has
28
+ // already happened, so close it right away.
29
+ if (moduleLoadEndChannel.hasSubscribers) {
30
+ moduleLoadEndChannel.publish(payload)
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Returns the ESM module loads published so far, one per package.
36
+ *
37
+ * @returns {string[]}
38
+ */
39
+ function getPublishedModuleLoads () {
40
+ return publishedFilenames
41
+ }
42
+
43
+ /**
44
+ * Builds the `module.register` options that hand the asynchronous loader thread a port to report
45
+ * unwrapped module loads back to the application thread.
46
+ *
47
+ * @returns {{ data: { moduleLoadPort: import('node:worker_threads').MessagePort },
48
+ * transferList: import('node:worker_threads').MessagePort[] }}
49
+ */
50
+ function getLoaderRegisterOptions () {
51
+ const { port1, port2 } = new MessageChannel()
52
+ port1.on('message', publishModuleLoad)
53
+ // The loader thread outlives short-lived applications; never keep them running.
54
+ port1.unref?.()
55
+ return { data: { moduleLoadPort: port2 }, transferList: [port2] }
56
+ }
57
+
58
+ module.exports = { getLoaderRegisterOptions, getPublishedModuleLoads, publishModuleLoad }
@@ -8,6 +8,8 @@ const { isTrue } = require('./util')
8
8
 
9
9
  module.exports = function getExporter (name) {
10
10
  switch (name) {
11
+ case exporters.LLMOBS:
12
+ return usesLambdaLogExporter() ? require('./exporters/log') : require('./exporters/llmobs')
11
13
  case exporters.ELECTRON:
12
14
  return require('./exporters/electron')
13
15
  case exporters.LOG:
@@ -31,12 +33,14 @@ module.exports = function getExporter (name) {
31
33
  return require('./ci-visibility/exporters/test-worker')
32
34
  }
33
35
 
34
- const inAWSLambda = getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined
35
- const usingAgent = inAWSLambda && (
36
- fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH) ||
37
- fs.existsSync(constants.DATADOG_MINI_AGENT_PATH)
38
- )
39
- return inAWSLambda && !usingAgent ? require('./exporters/log') : require('./exporters/agent')
36
+ return usesLambdaLogExporter() ? require('./exporters/log') : require('./exporters/agent')
37
+ }
38
+
39
+ function usesLambdaLogExporter () {
40
+ const { IS_AWS_LAMBDA } = require('./serverless')
41
+ return IS_AWS_LAMBDA &&
42
+ !fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH) &&
43
+ !fs.existsSync(constants.DATADOG_MINI_AGENT_PATH)
40
44
  }
41
45
 
42
46
  function hasCiValidationEnvironment () {
@@ -44,3 +48,18 @@ function hasCiValidationEnvironment () {
44
48
  getEnvironmentVariable('_DD_TEST_OPTIMIZATION_VALIDATION_MANIFEST_FILE') &&
45
49
  getEnvironmentVariable('_DD_TEST_OPTIMIZATION_VALIDATION_OUTPUT_DIR')
46
50
  }
51
+
52
+ /**
53
+ * Whether the tracer effectively uses OTLP for APM spans.
54
+ * Test Optimization and Electron do not support OTLP even when `OTEL_TRACES_EXPORTER` is `otlp`.
55
+ *
56
+ * @param {import('./config')} config
57
+ */
58
+ function usesOtlpTraceExporter (config) {
59
+ return config.OTEL_TRACES_EXPORTER === 'otlp' &&
60
+ !config.isCiVisibility &&
61
+ config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER !== exporters.ELECTRON &&
62
+ config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER !== exporters.AGENTLESS
63
+ }
64
+
65
+ module.exports.usesOtlpTraceExporter = usesOtlpTraceExporter
@@ -44,7 +44,7 @@ class AgentExporter {
44
44
  }
45
45
 
46
46
  export (spans) {
47
- this._writer.append(spans)
47
+ const appended = this._writer.append(spans)
48
48
 
49
49
  const { flushInterval } = this._config
50
50
 
@@ -57,6 +57,8 @@ class AgentExporter {
57
57
  }, flushInterval)
58
58
  this.#timer.unref?.()
59
59
  }
60
+
61
+ return appended
60
62
  }
61
63
 
62
64
  flush (done) {
@@ -86,7 +86,7 @@ class AgentlessExporter {
86
86
  * @param {object[]} spans - Array of spans (all from the same trace)
87
87
  */
88
88
  export (spans) {
89
- this._writer.append(spans)
89
+ const appended = this._writer.append(spans)
90
90
 
91
91
  const { flushInterval } = this.#config
92
92
 
@@ -107,6 +107,8 @@ class AgentlessExporter {
107
107
  }, flushInterval)
108
108
  this.#timer.unref?.()
109
109
  }
110
+
111
+ return appended
110
112
  }
111
113
 
112
114
  /**
@@ -224,10 +224,10 @@ function request (data, options, callback) {
224
224
  isRetriableNetworkError(error)) {
225
225
  settled = true
226
226
  finalize()
227
- // Unref so a pending retry never keeps the host process alive past
228
- // its natural exit point; long-running apps still retry because the
229
- // event loop is held open by their own work.
230
- setTimeout(attempt, getRetryDelay(options, attemptIndex), attemptIndex + 1).unref?.()
227
+ const retryTimer = setTimeout(attempt, getRetryDelay(options, attemptIndex), attemptIndex + 1)
228
+ // Background retries must not keep the host process alive. Lifecycle-owned
229
+ // requests can opt in when their final result must be observed.
230
+ if (!options.keepProcessAlive) retryTimer.unref?.()
231
231
  } else {
232
232
  complete(error)
233
233
  }
@@ -0,0 +1,135 @@
1
+ 'use strict'
2
+
3
+ const { fetchAgentInfo } = require('../../agent/info')
4
+ const { getValueFromEnvSources } = require('../../config/helper')
5
+ const { LLMOBS_META_STRUCT_KEY } = require('../../llmobs/constants/tags')
6
+ const logger = require('../../log')
7
+ const AgentExporter = require('../agent')
8
+ const AgentlessExporter = require('../agentless')
9
+ const BufferingExporter = require('../common/buffering-exporter')
10
+
11
+ const MAX_BUFFERED_SPANS = 1000
12
+
13
+ /**
14
+ * Buffers traces until LLMObs transport discovery selects either the Agent or
15
+ * agentless APM exporter.
16
+ */
17
+ class LLMObsExporter extends BufferingExporter {
18
+ #agentless = false
19
+ #bufferLimitWarned = false
20
+ #bufferedSpanCount = 0
21
+ #exporter
22
+ /** @type {Array<Function | undefined>} */
23
+ #pendingFlushes = []
24
+ #prioritySampler
25
+
26
+ /**
27
+ * @param {import('../../config/config-base')} config
28
+ * @param {import('../../priority_sampler')} prioritySampler
29
+ */
30
+ constructor (config, prioritySampler) {
31
+ super(config)
32
+ this.#prioritySampler = prioritySampler
33
+ this._url = undefined
34
+
35
+ const globalAgentlessEnabled = getValueFromEnvSources('DD_AGENTLESS_ENABLED', true)
36
+
37
+ const exporter = config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER
38
+ const useAgentlessExporter = exporter === 'agentless' ? true : exporter === 'agent' ? false : undefined
39
+
40
+ const agentlessEnabled = useAgentlessExporter ?? globalAgentlessEnabled ?? config.llmobs.DD_LLMOBS_AGENTLESS_ENABLED
41
+
42
+ if (agentlessEnabled === undefined) {
43
+ fetchAgentInfo(config.url, (err) => {
44
+ this.#initialize(err != null)
45
+ }, { keepProcessAlive: true })
46
+ } else {
47
+ this.#initialize(agentlessEnabled)
48
+ }
49
+ }
50
+
51
+ /**
52
+ *
53
+ * @param {boolean} useAgentless
54
+ */
55
+ #initialize (useAgentless) {
56
+ const Exporter = useAgentless ? AgentlessExporter : AgentExporter
57
+ const pendingUrl = this._url
58
+ this.#agentless = useAgentless
59
+ this.#exporter = new Exporter(this._config, this.#prioritySampler)
60
+ if (pendingUrl !== undefined) this.#exporter.setUrl?.(pendingUrl)
61
+ this._url = this.#exporter._url
62
+
63
+ this._isInitialized = true
64
+ this.exportUncodedTraces()
65
+ this.#bufferedSpanCount = 0
66
+
67
+ const pendingFlushes = this.#pendingFlushes
68
+ this.#pendingFlushes = []
69
+ for (const done of pendingFlushes) this.#exporter.flush(done)
70
+ }
71
+
72
+ /** @param {object[]} trace */
73
+ export (trace) {
74
+ if (!this._isInitialized) {
75
+ if (trace.length > MAX_BUFFERED_SPANS) {
76
+ this.#warnBufferLimit()
77
+ return false
78
+ }
79
+
80
+ if (this.#bufferedSpanCount + trace.length > MAX_BUFFERED_SPANS) this.#warnBufferLimit()
81
+ while (this.#bufferedSpanCount + trace.length > MAX_BUFFERED_SPANS) {
82
+ this.#bufferedSpanCount -= this._traceBuffer.shift().length
83
+ }
84
+
85
+ this._traceBuffer.push(trace)
86
+ this.#bufferedSpanCount += trace.length
87
+ return true
88
+ }
89
+
90
+ if (this.#agentless) this.#normalizeTagKeys(trace)
91
+ return this.#exporter.export(trace)
92
+ }
93
+
94
+ #warnBufferLimit () {
95
+ if (this.#bufferLimitWarned) return
96
+
97
+ this.#bufferLimitWarned = true
98
+ logger.warn('LLMObs exporter trace buffer full (limit is %d spans), dropping trace data', MAX_BUFFERED_SPANS)
99
+ }
100
+
101
+ /** @param {object[]} trace */
102
+ #normalizeTagKeys (trace) {
103
+ for (const span of trace) {
104
+ const llmobs = span.meta_struct?.[LLMOBS_META_STRUCT_KEY]
105
+ if (!llmobs?.tags) continue
106
+
107
+ const tags = {}
108
+ for (const [key, value] of Object.entries(llmobs.tags)) {
109
+ tags[key.replaceAll('.', '_')] = value
110
+ }
111
+ llmobs.tags = tags
112
+ }
113
+ }
114
+
115
+ /** @param {Function} [done] */
116
+ flush (done) {
117
+ if (this._isInitialized) {
118
+ this.#exporter.flush(done)
119
+ } else {
120
+ this.#pendingFlushes.push(done)
121
+ }
122
+ }
123
+
124
+ /** @param {string | URL} url */
125
+ setUrl (url) {
126
+ if (this._isInitialized) {
127
+ this.#exporter.setUrl?.(url)
128
+ this._url = this.#exporter._url
129
+ } else {
130
+ this._url = url
131
+ }
132
+ }
133
+ }
134
+
135
+ module.exports = LLMObsExporter
@@ -16,16 +16,17 @@ class LogExporter {
16
16
 
17
17
  for (const span of spans) {
18
18
  const spanStr = JSON.stringify(span)
19
- if (spanStr.length + TRACE_FORMAT_OVERHEAD > MAX_SIZE) {
19
+ const spanSize = Buffer.byteLength(spanStr, 'utf8')
20
+ if (spanSize + TRACE_FORMAT_OVERHEAD > MAX_SIZE) {
20
21
  log.debug('Span too large to send to logs, dropping')
21
22
  continue
22
23
  }
23
- if (spanStr.length + size > MAX_SIZE) {
24
+ if (spanSize + size > MAX_SIZE) {
24
25
  this._printSpans(queue)
25
26
  queue = []
26
27
  size = TRACE_FORMAT_OVERHEAD
27
28
  }
28
- size += spanStr.length + 1 // includes length of ',' character
29
+ size += spanSize + 1 // includes length of ',' character
29
30
  queue.push(spanStr)
30
31
  }
31
32
  if (queue.length > 0) {