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
@@ -0,0 +1,148 @@
1
+ 'use strict'
2
+
3
+ const v10Procedure = 'FunctionDeclaration[id.name="createProcedureCaller"] ' +
4
+ 'VariableDeclarator[id.name="procedure"] > FunctionExpression[id.name="resolve"]'
5
+ const v11Procedure = 'FunctionDeclaration[id.name="createProcedureCaller"] FunctionDeclaration[id.name="procedure"]'
6
+
7
+ module.exports = [
8
+ {
9
+ module: { name: '@trpc/server', versionRange: '>=10.45.2 <11', filePath: 'dist/index.js' },
10
+ astQuery: v10Procedure,
11
+ functionQuery: { kind: 'Async' },
12
+ channelName: 'procedure',
13
+ },
14
+ {
15
+ module: { name: '@trpc/server', versionRange: '>=10.45.2 <11', filePath: 'dist/index.mjs' },
16
+ astQuery: v10Procedure,
17
+ functionQuery: { kind: 'Async' },
18
+ channelName: 'procedure',
19
+ },
20
+ {
21
+ module: {
22
+ name: '@trpc/server',
23
+ versionRange: '>=11 <11.4',
24
+ filePath: 'dist/unstable-core-do-not-import/procedureBuilder.js',
25
+ },
26
+ astQuery: v11Procedure,
27
+ functionQuery: { kind: 'Async' },
28
+ channelName: 'procedure',
29
+ },
30
+ {
31
+ module: {
32
+ name: '@trpc/server',
33
+ versionRange: '>=11 <11.4',
34
+ filePath: 'dist/unstable-core-do-not-import/procedureBuilder.mjs',
35
+ },
36
+ astQuery: v11Procedure,
37
+ functionQuery: { kind: 'Async' },
38
+ channelName: 'procedure',
39
+ },
40
+ {
41
+ module: {
42
+ name: '@trpc/server',
43
+ versionRange: '>=11.4',
44
+ filePath: /^dist\/initTRPC-[A-Za-z0-9_-]+\.cjs$/,
45
+ },
46
+ astQuery: v11Procedure,
47
+ functionQuery: { kind: 'Async' },
48
+ channelName: 'procedure',
49
+ },
50
+ {
51
+ module: {
52
+ name: '@trpc/server',
53
+ versionRange: '>=11.4',
54
+ filePath: /^dist\/initTRPC-[A-Za-z0-9_-]+\.mjs$/,
55
+ },
56
+ astQuery: v11Procedure,
57
+ functionQuery: { kind: 'Async' },
58
+ channelName: 'procedure',
59
+ },
60
+ {
61
+ module: { name: '@trpc/server', versionRange: '>=10.45.2 <11', filePath: /^dist\/nodeHTTPRequestHandler-[A-Za-z0-9_-]+\.js$/ },
62
+ astQuery: 'FunctionDeclaration[id.name="nodeHTTPRequestHandler"]',
63
+ functionQuery: { kind: 'Sync' },
64
+ channelName: 'request',
65
+ },
66
+ {
67
+ module: { name: '@trpc/server', versionRange: '>=10.45.2 <11', filePath: /^dist\/nodeHTTPRequestHandler-[A-Za-z0-9_-]+\.mjs$/ },
68
+ astQuery: 'FunctionDeclaration[id.name="nodeHTTPRequestHandler"]',
69
+ functionQuery: { kind: 'Sync' },
70
+ channelName: 'request',
71
+ },
72
+ {
73
+ module: {
74
+ name: '@trpc/server',
75
+ versionRange: '>=11 <11.4',
76
+ filePath: 'dist/adapters/node-http/nodeHTTPRequestHandler.js',
77
+ },
78
+ astQuery: 'FunctionDeclaration[id.name="nodeHTTPRequestHandler"]',
79
+ functionQuery: { kind: 'Sync' },
80
+ channelName: 'request',
81
+ },
82
+ {
83
+ module: {
84
+ name: '@trpc/server',
85
+ versionRange: '>=11 <11.4',
86
+ filePath: 'dist/adapters/node-http/nodeHTTPRequestHandler.mjs',
87
+ },
88
+ astQuery: 'FunctionDeclaration[id.name="nodeHTTPRequestHandler"]',
89
+ functionQuery: { kind: 'Sync' },
90
+ channelName: 'request',
91
+ },
92
+ {
93
+ module: { name: '@trpc/server', versionRange: '>=11.4', filePath: /^dist\/node-http-[A-Za-z0-9_-]+\.cjs$/ },
94
+ astQuery: 'FunctionDeclaration[id.name="nodeHTTPRequestHandler"]',
95
+ functionQuery: { kind: 'Sync' },
96
+ channelName: 'request',
97
+ },
98
+ {
99
+ module: { name: '@trpc/server', versionRange: '>=11.4', filePath: /^dist\/node-http-[A-Za-z0-9_-]+\.mjs$/ },
100
+ astQuery: 'FunctionDeclaration[id.name="nodeHTTPRequestHandler"]',
101
+ functionQuery: { kind: 'Sync' },
102
+ channelName: 'request',
103
+ },
104
+ {
105
+ module: { name: '@trpc/server', versionRange: '>=10.45.2 <11', filePath: /^dist\/resolveHTTPResponse-[A-Za-z0-9_-]+\.js$/ },
106
+ astQuery: 'FunctionDeclaration[id.name="resolveHTTPResponse"]',
107
+ transform: 'publishTrpcRequestInfo',
108
+ channelName: 'requestInfo',
109
+ },
110
+ {
111
+ module: { name: '@trpc/server', versionRange: '>=10.45.2 <11', filePath: /^dist\/resolveHTTPResponse-[A-Za-z0-9_-]+\.mjs$/ },
112
+ astQuery: 'FunctionDeclaration[id.name="resolveHTTPResponse"]',
113
+ transform: 'publishTrpcRequestInfo',
114
+ channelName: 'requestInfo',
115
+ },
116
+ {
117
+ module: {
118
+ name: '@trpc/server',
119
+ versionRange: '>=11 <11.4',
120
+ filePath: 'dist/unstable-core-do-not-import/http/contentType.js',
121
+ },
122
+ astQuery: 'FunctionDeclaration[id.name="getRequestInfo"]',
123
+ functionQuery: { kind: 'Async' },
124
+ channelName: 'requestInfo',
125
+ },
126
+ {
127
+ module: {
128
+ name: '@trpc/server',
129
+ versionRange: '>=11 <11.4',
130
+ filePath: 'dist/unstable-core-do-not-import/http/contentType.mjs',
131
+ },
132
+ astQuery: 'FunctionDeclaration[id.name="getRequestInfo"]',
133
+ functionQuery: { kind: 'Async' },
134
+ channelName: 'requestInfo',
135
+ },
136
+ {
137
+ module: { name: '@trpc/server', versionRange: '>=11.4', filePath: /^dist\/resolveResponse-[A-Za-z0-9_-]+\.cjs$/ },
138
+ astQuery: 'FunctionDeclaration[id.name="getRequestInfo"]',
139
+ functionQuery: { kind: 'Async' },
140
+ channelName: 'requestInfo',
141
+ },
142
+ {
143
+ module: { name: '@trpc/server', versionRange: '>=11.4', filePath: /^dist\/resolveResponse-[A-Za-z0-9_-]+\.mjs$/ },
144
+ astQuery: 'FunctionDeclaration[id.name="getRequestInfo"]',
145
+ functionQuery: { kind: 'Async' },
146
+ channelName: 'requestInfo',
147
+ },
148
+ ]
@@ -4,5 +4,55 @@
4
4
  "source": "^dist\\/(?:development|production)\\/chunk-[A-Z0-9]+\\.mjs$",
5
5
  "flags": "",
6
6
  "sourceMatch": "function derive("
7
+ },
8
+ {
9
+ "name": "@trpc/server",
10
+ "source": "^dist\\/initTRPC-[A-Za-z0-9_-]+\\.cjs$",
11
+ "flags": ""
12
+ },
13
+ {
14
+ "name": "@trpc/server",
15
+ "source": "^dist\\/initTRPC-[A-Za-z0-9_-]+\\.mjs$",
16
+ "flags": ""
17
+ },
18
+ {
19
+ "name": "@trpc/server",
20
+ "source": "^dist\\/nodeHTTPRequestHandler-[A-Za-z0-9_-]+\\.js$",
21
+ "flags": ""
22
+ },
23
+ {
24
+ "name": "@trpc/server",
25
+ "source": "^dist\\/nodeHTTPRequestHandler-[A-Za-z0-9_-]+\\.mjs$",
26
+ "flags": ""
27
+ },
28
+ {
29
+ "name": "@trpc/server",
30
+ "source": "^dist\\/node-http-[A-Za-z0-9_-]+\\.cjs$",
31
+ "flags": ""
32
+ },
33
+ {
34
+ "name": "@trpc/server",
35
+ "source": "^dist\\/node-http-[A-Za-z0-9_-]+\\.mjs$",
36
+ "flags": ""
37
+ },
38
+ {
39
+ "name": "@trpc/server",
40
+ "source": "^dist\\/resolveHTTPResponse-[A-Za-z0-9_-]+\\.js$",
41
+ "flags": ""
42
+ },
43
+ {
44
+ "name": "@trpc/server",
45
+ "source": "^dist\\/resolveHTTPResponse-[A-Za-z0-9_-]+\\.mjs$",
46
+ "flags": ""
47
+ },
48
+ {
49
+ "name": "@trpc/server",
50
+ "source": "^dist\\/resolveResponse-[A-Za-z0-9_-]+\\.cjs$",
51
+ "flags": ""
52
+ },
53
+ {
54
+ "name": "@trpc/server",
55
+ "source": "^dist\\/resolveResponse-[A-Za-z0-9_-]+\\.mjs$",
56
+ "flags": ""
7
57
  }
8
58
  ]
@@ -6,6 +6,8 @@
6
6
  "@azure/cosmos/dist/commonjs/plugins/Plugin.js": "@azure/cosmos",
7
7
  "@azure/cosmos/dist/esm/plugins/Plugin.js": "@azure/cosmos",
8
8
  "@azure/cosmos/dist/react-native/plugins/Plugin.js": "@azure/cosmos",
9
+ "@elevenlabs/elevenlabs-js/api/resources/conversationalAi/conversation/ClientTools.js": "@elevenlabs/elevenlabs-js",
10
+ "@elevenlabs/elevenlabs-js/api/resources/conversationalAi/conversation/Conversation.js": "@elevenlabs/elevenlabs-js",
9
11
  "@graphql-tools/executor/cjs/execution/execute.js": "@graphql-tools/executor",
10
12
  "@graphql-tools/executor/cjs/execution/normalizedExecutor.js": "@graphql-tools/executor",
11
13
  "@graphql-tools/executor/esm/execution/execute.js": "@graphql-tools/executor",
@@ -30,6 +32,8 @@
30
32
  "@modelcontextprotocol/sdk/dist/esm/server/mcp.js": "@modelcontextprotocol/sdk",
31
33
  "@openai/agents-openai/dist/openaiChatCompletionsModel.js": "@openai/agents-openai",
32
34
  "@openai/agents-openai/dist/openaiChatCompletionsModel.mjs": "@openai/agents-openai",
35
+ "@openai/agents-realtime/dist/openaiRealtimeWebsocket.js": "@openai/agents-realtime",
36
+ "@openai/agents-realtime/dist/openaiRealtimeWebsocket.mjs": "@openai/agents-realtime",
33
37
  "@playwright/test/lib/reporters/multiplexer.js": "@playwright/test",
34
38
  "@supabase/auth-js/dist/main/GoTrueClient.js": "@supabase/auth-js",
35
39
  "@supabase/auth-js/dist/module/GoTrueClient.js": "@supabase/auth-js",
@@ -41,6 +45,14 @@
41
45
  "@supabase/realtime-js/dist/module/RealtimeChannel.js": "@supabase/realtime-js",
42
46
  "@supabase/storage-js/dist/index.cjs": "@supabase/storage-js",
43
47
  "@supabase/storage-js/dist/index.mjs": "@supabase/storage-js",
48
+ "@trpc/server/dist/adapters/node-http/nodeHTTPRequestHandler.js": "@trpc/server",
49
+ "@trpc/server/dist/adapters/node-http/nodeHTTPRequestHandler.mjs": "@trpc/server",
50
+ "@trpc/server/dist/index.js": "@trpc/server",
51
+ "@trpc/server/dist/index.mjs": "@trpc/server",
52
+ "@trpc/server/dist/unstable-core-do-not-import/http/contentType.js": "@trpc/server",
53
+ "@trpc/server/dist/unstable-core-do-not-import/http/contentType.mjs": "@trpc/server",
54
+ "@trpc/server/dist/unstable-core-do-not-import/procedureBuilder.js": "@trpc/server",
55
+ "@trpc/server/dist/unstable-core-do-not-import/procedureBuilder.mjs": "@trpc/server",
44
56
  "@typesafe-ai/sdk/dist/index.cjs": "@typesafe-ai/sdk",
45
57
  "@typesafe-ai/sdk/dist/index.mjs": "@typesafe-ai/sdk",
46
58
  "@vitest/runner/dist/chunk-hooks.js": "@vitest/runner",
@@ -54,6 +66,9 @@
54
66
  "@wdio/utils/build/index.js": "@wdio/utils",
55
67
  "ai/dist/index.js": "ai",
56
68
  "ai/dist/index.mjs": "ai",
69
+ "async-mutex/es6/Semaphore.js": "async-mutex",
70
+ "async-mutex/index.mjs": "async-mutex",
71
+ "async-mutex/lib/Semaphore.js": "async-mutex",
57
72
  "bullmq/dist/cjs/classes/flow-producer.js": "bullmq",
58
73
  "bullmq/dist/cjs/classes/queue.js": "bullmq",
59
74
  "bullmq/dist/cjs/classes/worker.js": "bullmq",
@@ -72,11 +87,8 @@
72
87
  "graphql/language/parser.js": "graphql",
73
88
  "graphql/language/parser.mjs": "graphql",
74
89
  "graphql/language/printer.js": "graphql",
75
- "graphql/language/printer.mjs": "graphql",
76
90
  "graphql/language/visitor.js": "graphql",
77
- "graphql/language/visitor.mjs": "graphql",
78
91
  "graphql/utilities/index.js": "graphql",
79
- "graphql/utilities/index.mjs": "graphql",
80
92
  "graphql/validation/validate.js": "graphql",
81
93
  "graphql/validation/validate.mjs": "graphql",
82
94
  "jasmine-core/lib/jasmine-core/jasmine.js": "jasmine-core",
@@ -84,6 +96,8 @@
84
96
  "jest-runner/build/runTest.js": "jest-runner",
85
97
  "jest-runner/build/testWorker.js": "jest-runner",
86
98
  "mercurius/index.js": "mercurius",
99
+ "next/dist/next-server/server/next-server.js": "next",
100
+ "next/dist/server/next-server.js": "next",
87
101
  "playwright-core/lib/coreBundle.js": "playwright-core",
88
102
  "playwright/lib/common/config.js": "playwright",
89
103
  "playwright/lib/common/index.js": "playwright",
@@ -27,9 +27,44 @@ module.exports = {
27
27
  configureGraphqlFastPath,
28
28
  configureMercuriusRequest,
29
29
  publishDurableOrchestrationFailure,
30
+ publishTrpcRequestInfo,
30
31
  waitForAsyncEnd,
31
32
  }
32
33
 
34
+ /**
35
+ * @param {{ channelName: string, transforms: { tracingChannelDeclaration: Function } }} state
36
+ * @param {import('estree').FunctionDeclaration} node
37
+ * @param {import('estree').Node} _parent
38
+ * @param {import('estree').Node[]} ancestry
39
+ */
40
+ function publishTrpcRequestInfo (state, node, _parent, ancestry) {
41
+ let insertionBlock
42
+ let insertionIndex = -1
43
+ for (const block of query(node, 'TryStatement > BlockStatement')) {
44
+ for (let index = 0; index < block.body.length; index++) {
45
+ const statement = block.body[index]
46
+ if (statement.type !== 'ExpressionStatement' || statement.expression.type !== 'AssignmentExpression' ||
47
+ statement.expression.left.name !== 'paths') continue
48
+
49
+ assert.strictEqual(insertionBlock, undefined, 'publishTrpcRequestInfo: multiple paths assignments')
50
+ insertionBlock = block
51
+ insertionIndex = index
52
+ }
53
+ }
54
+ assert(insertionBlock, 'publishTrpcRequestInfo: paths assignment not found')
55
+
56
+ state.transforms.tracingChannelDeclaration(state, ancestry.at(-1))
57
+ const channelVariable = `tr_ch_apm$${state.channelName.replaceAll(/[^\w]/g, '_')}`
58
+ insertionBlock.body.splice(insertionIndex + 1, 0, ...parse(`
59
+ if (${channelVariable}.asyncEnd.hasSubscribers) {
60
+ ${channelVariable}.asyncEnd.publish({ result: {
61
+ isBatchCall,
62
+ path: paths.length === 1 ? paths[0] : undefined
63
+ } })
64
+ }
65
+ `).body)
66
+ }
67
+
33
68
  /**
34
69
  * Publishes the error captured by Durable Functions immediately before its
35
70
  * executor converts that error into a serialized failed orchestration state.
@@ -243,8 +278,10 @@ function createAwaitedContextCallback (state, insertionTarget, ancestry) {
243
278
  /**
244
279
  * @param {object} _state
245
280
  * @param {import('estree').FunctionDeclaration} node
281
+ * @param {import('estree').Node} _parent
282
+ * @param {import('estree').Node[]} ancestry
246
283
  */
247
- function configureGraphqlJitCompileObject (_state, node) {
284
+ function configureGraphqlJitCompileObject (_state, node, _parent, ancestry) {
248
285
  const resolverConditions = query(node, 'IfStatement[test.name="resolver"]')
249
286
  const compileTypeCalls = query(node, 'CallExpression[callee.name="compileType"]')
250
287
 
@@ -284,7 +321,7 @@ function configureGraphqlJitCompileObject (_state, node) {
284
321
  DD_FIELD_NODES,
285
322
  originPaths,
286
323
  ddTraceArguments,
287
- objectStringify,
324
+ DD_STRINGIFY,
288
325
  DD_COMPILED
289
326
  )
290
327
  : undefined
@@ -293,6 +330,26 @@ function configureGraphqlJitCompileObject (_state, node) {
293
330
  replaceIdentifier(inlineField, 'DD_FIELD_NODES', clone(compileTypeCall.arguments[3]))
294
331
  replaceIdentifier(inlineField, 'DD_COMPILED', inlineCompileCall)
295
332
 
333
+ const program = ancestry.find(ancestor => ancestor.type === 'Program')
334
+ let stringify = parse('objectStringify').body[0].expression
335
+ if (query(program, 'FunctionDeclaration[id.name="objectStringify"]').length === 0) {
336
+ const values = queryOne(
337
+ program,
338
+ 'FunctionDeclaration[id.name="compileArguments"][params.1.name="args"]' +
339
+ ':has(VariableDeclarator[id.name="bind"]) VariableDeclarator[id.name="valuesExpression"]'
340
+ )
341
+ assert(values?.init, 'configureGraphqlJitCompileObject: argument serializer not found')
342
+ stringify = parse(`
343
+ (values, hoist) => {
344
+ const args = { values, types: ddTraceArguments.types }
345
+ const bind = value => '__context.literals.' + hoist(value)
346
+ return DD_VALUES
347
+ }
348
+ `).body[0].expression
349
+ replaceIdentifier(stringify, 'DD_VALUES', values.init)
350
+ }
351
+ replaceIdentifier(inlineField, 'DD_STRINGIFY', stringify)
352
+
296
353
  assert(
297
354
  insertBeforeStatement(node.body, resolverCondition, [...defaultSetup, inlineField]),
298
355
  'configureGraphqlJitCompileObject: could not insert default field setup'
@@ -11,10 +11,14 @@ const finishCh = channel('apm:ioredis:command:finish')
11
11
  const errorCh = channel('apm:ioredis:command:error')
12
12
 
13
13
  const connectionOptionsCache = new WeakMap()
14
+ let replayPromises
15
+ let replaying = false
14
16
 
15
17
  function wrapRedis (Redis) {
16
18
  shimmer.wrap(Redis.prototype, 'sendCommand', sendCommand => function (command, stream) {
17
- if (!startCh.hasSubscribers || !command?.promise) return sendCommand.call(this, command, stream)
19
+ if (!startCh.hasSubscribers || !command?.promise || (replaying && replayPromises.has(command.promise))) {
20
+ return sendCommand.call(this, command, stream)
21
+ }
18
22
 
19
23
  const options = this.options || {}
20
24
  let connectionOptions = connectionOptionsCache.get(this)
@@ -30,14 +34,108 @@ function wrapRedis (Redis) {
30
34
  connectionName: options.connectionName,
31
35
  }
32
36
  return startCh.runStores(ctx, () => {
33
- command.promise.then(() => finish(ctx), err => finish(ctx, err))
34
-
37
+ command.promise.then(() => finish(ctx), error => finish(ctx, error))
35
38
  return sendCommand.call(this, command, stream)
36
39
  })
37
40
  })
41
+
42
+ const errorHandler = Redis.prototype.handleReconnection ? 'handleReconnection' : 'returnError'
43
+ shimmer.wrap(Redis.prototype, errorHandler, handleReconnection => function (error, item) {
44
+ if (startCh.hasSubscribers) {
45
+ const command = item ? item.command : this.commandQueue.get(0).command
46
+ trackReplay(command.promise)
47
+ }
48
+ return handleReconnection.call(this, error, item)
49
+ })
50
+ shimmer.wrap(Redis.prototype, 'flushQueue', flushQueue => function () {
51
+ if (startCh.hasSubscribers) {
52
+ trackQueue(this.offlineQueue)
53
+ trackQueue(this.commandQueue)
54
+ }
55
+ return flushQueue.apply(this, arguments)
56
+ })
57
+ shimmer.wrap(Redis.prototype, 'setStatus', setStatus => function (status) {
58
+ if (status === 'ready' && startCh.hasSubscribers) {
59
+ trackQueue(this.offlineQueue)
60
+ if (this.options.autoResendUnfulfilledCommands) trackQueue(this.prevCommandQueue)
61
+ }
62
+ return setStatus.apply(this, arguments)
63
+ })
38
64
  return Redis
39
65
  }
40
66
 
67
+ /**
68
+ * @param {import('denque')<{ command: import('ioredis').Command }> | undefined} queue
69
+ */
70
+ function trackQueue (queue) {
71
+ for (let i = 0; i < (queue?.length ?? 0); i++) {
72
+ trackReplay(queue.get(i).command.promise)
73
+ }
74
+ }
75
+
76
+ /** @param {import('ioredis').Command['promise']} promise */
77
+ function trackReplay (promise) {
78
+ const promises = replayPromises ??= new WeakSet()
79
+ promises.add(promise)
80
+ if (!replaying) {
81
+ replaying = true
82
+ queueMicrotask(clearReplayScope)
83
+ }
84
+ }
85
+
86
+ function clearReplayScope () {
87
+ replaying = false
88
+ }
89
+
90
+ /** @param {((bucket: string) => void) | (() => void)} callback */
91
+ function wrapReplay (callback) {
92
+ return function () {
93
+ if (!replayPromises || !startCh.hasSubscribers) return callback.apply(this, arguments)
94
+ const previous = replaying
95
+ replaying = true
96
+ try {
97
+ return callback.apply(this, arguments)
98
+ } finally {
99
+ replaying = previous
100
+ }
101
+ }
102
+ }
103
+
104
+ /** @param {typeof import('ioredis/built/cluster/DelayQueue').default} DelayQueue */
105
+ function wrapDelayQueue (DelayQueue) {
106
+ const execute = DelayQueue.prototype.execute ? 'execute' : '_execute'
107
+ shimmer.wrap(DelayQueue.prototype, execute, wrapReplay)
108
+ return DelayQueue
109
+ }
110
+
111
+ /** @param {typeof import('ioredis').Cluster} Cluster */
112
+ function wrapCluster (Cluster) {
113
+ shimmer.wrap(Cluster.prototype, 'executeOfflineCommands', wrapReplay)
114
+ return Cluster
115
+ }
116
+
117
+ addHook({ name: 'ioredis', versions: ['>=6'], file: 'built/himport/HimportCoordinator.js' }, exports => {
118
+ shimmer.wrap(exports.default.prototype, 'allowNextSend', allowNextSend => function (redis, command) {
119
+ if (startCh.hasSubscribers) trackReplay(command.promise)
120
+ return allowNextSend.apply(this, arguments)
121
+ })
122
+ return exports
123
+ })
124
+
125
+ addHook({ name: 'ioredis', versions: ['>=2 <4'], file: 'lib/cluster/delay_queue.js' }, wrapDelayQueue)
126
+
127
+ addHook({ name: 'ioredis', versions: ['>=4'], file: 'built/cluster/DelayQueue.js' }, exports => {
128
+ wrapDelayQueue(exports.default)
129
+ return exports
130
+ })
131
+
132
+ addHook({ name: 'ioredis', versions: ['>=2 <4'], file: 'lib/cluster/index.js' }, wrapCluster)
133
+
134
+ addHook({ name: 'ioredis', versions: ['>=4'], file: 'built/cluster/index.js' }, exports => {
135
+ wrapCluster(exports.default || exports)
136
+ return exports
137
+ })
138
+
41
139
  addHook({ name: 'ioredis', versions: ['>=2 <4'], file: 'lib/redis.js' }, wrapRedis)
42
140
 
43
141
  addHook({ name: 'ioredis', versions: ['>=4 <4.11.0'], file: 'built/redis.js' }, wrapRedis)
@@ -5,6 +5,11 @@ const { isNativeError } = require('node:util').types
5
5
  const shimmer = require('../../datadog-shimmer')
6
6
  const nomenclature = require('../../dd-trace/src/service-naming')
7
7
  const spanEndingHook = require('../../dd-trace/src/opentelemetry/span-ending-hook')
8
+ const {
9
+ HTTP_STATUS_ERROR,
10
+ otelHttpResourceName,
11
+ setInstrumentationHttpResource,
12
+ } = require('../../dd-trace/src/plugins/util/http-otel-semantics')
8
13
  const { RESOURCE_NAME } = require('../../../ext/tags')
9
14
  const { channel, addHook } = require('./helpers/instrument')
10
15
 
@@ -67,18 +72,26 @@ const NEXT_BASE_SERVER_HANDLE_REQUEST = 'BaseServer.handleRequest'
67
72
  // own OTel spans and renames the root request span to `${method} ${route}` at finish, which the
68
73
  // bridge routes into the DD operation name and leaves the resource as the bare method — the reverse
69
74
  // of Datadog's contract. Correct it via the bridge's pre-finish hook. See span-ending-hook.js.
70
- spanEndingHook.hook = (ddSpan) => {
75
+ spanEndingHook.hook = (ddSpan, otelSemanticsEnabled) => {
71
76
  const tags = ddSpan.context().getTags()
72
77
  if (tags['next.span_type'] !== NEXT_BASE_SERVER_HANDLE_REQUEST) return
73
78
 
74
79
  const method = tags['http.method']
75
80
  const route = tags['next.route'] ?? tags['http.route']
76
- // Next already wrote the RSC-aware `${method} ${route}` into `next.span_name`; prefer it so we
77
- // mirror Next's own naming, and only construct the resource when it is absent.
78
- const resource = tags['next.span_name'] ?? (route ? `${method} ${route}` : method)
79
-
80
81
  ddSpan.setOperationName(nomenclature.opName('web', 'server', 'next'))
81
- ddSpan.setTag(RESOURCE_NAME, resource)
82
+ if (otelSemanticsEnabled) {
83
+ setInstrumentationHttpResource(ddSpan, otelHttpResourceName(method, route))
84
+ const status = tags['http.status_code']
85
+ if (status >= 500) {
86
+ ddSpan.setTag(HTTP_STATUS_ERROR, String(status))
87
+ return true
88
+ }
89
+ } else {
90
+ // Next already wrote the RSC-aware `${method} ${route}` into `next.span_name`; prefer it so we
91
+ // mirror Next's own naming, and only construct the resource when it is absent.
92
+ const resource = tags['next.span_name'] ?? (route ? `${method} ${route}` : method)
93
+ ddSpan.setTag(RESOURCE_NAME, resource)
94
+ }
82
95
  }
83
96
 
84
97
  function wrapHandleRequest (handleRequest) {
@@ -0,0 +1,149 @@
1
+ 'use strict'
2
+
3
+ const dc = require('dc-polyfill')
4
+
5
+ const { getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
6
+ const log = require('../../dd-trace/src/log')
7
+ const shimmer = require('../../datadog-shimmer')
8
+ const { attachSocketClose, createSession, realtimeEnabled } = require('./openai-realtime')
9
+
10
+ const turnChannel = dc.tracingChannel('apm:openai:realtime:turn')
11
+ const records = new WeakMap()
12
+ const listening = new WeakSet()
13
+ const defaultUrls = new WeakMap()
14
+
15
+ /** @param {string | URL} value */
16
+ function connectionOptions (value) {
17
+ const url = new URL(value)
18
+ return {
19
+ basePath: url.origin + url.pathname,
20
+ callId: url.searchParams.get('call_id') || undefined,
21
+ }
22
+ }
23
+
24
+ /** @param {object} ctx */
25
+ function listen (ctx) {
26
+ const transport = ctx.self
27
+ if (!transport || listening.has(transport)) return
28
+ try {
29
+ const url = ctx.arguments?.[0]?.url
30
+ if (url) defaultUrls.set(transport, connectionOptions(url))
31
+ // emit is inherited from agents-core's shared delegate. Orchestrion cannot skip
32
+ // its body, so wrap this instance to filter only tracer-owned request failures.
33
+ // Raw events still reach the session before any SDK/application listeners.
34
+ shimmer.wrap(transport, 'emit', emit => function (name, event) {
35
+ if (name === 'connection_change' && event === 'disconnected') {
36
+ // SDK listeners can reconnect before the old socket's close callback runs.
37
+ // Keep that callback's record alive so it still classifies the close code.
38
+ const record = records.get(this)
39
+ if (record) record.detached = true
40
+ }
41
+ if (name === '*' || name === 'error') {
42
+ const record = records.get(this)
43
+ if (record) {
44
+ const providerEvent = name === '*' ? event : event?.error
45
+ if (name === '*' && !record.closed) record.session.onServerEvent(event, Date.now())
46
+ if (record.session.isRetrievalError(providerEvent)) return false
47
+ }
48
+ }
49
+ return emit.apply(this, arguments)
50
+ })
51
+ listening.add(transport)
52
+ } catch (error) {
53
+ log.debug('Error observing Agents realtime events: %s', error?.message)
54
+ }
55
+ }
56
+
57
+ /** @param {object} ctx */
58
+ function connect (ctx) {
59
+ try {
60
+ const options = ctx.arguments?.[0] || {}
61
+ if (options.url) ctx.realtimeDefaultUrl = connectionOptions(options.url)
62
+ if (!turnChannel.start.hasSubscribers) return
63
+ listen(ctx)
64
+ const transport = ctx.self
65
+ const previous = records.get(transport)
66
+ if (previous && !previous.closed && !previous.detached) return
67
+ // Match the SDK's precedence. An explicit URL wins even when callId is also supplied.
68
+ const effective = ctx.realtimeDefaultUrl ?? (options.callId
69
+ ? connectionOptions('wss://api.openai.com/v1/realtime?call_id=' + options.callId)
70
+ : defaultUrls.get(transport) || connectionOptions('wss://api.openai.com/v1/realtime'))
71
+ const retrieveAudio = getValueFromEnvSources('DD_OPENAI_REALTIME_SIDEBAND_AUDIO_RETRIEVAL_ENABLED') !== false
72
+ const connection = createSession({
73
+ model: options.model ?? transport.currentModel,
74
+ basePath: effective.basePath,
75
+ sessionId: effective.callId,
76
+ serverPlayback: effective.callId !== undefined,
77
+ requestItem: retrieveAudio
78
+ ? (itemId, eventId) => {
79
+ if (transport.status === 'connected') {
80
+ transport.sendEvent({ type: 'conversation.item.retrieve', item_id: itemId, event_id: eventId })
81
+ }
82
+ }
83
+ : undefined,
84
+ })
85
+ const record = {
86
+ session: connection.session,
87
+ closed: false,
88
+ detached: false,
89
+ finalize: failed => {
90
+ if (record.closed) return
91
+ record.closed = true
92
+ connection.finalize(failed)
93
+ },
94
+ }
95
+ records.set(transport, record)
96
+ ctx.realtimeConnection = record
97
+ } catch (error) {
98
+ log.debug('Error starting Agents realtime instrumentation: %s', error?.message)
99
+ }
100
+ }
101
+
102
+ /** @param {object} ctx */
103
+ function connected (ctx) {
104
+ try {
105
+ if (ctx.realtimeConnectFailed) return
106
+ // The SDK retains successful URL overrides even while tracing is disabled.
107
+ if (ctx.realtimeDefaultUrl) defaultUrls.set(ctx.self, ctx.realtimeDefaultUrl)
108
+ const record = ctx.realtimeConnection
109
+ if (record && !record.closed) {
110
+ attachSocketClose({ socket: ctx.self.connectionState?.websocket }, record.finalize)
111
+ }
112
+ } catch (error) {
113
+ log.debug('Error observing Agents realtime connection: %s', error?.message)
114
+ }
115
+ }
116
+
117
+ /** @param {object} ctx */
118
+ function sent (ctx) {
119
+ const record = records.get(ctx.self)
120
+ if (record && !record.closed && !ctx.error) record.session.onClientEvent(ctx.arguments[0], Date.now())
121
+ }
122
+
123
+ /** @param {{ self: object, realtimeConnection?: { finalize: (failed?: boolean) => void } }} ctx */
124
+ function closing (ctx) {
125
+ ctx.realtimeConnection = records.get(ctx.self)
126
+ }
127
+
128
+ /** @param {object} ctx */
129
+ function closed (ctx) {
130
+ ctx.realtimeConnection?.finalize(false)
131
+ }
132
+
133
+ /** @param {object} ctx */
134
+ function failed (ctx) {
135
+ ctx.realtimeConnectFailed = true
136
+ ctx.realtimeConnection?.finalize(true)
137
+ }
138
+
139
+ if (realtimeEnabled()) {
140
+ dc.tracingChannel('orchestrion:@openai/agents-realtime:constructor').end.subscribe(listen)
141
+ const connection = dc.tracingChannel('orchestrion:@openai/agents-realtime:connect')
142
+ connection.start.subscribe(connect)
143
+ connection.asyncEnd.subscribe(connected)
144
+ connection.error.subscribe(failed)
145
+ dc.tracingChannel('orchestrion:@openai/agents-realtime:send').end.subscribe(sent)
146
+ const close = dc.tracingChannel('orchestrion:@openai/agents-realtime:close')
147
+ close.start.subscribe(closing)
148
+ close.end.subscribe(closed)
149
+ }