dd-trace 6.24.0 → 6.25.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
package/ci/init.js CHANGED
@@ -4,15 +4,12 @@
4
4
  const exporters = require('../ext/exporters')
5
5
  const log = require('../packages/dd-trace/src/log')
6
6
  const { getEnvironmentVariable, getValueFromEnvSources } = require('../packages/dd-trace/src/config/helper')
7
- const { isFalse, isTrue } = require('../packages/dd-trace/src/util')
7
+ const { isTrue } = require('../packages/dd-trace/src/util')
8
8
 
9
9
  const PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm']
10
10
  const DEFAULT_FLUSH_INTERVAL = 10_000
11
11
  const JEST_FLUSH_INTERVAL = 0
12
12
  const VITEST_NO_WORKER_INIT_ACTIVE_ENV = 'DD_TEST_OPT_VITEST_NO_WORKER_INIT_ACTIVE'
13
- const VALIDATION_MODE_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MODE'
14
- const VALIDATION_MANIFEST_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MANIFEST_FILE'
15
- const VALIDATION_OUTPUT_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_OUTPUT_DIR'
16
13
  const EXPORTER_MAP = {
17
14
  jest: exporters.JEST_WORKER,
18
15
  cucumber: exporters.CUCUMBER_WORKER,
@@ -46,22 +43,9 @@ const baseOptions = {
46
43
  flushInterval: isJestWorker ? JEST_FLUSH_INTERVAL : DEFAULT_FLUSH_INTERVAL,
47
44
  }
48
45
 
49
- const isValidationModeRequested = isTrue(getEnvironmentVariable(VALIDATION_MODE_ENV))
50
- const missingValidationEnvironment = [VALIDATION_MANIFEST_ENV, VALIDATION_OUTPUT_ENV].filter(name => {
51
- return !getEnvironmentVariable(name)
52
- })
53
- const isValidationMode = isValidationModeRequested && missingValidationEnvironment.length === 0
54
- if (isValidationModeRequested && !isValidationMode) {
55
- console.error(
56
- `${VALIDATION_MODE_ENV} requires ${missingValidationEnvironment.join(' and ')}; ` +
57
- 'dd-trace will not be initialized.'
58
- )
59
- }
60
46
  // skipDefault: CI visibility stays on unless DD_CIVISIBILITY_ENABLED is explicitly false; the
61
47
  // registered default (false) would otherwise turn it off whenever the variable is unset.
62
- let shouldInit = isValidationModeRequested
63
- ? isValidationMode && !isFalse(getEnvironmentVariable('DD_CIVISIBILITY_ENABLED'))
64
- : getValueFromEnvSources('DD_CIVISIBILITY_ENABLED', true) !== false
48
+ let shouldInit = getValueFromEnvSources('DD_CIVISIBILITY_ENABLED', true) !== false
65
49
  const isGlobalAgentlessEnabled = getValueFromEnvSources('DD_AGENTLESS_ENABLED')
66
50
  const isAgentlessEnabled = isGlobalAgentlessEnabled ||
67
51
  getValueFromEnvSources('DD_CIVISIBILITY_AGENTLESS_ENABLED')
@@ -75,10 +59,6 @@ if (isTestWorker) {
75
59
  baseOptions.experimental = {
76
60
  exporter: EXPORTER_MAP[testWorkerType],
77
61
  }
78
- } else if (isValidationMode) {
79
- baseOptions.experimental = {
80
- exporter: 'ci_validation',
81
- }
82
62
  } else {
83
63
  if (isAgentlessEnabled) {
84
64
  if (getValueFromEnvSources('DD_API_KEY')) {
package/ext/exporters.js CHANGED
@@ -6,7 +6,6 @@ module.exports = {
6
6
  AGENTLESS: 'agentless',
7
7
  DATADOG: 'datadog',
8
8
  AGENT_PROXY: 'agent_proxy',
9
- CI_VALIDATION: 'ci_validation',
10
9
  JEST_WORKER: 'jest_worker',
11
10
  CUCUMBER_WORKER: 'cucumber_worker',
12
11
  MOCHA_WORKER: 'mocha_worker',
package/index.d.ts CHANGED
@@ -213,7 +213,9 @@ interface Tracer extends opentracing.Tracer {
213
213
  /**
214
214
  * OpenFeature Provider with agentless and Agent Remote Config delivery.
215
215
  *
216
- * Agentless delivery is enabled by default and starts when the provider is first accessed.
216
+ * Agentless delivery is enabled by default and starts when the provider is first accessed. The default agentless
217
+ * endpoint requires DD_API_KEY. Without it, provider initialization fails at once. A custom agentless base URL
218
+ * and Remote Config delivery do not need the key.
217
219
  *
218
220
  * @env DD_FEATURE_FLAGS_ENABLED
219
221
  * @env DD_FEATURE_FLAGS_CONFIGURATION_SOURCE
@@ -291,8 +293,10 @@ interface Plugins {
291
293
  "anthropic": tracer.plugins.anthropic;
292
294
  "claude-agent-sdk": tracer.plugins.claude_agent_sdk;
293
295
  "apollo": tracer.plugins.apollo;
296
+ "async-mutex": tracer.plugins.async_mutex;
294
297
  "avsc": tracer.plugins.avsc;
295
298
  "aws-durable-execution-sdk-js": tracer.plugins.aws_durable_execution_sdk_js;
299
+ "aws-lambda": tracer.plugins.aws_lambda;
296
300
  "aws-sdk": tracer.plugins.aws_sdk;
297
301
  "azure-cosmos": tracer.plugins.azure_cosmos;
298
302
  "azure-event-hubs": tracer.plugins.azure_event_hubs;
@@ -312,6 +316,7 @@ interface Plugins {
312
316
  "dns": tracer.plugins.dns;
313
317
  "elasticsearch": tracer.plugins.elasticsearch;
314
318
  "electron": tracer.plugins.electron;
319
+ "elevenlabs": tracer.plugins.elevenlabs;
315
320
  "express": tracer.plugins.express;
316
321
  "fastify": tracer.plugins.fastify;
317
322
  "fetch": tracer.plugins.fetch;
@@ -366,6 +371,7 @@ interface Plugins {
366
371
  "sharedb": tracer.plugins.sharedb;
367
372
  "supabase": tracer.plugins.supabase;
368
373
  "tedious": tracer.plugins.tedious;
374
+ "trpc": tracer.plugins.trpc;
369
375
  "typesafe": tracer.plugins.typesafe;
370
376
  "undici": tracer.plugins.undici;
371
377
  "vitest": tracer.plugins.vitest;
@@ -834,6 +840,25 @@ declare namespace tracer {
834
840
  * @env DD_FEATURE_FLAGS_EVALUATION_TELEMETRY_PER_SUBJECT_OPT_OUT_ENABLED
835
841
  */
836
842
  enableEvaluationTelemetryOptOutParameter?: boolean
843
+
844
+ /**
845
+ * Loads only the flags that have any of these tags or whose key matches any of these key patterns,
846
+ * instead of every flag. Each list accepts at most 31 values of at most 200 UTF-8 bytes each.
847
+ * A selection that cannot be sent is dropped with an error log, and every flag is loaded.
848
+ * Programmatic only, with no environment variable, so `dd-trace/init` cannot set it.
849
+ * Captured when `tracer.openfeature` is first accessed. Agentless delivery only.
850
+ */
851
+ flagSelection?: {
852
+ /**
853
+ * Flag tags, such as `checkout`, matched exactly and case-sensitively.
854
+ */
855
+ tags?: string[]
856
+ /**
857
+ * Flag key patterns, such as `checkout.*`, matched case-sensitively against the whole key.
858
+ * `*` matches any run of characters, including none; every other character, including `?`, is literal.
859
+ */
860
+ keyPatterns?: string[]
861
+ }
837
862
  }
838
863
 
839
864
  /**
@@ -922,7 +947,8 @@ declare namespace tracer {
922
947
  enabled?: boolean
923
948
  /**
924
949
  * Timeout in milliseconds for OpenFeature provider initialization.
925
- * If configuration is not received within this time, initialization fails.
950
+ * If configuration is not received within this time, initialization fails. It fails at once when the agentless
951
+ * configuration source cannot start, such as the default endpoint without DD_API_KEY.
926
952
  * Can be configured via DD_EXPERIMENTAL_FLAGGING_PROVIDER_INITIALIZATION_TIMEOUT_MS environment variable.
927
953
  *
928
954
  * @default 30000
@@ -2020,11 +2046,21 @@ declare namespace tracer {
2020
2046
  * @param opts - Optional configuration object:
2021
2047
  * - `block`: When true, throws an exception if evaluation result is not 'ALLOW'
2022
2048
  * and the AI Guard service has blocking mode enabled (default: false).
2049
+ * - `tags`: Custom tags to set on the AI Guard span. Keys are set verbatim. Keys equal to
2050
+ * `ai_guard` or starting with `ai_guard.` are reserved and ignored. Entries with an
2051
+ * empty key, a key longer than 200 characters, a string value longer than 25000
2052
+ * characters, or a value that is not a string, finite number or boolean are dropped.
2023
2053
  * @returns Promise resolving to an Evaluation with the security decision and reasoning.
2024
2054
  * The promise rejects with AIGuardAbortError when `opts.block` is true and the evaluation result would block the request.
2025
2055
  * The promise rejects with AIGuardClientError when communication with the AI Guard service fails.
2026
2056
  */
2027
- evaluate (messages: Message[], opts?: { block?: boolean }): Promise<Evaluation>;
2057
+ evaluate (
2058
+ messages: Message[],
2059
+ opts?: {
2060
+ block?: boolean,
2061
+ tags?: { [key: string]: string | number | boolean },
2062
+ }
2063
+ ): Promise<Evaluation>;
2028
2064
  }
2029
2065
  }
2030
2066
 
@@ -2418,6 +2454,12 @@ declare namespace tracer {
2418
2454
  };
2419
2455
  }
2420
2456
 
2457
+ /**
2458
+ * This plugin automatically instruments the
2459
+ * [async-mutex](https://github.com/DirtyHairy/async-mutex) module.
2460
+ */
2461
+ interface async_mutex extends Instrumentation {}
2462
+
2421
2463
  /**
2422
2464
  * This plugin automatically patches the [avsc](https://github.com/mtth/avsc) module
2423
2465
  * to collect avro message schemas when Datastreams Monitoring is enabled.
@@ -2430,6 +2472,46 @@ declare namespace tracer {
2430
2472
  */
2431
2473
  interface aws_durable_execution_sdk_js extends Integration {}
2432
2474
 
2475
+ /** Configuration for AWS Lambda invocation instrumentation in Lambda runtimes. */
2476
+ interface aws_lambda extends Instrumentation {
2477
+ /** @default true @env DD_TRACE_AWS_SERVICE_REPRESENTATION_ENABLED */
2478
+ serviceRepresentationEnabled?: boolean;
2479
+ /** @default true @env DD_ENHANCED_METRICS */
2480
+ enhancedMetrics?: boolean;
2481
+ /** @default false @env DD_CAPTURE_LAMBDA_PAYLOAD */
2482
+ captureLambdaPayload?: boolean;
2483
+ /** @default 10 @env DD_CAPTURE_LAMBDA_PAYLOAD_MAX_DEPTH */
2484
+ captureLambdaPayloadMaxDepth?: number;
2485
+ /** @default true @env DD_TRACE_MANAGED_SERVICES */
2486
+ createInferredSpan?: boolean;
2487
+ /** @default false @env DD_MERGE_XRAY_TRACES */
2488
+ mergeXrayTraces?: boolean;
2489
+ /** @default true @env DD_ENCODE_AUTHORIZER_CONTEXT */
2490
+ encodeAuthorizerContext?: boolean;
2491
+ /** @default true @env DD_DECODE_AUTHORIZER_CONTEXT */
2492
+ decodeAuthorizerContext?: boolean;
2493
+ /** @default true @env DD_COLD_START_TRACING */
2494
+ coldStartTracing?: boolean;
2495
+ /** @default 3 @env DD_MIN_COLD_START_DURATION */
2496
+ minColdStartTraceDurationMs?: number;
2497
+ /** @default './opentracing/tracer' @env DD_COLD_START_TRACE_SKIP_LIB */
2498
+ coldStartTraceSkipLib?: string;
2499
+ /** @default false @env DD_FLUSH_TO_LOG */
2500
+ logForwarding?: boolean;
2501
+ /** Defaults to true in AWS GovCloud regions. @env DD_LAMBDA_FIPS_MODE */
2502
+ fipsMode?: boolean;
2503
+ /** @env DD_KMS_API_KEY */
2504
+ apiKeyKms?: string;
2505
+ /** @env DD_API_KEY_SECRET_ARN */
2506
+ apiKeySecretArn?: string;
2507
+ /** @default true @env DD_TRACE_AWS_ADD_SPAN_POINTERS */
2508
+ addSpanPointers?: boolean;
2509
+ /** @default false @env DD_DATA_STREAMS_ENABLED */
2510
+ dataStreamsEnabled?: boolean;
2511
+ /** Force a second wrapper even when the handler carries the shared wrapped marker. */
2512
+ forceWrap?: boolean;
2513
+ }
2514
+
2433
2515
  /**
2434
2516
  * This plugin automatically instruments the
2435
2517
  * [aws-sdk](https://github.com/aws/aws-sdk-js) module.
@@ -2625,6 +2707,12 @@ declare namespace tracer {
2625
2707
  net?: boolean;
2626
2708
  }
2627
2709
 
2710
+ /**
2711
+ * This plugin automatically instruments the
2712
+ * [@elevenlabs/elevenlabs-js](https://www.npmjs.com/package/@elevenlabs/elevenlabs-js) module.
2713
+ */
2714
+ interface elevenlabs extends Instrumentation, LLMObsIntegration {}
2715
+
2628
2716
  /**
2629
2717
  * This plugin automatically instruments the
2630
2718
  * [express](http://expressjs.com/) module.
@@ -3234,12 +3322,12 @@ declare namespace tracer {
3234
3322
  */
3235
3323
  interface prisma extends PrismaClient, PrismaEngine {
3236
3324
  /**
3237
- * Configuration for prisma client.
3325
+ * Configuration for prisma client. Set to `false` to skip `prisma.client` spans.
3238
3326
  */
3239
3327
  client?: PrismaClient | boolean,
3240
3328
 
3241
3329
  /**
3242
- * Configuration for Prisma engine.
3330
+ * Configuration for Prisma engine. Set to `false` to skip `prisma.engine` spans.
3243
3331
  */
3244
3332
  engine?: PrismaEngine | boolean
3245
3333
  }
@@ -3366,6 +3454,12 @@ declare namespace tracer {
3366
3454
  */
3367
3455
  interface tedious extends Instrumentation {}
3368
3456
 
3457
+ /**
3458
+ * Traces tRPC server queries and mutations. Express requests with one resolved procedure
3459
+ * use its route as the HTTP resource; batches retain the Express mount route.
3460
+ */
3461
+ interface trpc extends Instrumentation {}
3462
+
3369
3463
  /**
3370
3464
  * This plugin automatically instruments the
3371
3465
  * [@typesafe-ai/sdk](https://www.npmjs.com/package/@typesafe-ai/sdk) module.
@@ -4512,6 +4606,12 @@ declare namespace tracer {
4512
4606
  */
4513
4607
  output: { content: JSONType, role?: string }[]
4514
4608
 
4609
+ /**
4610
+ * The expected output associated with an experiment span.
4611
+ * Delete this property or set it to `undefined` to omit the expected output.
4612
+ */
4613
+ expectedOutput?: JSONType
4614
+
4515
4615
  /**
4516
4616
  * Get a tag from the span.
4517
4617
  * @param key The key of the tag to get.
package/initialize.mjs CHANGED
@@ -9,7 +9,9 @@
9
9
  * hook will always be active for ESM support.
10
10
  */
11
11
 
12
- /* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */
12
+ /* eslint n/no-unsupported-features/node-builtins: [
13
+ 'error', { ignores: ['module.register', 'module.registerHooks'] }
14
+ ] */
13
15
 
14
16
  import { Buffer } from 'buffer'
15
17
  import * as Module from 'module'
@@ -100,7 +102,8 @@ if (isMainThread) {
100
102
  const initialized = require('./init.js')
101
103
  // Only register the loader hook when instrumentation initialized. On a bailout the
102
104
  // loader has nothing to instrument and can keep a short-lived process from exiting.
103
- if (Module.register && initialized) {
105
+ // `registerHooks` alone keeps the gate open once Node.js drops `register` (nodejs/node#67090).
106
+ if ((Module.registerHooks || Module.register) && initialized) {
104
107
  require('./register.js')
105
108
  }
106
109
  }
package/lambda.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import tracer = require('./index')
2
+
3
+ export type LambdaHandler = (...args: any[]) => any
4
+
5
+ export interface LambdaWrapOptions extends tracer.plugins.aws_lambda {}
6
+
7
+ // Buffered wrappers require an event and context even when the customer handler omits them.
8
+ type LambdaHandlerArguments<THandler extends LambdaHandler> =
9
+ Parameters<THandler> extends [unknown, unknown, ...unknown[]]
10
+ ? Parameters<THandler>
11
+ : Parameters<THandler> extends [event?: infer TEvent, context?: infer TContext, ...unknown[]]
12
+ ? [event: TEvent, context: TContext & object]
13
+ : [event: unknown, context: object]
14
+
15
+ export function wrap<THandler extends LambdaHandler>(
16
+ handler: THandler,
17
+ config?: LambdaWrapOptions
18
+ ): ((...args: LambdaHandlerArguments<THandler>) => Promise<Awaited<ReturnType<THandler>>>) &
19
+ Pick<THandler, keyof THandler>
20
+
21
+ export function sendDistributionMetric(name: string, value: number, ...tags: string[]): void
22
+
23
+ export function sendDistributionMetricWithDate(
24
+ name: string,
25
+ value: number,
26
+ metricTime: Date,
27
+ ...tags: string[]
28
+ ): void
29
+
30
+ export function getTraceHeaders(): Record<string, string>
31
+
32
+ export interface LambdaInitFailure {
33
+ error: Error
34
+ functionName: string
35
+ /** `Date.now()` at the start of handler module evaluation. */
36
+ startTime: number
37
+ }
38
+
39
+ export function reportInitFailure(failure: LambdaInitFailure): Promise<void>
package/lambda.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('./packages/dd-trace/src/lambda/facade')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.24.0",
3
+ "version": "6.25.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -9,6 +9,7 @@
9
9
  "prepare": "node scripts/patch-istanbul-lib-coverage.js && node scripts/patch-v8-to-istanbul.js && cd vendor && npm ci --include=dev",
10
10
  "prepack": "node scripts/release/swap-v5-types.js",
11
11
  "bench": "node benchmark/index.js",
12
+ "bench:elevenlabs": "node benchmark/elevenlabs.js",
12
13
  "bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
13
14
  "dependencies:dedupe": "yarn-deduplicate yarn.lock",
14
15
  "generate:config:types": "node scripts/generate-config-types.js",
@@ -18,12 +19,11 @@
18
19
  "generate:rewriter:targets": "node scripts/generate-rewriter-targets.js",
19
20
  "verify:rewriter:targets": "node scripts/generate-rewriter-targets.js --check",
20
21
  "generate:supported-integrations": "node scripts/generate-supported-integrations.js",
21
- "verify:supported-integrations": "node scripts/generate-supported-integrations.js --check",
22
22
  "type:check": "tsc --noEmit -p tsconfig.dev.json",
23
23
  "type:doc:build": "cd docs && yarn && yarn build",
24
24
  "type:doc:test": "cd docs && yarn && yarn test",
25
25
  "lint": "bash ./scripts/lint.sh",
26
- "lint:fix": "node scripts/check_licenses.js && node scripts/check-agents-md-size.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && eslint . --concurrency=auto --max-warnings 0 --fix",
26
+ "lint:fix": "node scripts/check_licenses.js && node scripts/check-agents-md-size.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && node scripts/check-workflow-inline-js.js && eslint . --concurrency=auto --max-warnings 0 --fix",
27
27
  "verify:carrier-fields": "node scripts/verify-carrier-fields.mjs",
28
28
  "lint:inspect": "npx @eslint/config-inspector@latest",
29
29
  "lint:codeowners": "codeowners-audit",
@@ -76,8 +76,8 @@
76
76
  "test:profiler:ci": "node scripts/c8-ci.js test:profiler",
77
77
  "test:otel-thread-ctx": "mocha --timeout 60000 packages/dd-trace/test/otel-thread-ctx.spec.js",
78
78
  "test:docker:otel-thread-ctx": "./scripts/docker/run-otel-thread-ctx-spec.sh",
79
- "test:integration": "mocha --timeout 60000 \"integration-tests/*.spec.js\"",
80
- "test:integration:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/*.spec.js\"",
79
+ "test:integration": "mocha --timeout 60000 \"integration-tests/*.spec.js\" \"integration-tests/helpers/*.spec.js\"",
80
+ "test:integration:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/*.spec.js\" \"integration-tests/helpers/*.spec.js\"",
81
81
  "test:integration:aiguard": "mocha --timeout 60000 \"integration-tests/aiguard/*.spec.js\"",
82
82
  "test:integration:aiguard:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/aiguard/*.spec.js\"",
83
83
  "test:integration:appsec": "mocha --timeout 60000 \"integration-tests/appsec/*.spec.js\"",
@@ -106,7 +106,7 @@
106
106
  "test:integration:playwright:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/playwright/${SPEC:-playwright-*}.spec.js\"",
107
107
  "test:integration:selenium": "mocha --timeout 60000 \"integration-tests/selenium/*.spec.js\"",
108
108
  "test:integration:selenium:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/selenium/*.spec.js\"",
109
- "test:integration:test-optimization:helpers": "mocha \"integration-tests/cypress/config-lifecycle*.spec.js\" \"integration-tests/cypress/*dependencies.spec.js\" \"integration-tests/jest/*dependencies.spec.js\" \"integration-tests/playwright/version*.spec.js\" \"integration-tests/mocha/version*.spec.js\"",
109
+ "test:integration:test-optimization:helpers": "mocha \"integration-tests/cypress/config-lifecycle*.spec.js\" \"integration-tests/cypress/checkout-context*.spec.js\" \"integration-tests/cypress/*dependencies.spec.js\" \"integration-tests/jest/*dependencies.spec.js\" \"integration-tests/playwright/version*.spec.js\" \"integration-tests/mocha/version*.spec.js\"",
110
110
  "test:integration:webdriverio": "mocha --timeout 60000 \"integration-tests/webdriverio/${SPEC:-*}.spec.js\"",
111
111
  "test:integration:webdriverio:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/webdriverio/${SPEC:-*}.spec.js\"",
112
112
  "test:integration:vitest": "mocha --timeout 60000 \"integration-tests/vitest/${SPEC:-vitest*}.spec.js\"",
@@ -119,7 +119,7 @@
119
119
  "test:integration:plugins:coverage": "yarn services && node ./integration-tests/coverage/run-suite.js \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
120
120
  "test:unit:plugins": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\" \"packages/datadog-plugin-@(${PLUGINS})/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/*.spec.js\"",
121
121
  "test:release": "mocha \"scripts/release/**/*.spec.js\"",
122
- "test:scripts": "mocha \"benchmark/e2e-test-optimization/*.spec.js\" \"benchmark/sirun/*.spec.js\" \"scripts/helpers/**/*.spec.js\" \"scripts/*.spec.mjs\"",
122
+ "test:scripts": "mocha \"benchmark/e2e-test-optimization/*.spec.js\" \"benchmark/sirun/*.spec.js\" \"scripts/helpers/**/*.spec.js\" \"scripts/test/**/*.spec.js\" \"scripts/*.spec.mjs\"",
123
123
  "test:shimmer": "mocha \"packages/datadog-shimmer/test/**/*.spec.js\"",
124
124
  "test:shimmer:ci": "node scripts/c8-ci.js test:shimmer",
125
125
  "verify:workflow-job-names": "node scripts/verify-workflow-job-names.js",
@@ -168,6 +168,8 @@
168
168
  "LICENSE.Apache",
169
169
  "LICENSE.BSD3",
170
170
  "loader-hook.mjs",
171
+ "lambda.d.ts",
172
+ "lambda.js",
171
173
  "openfeature.d.ts",
172
174
  "openfeature.js",
173
175
  "openfeature/rules-based.js",
@@ -198,9 +200,9 @@
198
200
  "@datadog/native-appsec": "11.0.3",
199
201
  "@datadog/native-iast-taint-tracking": "4.2.1",
200
202
  "@datadog/native-metrics": "4.0.0",
201
- "@datadog/pprof": "5.20.0",
203
+ "@datadog/pprof": "5.20.1",
202
204
  "@datadog/wasm-js-rewriter": "5.0.4",
203
- "@opentelemetry/api": ">=1.4.1 <1.10.0",
205
+ "@opentelemetry/api": ">=1.4.1 <1.11.0",
204
206
  "@opentelemetry/api-logs": "<1.0.0",
205
207
  "oxc-parser": "^0.132.0"
206
208
  },
@@ -1,19 +1,21 @@
1
1
  'use strict'
2
2
 
3
- const { execSync } = require('node:child_process')
4
3
  const fs = require('node:fs')
5
4
  const path = require('node:path')
6
5
  const { pathToFileURL, fileURLToPath } = require('node:url')
7
6
 
8
7
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
8
+ const {
9
+ createEsmResolver,
10
+ processModule,
11
+ } = require('../datadog-instrumentations/src/helpers/bundler-esm-exports')
12
+ const { getGitMetadataBanner, isESMFile } = require('../datadog-instrumentations/src/helpers/bundler-utils')
9
13
  const extractPackageAndModulePath = require('../datadog-instrumentations/src/helpers/extract-package-and-module-path')
10
14
  const hooks = require('../datadog-instrumentations/src/helpers/hooks')
11
15
  const { createBundlerRewriter } = require('../datadog-instrumentations/src/helpers/rewriter')
12
16
  const { getRewriteTarget, isRewriteTargetName } = require('../datadog-instrumentations/src/helpers/rewriter/targets')
13
17
  const { getValueFromEnvSources } = require('../dd-trace/src/config/helper')
14
18
  const log = require('./src/log')
15
- const { createEsmResolver } = require('./src/resolver')
16
- const { isESMFile, processModule } = require('./src/utils')
17
19
 
18
20
  const ESM_INTERCEPTED_SUFFIX = '._dd_esbuild_intercepted'
19
21
  const INTERNAL_ESM_INTERCEPTED_PREFIX = '/_dd_esm_internal_/'
@@ -82,40 +84,6 @@ function isESMBuild (build) {
82
84
  return format === 'esm' || outputFile?.endsWith('.mjs') || outExtension === '.mjs'
83
85
  }
84
86
 
85
- function getGitMetadata () {
86
- /**
87
- * @type {object}
88
- * @property {string | null} repositoryURL
89
- * @property {string | null} commitSHA
90
- */
91
- const gitMetadata = {
92
- repositoryURL: null,
93
- commitSHA: null,
94
- }
95
-
96
- try {
97
- gitMetadata.repositoryURL = execSync('git config --get remote.origin.url', {
98
- encoding: 'utf8',
99
- stdio: ['pipe', 'pipe', 'ignore'],
100
- cwd: process.cwd(),
101
- }).trim()
102
- } catch (e) {
103
- log.warn('failed to get git repository URL:', e.message)
104
- }
105
-
106
- try {
107
- gitMetadata.commitSHA = execSync('git rev-parse HEAD', {
108
- encoding: 'utf8',
109
- stdio: ['pipe', 'pipe', 'ignore'],
110
- cwd: process.cwd(),
111
- }).trim()
112
- } catch (e) {
113
- log.warn('failed to get git commit SHA:', e.message)
114
- }
115
-
116
- return gitMetadata
117
- }
118
-
119
87
  module.exports.setup = function (build) {
120
88
  if (build.initialOptions.minify && !build.initialOptions.keepNames) {
121
89
  throw new Error(
@@ -156,25 +124,10 @@ ${build.initialOptions.banner.js}`
156
124
 
157
125
  // Bake DD_GIT_* into the banner unless DD_BUNDLER_INJECT_GIT_METADATA=false (stable artifact hashes).
158
126
  if (DD_BUNDLER_INJECT_GIT_METADATA) {
159
- const gitMetadata = getGitMetadata()
160
- if (gitMetadata.repositoryURL || gitMetadata.commitSHA) {
127
+ const banner = getGitMetadataBanner(log)
128
+ if (banner) {
161
129
  build.initialOptions.banner ??= {}
162
- build.initialOptions.banner.js ??= ''
163
-
164
- build.initialOptions.banner.js = `if (typeof process === 'object' && process !== null &&
165
- process.env !== null && typeof process.env === 'object') {
166
- ${gitMetadata.repositoryURL ? `process.env.DD_GIT_REPOSITORY_URL = '${gitMetadata.repositoryURL}';` : ''}
167
- ${gitMetadata.commitSHA ? `process.env.DD_GIT_COMMIT_SHA = '${gitMetadata.commitSHA}';` : ''}
168
- }
169
- ${build.initialOptions.banner.js}`
170
-
171
- log.debug(
172
- 'Automatically injected git metadata (DD_GIT_REPOSITORY_URL: %s, DD_GIT_COMMIT_SHA: %s)',
173
- gitMetadata.repositoryURL || 'not available',
174
- gitMetadata.commitSHA || 'not available'
175
- )
176
- } else {
177
- log.warn('No git metadata available - skipping injection')
130
+ build.initialOptions.banner.js = `${banner}${build.initialOptions.banner.js ?? ''}`
178
131
  }
179
132
  } else {
180
133
  log.debug('Skipping git metadata injection (DD_BUNDLER_INJECT_GIT_METADATA=false)')
@@ -0,0 +1,88 @@
1
+ 'use strict'
2
+
3
+ const dc = require('dc-polyfill')
4
+
5
+ const {
6
+ HANDLER_STREAMING,
7
+ STREAM_RESPONSE,
8
+ promisifiedHandler,
9
+ copyHandlerMetadata,
10
+ getDataProperty,
11
+ } = require('./helpers/lambda-handler')
12
+
13
+ // Read through the process-global registry so two dd-trace copies (layer + bundled) resolve the
14
+ // same marker. The value is the wrapper itself, so a second wrap of the same handler returns the
15
+ // instrumented function rather than the raw one.
16
+ const WRAPPED = Symbol.for('dd-trace.lambda.wrapped')
17
+ const invocationChannel = dc.tracingChannel('datadog:aws-lambda:invoke')
18
+
19
+ /**
20
+ * Wraps one customer handler with the shared Lambda invocation channel.
21
+ *
22
+ * @param {Function} handler Customer Lambda handler.
23
+ * @param {Record<string, unknown>} [config] Per-handler configuration overrides.
24
+ * @param {Function} [monitor] Monitors the shim adapter for impending timeouts.
25
+ * @returns {Function} Wrapped handler, or the existing wrapper when already marked.
26
+ */
27
+ function wrapHandler (handler, config, monitor) {
28
+ if (typeof handler !== 'function') {
29
+ throw new TypeError('AWS Lambda handler must be a function')
30
+ }
31
+ const existing = getWrappedHandler(handler)
32
+ if (existing !== undefined && config?.forceWrap !== true) return existing
33
+
34
+ const isResponseStream = getDataProperty(handler, HANDLER_STREAMING) === STREAM_RESPONSE
35
+ const completion = promisifiedHandler(handler)
36
+ const invoke = monitor ? monitor(completion, true) : completion
37
+
38
+ function wrappedHandler (...args) {
39
+ const invocationContext = {
40
+ config,
41
+ context: args[isResponseStream ? 2 : 1],
42
+ event: args[0],
43
+ isResponseStream,
44
+ responseStream: isResponseStream ? args[1] : undefined,
45
+ }
46
+
47
+ // The shim awaits its startup listeners before calling the adapter. Preserve that boundary so
48
+ // legacy RIC captures native context completion methods before the adapter replaces them.
49
+ return invocationChannel.tracePromise(
50
+ () => Promise.resolve().then(() => Reflect.apply(invoke, this, args)),
51
+ invocationContext
52
+ )
53
+ }
54
+
55
+ // Frozen customer handlers cannot carry markers; share their identity through the tracer registry.
56
+ const ddGlobal = globalThis[Symbol.for('dd-trace')] ??= { beforeExitHandlers: new Set() }
57
+ const lambda = ddGlobal.lambda ??= {}
58
+ const wrappers = lambda.wrappers ??= new WeakMap()
59
+ wrappers.set(handler, wrappedHandler)
60
+ wrappers.set(wrappedHandler, wrappedHandler)
61
+ Object.defineProperty(wrappedHandler, WRAPPED, { value: wrappedHandler })
62
+ copyHandlerMetadata(handler, wrappedHandler)
63
+
64
+ return wrappedHandler
65
+ }
66
+
67
+ /**
68
+ * Looks up the invocation wrapper, including markers from older tracer copies.
69
+ *
70
+ * Deliberately does not set datadog-lambda-js's `_ddWrapped` property: the released shim treats
71
+ * that property as "already fully instrumented" and returns early, which would suppress its
72
+ * extractors, inferred spans, enhanced metrics, log injection, and cold-start tracing. dd-trace
73
+ * may only claim that marker once it reproduces those behaviors (Phases 2-3).
74
+ *
75
+ * @param {Function} handler Handler whose invocation wrapper is needed.
76
+ * @returns {Function|undefined} Existing invocation wrapper.
77
+ */
78
+ function getWrappedHandler (handler) {
79
+ const wrappers = globalThis[Symbol.for('dd-trace')]?.lambda?.wrappers
80
+ return wrappers?.get(handler) || getDataProperty(handler, WRAPPED)
81
+ }
82
+
83
+ module.exports = {
84
+ WRAPPED,
85
+ invocationChannel,
86
+ getWrappedHandler,
87
+ wrapHandler,
88
+ }
@@ -584,9 +584,12 @@ function isNewTest (testSuite, testName) {
584
584
  /** @param {{ tags?: Array<{ name: string }> }} pickle */
585
585
  function getScenarioAnnotations (pickle) {
586
586
  const tags = pickle.tags || []
587
+ // Preserve the colon spellings accepted by earlier tracer releases.
587
588
  return {
588
- mustFail: tags.some(tag => tag.name === '@datadog:prevent_failure_suppression'),
589
- noAutoRetry: tags.some(tag => tag.name === '@datadog:no_auto_retry'),
589
+ mustFail: tags.some(tag => tag.name === '@datadog_prevent_failure_suppression' ||
590
+ tag.name === '@datadog:prevent_failure_suppression'),
591
+ noAutoRetry: tags.some(tag => tag.name === '@datadog_no_auto_retry' ||
592
+ tag.name === '@datadog:no_auto_retry'),
590
593
  }
591
594
  }
592
595