dd-trace 6.15.0 → 6.17.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 (378) hide show
  1. package/README.md +15 -0
  2. package/ci/diagnose.js +0 -23
  3. package/ci/test-optimization-validation/approval-artifacts.js +0 -3
  4. package/ci/test-optimization-validation/approval.js +0 -6
  5. package/ci/test-optimization-validation/artifact-id.js +0 -1
  6. package/ci/test-optimization-validation/bounded-json.js +0 -1
  7. package/ci/test-optimization-validation/cli.js +0 -12
  8. package/ci/test-optimization-validation/command-output-policy.js +0 -1
  9. package/ci/test-optimization-validation/command-runner.js +0 -3
  10. package/ci/test-optimization-validation/environment.js +0 -4
  11. package/ci/test-optimization-validation/executable-approval.js +0 -1
  12. package/ci/test-optimization-validation/executable.js +0 -5
  13. package/ci/test-optimization-validation/framework-adapters/cucumber.js +4 -8
  14. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -3
  15. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -6
  16. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -4
  17. package/ci/test-optimization-validation/generated-test-contract.js +0 -5
  18. package/ci/test-optimization-validation/generated-verifier.js +0 -1
  19. package/ci/test-optimization-validation/literal-environment.js +0 -1
  20. package/ci/test-optimization-validation/manifest-scaffold.js +0 -17
  21. package/ci/test-optimization-validation/manifest-schema.js +0 -21
  22. package/ci/test-optimization-validation/offline-fixtures.js +0 -4
  23. package/ci/test-optimization-validation/package-check.js +4 -1
  24. package/ci/test-optimization-validation/plan-writer.js +0 -11
  25. package/ci/test-optimization-validation/preflight-runner.js +0 -1
  26. package/ci/test-optimization-validation/redaction.js +0 -4
  27. package/ci/test-optimization-validation/report-writer.js +0 -16
  28. package/ci/test-optimization-validation/runner-command.js +0 -3
  29. package/ci/test-optimization-validation/runner-contract.js +0 -4
  30. package/ci/test-optimization-validation/safe-files.js +0 -1
  31. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -1
  32. package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -2
  33. package/ci/test-optimization-validation/source-text.js +0 -3
  34. package/ci/vitest-no-worker-init-setup.mjs +41 -16
  35. package/index.d.ts +169 -0
  36. package/next.d.ts +27 -0
  37. package/next.js +3 -0
  38. package/package.json +28 -23
  39. package/packages/datadog-esbuild/index.js +14 -1
  40. package/packages/datadog-esbuild/src/resolver.js +284 -0
  41. package/packages/datadog-esbuild/src/utils.js +162 -120
  42. package/packages/datadog-instrumentations/src/aerospike.js +28 -6
  43. package/packages/datadog-instrumentations/src/ai.js +39 -97
  44. package/packages/datadog-instrumentations/src/anthropic.js +76 -134
  45. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +1 -3
  46. package/packages/datadog-instrumentations/src/aws-sdk.js +0 -2
  47. package/packages/datadog-instrumentations/src/azure-cosmos.js +1 -1
  48. package/packages/datadog-instrumentations/src/azure-durable-functions.js +23 -9
  49. package/packages/datadog-instrumentations/src/azure-functions.js +48 -0
  50. package/packages/datadog-instrumentations/src/bullmq.js +1 -1
  51. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +1 -3
  52. package/packages/datadog-instrumentations/src/console.js +97 -0
  53. package/packages/datadog-instrumentations/src/cucumber.js +72 -12
  54. package/packages/datadog-instrumentations/src/cypress-config.js +0 -23
  55. package/packages/datadog-instrumentations/src/dd-trace-api.js +2 -2
  56. package/packages/datadog-instrumentations/src/graphql.js +1 -1
  57. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +39 -14
  58. package/packages/datadog-instrumentations/src/helpers/channel.js +0 -2
  59. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +0 -5
  60. package/packages/datadog-instrumentations/src/helpers/hooks.js +8 -0
  61. package/packages/datadog-instrumentations/src/helpers/instrument.js +25 -8
  62. package/packages/datadog-instrumentations/src/helpers/instrumentation-utils.js +69 -0
  63. package/packages/datadog-instrumentations/src/helpers/pool-acquire.js +0 -6
  64. package/packages/datadog-instrumentations/src/helpers/register.js +13 -64
  65. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +109 -29
  66. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +39 -0
  67. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-durable-functions.js +17 -0
  68. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +3 -16
  69. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +12 -0
  70. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +36 -0
  71. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/supabase.js +128 -0
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +6 -7
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -0
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +388 -0
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +99 -75
  76. package/packages/datadog-instrumentations/src/helpers/router-helper.js +0 -1
  77. package/packages/datadog-instrumentations/src/jest.js +141 -51
  78. package/packages/datadog-instrumentations/src/knex.js +0 -1
  79. package/packages/datadog-instrumentations/src/langchain.js +1 -1
  80. package/packages/datadog-instrumentations/src/langgraph.js +1 -1
  81. package/packages/datadog-instrumentations/src/mariadb-bundle.js +0 -24
  82. package/packages/datadog-instrumentations/src/mariadb.js +0 -2
  83. package/packages/datadog-instrumentations/src/mercurius.js +1 -1
  84. package/packages/datadog-instrumentations/src/mocha/common.js +0 -1
  85. package/packages/datadog-instrumentations/src/mocha/main.js +22 -25
  86. package/packages/datadog-instrumentations/src/mocha/utils.js +119 -49
  87. package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +0 -6
  88. package/packages/datadog-instrumentations/src/mocha/worker.js +14 -17
  89. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +1 -1
  90. package/packages/datadog-instrumentations/src/mysql2.js +0 -2
  91. package/packages/datadog-instrumentations/src/openai-agents.js +1 -1
  92. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +241 -0
  93. package/packages/datadog-instrumentations/src/openai-realtime/events.js +76 -0
  94. package/packages/datadog-instrumentations/src/openai-realtime/index.js +301 -0
  95. package/packages/datadog-instrumentations/src/openai-realtime/session.js +998 -0
  96. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +211 -0
  97. package/packages/datadog-instrumentations/src/openai.js +97 -80
  98. package/packages/datadog-instrumentations/src/oracledb.js +9 -3
  99. package/packages/datadog-instrumentations/src/playwright-reporter.js +3 -16
  100. package/packages/datadog-instrumentations/src/playwright.js +238 -55
  101. package/packages/datadog-instrumentations/src/postgres.js +7 -0
  102. package/packages/datadog-instrumentations/src/router.js +0 -2
  103. package/packages/datadog-instrumentations/src/rum-browser-scripts.js +0 -2
  104. package/packages/datadog-instrumentations/src/sequelize.js +0 -1
  105. package/packages/datadog-instrumentations/src/supabase.js +15 -0
  106. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +18 -18
  107. package/packages/datadog-instrumentations/src/vitest-main.js +37 -17
  108. package/packages/datadog-instrumentations/src/vitest-util.js +7 -1
  109. package/packages/datadog-instrumentations/src/vitest-worker.js +56 -23
  110. package/packages/datadog-instrumentations/src/webdriverio.js +23 -42
  111. package/packages/datadog-instrumentations/src/ws.js +0 -1
  112. package/packages/datadog-plugin-ai/src/utils.js +0 -2
  113. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +0 -1
  114. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +0 -2
  115. package/packages/datadog-plugin-aws-sdk/src/base.js +0 -1
  116. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +7 -2
  117. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +0 -1
  118. package/packages/datadog-plugin-aws-sdk/src/util.js +0 -1
  119. package/packages/datadog-plugin-azure-cosmos/src/index.js +1 -1
  120. package/packages/datadog-plugin-azure-durable-functions/src/index.js +95 -1
  121. package/packages/datadog-plugin-cucumber/src/index.js +10 -0
  122. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +171 -75
  123. package/packages/datadog-plugin-cypress/src/finalization.js +0 -3
  124. package/packages/datadog-plugin-cypress/src/source-map-utils.js +0 -4
  125. package/packages/datadog-plugin-cypress/src/support.js +52 -7
  126. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -24
  127. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +2 -36
  128. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +31 -0
  129. package/packages/datadog-plugin-graphql/src/resolve-error.js +32 -11
  130. package/packages/datadog-plugin-graphql/src/utils.js +0 -5
  131. package/packages/datadog-plugin-jest/src/index.js +13 -0
  132. package/packages/datadog-plugin-kafkajs/src/producer.js +0 -1
  133. package/packages/datadog-plugin-mocha/src/index.js +39 -11
  134. package/packages/datadog-plugin-mongodb-core/src/query.js +0 -1
  135. package/packages/datadog-plugin-openai/src/index.js +16 -1
  136. package/packages/datadog-plugin-openai/src/realtime.js +144 -0
  137. package/packages/datadog-plugin-openai-agents/src/integration.js +0 -4
  138. package/packages/datadog-plugin-openai-agents/src/util.js +0 -1
  139. package/packages/datadog-plugin-playwright/src/index.js +76 -9
  140. package/packages/datadog-plugin-postgres/src/index.js +167 -0
  141. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +0 -1
  142. package/packages/datadog-plugin-redis/src/index.js +15 -1
  143. package/packages/datadog-plugin-supabase/src/error.js +18 -0
  144. package/packages/datadog-plugin-supabase/src/index.js +21 -0
  145. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +69 -0
  146. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +70 -0
  147. package/packages/datadog-plugin-supabase/src/supabase-postgrest-js-postgrestbuilder-then.js +122 -0
  148. package/packages/datadog-plugin-supabase/src/supabase-realtime-js-realtimechannel-send.js +66 -0
  149. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +93 -0
  150. package/packages/datadog-plugin-supabase/src/url.js +17 -0
  151. package/packages/datadog-plugin-vitest/src/index.js +10 -0
  152. package/packages/datadog-plugin-ws/src/util.js +0 -4
  153. package/packages/datadog-turbopack/index.js +206 -0
  154. package/packages/datadog-turbopack/src/constants.js +5 -0
  155. package/packages/datadog-turbopack/src/loader.js +484 -0
  156. package/packages/datadog-webpack/src/loader.js +0 -1
  157. package/packages/dd-trace/src/aiguard/client.js +2 -3
  158. package/packages/dd-trace/src/aiguard/evaluation.js +6 -12
  159. package/packages/dd-trace/src/aiguard/index.js +3 -2
  160. package/packages/dd-trace/src/aiguard/integrations/anthropic.js +53 -25
  161. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +49 -25
  162. package/packages/dd-trace/src/aiguard/integrations/index.js +4 -3
  163. package/packages/dd-trace/src/aiguard/integrations/openai.js +132 -29
  164. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +116 -42
  165. package/packages/dd-trace/src/aiguard/messages/anthropic.js +0 -2
  166. package/packages/dd-trace/src/aiguard/messages/openai.js +64 -1
  167. package/packages/dd-trace/src/aiguard/messages/utils.js +29 -2
  168. package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +25 -0
  169. package/packages/dd-trace/src/aiguard/redaction.js +0 -1
  170. package/packages/dd-trace/src/aiguard/sdk.js +1 -1
  171. package/packages/dd-trace/src/appsec/activation.js +1 -1
  172. package/packages/dd-trace/src/appsec/api_security/normalized-route.js +0 -5
  173. package/packages/dd-trace/src/appsec/api_security/sampler.js +0 -4
  174. package/packages/dd-trace/src/appsec/blocking/index.js +3 -3
  175. package/packages/dd-trace/src/appsec/downstream_requests.js +1 -4
  176. package/packages/dd-trace/src/appsec/iast/index.js +1 -1
  177. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +5 -5
  178. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +1 -1
  179. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
  180. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +3 -3
  181. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +8 -10
  182. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +2 -2
  183. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +2 -2
  184. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +4 -1
  185. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +7 -7
  186. package/packages/dd-trace/src/appsec/index.js +2 -2
  187. package/packages/dd-trace/src/appsec/lambda.js +71 -2
  188. package/packages/dd-trace/src/appsec/rasp/utils.js +5 -1
  189. package/packages/dd-trace/src/appsec/remote_config.js +8 -6
  190. package/packages/dd-trace/src/appsec/reporter.js +10 -6
  191. package/packages/dd-trace/src/appsec/rule_manager.js +3 -3
  192. package/packages/dd-trace/src/appsec/sdk/track_event.js +0 -2
  193. package/packages/dd-trace/src/appsec/telemetry/api_security.js +1 -3
  194. package/packages/dd-trace/src/appsec/telemetry/common.js +4 -0
  195. package/packages/dd-trace/src/appsec/telemetry/index.js +23 -5
  196. package/packages/dd-trace/src/appsec/telemetry/rasp.js +1 -20
  197. package/packages/dd-trace/src/appsec/telemetry/user.js +1 -3
  198. package/packages/dd-trace/src/appsec/telemetry/waf.js +1 -20
  199. package/packages/dd-trace/src/appsec/waf/index.js +2 -2
  200. package/packages/dd-trace/src/appsec/waf/waf_manager.js +8 -5
  201. package/packages/dd-trace/src/carrier.js +0 -5
  202. package/packages/dd-trace/src/ci-visibility/dynamic-atr-retries.js +104 -0
  203. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +0 -2
  204. package/packages/dd-trace/src/ci-visibility/efd-retry-policy.js +34 -3
  205. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +0 -1
  206. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +0 -1
  207. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +0 -1
  208. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -4
  209. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -1
  210. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -2
  211. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +37 -15
  212. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +0 -3
  213. package/packages/dd-trace/src/ci-visibility/exporters/request.js +0 -11
  214. package/packages/dd-trace/src/ci-visibility/exporters/settings-cache-key.js +0 -1
  215. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +0 -1
  216. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +0 -6
  217. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +2 -2
  218. package/packages/dd-trace/src/ci-visibility/requests/rate-limit.js +0 -1
  219. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +0 -5
  220. package/packages/dd-trace/src/ci-visibility/requests/video-request.js +0 -1
  221. package/packages/dd-trace/src/ci-visibility/telemetry.js +13 -0
  222. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +0 -1
  223. package/packages/dd-trace/src/ci-visibility/test-screenshot.js +0 -2
  224. package/packages/dd-trace/src/ci-visibility/test-video.js +0 -1
  225. package/packages/dd-trace/src/config/defaults.js +3 -2
  226. package/packages/dd-trace/src/config/generated-config-types.d.ts +74 -66
  227. package/packages/dd-trace/src/config/helper.js +9 -2
  228. package/packages/dd-trace/src/config/index.js +44 -29
  229. package/packages/dd-trace/src/config/parsers.js +34 -6
  230. package/packages/dd-trace/src/config/remote_config.js +25 -109
  231. package/packages/dd-trace/src/config/supported-configurations.json +146 -9
  232. package/packages/dd-trace/src/datastreams/encoding.js +0 -1
  233. package/packages/dd-trace/src/datastreams/pathway.js +0 -1
  234. package/packages/dd-trace/src/debugger/constants.js +10 -0
  235. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +76 -17
  236. package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
  237. package/packages/dd-trace/src/debugger/devtools_client/guardrail-metrics.js +15 -0
  238. package/packages/dd-trace/src/debugger/devtools_client/index.js +103 -27
  239. package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +50 -7
  240. package/packages/dd-trace/src/debugger/devtools_client/log.js +3 -1
  241. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +34 -8
  242. package/packages/dd-trace/src/debugger/devtools_client/send.js +40 -14
  243. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +53 -13
  244. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +118 -71
  245. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +0 -3
  246. package/packages/dd-trace/src/debugger/devtools_client/status.js +20 -6
  247. package/packages/dd-trace/src/debugger/guardrail-metrics.js +167 -0
  248. package/packages/dd-trace/src/debugger/index.js +50 -2
  249. package/packages/dd-trace/src/debugger/inspect-segment.js +0 -3
  250. package/packages/dd-trace/src/debugger/probe_sampler.js +133 -9
  251. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +31 -1
  252. package/packages/dd-trace/src/dogstatsd.js +0 -23
  253. package/packages/dd-trace/src/encode/0.4-cross-payload.js +0 -3
  254. package/packages/dd-trace/src/encode/0.4.js +0 -7
  255. package/packages/dd-trace/src/encode/0.5.js +0 -2
  256. package/packages/dd-trace/src/encode/tags-processors.js +0 -1
  257. package/packages/dd-trace/src/evp_proxy/discovery.js +3 -5
  258. package/packages/dd-trace/src/evp_proxy/path.js +11 -4
  259. package/packages/dd-trace/src/exporters/agent/writer.js +0 -1
  260. package/packages/dd-trace/src/exporters/agentless/index.js +0 -1
  261. package/packages/dd-trace/src/exporters/agentless/intake.js +0 -1
  262. package/packages/dd-trace/src/exporters/agentless/writer.js +0 -3
  263. package/packages/dd-trace/src/exporters/common/docker.js +4 -1
  264. package/packages/dd-trace/src/exporters/common/final-flush-request-tracker.js +0 -6
  265. package/packages/dd-trace/src/exporters/common/proxy.js +3 -0
  266. package/packages/dd-trace/src/exporters/common/request.js +1 -0
  267. package/packages/dd-trace/src/exporters/common/url.js +0 -2
  268. package/packages/dd-trace/src/exporters/common/writer.js +0 -2
  269. package/packages/dd-trace/src/id.js +0 -11
  270. package/packages/dd-trace/src/llmobs/audio-codec.js +192 -0
  271. package/packages/dd-trace/src/llmobs/audio-utils.js +121 -0
  272. package/packages/dd-trace/src/llmobs/constants/audio.js +35 -0
  273. package/packages/dd-trace/src/llmobs/constants/prompts.js +14 -0
  274. package/packages/dd-trace/src/llmobs/constants/tags.js +17 -0
  275. package/packages/dd-trace/src/llmobs/eval-metric.js +0 -6
  276. package/packages/dd-trace/src/llmobs/experiments/dataset.js +0 -4
  277. package/packages/dd-trace/src/llmobs/experiments/experiment.js +0 -3
  278. package/packages/dd-trace/src/llmobs/experiments/index.js +7 -6
  279. package/packages/dd-trace/src/llmobs/experiments/util.js +1 -11
  280. package/packages/dd-trace/src/llmobs/index.js +1 -3
  281. package/packages/dd-trace/src/llmobs/noop.js +10 -0
  282. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +0 -4
  283. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +0 -1
  284. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +0 -4
  285. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +0 -2
  286. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +0 -2
  287. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +4 -6
  288. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +285 -0
  289. package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +16 -3
  290. package/packages/dd-trace/src/llmobs/prompts/cache.js +272 -0
  291. package/packages/dd-trace/src/llmobs/prompts/manager.js +639 -0
  292. package/packages/dd-trace/src/llmobs/prompts/noop.js +29 -0
  293. package/packages/dd-trace/src/llmobs/prompts/prompt.js +92 -0
  294. package/packages/dd-trace/src/llmobs/sdk.js +21 -6
  295. package/packages/dd-trace/src/llmobs/span_processor.js +81 -2
  296. package/packages/dd-trace/src/llmobs/tagger.js +30 -7
  297. package/packages/dd-trace/src/llmobs/telemetry.js +36 -4
  298. package/packages/dd-trace/src/llmobs/util.js +0 -34
  299. package/packages/dd-trace/src/llmobs/writers/base.js +0 -1
  300. package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
  301. package/packages/dd-trace/src/log/channels.js +3 -0
  302. package/packages/dd-trace/src/log/index.js +23 -5
  303. package/packages/dd-trace/src/log-submission/log-submission-plugin.js +74 -6
  304. package/packages/dd-trace/src/msgpack/chunk.js +0 -1
  305. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +0 -12
  306. package/packages/dd-trace/src/openfeature/encoding.js +0 -2
  307. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +0 -1
  308. package/packages/dd-trace/src/openfeature/index.js +0 -4
  309. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +0 -1
  310. package/packages/dd-trace/src/openfeature/span-enrichment.js +0 -4
  311. package/packages/dd-trace/src/openfeature/writers/base.js +0 -6
  312. package/packages/dd-trace/src/openfeature/writers/exposures.js +0 -5
  313. package/packages/dd-trace/src/openfeature/writers/util.js +0 -4
  314. package/packages/dd-trace/src/opentelemetry/logs/logger.js +0 -1
  315. package/packages/dd-trace/src/opentelemetry/logs/logger_provider.js +0 -1
  316. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +0 -1
  317. package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +0 -2
  318. package/packages/dd-trace/src/opentelemetry/metrics/index.js +1 -1
  319. package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +4 -4
  320. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +0 -1
  321. package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +0 -1
  322. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +103 -35
  323. package/packages/dd-trace/src/opentelemetry/metrics/time.js +0 -1
  324. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +36 -13
  325. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +0 -1
  326. package/packages/dd-trace/src/opentelemetry/span-helpers.js +0 -1
  327. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +0 -1
  328. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +0 -3
  329. package/packages/dd-trace/src/opentracing/propagation/text_map.js +0 -6
  330. package/packages/dd-trace/src/opentracing/span_context.js +0 -1
  331. package/packages/dd-trace/src/otel-thread-ctx.js +38 -11
  332. package/packages/dd-trace/src/payload-tagging/tagging.js +15 -3
  333. package/packages/dd-trace/src/plugin_manager.js +9 -3
  334. package/packages/dd-trace/src/plugins/ci_plugin.js +0 -1
  335. package/packages/dd-trace/src/plugins/database.js +2 -6
  336. package/packages/dd-trace/src/plugins/index.js +8 -0
  337. package/packages/dd-trace/src/plugins/plugin.js +0 -4
  338. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  339. package/packages/dd-trace/src/plugins/util/git.js +1 -3
  340. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +0 -1
  341. package/packages/dd-trace/src/plugins/util/llm.js +0 -2
  342. package/packages/dd-trace/src/plugins/util/status-validator.js +0 -1
  343. package/packages/dd-trace/src/plugins/util/test.js +25 -21
  344. package/packages/dd-trace/src/plugins/util/url.js +0 -5
  345. package/packages/dd-trace/src/priority_sampler.js +0 -6
  346. package/packages/dd-trace/src/process-tags/index.js +0 -1
  347. package/packages/dd-trace/src/profiler.js +132 -35
  348. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +0 -1
  349. package/packages/dd-trace/src/profiling/profiler.js +101 -41
  350. package/packages/dd-trace/src/profiling/ssi-heuristics.js +29 -15
  351. package/packages/dd-trace/src/propagation-hash/index.js +0 -1
  352. package/packages/dd-trace/src/proxy.js +21 -45
  353. package/packages/dd-trace/src/random_sampler.js +0 -4
  354. package/packages/dd-trace/src/rate_limiter.js +0 -4
  355. package/packages/dd-trace/src/remote_config/capabilities.js +1 -9
  356. package/packages/dd-trace/src/remote_config/index.js +0 -1
  357. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +0 -3
  358. package/packages/dd-trace/src/sampler.js +0 -4
  359. package/packages/dd-trace/src/sampling_rule.js +0 -7
  360. package/packages/dd-trace/src/serverless/vercel.js +0 -1
  361. package/packages/dd-trace/src/serverless.js +0 -1
  362. package/packages/dd-trace/src/service-naming/index.js +0 -1
  363. package/packages/dd-trace/src/service-naming/schemas/util.js +0 -1
  364. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +7 -0
  365. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +5 -0
  366. package/packages/dd-trace/src/span_processor.js +2 -2
  367. package/packages/dd-trace/src/span_sampler.js +0 -1
  368. package/packages/dd-trace/src/standalone/product.js +2 -2
  369. package/packages/dd-trace/src/standalone/tracesource.js +0 -1
  370. package/packages/dd-trace/src/startup-log.js +1 -1
  371. package/packages/dd-trace/src/telemetry/endpoints.js +0 -8
  372. package/packages/dd-trace/src/telemetry/logs/index.js +16 -5
  373. package/packages/dd-trace/src/telemetry/logs/log-collector.js +16 -6
  374. package/packages/dd-trace/src/telemetry/metrics.js +0 -2
  375. package/packages/dd-trace/src/telemetry/telemetry.js +4 -1
  376. package/packages/dd-trace/src/util.js +13 -1
  377. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  378. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +0 -10
@@ -0,0 +1,69 @@
1
+ 'use strict'
2
+
3
+ const { builtinModules } = require('node:module')
4
+
5
+ const satisfies = require('../../../../vendor/dist/semifies')
6
+ const { getValueFromEnvSources } = require('../../../dd-trace/src/config/helper')
7
+ const { isRelativeRequire } = require('./shared-utils')
8
+
9
+ /**
10
+ * @param {string|undefined} version
11
+ * @param {string[]|undefined} ranges
12
+ */
13
+ function matchVersion (version, ranges) {
14
+ return !version || !ranges || ranges.some(range => satisfies(version, range))
15
+ }
16
+
17
+ /**
18
+ * @param {string} name
19
+ * @param {string} [file]
20
+ */
21
+ function filename (name, file) {
22
+ return file ? `${name}/${file}` : name
23
+ }
24
+
25
+ /**
26
+ * @param {string} name
27
+ * @param {string|undefined} version
28
+ * @param {string} moduleName
29
+ * @param {{ file?: string, filePattern?: string, versions?: string[] }} instrumentation
30
+ */
31
+ function matchesInstrumentation (name, version, moduleName, instrumentation) {
32
+ const { file, filePattern, versions } = instrumentation
33
+ let matchesFile = moduleName === filename(name, file)
34
+ if (!matchesFile && isRelativeRequire(name)) matchesFile = true
35
+ if (!matchesFile && filePattern) {
36
+ matchesFile = new RegExp(filename(name, filePattern)).test(moduleName)
37
+ }
38
+ return matchesFile && matchVersion(version, versions)
39
+ }
40
+
41
+ /**
42
+ * @returns {Set<string>}
43
+ */
44
+ function getDisabledInstrumentations () {
45
+ const disabled = new Set(
46
+ getValueFromEnvSources('DD_TRACE_DISABLED_INSTRUMENTATIONS')?.split(',').filter(Boolean)
47
+ )
48
+ if (disabled.size === 0) return disabled
49
+
50
+ const expanded = new Set(disabled)
51
+ const builtins = new Set(builtinModules)
52
+
53
+ for (const name of disabled) {
54
+ const prefixed = name.startsWith('node:')
55
+ if (!prefixed && !builtins.has(name)) continue
56
+
57
+ const counterpart = prefixed ? name.slice(5) : `node:${name}`
58
+ expanded.add(counterpart)
59
+ }
60
+
61
+ return expanded
62
+ }
63
+
64
+ module.exports = {
65
+ filename,
66
+ getDisabledInstrumentations,
67
+ matchesInstrumentation,
68
+ matchVersion,
69
+ }
@@ -400,9 +400,6 @@ function getConnectionForAcquire (getConnection, pool, args, acquireCtx, start,
400
400
  }
401
401
  }
402
402
 
403
- /**
404
- * @returns {boolean}
405
- */
406
403
  function isPoolQueryAcquire () {
407
404
  return currentPoolQueryAcquire !== undefined
408
405
  }
@@ -436,7 +433,6 @@ function runWithPoolQueryAcquire (acquire, method, receiver, args) {
436
433
 
437
434
  /**
438
435
  * @param {object} pool
439
- * @returns {boolean}
440
436
  */
441
437
  function takeDeferredPoolQueryAcquire (pool) {
442
438
  const acquire = deferredPoolQueryAcquireStorage?.getStore()
@@ -579,7 +575,6 @@ function setPoolAcquireCaptureWaitTime (capture, waitTime) {
579
575
  * @param {Record<string, unknown>} receiver
580
576
  * @param {string} acquireMethod
581
577
  * @param {unknown[]} args
582
- * @returns {boolean}
583
578
  */
584
579
  function dispatchesAcquireSynchronously (method, receiver, acquireMethod, args) {
585
580
  let dispatched = false
@@ -618,7 +613,6 @@ function acquireStart (pool, acquire) {
618
613
 
619
614
  /**
620
615
  * @param {number|undefined} start
621
- * @returns {number}
622
616
  */
623
617
  function acquireWait (start) {
624
618
  return start === undefined ? 0 : performance.now() - start
@@ -1,20 +1,20 @@
1
1
  'use strict'
2
2
 
3
- const { builtinModules } = require('module')
4
3
  const path = require('path')
5
4
  const { channel } = require('dc-polyfill')
6
- const satisfies = require('../../../../vendor/dist/semifies')
7
5
  const log = require('../../../dd-trace/src/log')
8
6
  const telemetry = require('../../../dd-trace/src/guardrails/telemetry')
9
7
  const { IS_SERVERLESS } = require('../../../dd-trace/src/serverless')
10
8
  const { getValueFromEnvSources } = require('../../../dd-trace/src/config/helper')
11
9
  const checkRequireCache = require('./check-require-cache')
12
10
  const Hook = require('./hook')
13
- const { isRelativeRequire } = require('./shared-utils')
11
+ const {
12
+ filename,
13
+ getDisabledInstrumentations,
14
+ matchesInstrumentation,
15
+ } = require('./instrumentation-utils')
14
16
  const rewriter = require('./rewriter')
15
17
 
16
- const DD_TRACE_DISABLED_INSTRUMENTATIONS =
17
- getValueFromEnvSources('DD_TRACE_DISABLED_INSTRUMENTATIONS')
18
18
  const DD_TRACE_DEBUG = getValueFromEnvSources('DD_TRACE_DEBUG')
19
19
 
20
20
  const hooks = require('./hooks')
@@ -22,9 +22,7 @@ const instrumentations = require('./instrumentations')
22
22
  const names = Object.keys(hooks)
23
23
  const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
24
24
 
25
- const disabledInstrumentations = new Set(
26
- DD_TRACE_DISABLED_INSTRUMENTATIONS?.split(',')
27
- )
25
+ const disabledInstrumentations = getDisabledInstrumentations()
28
26
 
29
27
  const loadChannel = channel('dd-trace:instrumentation:load')
30
28
 
@@ -37,6 +35,10 @@ if (!disabledInstrumentations.has('process')) {
37
35
  require('../process')
38
36
  }
39
37
 
38
+ if (!disabledInstrumentations.has('console')) {
39
+ require('../console')
40
+ }
41
+
40
42
  const debugEnabled = DD_TRACE_DEBUG
41
43
  checkRequireCache.checkForRequiredModules()
42
44
  if (debugEnabled) {
@@ -54,29 +56,6 @@ const instrumentedIntegrationsSuccess = new Map()
54
56
  /** @type {Set<string>} */
55
57
  const alreadyLoggedIncompatibleIntegrations = new Set()
56
58
 
57
- // Always disable prefixed and unprefixed node modules if one is disabled.
58
- if (disabledInstrumentations.size) {
59
- const builtinsSet = new Set(builtinModules)
60
- const disabledBuiltinCounterparts = []
61
- for (const name of disabledInstrumentations) {
62
- const hasPrefix = name.startsWith('node:')
63
- if (hasPrefix || builtinsSet.has(name)) {
64
- if (hasPrefix) {
65
- const unprefixedName = name.slice(5)
66
- if (!disabledInstrumentations.has(unprefixedName)) {
67
- disabledBuiltinCounterparts.push(unprefixedName)
68
- }
69
- } else if (!disabledInstrumentations.has(`node:${name}`)) {
70
- disabledBuiltinCounterparts.push(`node:${name}`)
71
- }
72
- }
73
- }
74
- for (const name of disabledBuiltinCounterparts) {
75
- disabledInstrumentations.add(name)
76
- }
77
- builtinsSet.clear()
78
- }
79
-
80
59
  for (const name of names) {
81
60
  if (disabledInstrumentations.has(name)) continue
82
61
 
@@ -111,21 +90,9 @@ for (const name of names) {
111
90
  instrumentedNodeModules.set(name, moduleExports)
112
91
  }
113
92
 
114
- for (const { file, versions, hook, filePattern, patchDefault } of instrumentations[name]) {
115
- const fullFilename = filename(name, file)
116
-
117
- let matchesFile = moduleName === fullFilename
118
-
119
- if (!matchesFile && isRelativeRequire(name)) matchesFile = true
120
-
121
- const fullFilePattern = filePattern && filename(name, filePattern)
122
- if (fullFilePattern) {
123
- // Some libraries include a hash in their filenames when installed,
124
- // so our instrumentation has to include a '.*' to match them for more than a single version.
125
- matchesFile ||= new RegExp(fullFilePattern).test(moduleName)
126
- }
127
-
128
- if (matchesFile && matchVersion(moduleVersion, versions)) {
93
+ for (const instrumentation of instrumentations[name]) {
94
+ if (matchesInstrumentation(name, moduleVersion, moduleName, instrumentation)) {
95
+ const { hook, patchDefault } = instrumentation
129
96
  // IITM invokes this callback for every module in the package. Only unwrap the namespace after its file and
130
97
  // version match, otherwise a default export from an unrelated internal module can replace that module.
131
98
  if (isIitm && patchDefault === !!moduleExports.default) {
@@ -188,26 +155,8 @@ function logAbortedIntegrations () {
188
155
  instrumentedIntegrationsSuccess.clear()
189
156
  }
190
157
 
191
- /**
192
- * @param {string|undefined} version
193
- * @param {string[]|undefined} ranges
194
- */
195
- function matchVersion (version, ranges) {
196
- return !version || !ranges || ranges.some(range => satisfies(version, range))
197
- }
198
-
199
- /**
200
- * @param {string} name
201
- * @param {string} [file]
202
- * @returns {string}
203
- */
204
- function filename (name, file) {
205
- return file ? `${name}/${file}` : name
206
- }
207
-
208
158
  module.exports = {
209
159
  filename,
210
160
  pathSepExpr,
211
161
  loadChannel,
212
- matchVersion,
213
162
  }
@@ -1,9 +1,11 @@
1
1
  'use strict'
2
2
 
3
- const { readFileSync } = require('fs')
4
- const { join } = require('path')
5
- const { pathToFileURL } = require('url')
3
+ const { readFileSync } = require('node:fs')
4
+ const { join } = require('node:path')
5
+ const { fileURLToPath, pathToFileURL } = require('node:url')
6
+
6
7
  const log = require('../../../../dd-trace/src/log')
8
+ const { getDisabledInstrumentations } = require('../instrumentation-utils')
7
9
  const instrumentations = require('./instrumentations')
8
10
  const { getRewriteTarget } = require('./targets')
9
11
 
@@ -13,14 +15,20 @@ const { getRewriteTarget } = require('./targets')
13
15
  * @property {(moduleName: string, version: string|undefined, filePath: string) => Transformer|undefined} getTransformer
14
16
  *
15
17
  * @typedef {object} Transformer
16
- * @property {(source: string, moduleType: 'cjs'|'esm') => { code: string, map?: string }} transform
18
+ * @property {(source: string, moduleType: 'cjs'|'esm', sourceMap?: string|object) =>
19
+ * { code: string, map?: string|object }} transform
20
+ *
21
+ * @typedef {(content: string|Buffer|ArrayBuffer|Uint8Array, filename: string, format?: string,
22
+ * target?: { moduleName: string, filePath: string }, sourceMap?: string|object) =>
23
+ * { code: string|Buffer|ArrayBuffer|Uint8Array, map?: string|object }} BundlerRewriter
17
24
  */
18
25
 
19
26
  /**
20
27
  * @type {Record<string, string>} map of module base name to version
21
28
  */
22
29
  const moduleVersions = {}
23
- const disabled = new Set()
30
+ // Asynchronous loader workers have their own module graph and cannot receive disable() calls made on the main thread.
31
+ const disabled = getDisabledInstrumentations()
24
32
 
25
33
  // Matchers are built on the first module that actually needs rewriting. The
26
34
  // vendored transformer is a quarter megabyte of bundle that an application
@@ -36,6 +44,20 @@ let matcherEsm
36
44
  // eslint-disable-next-line unicorn/no-useless-concat -- Keep the source-map marker non-contiguous.
37
45
  const SOURCE_MAP_PREFIX = '//# sourceMapping' + 'URL=data:application/json;base64,'
38
46
 
47
+ /**
48
+ * Loader hooks hand `file://` URLs to the rewriter while CommonJS and bundler
49
+ * callers pass plain paths. `fileURLToPath` is the only correct conversion: a
50
+ * plain scheme strip leaves Windows paths rooted at `/C:/` and keeps
51
+ * percent-encoded characters undecoded, which breaks version resolution.
52
+ * Rewrite-target paths use forward slashes, including on Windows.
53
+ *
54
+ * @param {string} filename
55
+ */
56
+ function normalizeFilename (filename) {
57
+ const path = filename.startsWith('file://') ? fileURLToPath(filename) : filename
58
+ return path.replaceAll('\\', '/')
59
+ }
60
+
39
61
  /**
40
62
  * @param {string|Buffer|ArrayBuffer|Uint8Array} content
41
63
  * @param {string} filename
@@ -46,30 +68,39 @@ const SOURCE_MAP_PREFIX = '//# sourceMapping' + 'URL=data:application/json;base6
46
68
  function rewrite (content, filename, format, target) {
47
69
  if (!content) return content
48
70
 
49
- target ||= getRewriteTarget(filename)
50
- if (!target) return content
51
-
52
- filename = filename.replace('file://', '')
71
+ try {
72
+ filename = normalizeFilename(filename)
73
+ target ||= getRewriteTarget(filename)
74
+ if (!target) return content
53
75
 
54
- const moduleType = format === 'module' ? 'esm' : 'cjs'
55
- const { moduleName, filePath } = target
56
- const version = getVersion(filename, filePath)
76
+ const moduleType = format === 'module' ? 'esm' : 'cjs'
77
+ const { moduleName, filePath } = target
78
+ if (disabled.has(moduleName)) return content
57
79
 
58
- if (disabled.has(moduleName)) return content
80
+ const version = getVersion(filename, filePath)
81
+ if (!version) return content
59
82
 
60
- const transformer = getMatcher(moduleType).getTransformer(moduleName, version, filePath)
83
+ const transformer = getMatcher(moduleType).getTransformer(moduleName, version, filePath)
61
84
 
62
- if (!transformer) return content
85
+ if (!transformer) return content
63
86
 
64
- try {
65
87
  const source = getSourceText(content)
66
88
 
67
89
  // TODO: pass existing sourcemap as input for remapping
68
- const { code, map } = transformer.transform(source, moduleType)
90
+ let { code, map } = transformer.transform(source, moduleType)
91
+
92
+ if (source.startsWith('#!') && !code.startsWith('#!')) {
93
+ // A shebang must be the entire first line, and JavaScript recognizes
94
+ // exactly four line terminators: \n, \r, \u2028 (line separator), and
95
+ // \u2029 (paragraph separator). Any of the four can end the shebang line.
96
+ const shebangEnd = source.search(/[\r\n\u2028\u2029]/)
97
+ code = (shebangEnd === -1 ? source : source.slice(0, shebangEnd)) + '\n' + code
98
+ map = shiftSourceMapLine(map)
99
+ }
69
100
 
70
101
  if (!map) return code
71
102
 
72
- const inlineMap = Buffer.from(map).toString('base64')
103
+ const inlineMap = Buffer.from(typeof map === 'string' ? map : JSON.stringify(map)).toString('base64')
73
104
 
74
105
  return code + '\n' + SOURCE_MAP_PREFIX + inlineMap
75
106
  } catch (e) {
@@ -79,46 +110,79 @@ function rewrite (content, filename, format, target) {
79
110
  return content
80
111
  }
81
112
 
113
+ /**
114
+ * @param {string} dcModule
115
+ * @returns {BundlerRewriter}
116
+ */
117
+ function createBundlerRewriter (dcModule) {
118
+ const matcher = createMatcher(dcModule)
119
+
120
+ return function rewriteBundled (content, filename, format, target, sourceMap) {
121
+ if (!content) return { code: content, map: sourceMap }
122
+
123
+ try {
124
+ filename = normalizeFilename(filename)
125
+ target ||= getRewriteTarget(filename)
126
+ if (!target) return { code: content, map: sourceMap }
127
+
128
+ const moduleType = format === 'module' ? 'esm' : 'cjs'
129
+ const { moduleName, filePath } = target
130
+ const version = getVersion(filename, filePath)
131
+ if (!version) return { code: content, map: sourceMap }
132
+
133
+ const transformer = matcher.getTransformer(moduleName, version, filePath)
134
+ if (!transformer) return { code: content, map: sourceMap }
135
+
136
+ return transformer.transform(getSourceText(content), moduleType, sourceMap)
137
+ } catch (error) {
138
+ log.error(error)
139
+ return { code: content, map: sourceMap }
140
+ }
141
+ }
142
+ }
143
+
82
144
  /**
83
145
  * @param {'cjs'|'esm'} moduleType
84
146
  * @returns {InstrumentationMatcher}
85
147
  */
86
148
  function getMatcher (moduleType) {
87
149
  if (moduleType === 'esm') {
88
- matcherEsm ??= createMatcher(moduleType)
150
+ matcherEsm ??= createMatcher(getDcPolyfillSpecifier(moduleType))
89
151
 
90
152
  return matcherEsm
91
153
  }
92
154
 
93
- matcherCjs ??= createMatcher(moduleType)
155
+ matcherCjs ??= createMatcher(getDcPolyfillSpecifier(moduleType))
94
156
 
95
157
  return matcherCjs
96
158
  }
97
159
 
98
160
  /**
99
- * @param {'cjs'|'esm'} moduleType
161
+ * @param {string|undefined} dcModule
100
162
  * @returns {InstrumentationMatcher}
101
163
  */
102
- function createMatcher (moduleType) {
164
+ function createMatcher (dcModule) {
103
165
  const { create } = require('../../../../../vendor/dist/@apm-js-collab/code-transformer')
104
166
  const {
105
167
  awaitContextCallback,
106
- awaitContextCallbackAtFunctionStart,
107
- awaitContextCallbackAtTryStart,
108
168
  configureGraphqlFastPath,
109
169
  configureGraphqlJitCompileObject,
110
170
  configureGraphqlJitDeferredField,
111
171
  configureGraphqlJitExecute,
112
172
  configureGraphqlJitRuntime,
113
173
  configureMercuriusRequest,
174
+ publishDurableOrchestrationFailure,
114
175
  waitForAsyncEnd,
115
176
  } = require('./transforms')
177
+ const {
178
+ postgresQueryHandlers,
179
+ postgresQueryLifecycle,
180
+ postgresQueryPreparation,
181
+ } = require('./transforms/postgres')
116
182
 
117
- const matcher = create(instrumentations, getDcPolyfillSpecifier(moduleType))
183
+ const matcher = create(instrumentations, dcModule)
118
184
 
119
185
  matcher.addTransform('awaitContextCallback', awaitContextCallback)
120
- matcher.addTransform('awaitContextCallbackAtFunctionStart', awaitContextCallbackAtFunctionStart)
121
- matcher.addTransform('awaitContextCallbackAtTryStart', awaitContextCallbackAtTryStart)
122
186
  matcher.addTransform('waitForAsyncEnd', waitForAsyncEnd)
123
187
  matcher.addTransform('configureGraphqlFastPath', configureGraphqlFastPath)
124
188
  matcher.addTransform('configureGraphqlJitCompileObject', configureGraphqlJitCompileObject)
@@ -126,6 +190,10 @@ function createMatcher (moduleType) {
126
190
  matcher.addTransform('configureGraphqlJitExecute', configureGraphqlJitExecute)
127
191
  matcher.addTransform('configureGraphqlJitRuntime', configureGraphqlJitRuntime)
128
192
  matcher.addTransform('configureMercuriusRequest', configureMercuriusRequest)
193
+ matcher.addTransform('publishDurableOrchestrationFailure', publishDurableOrchestrationFailure)
194
+ matcher.addTransform('postgresQueryHandlers', postgresQueryHandlers)
195
+ matcher.addTransform('postgresQueryLifecycle', postgresQueryLifecycle)
196
+ matcher.addTransform('postgresQueryPreparation', postgresQueryPreparation)
129
197
 
130
198
  return matcher
131
199
  }
@@ -159,7 +227,6 @@ function getDcPolyfillSpecifier (moduleType) {
159
227
  * Convert the source representations accepted by Node.js loader hooks to text.
160
228
  *
161
229
  * @param {string | ArrayBuffer | BufferView} source
162
- * @returns {string}
163
230
  */
164
231
  function getSourceText (source) {
165
232
  if (typeof source === 'string') return source
@@ -169,6 +236,19 @@ function getSourceText (source) {
169
236
  return Buffer.from(source).toString('utf8')
170
237
  }
171
238
 
239
+ /**
240
+ * Account for a shebang restored ahead of the generated program. The transformer already maps original positions
241
+ * past the input shebang, so only the generated side needs an additional empty line.
242
+ *
243
+ * @param {string|object|undefined} map
244
+ */
245
+ function shiftSourceMapLine (map) {
246
+ if (!map) return map
247
+ const sourceMap = typeof map === 'string' ? JSON.parse(map) : map
248
+ const shifted = { ...sourceMap, mappings: `;${sourceMap.mappings}` }
249
+ return typeof map === 'string' ? JSON.stringify(shifted) : shifted
250
+ }
251
+
172
252
  function disable (instrumentation) {
173
253
  disabled.add(instrumentation)
174
254
  }
@@ -189,4 +269,4 @@ function getVersion (filename, filePath) {
189
269
  return moduleVersions[basename]
190
270
  }
191
271
 
192
- module.exports = { rewrite, disable }
272
+ module.exports = { createBundlerRewriter, disable, rewrite }
@@ -0,0 +1,39 @@
1
+ 'use strict'
2
+
3
+ // activationName is the plugin-manager key published after a target is successfully rewritten.
4
+ const registry = [
5
+ { instrumentations: require('./instrumentations/ai') },
6
+ { activationName: '@azure/cosmos', instrumentations: require('./instrumentations/azure-cosmos') },
7
+ { instrumentations: require('./instrumentations/azure-durable-functions') },
8
+ { activationName: 'bullmq', instrumentations: require('./instrumentations/bullmq') },
9
+ { instrumentations: require('./instrumentations/claude-agent-sdk') },
10
+ { instrumentations: require('./instrumentations/graphql') },
11
+ { instrumentations: require('./instrumentations/graphql-jit') },
12
+ { activationName: '@langchain/core', instrumentations: require('./instrumentations/langchain') },
13
+ { activationName: '@langchain/langgraph', instrumentations: require('./instrumentations/langgraph') },
14
+ { activationName: 'mercurius', instrumentations: require('./instrumentations/mercurius') },
15
+ { instrumentations: require('./instrumentations/modelcontextprotocol-sdk') },
16
+ { instrumentations: require('./instrumentations/openai-agents') },
17
+ { instrumentations: require('./instrumentations/playwright') },
18
+ { instrumentations: require('./instrumentations/postgres') },
19
+ { instrumentations: require('./instrumentations/webdriverio') },
20
+ { instrumentations: require('./instrumentations/aws-durable-execution-sdk-js') },
21
+ { instrumentations: require('./instrumentations/supabase') },
22
+ ]
23
+
24
+ const activationNames = new Map()
25
+ for (const { activationName, instrumentations } of registry) {
26
+ if (!activationName) continue
27
+ for (const { module } of instrumentations) activationNames.set(module.name, activationName)
28
+ }
29
+
30
+ const instrumentations = registry.flatMap(entry => entry.instrumentations)
31
+
32
+ /**
33
+ * @param {string} moduleName
34
+ */
35
+ function getRewriteActivationName (moduleName) {
36
+ return activationNames.get(moduleName)
37
+ }
38
+
39
+ module.exports = { getRewriteActivationName, instrumentations, registry }
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ module.exports = [
4
+ {
5
+ module: {
6
+ name: 'durable-functions',
7
+ versionRange: '>=3 <4',
8
+ filePath: 'lib/src/orchestrations/TaskOrchestrationExecutor.js',
9
+ },
10
+ functionQuery: {
11
+ className: 'TaskOrchestrationExecutor',
12
+ methodName: 'execute',
13
+ },
14
+ transform: 'publishDurableOrchestrationFailure',
15
+ channelName: 'TaskOrchestrationExecutor_failure',
16
+ },
17
+ ]
@@ -1,18 +1,5 @@
1
1
  'use strict'
2
2
 
3
- module.exports = [
4
- ...require('./ai'),
5
- ...require('./azure-cosmos'),
6
- ...require('./bullmq'),
7
- ...require('./claude-agent-sdk'),
8
- ...require('./graphql'),
9
- ...require('./graphql-jit'),
10
- ...require('./langchain'),
11
- ...require('./langgraph'),
12
- ...require('./mercurius'),
13
- ...require('./modelcontextprotocol-sdk'),
14
- ...require('./openai-agents'),
15
- ...require('./playwright'),
16
- ...require('./webdriverio'),
17
- ...require('./aws-durable-execution-sdk-js'),
18
- ]
3
+ const { instrumentations } = require('../instrumentation-registry')
4
+
5
+ module.exports = instrumentations
@@ -93,6 +93,18 @@ module.exports = [
93
93
  },
94
94
  channelName: 'createRootSuite',
95
95
  },
96
+ {
97
+ module: {
98
+ name: 'playwright',
99
+ versionRange: '>=1.60.0',
100
+ filePath: 'lib/runner/index.js',
101
+ },
102
+ functionQuery: {
103
+ functionName: 'filterForShard',
104
+ kind: 'Sync',
105
+ },
106
+ channelName: 'filterForShard',
107
+ },
96
108
  {
97
109
  module: {
98
110
  name: 'playwright-core',
@@ -0,0 +1,36 @@
1
+ 'use strict'
2
+
3
+ const handlers = ['src/index.js', 'cjs/src/index.js'].map(filePath => ({
4
+ module: {
5
+ name: 'postgres',
6
+ versionRange: '>=3.0.0',
7
+ filePath,
8
+ },
9
+ astQuery: 'Program',
10
+ transform: 'postgresQueryHandlers',
11
+ channelName: 'query',
12
+ }))
13
+
14
+ const preparations = ['src/connection.js', 'cjs/src/connection.js'].map(filePath => ({
15
+ module: {
16
+ name: 'postgres',
17
+ versionRange: '>=3.0.0',
18
+ filePath,
19
+ },
20
+ astQuery: 'Program',
21
+ transform: 'postgresQueryPreparation',
22
+ channelName: 'query:prepare',
23
+ }))
24
+
25
+ const lifecycles = ['src/query.js', 'cjs/src/query.js'].map(filePath => ({
26
+ module: {
27
+ name: 'postgres',
28
+ versionRange: '>=3.0.0',
29
+ filePath,
30
+ },
31
+ astQuery: 'Program',
32
+ transform: 'postgresQueryLifecycle',
33
+ channelName: 'query',
34
+ }))
35
+
36
+ module.exports = [...handlers, ...preparations, ...lifecycles]