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
@@ -5,6 +5,7 @@ const { channel } = require('dc-polyfill')
5
5
  const { DatadogNodeServerProvider } = require('../../../../vendor/dist/@datadog/openfeature-node-server')
6
6
  const log = require('../log')
7
7
  const { debugChannel } = require('../log/channels')
8
+ const { warn } = require('../log/writer')
8
9
  const configurationSource = require('./configuration_source')
9
10
  const { EXPOSURE_CHANNEL } = require('./constants/constants')
10
11
  const DebugLoggingHook = require('./debug-logging-hook')
@@ -16,6 +17,7 @@ const FlagEvalEVPHook = require('./writers/flag-eval-evp-hook')
16
17
  const RAW_EVALUATION_DATA_WARNING = 'Feature Flags: debug logging is enabled, so feature flag logs include raw ' +
17
18
  'evaluation data (targeting keys, evaluation context attributes, flag values, and default values) that may ' +
18
19
  'contain personal or sensitive information. Unset DD_TRACE_DEBUG when you no longer need it.'
20
+ const SOURCE_UNAVAILABLE_CONSEQUENCE = 'Provider initialization fails and flag evaluations return their default values.'
19
21
 
20
22
  /**
21
23
  * OpenFeature provider that integrates with Datadog's feature flagging system.
@@ -34,6 +36,9 @@ class FlaggingProvider extends DatadogNodeServerProvider {
34
36
  /** @type {{ start: Function, stop: Function } | undefined} */
35
37
  #configurationSource
36
38
 
39
+ /** @type {Error | undefined} */
40
+ #configurationSourceError
41
+
37
42
  /** @type {number} */
38
43
  #initializationTimeoutMs
39
44
 
@@ -82,7 +87,17 @@ class FlaggingProvider extends DatadogNodeServerProvider {
82
87
  this.hooks.push(telemetryHook(this.#flagEvalEVPHook))
83
88
  }
84
89
 
85
- this.#configurationSource = configurationSource.create(config, this.setConfiguration.bind(this))
90
+ try {
91
+ this.#configurationSource = configurationSource.create(config, this.setConfiguration.bind(this))
92
+ } catch (error) {
93
+ this.#configurationSourceError = error
94
+ log.error('Unable to configure Feature Flagging configuration source', error)
95
+ // log.error prints only with debug logging enabled, so write the diagnostic like the startup logs do.
96
+ // Only an explicit startupLogs=false (option or DD_TRACE_STARTUP_LOGS) hides it: v5 defaults it to false.
97
+ if (config.startupLogs || config.getOrigin('startupLogs') === 'default') {
98
+ warn(`DATADOG TRACER DIAGNOSTIC - Feature Flags: ${error.message}. ${SOURCE_UNAVAILABLE_CONSEQUENCE}`)
99
+ }
100
+ }
86
101
  this.#configurationSource?.start()
87
102
  }
88
103
 
@@ -98,6 +113,9 @@ class FlaggingProvider extends DatadogNodeServerProvider {
98
113
 
99
114
  if (hasConfiguration) {
100
115
  this.#logInitialConfiguration()
116
+ } else if (this.#configurationSourceError) {
117
+ // No configuration can arrive, so fail now instead of waiting for the timeout.
118
+ this.setError(this.#configurationSourceError)
101
119
  } else {
102
120
  log.debug('Feature Flags: waiting for provider initialization (timeout %dms)...', this.#initializationTimeoutMs)
103
121
  }
@@ -329,9 +329,7 @@ class BaseFFEWriter {
329
329
  * @param {(delivered: boolean) => void} [onComplete] - True only for a successful final response
330
330
  */
331
331
  #sendRequest (payload, eventCount, route, fallbackRoute, onComplete) {
332
- // The request helper mutates headers. Concurrent envelopes must not share them.
333
- const requestOptions = { ...route.requestOptions, headers: { ...route.requestOptions.headers } }
334
- request(payload, requestOptions, (error, response, statusCode) => {
332
+ request(payload, route.requestOptions, (error, response, statusCode) => {
335
333
  const errorMessage = error && (this.#formatError
336
334
  ? this.#formatError(error, statusCode)
337
335
  : error.message)
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { logs } = require('@opentelemetry/api-logs')
4
+
3
5
  const { buildResourceAttributes, registerResourceAttributeRefresh } = require('../resource-attributes')
4
6
 
5
7
  /**
@@ -35,6 +37,8 @@ const OtlpHttpLogExporter = require('./otlp_http_log_exporter')
35
37
  /**
36
38
  * Initializes OpenTelemetry Logs support
37
39
  * @param {import('../../config/config-base')} config - Tracer configuration instance
40
+ * @returns {import('../startup-config').InitializedExporter | undefined} Startup reporting metadata
41
+ * with the effective protocol and resource, or undefined when another provider owns the global Logs API.
38
42
  */
39
43
  function initializeOpenTelemetryLogs (config) {
40
44
  // Create OTLP exporter using resolved config values
@@ -58,11 +62,18 @@ function initializeOpenTelemetryLogs (config) {
58
62
 
59
63
  // Expose this provider to application calls through the OpenTelemetry Logs API.
60
64
  loggerProvider.register()
65
+ // Registration can leave an existing global provider in place; only report ours when it is active.
66
+ const registered = logs.getLoggerProvider() === loggerProvider
61
67
 
62
68
  // Include final log batches in lifecycle retention with trace delivery.
63
69
  registerTelemetryFlusher(done => loggerProvider.forceFlush(done))
64
70
 
65
71
  registerResourceAttributeRefresh(exporter, () => buildResourceAttributes(config))
72
+ if (!registered) return
73
+ return {
74
+ protocol: exporter.transformer.protocol,
75
+ resourceAttributes: exporter.getStartupResourceAttributes(),
76
+ }
66
77
  }
67
78
 
68
79
  module.exports = {
@@ -29,7 +29,7 @@ class OtlpHttpLogExporter extends OtlpHttpExporterBase {
29
29
  * @param {Attributes} resourceAttributes - Resource attributes
30
30
  */
31
31
  constructor (url, headers, timeout, protocol, resourceAttributes) {
32
- super(url, headers, timeout, protocol, 'logs')
32
+ super(url, headers, timeout, protocol, 'logs', resourceAttributes)
33
33
  this.transformer = new OtlpTransformer(resourceAttributes, protocol)
34
34
  }
35
35
 
@@ -45,6 +45,7 @@ const RESERVED_TRACER_TAGS = new Set(['service', 'env', 'version', 'runtime_id',
45
45
  /**
46
46
  * Initializes OpenTelemetry Metrics support
47
47
  * @param {import('../../config/config-base')} config - Tracer configuration instance
48
+ * @returns {import('../startup-config').InitializedExporter | undefined}
48
49
  */
49
50
  function initializeOpenTelemetryMetrics (config) {
50
51
  const exporter = new OtlpHttpMetricExporter(
@@ -63,12 +64,17 @@ function initializeOpenTelemetryMetrics (config) {
63
64
  )
64
65
 
65
66
  const meterProvider = new MeterProvider({ reader })
66
- metrics.setGlobalMeterProvider(meterProvider)
67
+ const registered = metrics.setGlobalMeterProvider(meterProvider)
67
68
 
68
69
  // Include the final metric collection and export in lifecycle retention.
69
70
  registerTelemetryFlusher(done => reader.forceFlush(done))
70
71
 
71
72
  registerResourceAttributeRefresh(exporter, () => buildGeneralResourceAttributes(config))
73
+ if (!registered) return
74
+ return {
75
+ protocol: exporter.transformer.protocol,
76
+ resourceAttributes: exporter.getStartupResourceAttributes(),
77
+ }
72
78
  }
73
79
 
74
80
  /**
@@ -25,7 +25,7 @@ class OtlpHttpMetricExporter extends OtlpHttpExporterBase {
25
25
  * @param {Attributes} resourceAttributes - Resource attributes
26
26
  */
27
27
  constructor (url, headers, timeout, protocol, resourceAttributes) {
28
- super(url, headers, timeout, protocol, 'metrics')
28
+ super(url, headers, timeout, protocol, 'metrics', resourceAttributes)
29
29
  this.transformer = new OtlpTransformer(resourceAttributes, protocol)
30
30
  }
31
31
 
@@ -15,8 +15,11 @@ class OtlpStatsExporter extends OtlpHttpExporterBase {
15
15
  * @param {number} [timeout]
16
16
  */
17
17
  constructor (url, protocol, resourceAttributes, headers, timeout = 10_000) {
18
- super(url, headers, timeout, protocol, 'span-stats')
18
+ super(url, headers, timeout, protocol, 'span-stats', resourceAttributes)
19
19
  this.#transformer = new OtlpStatsTransformer(resourceAttributes, protocol)
20
+ // Expose the protocol actually used after transformer fallback (e.g. grpc -> http/protobuf)
21
+ // so startup reporting describes the exporter rather than the requested protocol.
22
+ this.protocol = this.#transformer.protocol
20
23
  }
21
24
 
22
25
  /**
@@ -22,6 +22,12 @@ const legacyStorage = storage('legacy')
22
22
  * @class OtlpHttpExporterBase
23
23
  */
24
24
  class OtlpHttpExporterBase {
25
+ /**
26
+ * @readonly
27
+ * @type {Readonly<Record<string, unknown>>}
28
+ */
29
+ #startupResourceAttributes
30
+
25
31
  #transport = https
26
32
  #serverlessDeliveryTracker
27
33
 
@@ -34,8 +40,12 @@ class OtlpHttpExporterBase {
34
40
  * @param {number} timeout - Request timeout in milliseconds
35
41
  * @param {string} protocol - OTLP protocol (http/protobuf or http/json)
36
42
  * @param {string} signalType - Signal type for error messages (e.g., 'logs', 'metrics')
43
+ * @param {import('@opentelemetry/api').Attributes} [resourceAttributes] - Resource passed to the transformer
37
44
  */
38
- constructor (url, headers, timeout, protocol, signalType) {
45
+ constructor (url, headers, timeout, protocol, signalType, resourceAttributes = {}) {
46
+ this.#startupResourceAttributes = Object.fromEntries(Object.entries(resourceAttributes).map(([key, value]) => [
47
+ key, Array.isArray(value) ? [...value] : value,
48
+ ]))
39
49
  this.#serverlessDeliveryTracker = createServerlessDeliveryTracker()
40
50
  this.protocol = protocol
41
51
  this.signalType = signalType
@@ -59,6 +69,14 @@ class OtlpHttpExporterBase {
59
69
  this.#applyUrl(url)
60
70
  }
61
71
 
72
+ /**
73
+ * Returns the resource captured at construction, before later identity refreshes.
74
+ * @returns {Readonly<Record<string, unknown>>}
75
+ */
76
+ getStartupResourceAttributes () {
77
+ return this.#startupResourceAttributes
78
+ }
79
+
62
80
  /**
63
81
  * Records telemetry metrics for exported data.
64
82
  * @param {string} metricName - Name of the metric to record
@@ -6,5 +6,9 @@
6
6
  // the already-built payload. Its own dependency-free module so an instrumentation can register
7
7
  // without loading the OTel bridge, and a plain holder so the caller gates on `hook` existing.
8
8
 
9
- /** @type {{ hook: ((ddSpan: import('../opentracing/span')) => void) | undefined }} */
9
+ /**
10
+ * @type {{
11
+ * hook: ((ddSpan: import('../opentracing/span'), otelSemanticsEnabled: boolean) => boolean | undefined) | undefined
12
+ * }}
13
+ */
10
14
  module.exports = { hook: undefined }
@@ -254,7 +254,7 @@ function recordException (ddSpan, exception, timeInput, otelTraceSemanticsEnable
254
254
 
255
255
  /**
256
256
  * Applies OTel `setStatus({ code, message })` per spec: UNSET / missing is a no-op, OK is
257
- * final, ERROR is replaceable. Only ERROR writes tags; the returned code is the one the
257
+ * final, ERROR is replaceable. Only ERROR writes error metadata; the returned code is the one the
258
258
  * caller must store for the next call.
259
259
  *
260
260
  * @param {import('../opentracing/span')} ddSpan
@@ -266,6 +266,11 @@ function applyOtelStatus (ddSpan, currentCode, status, otelTraceSemanticsEnabled
266
266
  if (!isWritable(ddSpan)) return currentCode
267
267
 
268
268
  const code = status?.code
269
+ if (otelTraceSemanticsEnabled && (code === 1 || currentCode === 1)) {
270
+ ddSpan.context().deleteTag(ERROR_MESSAGE)
271
+ ddSpan.setTag(IGNORE_OTEL_ERROR, true)
272
+ return 1
273
+ }
269
274
  if (!code || currentCode === 1) {
270
275
  if (otelTraceSemanticsEnabled) {
271
276
  ddSpan.context().deleteTag(ERROR_MESSAGE)
@@ -261,8 +261,8 @@ class Span extends BridgeSpanBase {
261
261
  const endTime = hrTimeToMilliseconds(hrEndTime)
262
262
 
263
263
  // Must run before `finish()`, while the DD span is still unfinished. See span-ending-hook.js.
264
- if (spanEndingHook.hook !== undefined) {
265
- spanEndingHook.hook(this._ddSpan)
264
+ if (spanEndingHook.hook?.(this._ddSpan, this._otelTraceSemanticsEnabled)) {
265
+ this.setStatus({ code: api.SpanStatusCode.ERROR, message: this._ddSpan.context().getTag('error.message') })
266
266
  }
267
267
  this._ddSpan.finish(endTime)
268
268
  this._spanProcessor.onEnd(this)
@@ -0,0 +1,174 @@
1
+ 'use strict'
2
+
3
+ const { isDeepStrictEqual } = require('node:util')
4
+
5
+ const { DD_MAJOR } = require('../../../../version')
6
+ const { VALID_PROPAGATION_STYLES } = require('../config/parsers')
7
+ const { getLogLevel } = require('../log/writer')
8
+
9
+ /**
10
+ * @typedef {Readonly<{
11
+ * protocol: string,
12
+ * resourceAttributes: Readonly<Record<string, unknown>>,
13
+ * }>} InitializedExporter
14
+ * @typedef {Readonly<{
15
+ * tracing?: boolean,
16
+ * traces?: InitializedExporter,
17
+ * metrics?: InitializedExporter,
18
+ * logs?: InitializedExporter,
19
+ * spanMetrics?: InitializedExporter,
20
+ * }>} Pipelines
21
+ */
22
+
23
+ /**
24
+ * @param {ReturnType<import('../config')>} config
25
+ * @param {import('../sampling_rule')[]} rules
26
+ * @param {Pipelines} [pipelines]
27
+ * @returns {Record<string, unknown>}
28
+ */
29
+ function startupConfig (config, rules, pipelines = {}) {
30
+ const tracing = !!pipelines.tracing
31
+ const traces = !!pipelines.traces
32
+ const metrics = !!pipelines.metrics
33
+ const logs = !!pipelines.logs
34
+ const spanMetrics = !!pipelines.spanMetrics
35
+ const resources = [pipelines.traces, pipelines.metrics, pipelines.logs, pipelines.spanMetrics]
36
+ .filter(exporter => exporter !== undefined)
37
+ .map(exporter => exporter.resourceAttributes)
38
+ const attributes = commonResourceAttributes(resources)
39
+
40
+ /** @type {Record<string, unknown>} */
41
+ const out = {
42
+ DD_TRACE_OTEL_ENABLED: !!config.DD_TRACE_OTEL_ENABLED,
43
+ DD_TRACE_OTEL_SEMANTICS_ENABLED: !!config.DD_TRACE_OTEL_SEMANTICS_ENABLED,
44
+ DD_METRICS_OTEL_ENABLED: !!config.DD_METRICS_OTEL_ENABLED,
45
+ DD_LOGS_OTEL_ENABLED: !!config.DD_LOGS_OTEL_ENABLED,
46
+ OTEL_LOG_LEVEL: getLogLevel(),
47
+ OTEL_SERVICE_NAME: typeof attributes['service.name'] === 'string'
48
+ ? attributes['service.name']
49
+ : undefined,
50
+ OTEL_RESOURCE_ATTRIBUTES: attributes,
51
+ OTEL_TRACES_EXPORTER: traces ? 'otlp' : 'none',
52
+ OTEL_METRICS_EXPORTER: metrics ? 'otlp' : 'none',
53
+ OTEL_LOGS_EXPORTER: logs ? 'otlp' : 'none',
54
+ OTEL_TRACES_SPAN_METRICS_ENABLED: spanMetrics,
55
+ }
56
+
57
+ if (tracing) {
58
+ const { inject, extract } = config.tracePropagationStyle
59
+ if (DD_MAJOR >= 6 && config.DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT === 'continue' &&
60
+ inject.length === extract.length &&
61
+ inject.every((name, i) => name === extract[i] && VALID_PROPAGATION_STYLES.has(name))) {
62
+ const propagators = inject.filter(name => name !== 'none')
63
+ .map(name => name === 'b3 single header' ? 'b3' : name)
64
+ out.OTEL_PROPAGATORS = propagators.join(',') || 'none'
65
+ }
66
+ const firstRule = rules[0]
67
+ if (config.apmTracingEnabled !== false && firstRule) {
68
+ const globalRuleCount = config.sampler.sampleRate === undefined ? 0 : 1
69
+ if (rules.length > globalRuleCount) {
70
+ out.OTEL_TRACES_SAMPLER = 'datadog_custom_rules'
71
+ } else {
72
+ const rate = firstRule.sampleRate
73
+ out.OTEL_TRACES_SAMPLER = rate === 0
74
+ ? 'parentbased_always_off'
75
+ : rate === 1 ? 'parentbased_always_on' : 'parentbased_traceidratio'
76
+ if (rate > 0 && rate < 1) out.OTEL_TRACES_SAMPLER_ARG = rate
77
+ }
78
+ }
79
+ }
80
+
81
+ if (pipelines.traces) {
82
+ Object.assign(out, buildSanitizedExporterConfig(config, 'TRACES', pipelines.traces.protocol))
83
+ }
84
+ const metricsExporter = pipelines.metrics || pipelines.spanMetrics
85
+ if (metricsExporter) {
86
+ Object.assign(out, buildSanitizedExporterConfig(config, 'METRICS', metricsExporter.protocol))
87
+ }
88
+ if (metrics) {
89
+ out.OTEL_METRIC_EXPORT_INTERVAL = config.OTEL_METRIC_EXPORT_INTERVAL
90
+ out.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE =
91
+ config.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE.toLowerCase()
92
+ }
93
+ if (pipelines.logs) {
94
+ Object.assign(out, buildSanitizedExporterConfig(config, 'LOGS', pipelines.logs.protocol))
95
+ out.OTEL_BLRP_SCHEDULE_DELAY = config.OTEL_BSP_SCHEDULE_DELAY
96
+ out.OTEL_BLRP_MAX_EXPORT_BATCH_SIZE = config.OTEL_BSP_MAX_EXPORT_BATCH_SIZE
97
+ }
98
+ return out
99
+ }
100
+
101
+ /**
102
+ * @param {Readonly<Record<string, unknown>>[]} resources
103
+ * @returns {Record<string, unknown>}
104
+ */
105
+ function commonResourceAttributes (resources) {
106
+ const [reference, ...others] = resources
107
+ /** @type {Record<string, unknown>} */
108
+ const shared = {}
109
+
110
+ if (!reference) return shared
111
+
112
+ for (const [key, value] of Object.entries(reference)) {
113
+ const supported = isAttributeValue(value) ||
114
+ (Array.isArray(value) && value.every(isAttributeValue))
115
+ if (!supported) continue
116
+
117
+ const matchesEveryResource = others.every(resource =>
118
+ Object.hasOwn(resource, key) && isDeepStrictEqual(resource[key], value))
119
+ if (!matchesEveryResource) continue
120
+
121
+ shared[key] = Array.isArray(value) ? [...value] : value
122
+ }
123
+
124
+ return shared
125
+ }
126
+
127
+ /** @param {unknown} value */
128
+ function isAttributeValue (value) {
129
+ return typeof value === 'string' || typeof value === 'boolean' ||
130
+ (typeof value === 'number' && Number.isFinite(value))
131
+ }
132
+
133
+ /**
134
+ * @param {ReturnType<import('../config')>} config
135
+ * @param {'TRACES' | 'METRICS' | 'LOGS'} signal
136
+ * @param {string} protocol
137
+ * @returns {Record<string, unknown>}
138
+ */
139
+ function buildSanitizedExporterConfig (config, signal, protocol) {
140
+ const prefix = `OTEL_EXPORTER_OTLP_${signal}`
141
+ const endpoint = sanitizeEndpoint(config[`${prefix}_ENDPOINT`])
142
+ return {
143
+ ...(endpoint && { [`${prefix}_ENDPOINT`]: endpoint }),
144
+ [`${prefix}_PROTOCOL`]: protocol,
145
+ [`${prefix}_HEADERS`]: redactHeaders(config[`${prefix}_HEADERS`]),
146
+ [`${prefix}_TIMEOUT`]: config[`${prefix}_TIMEOUT`],
147
+ }
148
+ }
149
+
150
+ /** @param {string} endpoint */
151
+ function sanitizeEndpoint (endpoint) {
152
+ let sanitized
153
+ try {
154
+ const url = new URL(endpoint)
155
+ url.username = ''
156
+ url.password = ''
157
+ url.search = ''
158
+ url.hash = ''
159
+ if (url.protocol === 'http:' || url.protocol === 'https:') sanitized = url.href
160
+ } catch {
161
+ // A malformed endpoint has no safe representation in diagnostics.
162
+ }
163
+ return sanitized
164
+ }
165
+
166
+ /**
167
+ * @param {Record<string, string> | undefined} headers
168
+ * @returns {Record<string, string>}
169
+ */
170
+ function redactHeaders (headers) {
171
+ return Object.fromEntries(Object.keys(headers ?? {}).map(name => [name, '<redacted>']))
172
+ }
173
+
174
+ module.exports = startupConfig
@@ -39,7 +39,7 @@ class OtlpHttpTraceExporter extends OtlpHttpExporterBase {
39
39
  * @param {boolean} otelTraceSemanticsEnabled - When true, do not emit Datadog-only attributes as span attributes
40
40
  */
41
41
  constructor (url, headers, timeout, resourceAttributes, otelTraceSemanticsEnabled) {
42
- super(url, headers, timeout, 'http/json', 'traces')
42
+ super(url, headers, timeout, 'http/json', 'traces', resourceAttributes)
43
43
  this.#transformer = new OtlpTraceTransformer(resourceAttributes, otelTraceSemanticsEnabled)
44
44
  }
45
45
 
@@ -295,7 +295,13 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
295
295
  if (errorType && errorMessage) {
296
296
  message = `${errorType}: ${errorMessage}`
297
297
  } else if (errorType) {
298
- message = errorType
298
+ const kind = span.meta?.['span.kind']
299
+ // The HTTP response status already explains a status-only error.
300
+ const isHttpStatusError = this.#otelTraceSemanticsEnabled &&
301
+ (kind === 'server' || kind === 'client') &&
302
+ !span.meta?.['error.stack'] &&
303
+ errorType === span.metrics?.['http.response.status_code']?.toString()
304
+ if (!isHttpStatusError) message = errorType
299
305
  } else if (errorMessage) {
300
306
  message = errorMessage
301
307
  }
@@ -15,49 +15,102 @@ const WHITESPACE = /[ \t]/
15
15
  * @param {boolean} rejectValueTabs Drop entries whose value contains an internal tab.
16
16
  * @param {number} [maxEntries] Maximum number of entries to parse.
17
17
  * @param {number} [maxValueLength] Maximum length of an entry value.
18
+ * @param {boolean} [prioritizeDd] Keep dd first even when it follows the member limit.
18
19
  * @returns {[string, string][]} Entries in reverse of wire order.
19
20
  */
20
- function parseEntries (value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength) {
21
- const segments = value.split(fieldSeparator, maxEntries)
22
-
23
- // TODO: We should extract dd no matter at what position and move it to the front of the list.
24
- // Extract up 31 additional entries.
21
+ function parseEntries (
22
+ value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries = Infinity, maxValueLength = Infinity, prioritizeDd
23
+ ) {
24
+ /** @type {[string, string][]} */
25
25
  const entries = []
26
- for (let index = 0; index < segments.length; index++) {
27
- const segment = segments[index]
28
- const splitIndex = segment.indexOf(pairSeparator)
29
- if (splitIndex === -1) continue
30
- const key = segment.slice(0, splitIndex).trim()
31
- if (!key || WHITESPACE.test(key)) continue
32
- // W3C §3.3.1.3.2: value = 0*255(chr) nblk-chr; chr = %x20 / nblk-chr (no tab).
33
- // Leading 0x20 is part of value; trailing whitespace is OWS.
34
- const entryValue = segment.slice(splitIndex + 1).trimEnd()
35
- if (!entryValue ||
36
- maxValueLength !== undefined && entryValue.length > maxValueLength ||
37
- rejectValueTabs && entryValue.includes('\t')) continue
38
- entries.push([key, entryValue])
26
+ /** @type {[string, string] | undefined} */
27
+ let ddEntry
28
+ let start = 0
29
+ let memberCount = 0
30
+ let splitIndex = -1
31
+
32
+ while (start <= value.length && memberCount < maxEntries) {
33
+ const separatorIndex = value.indexOf(fieldSeparator, start)
34
+ const end = separatorIndex === -1 ? value.length : separatorIndex
35
+ // Reuse the next separator (or end) so malformed members do not rescan the suffix.
36
+ if (splitIndex < start && start < end) {
37
+ splitIndex = value.indexOf(pairSeparator, start)
38
+ if (splitIndex === -1) splitIndex = value.length
39
+ }
40
+ const key = splitIndex > start && splitIndex < end ? value.slice(start, splitIndex).trim() : undefined
41
+ if (key && !WHITESPACE.test(key)) {
42
+ // W3C §3.3.1.3.2: value = 0*255(chr) nblk-chr; chr = %x20 / nblk-chr (no tab).
43
+ // Leading 0x20 is part of value; trailing whitespace is OWS.
44
+ const entryValue = value.slice(splitIndex + 1, end).trimEnd()
45
+ if (entryValue &&
46
+ entryValue.length <= maxValueLength &&
47
+ (!rejectValueTabs || !entryValue.includes('\t'))) {
48
+ if (prioritizeDd && key === 'dd') {
49
+ ddEntry ??= [key, entryValue]
50
+ } else {
51
+ entries.push([key, entryValue])
52
+ }
53
+ }
54
+ }
55
+
56
+ memberCount++
57
+ if (separatorIndex === -1) {
58
+ start = value.length + 1
59
+ break
60
+ }
61
+ start = separatorIndex + fieldSeparator.length
39
62
  }
63
+
64
+ if (prioritizeDd && ddEntry === undefined && start < value.length) {
65
+ let position = value.indexOf('dd', start)
66
+ while (position !== -1) {
67
+ const segmentStart = value.lastIndexOf(',', position) + 1
68
+ const separatorIndex = value.indexOf(',', position)
69
+ const end = separatorIndex === -1 ? value.length : separatorIndex
70
+ const segment = value.slice(segmentStart, end)
71
+ const splitIndex = segment.indexOf('=')
72
+
73
+ if (splitIndex > 0 && segment.slice(0, splitIndex).trim() === 'dd') {
74
+ const entryValue = segment.slice(splitIndex + 1).trimEnd()
75
+ if (entryValue && entryValue.length <= maxValueLength && !entryValue.includes('\t')) {
76
+ ddEntry = ['dd', entryValue]
77
+ break
78
+ }
79
+ }
80
+
81
+ if (separatorIndex === -1) break
82
+ position = value.indexOf('dd', separatorIndex + 1)
83
+ }
84
+ }
85
+
86
+ if (ddEntry && entries.length === maxEntries) entries.pop()
40
87
  // Reverse so the Map's insertion order is reverse of wire order. `toString`
41
88
  // prepends as it iterates, which yields the original wire order back.
42
89
  entries.reverse()
90
+ if (ddEntry) entries.push(ddEntry)
43
91
  return entries
44
92
  }
45
93
 
46
94
  /**
47
- * @param {typeof TraceState | typeof TraceStateData} Type
95
+ * @template T
96
+ * @param {new (entries?: [string, string][]) => T} Type
48
97
  * @param {string | undefined} value
49
98
  * @param {string} fieldSeparator
50
99
  * @param {string} pairSeparator
51
100
  * @param {boolean} rejectValueTabs
52
101
  * @param {number} [maxEntries]
53
102
  * @param {number} [maxValueLength]
54
- * @returns {TraceState | TraceStateData}
103
+ * @param {boolean} [prioritizeDd]
55
104
  */
56
- function fromString (Type, value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength) {
105
+ function fromString (
106
+ Type, value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength, prioritizeDd
107
+ ) {
57
108
  if (typeof value !== 'string' || !value.length) {
58
109
  return new Type()
59
110
  }
60
- return new Type(parseEntries(value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength))
111
+ return new Type(parseEntries(
112
+ value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength, prioritizeDd
113
+ ))
61
114
  }
62
115
 
63
116
  function toString (map, pairSeparator, fieldSeparator) {
@@ -221,8 +274,9 @@ class TraceState {
221
274
  return result
222
275
  }
223
276
 
277
+ /** @param {string | undefined} value */
224
278
  static fromString (value) {
225
- return fromString(TraceState, value, ',', '=', true, MAX_LIST_MEMBERS, MAX_VALUE_LENGTH)
279
+ return fromString(TraceState, value, ',', '=', true, MAX_LIST_MEMBERS, MAX_VALUE_LENGTH, true)
226
280
  }
227
281
 
228
282
  toString () {
@@ -21,6 +21,12 @@ const REFERENCE_CHILD_OF = 'child_of'
21
21
  const REFERENCE_FOLLOWS_FROM = 'follows_from'
22
22
 
23
23
  class DatadogTracer {
24
+ /**
25
+ * @readonly
26
+ * @type {import('../opentelemetry/startup-config').Pipelines}
27
+ */
28
+ #startupConfig
29
+
24
30
  constructor (config, prioritySampler) {
25
31
  this._config = config
26
32
  this._service = config.service
@@ -33,9 +39,14 @@ class DatadogTracer {
33
39
  this._prioritySampler = prioritySampler ?? new PrioritySampler(config.env, config.sampler)
34
40
 
35
41
  const exportOtlpTraces = getExporter.usesOtlpTraceExporter(config)
42
+ let traces
36
43
  if (exportOtlpTraces) {
37
44
  const { createOtlpTraceExporter } = require('../opentelemetry/trace')
38
45
  this._exporter = createOtlpTraceExporter(config)
46
+ traces = {
47
+ protocol: this._exporter.protocol,
48
+ resourceAttributes: this._exporter.getStartupResourceAttributes(),
49
+ }
39
50
  } else {
40
51
  let exporterName = config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER
41
52
  if (config.llmobs?.DD_LLMOBS_ENABLED && !config.isCiVisibility &&
@@ -67,11 +78,24 @@ class DatadogTracer {
67
78
  [formats.LOG]: new LogPropagator(config),
68
79
  [formats.TEXT_MAP_DSM]: new DSMTextMapPropagator(config),
69
80
  }
81
+ this.#startupConfig = {
82
+ tracing: true,
83
+ traces,
84
+ spanMetrics: this._processor.getSpanMetricsStartupConfig(),
85
+ }
70
86
  if (config.reportHostname) {
71
87
  this._hostname = os.hostname()
72
88
  }
73
89
  }
74
90
 
91
+ /**
92
+ * Returns the configuration captured when tracing initialized.
93
+ * @returns {import('../opentelemetry/startup-config').Pipelines}
94
+ */
95
+ getStartupConfig () {
96
+ return this.#startupConfig
97
+ }
98
+
75
99
  startSpan (name, options = {}) {
76
100
  const parent = options.childOf
77
101
  ? getContext(options.childOf)