@sentry/server-utils 10.62.0 → 10.64.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 (257) hide show
  1. package/build/cjs/index.js +10 -2
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/tracing-channel/anthropic.js +101 -0
  4. package/build/cjs/integrations/tracing-channel/anthropic.js.map +1 -0
  5. package/build/cjs/integrations/tracing-channel/fastify/errors.js +42 -0
  6. package/build/cjs/integrations/tracing-channel/fastify/errors.js.map +1 -0
  7. package/build/cjs/integrations/tracing-channel/fastify/index.js +34 -0
  8. package/build/cjs/integrations/tracing-channel/fastify/index.js.map +1 -0
  9. package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js +279 -0
  10. package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js.map +1 -0
  11. package/build/cjs/integrations/tracing-channel/fastify/utils.js +11 -0
  12. package/build/cjs/integrations/tracing-channel/fastify/utils.js.map +1 -0
  13. package/build/cjs/integrations/tracing-channel/hapi-types.js +30 -0
  14. package/build/cjs/integrations/tracing-channel/hapi-types.js.map +1 -0
  15. package/build/cjs/integrations/tracing-channel/hapi-utils.js +177 -0
  16. package/build/cjs/integrations/tracing-channel/hapi-utils.js.map +1 -0
  17. package/build/cjs/integrations/tracing-channel/hapi.js +52 -0
  18. package/build/cjs/integrations/tracing-channel/hapi.js.map +1 -0
  19. package/build/cjs/integrations/tracing-channel/ioredis.js +96 -0
  20. package/build/cjs/integrations/tracing-channel/ioredis.js.map +1 -0
  21. package/build/cjs/integrations/tracing-channel/lru-memoizer.js +31 -0
  22. package/build/cjs/integrations/tracing-channel/lru-memoizer.js.map +1 -0
  23. package/build/cjs/integrations/tracing-channel/mysql.js +46 -83
  24. package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
  25. package/build/cjs/integrations/tracing-channel/openai.js +83 -0
  26. package/build/cjs/integrations/tracing-channel/openai.js.map +1 -0
  27. package/build/cjs/integrations/tracing-channel/postgres.js +170 -0
  28. package/build/cjs/integrations/tracing-channel/postgres.js.map +1 -0
  29. package/build/cjs/integrations/tracing-channel/vercel-ai.js +25 -0
  30. package/build/cjs/integrations/tracing-channel/vercel-ai.js.map +1 -0
  31. package/build/cjs/mongoose/index.js +23 -0
  32. package/build/cjs/mongoose/index.js.map +1 -0
  33. package/build/cjs/mongoose/mongoose-dc-subscriber.js +97 -0
  34. package/build/cjs/mongoose/mongoose-dc-subscriber.js.map +1 -0
  35. package/build/cjs/orchestrion/bundler/vite.js +3 -3
  36. package/build/cjs/orchestrion/bundler/vite.js.map +1 -1
  37. package/build/cjs/orchestrion/channels.js +17 -1
  38. package/build/cjs/orchestrion/channels.js.map +1 -1
  39. package/build/cjs/orchestrion/config/anthropic-ai.js +43 -0
  40. package/build/cjs/orchestrion/config/anthropic-ai.js.map +1 -0
  41. package/build/cjs/orchestrion/config/hapi.js +26 -0
  42. package/build/cjs/orchestrion/config/hapi.js.map +1 -0
  43. package/build/cjs/orchestrion/config/index.js +35 -0
  44. package/build/cjs/orchestrion/config/index.js.map +1 -0
  45. package/build/cjs/orchestrion/config/ioredis.js +35 -0
  46. package/build/cjs/orchestrion/config/ioredis.js.map +1 -0
  47. package/build/cjs/orchestrion/config/lru-memoizer.js +17 -0
  48. package/build/cjs/orchestrion/config/lru-memoizer.js.map +1 -0
  49. package/build/cjs/orchestrion/config/mysql.js +16 -0
  50. package/build/cjs/orchestrion/config/mysql.js.map +1 -0
  51. package/build/cjs/orchestrion/config/openai.js +40 -0
  52. package/build/cjs/orchestrion/config/openai.js.map +1 -0
  53. package/build/cjs/orchestrion/config/pg.js +51 -0
  54. package/build/cjs/orchestrion/config/pg.js.map +1 -0
  55. package/build/cjs/orchestrion/config/vercel-ai.js +44 -0
  56. package/build/cjs/orchestrion/config/vercel-ai.js.map +1 -0
  57. package/build/cjs/orchestrion/detect.js +6 -1
  58. package/build/cjs/orchestrion/detect.js.map +1 -1
  59. package/build/cjs/orchestrion/index.js +27 -3
  60. package/build/cjs/orchestrion/index.js.map +1 -1
  61. package/build/cjs/orchestrion/runtime/register.js +10 -7
  62. package/build/cjs/orchestrion/runtime/register.js.map +1 -1
  63. package/build/cjs/redis/redis-statement-serializer.js +34 -0
  64. package/build/cjs/redis/redis-statement-serializer.js.map +1 -0
  65. package/build/cjs/tracing-channel.js +50 -11
  66. package/build/cjs/tracing-channel.js.map +1 -1
  67. package/build/cjs/vercel-ai/index.js +5 -3
  68. package/build/cjs/vercel-ai/index.js.map +1 -1
  69. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +11 -4
  70. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  71. package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js +256 -0
  72. package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +1 -0
  73. package/build/esm/index.js +3 -0
  74. package/build/esm/index.js.map +1 -1
  75. package/build/esm/integrations/tracing-channel/anthropic.js +99 -0
  76. package/build/esm/integrations/tracing-channel/anthropic.js.map +1 -0
  77. package/build/esm/integrations/tracing-channel/fastify/errors.js +39 -0
  78. package/build/esm/integrations/tracing-channel/fastify/errors.js.map +1 -0
  79. package/build/esm/integrations/tracing-channel/fastify/index.js +30 -0
  80. package/build/esm/integrations/tracing-channel/fastify/index.js.map +1 -0
  81. package/build/esm/integrations/tracing-channel/fastify/instrumentation.js +277 -0
  82. package/build/esm/integrations/tracing-channel/fastify/instrumentation.js.map +1 -0
  83. package/build/esm/integrations/tracing-channel/fastify/utils.js +8 -0
  84. package/build/esm/integrations/tracing-channel/fastify/utils.js.map +1 -0
  85. package/build/esm/integrations/tracing-channel/hapi-types.js +25 -0
  86. package/build/esm/integrations/tracing-channel/hapi-types.js.map +1 -0
  87. package/build/esm/integrations/tracing-channel/hapi-utils.js +172 -0
  88. package/build/esm/integrations/tracing-channel/hapi-utils.js.map +1 -0
  89. package/build/esm/integrations/tracing-channel/hapi.js +50 -0
  90. package/build/esm/integrations/tracing-channel/hapi.js.map +1 -0
  91. package/build/esm/integrations/tracing-channel/ioredis.js +94 -0
  92. package/build/esm/integrations/tracing-channel/ioredis.js.map +1 -0
  93. package/build/esm/integrations/tracing-channel/lru-memoizer.js +29 -0
  94. package/build/esm/integrations/tracing-channel/lru-memoizer.js.map +1 -0
  95. package/build/esm/integrations/tracing-channel/mysql.js +47 -84
  96. package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
  97. package/build/esm/integrations/tracing-channel/openai.js +81 -0
  98. package/build/esm/integrations/tracing-channel/openai.js.map +1 -0
  99. package/build/esm/integrations/tracing-channel/postgres.js +168 -0
  100. package/build/esm/integrations/tracing-channel/postgres.js.map +1 -0
  101. package/build/esm/integrations/tracing-channel/vercel-ai.js +23 -0
  102. package/build/esm/integrations/tracing-channel/vercel-ai.js.map +1 -0
  103. package/build/esm/mongoose/index.js +21 -0
  104. package/build/esm/mongoose/index.js.map +1 -0
  105. package/build/esm/mongoose/mongoose-dc-subscriber.js +89 -0
  106. package/build/esm/mongoose/mongoose-dc-subscriber.js.map +1 -0
  107. package/build/esm/orchestrion/bundler/vite.js +1 -1
  108. package/build/esm/orchestrion/channels.js +17 -1
  109. package/build/esm/orchestrion/channels.js.map +1 -1
  110. package/build/esm/orchestrion/config/anthropic-ai.js +40 -0
  111. package/build/esm/orchestrion/config/anthropic-ai.js.map +1 -0
  112. package/build/esm/orchestrion/config/hapi.js +23 -0
  113. package/build/esm/orchestrion/config/hapi.js.map +1 -0
  114. package/build/esm/orchestrion/config/index.js +31 -0
  115. package/build/esm/orchestrion/config/index.js.map +1 -0
  116. package/build/esm/orchestrion/config/ioredis.js +32 -0
  117. package/build/esm/orchestrion/config/ioredis.js.map +1 -0
  118. package/build/esm/orchestrion/config/lru-memoizer.js +14 -0
  119. package/build/esm/orchestrion/config/lru-memoizer.js.map +1 -0
  120. package/build/esm/orchestrion/config/mysql.js +13 -0
  121. package/build/esm/orchestrion/config/mysql.js.map +1 -0
  122. package/build/esm/orchestrion/config/openai.js +37 -0
  123. package/build/esm/orchestrion/config/openai.js.map +1 -0
  124. package/build/esm/orchestrion/config/pg.js +48 -0
  125. package/build/esm/orchestrion/config/pg.js.map +1 -0
  126. package/build/esm/orchestrion/config/vercel-ai.js +41 -0
  127. package/build/esm/orchestrion/config/vercel-ai.js.map +1 -0
  128. package/build/esm/orchestrion/detect.js +6 -2
  129. package/build/esm/orchestrion/detect.js.map +1 -1
  130. package/build/esm/orchestrion/index.js +21 -2
  131. package/build/esm/orchestrion/index.js.map +1 -1
  132. package/build/esm/orchestrion/runtime/register.js +8 -4
  133. package/build/esm/orchestrion/runtime/register.js.map +1 -1
  134. package/build/esm/package.json +1 -1
  135. package/build/esm/redis/redis-statement-serializer.js +32 -0
  136. package/build/esm/redis/redis-statement-serializer.js.map +1 -0
  137. package/build/esm/tracing-channel.js +51 -12
  138. package/build/esm/tracing-channel.js.map +1 -1
  139. package/build/esm/vercel-ai/index.js +6 -4
  140. package/build/esm/vercel-ai/index.js.map +1 -1
  141. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +14 -8
  142. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  143. package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js +254 -0
  144. package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +1 -0
  145. package/build/types/index.d.ts +3 -0
  146. package/build/types/index.d.ts.map +1 -1
  147. package/build/types/integrations/tracing-channel/anthropic.d.ts +10 -0
  148. package/build/types/integrations/tracing-channel/anthropic.d.ts.map +1 -0
  149. package/build/types/integrations/tracing-channel/fastify/errors.d.ts +12 -0
  150. package/build/types/integrations/tracing-channel/fastify/errors.d.ts.map +1 -0
  151. package/build/types/integrations/tracing-channel/fastify/index.d.ts +66 -0
  152. package/build/types/integrations/tracing-channel/fastify/index.d.ts.map +1 -0
  153. package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts +10 -0
  154. package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts.map +1 -0
  155. package/build/types/integrations/tracing-channel/fastify/types.d.ts +32 -0
  156. package/build/types/integrations/tracing-channel/fastify/types.d.ts.map +1 -0
  157. package/build/types/integrations/tracing-channel/fastify/utils.d.ts +9 -0
  158. package/build/types/integrations/tracing-channel/fastify/utils.d.ts.map +1 -0
  159. package/build/types/integrations/tracing-channel/hapi-types.d.ts +53 -0
  160. package/build/types/integrations/tracing-channel/hapi-types.d.ts.map +1 -0
  161. package/build/types/integrations/tracing-channel/hapi-utils.d.ts +25 -0
  162. package/build/types/integrations/tracing-channel/hapi-utils.d.ts.map +1 -0
  163. package/build/types/integrations/tracing-channel/hapi.d.ts +9 -0
  164. package/build/types/integrations/tracing-channel/hapi.d.ts.map +1 -0
  165. package/build/types/integrations/tracing-channel/ioredis.d.ts +17 -0
  166. package/build/types/integrations/tracing-channel/ioredis.d.ts.map +1 -0
  167. package/build/types/integrations/tracing-channel/lru-memoizer.d.ts +10 -0
  168. package/build/types/integrations/tracing-channel/lru-memoizer.d.ts.map +1 -0
  169. package/build/types/integrations/tracing-channel/mysql.d.ts +3 -1
  170. package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
  171. package/build/types/integrations/tracing-channel/openai.d.ts +10 -0
  172. package/build/types/integrations/tracing-channel/openai.d.ts.map +1 -0
  173. package/build/types/integrations/tracing-channel/postgres.d.ts +15 -0
  174. package/build/types/integrations/tracing-channel/postgres.d.ts.map +1 -0
  175. package/build/types/integrations/tracing-channel/vercel-ai.d.ts +13 -0
  176. package/build/types/integrations/tracing-channel/vercel-ai.d.ts.map +1 -0
  177. package/build/types/mongoose/index.d.ts +11 -0
  178. package/build/types/mongoose/index.d.ts.map +1 -0
  179. package/build/types/mongoose/mongoose-dc-subscriber.d.ts +63 -0
  180. package/build/types/mongoose/mongoose-dc-subscriber.d.ts.map +1 -0
  181. package/build/types/orchestrion/channels.d.ts +21 -0
  182. package/build/types/orchestrion/channels.d.ts.map +1 -1
  183. package/build/types/orchestrion/config/anthropic-ai.d.ts +31 -0
  184. package/build/types/orchestrion/config/anthropic-ai.d.ts.map +1 -0
  185. package/build/types/orchestrion/config/hapi.d.ts +17 -0
  186. package/build/types/orchestrion/config/hapi.d.ts.map +1 -0
  187. package/build/types/orchestrion/{config.d.ts → config/index.d.ts} +1 -12
  188. package/build/types/orchestrion/config/index.d.ts.map +1 -0
  189. package/build/types/orchestrion/config/ioredis.d.ts +7 -0
  190. package/build/types/orchestrion/config/ioredis.d.ts.map +1 -0
  191. package/build/types/orchestrion/config/lru-memoizer.d.ts +16 -0
  192. package/build/types/orchestrion/config/lru-memoizer.d.ts.map +1 -0
  193. package/build/types/orchestrion/config/mysql.d.ts +16 -0
  194. package/build/types/orchestrion/config/mysql.d.ts.map +1 -0
  195. package/build/types/orchestrion/config/openai.d.ts +20 -0
  196. package/build/types/orchestrion/config/openai.d.ts.map +1 -0
  197. package/build/types/orchestrion/config/pg.d.ts +33 -0
  198. package/build/types/orchestrion/config/pg.d.ts.map +1 -0
  199. package/build/types/orchestrion/config/vercel-ai.d.ts +11 -0
  200. package/build/types/orchestrion/config/vercel-ai.d.ts.map +1 -0
  201. package/build/types/orchestrion/detect.d.ts +10 -0
  202. package/build/types/orchestrion/detect.d.ts.map +1 -1
  203. package/build/types/orchestrion/index.d.ts +53 -2
  204. package/build/types/orchestrion/index.d.ts.map +1 -1
  205. package/build/types/orchestrion/runtime/register.d.ts.map +1 -1
  206. package/build/types/redis/redis-statement-serializer.d.ts +6 -0
  207. package/build/types/redis/redis-statement-serializer.d.ts.map +1 -0
  208. package/build/types/tracing-channel.d.ts +22 -0
  209. package/build/types/tracing-channel.d.ts.map +1 -1
  210. package/build/types/vercel-ai/index.d.ts +3 -1
  211. package/build/types/vercel-ai/index.d.ts.map +1 -1
  212. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +10 -4
  213. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  214. package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts +12 -0
  215. package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts.map +1 -0
  216. package/build/types-ts3.8/index.d.ts +4 -0
  217. package/build/types-ts3.8/integrations/tracing-channel/anthropic.d.ts +10 -0
  218. package/build/types-ts3.8/integrations/tracing-channel/fastify/errors.d.ts +12 -0
  219. package/build/types-ts3.8/integrations/tracing-channel/fastify/index.d.ts +66 -0
  220. package/build/types-ts3.8/integrations/tracing-channel/fastify/instrumentation.d.ts +10 -0
  221. package/build/types-ts3.8/integrations/tracing-channel/fastify/types.d.ts +32 -0
  222. package/build/types-ts3.8/integrations/tracing-channel/fastify/utils.d.ts +9 -0
  223. package/build/types-ts3.8/integrations/tracing-channel/hapi-types.d.ts +65 -0
  224. package/build/types-ts3.8/integrations/tracing-channel/hapi-utils.d.ts +25 -0
  225. package/build/types-ts3.8/integrations/tracing-channel/hapi.d.ts +9 -0
  226. package/build/types-ts3.8/integrations/tracing-channel/ioredis.d.ts +17 -0
  227. package/build/types-ts3.8/integrations/tracing-channel/lru-memoizer.d.ts +10 -0
  228. package/build/types-ts3.8/integrations/tracing-channel/mysql.d.ts +3 -1
  229. package/build/types-ts3.8/integrations/tracing-channel/openai.d.ts +10 -0
  230. package/build/types-ts3.8/integrations/tracing-channel/postgres.d.ts +15 -0
  231. package/build/types-ts3.8/integrations/tracing-channel/vercel-ai.d.ts +13 -0
  232. package/build/types-ts3.8/mongoose/index.d.ts +11 -0
  233. package/build/types-ts3.8/mongoose/mongoose-dc-subscriber.d.ts +63 -0
  234. package/build/types-ts3.8/node-diagnostics-channel.d.ts +19 -0
  235. package/build/types-ts3.8/orchestrion/channels.d.ts +21 -0
  236. package/build/types-ts3.8/orchestrion/config/anthropic-ai.d.ts +31 -0
  237. package/build/types-ts3.8/orchestrion/config/hapi.d.ts +17 -0
  238. package/build/types-ts3.8/orchestrion/{config.d.ts → config/index.d.ts} +1 -12
  239. package/build/types-ts3.8/orchestrion/config/ioredis.d.ts +7 -0
  240. package/build/types-ts3.8/orchestrion/config/lru-memoizer.d.ts +16 -0
  241. package/build/types-ts3.8/orchestrion/config/mysql.d.ts +16 -0
  242. package/build/types-ts3.8/orchestrion/config/openai.d.ts +20 -0
  243. package/build/types-ts3.8/orchestrion/config/pg.d.ts +33 -0
  244. package/build/types-ts3.8/orchestrion/config/vercel-ai.d.ts +11 -0
  245. package/build/types-ts3.8/orchestrion/detect.d.ts +10 -0
  246. package/build/types-ts3.8/orchestrion/index.d.ts +53 -2
  247. package/build/types-ts3.8/redis/redis-statement-serializer.d.ts +6 -0
  248. package/build/types-ts3.8/tracing-channel.d.ts +22 -0
  249. package/build/types-ts3.8/vercel-ai/index.d.ts +3 -1
  250. package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +10 -4
  251. package/build/types-ts3.8/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts +12 -0
  252. package/package.json +10 -10
  253. package/build/cjs/orchestrion/config.js +0 -38
  254. package/build/cjs/orchestrion/config.js.map +0 -1
  255. package/build/esm/orchestrion/config.js +0 -34
  256. package/build/esm/orchestrion/config.js.map +0 -1
  257. package/build/types/orchestrion/config.d.ts.map +0 -1
@@ -0,0 +1,94 @@
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+ import { DB_STATEMENT, NET_PEER_PORT, NET_PEER_NAME, DB_SYSTEM } from '@sentry/conventions/attributes';
3
+ import { defineIntegration, debug, waitForTracingChannelBinding, getActiveSpan, startInactiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
4
+ import { DEBUG_BUILD } from '../../debug-build.js';
5
+ import { CHANNELS } from '../../orchestrion/channels.js';
6
+ import { defaultDbStatementSerializer } from '../../redis/redis-statement-serializer.js';
7
+ import { bindTracingChannelToSpan } from '../../tracing-channel.js';
8
+
9
+ const INTEGRATION_NAME = "IORedis";
10
+ const ORIGIN = "auto.db.orchestrion.redis";
11
+ const ATTR_DB_CONNECTION_STRING = "db.connection_string";
12
+ function getConnectionOptions(self) {
13
+ return { host: self?.options?.host, port: self?.options?.port };
14
+ }
15
+ function connectionAttributes(host, port) {
16
+ return {
17
+ [DB_SYSTEM]: "redis",
18
+ [ATTR_DB_CONNECTION_STRING]: `redis://${host}:${port}`,
19
+ [NET_PEER_NAME]: host,
20
+ [NET_PEER_PORT]: port,
21
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN
22
+ };
23
+ }
24
+ const _ioredisChannelIntegration = ((options = {}) => {
25
+ const responseHook = options.responseHook;
26
+ return {
27
+ name: INTEGRATION_NAME,
28
+ setupOnce() {
29
+ if (!diagnosticsChannel.tracingChannel) {
30
+ return;
31
+ }
32
+ DEBUG_BUILD && debug.log(`[orchestrion:ioredis] subscribing to "${CHANNELS.IOREDIS_COMMAND}"/"${CHANNELS.IOREDIS_CONNECT}"`);
33
+ const commandChannel = diagnosticsChannel.tracingChannel(
34
+ CHANNELS.IOREDIS_COMMAND
35
+ );
36
+ const connectChannel = diagnosticsChannel.tracingChannel(
37
+ CHANNELS.IOREDIS_CONNECT
38
+ );
39
+ waitForTracingChannelBinding(() => {
40
+ bindTracingChannelToSpan(
41
+ commandChannel,
42
+ (data) => {
43
+ if (!getActiveSpan()) {
44
+ return void 0;
45
+ }
46
+ const command = data.arguments?.[0];
47
+ if (!command || typeof command !== "object") {
48
+ return void 0;
49
+ }
50
+ const { host, port } = getConnectionOptions(data.self);
51
+ const statement = defaultDbStatementSerializer(command.name, command.args ?? []);
52
+ return startInactiveSpan({
53
+ name: statement,
54
+ op: "db",
55
+ attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: statement }
56
+ });
57
+ },
58
+ {
59
+ beforeSpanEnd(span, data) {
60
+ if ("error" in data || !responseHook) {
61
+ return;
62
+ }
63
+ const command = data.arguments?.[0];
64
+ if (command) {
65
+ runResponseHook(responseHook, span, command, data.result);
66
+ }
67
+ }
68
+ }
69
+ );
70
+ bindTracingChannelToSpan(connectChannel, (data) => {
71
+ if (!getActiveSpan()) {
72
+ return void 0;
73
+ }
74
+ const { host, port } = getConnectionOptions(data.self);
75
+ return startInactiveSpan({
76
+ name: "connect",
77
+ op: "db",
78
+ attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: "connect" }
79
+ });
80
+ });
81
+ });
82
+ }
83
+ };
84
+ });
85
+ function runResponseHook(hook, span, command, result) {
86
+ try {
87
+ hook(span, command.name, command.args, result);
88
+ } catch {
89
+ }
90
+ }
91
+ const ioredisChannelIntegration = defineIntegration(_ioredisChannelIntegration);
92
+
93
+ export { ioredisChannelIntegration };
94
+ //# sourceMappingURL=ioredis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ioredis.js","sources":["../../../../src/integrations/tracing-channel/ioredis.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated -- we intentionally emit the OLD db/net semconv\n to match `@opentelemetry/instrumentation-ioredis` (and Sentry's `inferDbSpanData`, which keys off\n `db.statement`). TODO(v11): switch to the non-deprecated `db.system.name`/`db.query.text`/\n `server.address`/`server.port` conventions and drop this disable. */\nimport * as diagnosticsChannel from 'node:diagnostics_channel';\nimport { DB_STATEMENT, DB_SYSTEM, NET_PEER_NAME, NET_PEER_PORT } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n debug,\n defineIntegration,\n getActiveSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { defaultDbStatementSerializer } from '../../redis/redis-statement-serializer';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Distinct from the OTel `Redis` integration, which is composite (node-redis +\n// ioredis + the >=5.11.0 diagnostics_channel subscriber) and stays in the set;\n// only its ioredis monkey-patch is gated off in the node SDK when this is active.\nconst INTEGRATION_NAME = 'IORedis' as const;\n\nconst ORIGIN = 'auto.db.orchestrion.redis';\n\n// todo(v11): Let's drop this as this is already covered with host and port\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\n\n/** Mirrors `@opentelemetry/instrumentation-ioredis`' response hook. Not called for failed commands. */\nexport type IORedisResponseHook = (span: Span, command: string, args: Array<string | Buffer>, result: unknown) => void;\n\nexport interface IORedisChannelIntegrationOptions {\n responseHook?: IORedisResponseHook;\n}\n\n/** Structural type for the command object ioredis passes to `sendCommand`. */\ninterface RedisCommand {\n name: string;\n args: Array<string | Buffer>;\n}\n\ninterface RedisClientLike {\n options?: { host?: string; port?: number };\n}\n\ninterface IORedisCommandContext {\n arguments?: unknown[];\n self?: RedisClientLike;\n result?: unknown;\n error?: unknown;\n}\n\ntype IORedisConnectContext = Omit<IORedisCommandContext, 'arguments'>;\n\nfunction getConnectionOptions(self: RedisClientLike | undefined): { host?: string; port?: number } {\n return { host: self?.options?.host, port: self?.options?.port };\n}\n\nfunction connectionAttributes(host: string | undefined, port: number | undefined): Record<string, unknown> {\n return {\n [DB_SYSTEM]: 'redis',\n [ATTR_DB_CONNECTION_STRING]: `redis://${host}:${port}`,\n [NET_PEER_NAME]: host,\n [NET_PEER_PORT]: port,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n };\n}\n\nconst _ioredisChannelIntegration = ((options: IORedisChannelIntegrationOptions = {}) => {\n const responseHook = options.responseHook;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD &&\n debug.log(`[orchestrion:ioredis] subscribing to \"${CHANNELS.IOREDIS_COMMAND}\"/\"${CHANNELS.IOREDIS_CONNECT}\"`);\n\n const commandChannel = diagnosticsChannel.tracingChannel<IORedisCommandContext, IORedisCommandContext>(\n CHANNELS.IOREDIS_COMMAND,\n );\n const connectChannel = diagnosticsChannel.tracingChannel<IORedisConnectContext, IORedisConnectContext>(\n CHANNELS.IOREDIS_CONNECT,\n );\n\n // `bindTracingChannelToSpan` uses `bindStore`, which needs the async-context\n // binding that `initOpenTelemetry()` registers after integration `setupOnce` —\n // defer until it's available (matches the native redis diagnostics-channel subscriber).\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(\n commandChannel,\n data => {\n // ioredis' `requireParentSpan` default: only create a span under an active span.\n if (!getActiveSpan()) {\n return undefined;\n }\n const command = data.arguments?.[0] as RedisCommand | undefined;\n if (!command || typeof command !== 'object') {\n return undefined;\n }\n const { host, port } = getConnectionOptions(data.self);\n const statement = defaultDbStatementSerializer(command.name, command.args ?? []);\n return startInactiveSpan({\n name: statement,\n op: 'db',\n attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: statement },\n });\n },\n {\n beforeSpanEnd(span, data) {\n if ('error' in data || !responseHook) {\n return;\n }\n const command = data.arguments?.[0] as RedisCommand | undefined;\n if (command) {\n runResponseHook(responseHook, span, command, data.result);\n }\n },\n },\n );\n\n bindTracingChannelToSpan(connectChannel, data => {\n if (!getActiveSpan()) {\n return undefined;\n }\n const { host, port } = getConnectionOptions(data.self);\n return startInactiveSpan({\n name: 'connect',\n op: 'db',\n attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: 'connect' },\n });\n });\n });\n },\n };\n}) satisfies IntegrationFn;\n\nfunction runResponseHook(hook: IORedisResponseHook, span: Span, command: RedisCommand, result: unknown): void {\n try {\n hook(span, command.name, command.args, result);\n } catch {\n // never let a user-provided response hook break instrumentation\n }\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven ioredis integration. Subscribes to\n * `orchestrion:ioredis:command` / `:connect` (injected into ioredis' `<5.11.0`\n * `sendCommand`/`connect`) and creates db spans matching\n * `@opentelemetry/instrumentation-ioredis`. Requires the orchestrion runtime hook\n * or bundler plugin.\n */\nexport const ioredisChannelIntegration = defineIntegration(_ioredisChannelIntegration);\n"],"names":[],"mappings":";;;;;;;;AAuBA,MAAM,gBAAA,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EAAA,EAAI,IAAA;AAAA,YACJ,UAAA,EAAY,EAAE,GAAG,oBAAA,CAAqB,IAAA,EAAM,IAAI,CAAA,EAAG,CAAC,YAAY,GAAG,SAAA;AAAU,WAC9E,CAAA;AAAA,QACH,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAA,CAAA;AAEA,SAAS,eAAA,CAAgB,IAAA,EAA2B,IAAA,EAAY,OAAA,EAAuB,MAAA,EAAuB;AAC5G,EAAA,IAAI;AACF,IAAA,IAAA,CAAK,IAAA,EAAM,OAAA,CAAQ,IAAA,EAAM,OAAA,CAAQ,MAAM,MAAM,CAAA;AAAA,EAC/C,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;AASO,MAAM,yBAAA,GAA4B,kBAAkB,0BAA0B;;;;"}
@@ -0,0 +1,29 @@
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+ import { defineIntegration, debug, waitForTracingChannelBinding } from '@sentry/core';
3
+ import { DEBUG_BUILD } from '../../debug-build.js';
4
+ import { CHANNELS } from '../../orchestrion/channels.js';
5
+ import { bindTracingChannelToSpan } from '../../tracing-channel.js';
6
+
7
+ const INTEGRATION_NAME = "LruMemoizer";
8
+ const _lruMemoizerChannelIntegration = (() => {
9
+ return {
10
+ name: INTEGRATION_NAME,
11
+ setupOnce() {
12
+ if (!diagnosticsChannel.tracingChannel) {
13
+ return;
14
+ }
15
+ DEBUG_BUILD && debug.log(`[orchestrion:lru-memoizer] subscribing to channel "${CHANNELS.LRU_MEMOIZER_LOAD}"`);
16
+ waitForTracingChannelBinding(() => {
17
+ bindTracingChannelToSpan(
18
+ diagnosticsChannel.tracingChannel(CHANNELS.LRU_MEMOIZER_LOAD),
19
+ // We only want the helper's caller-context restore for the callback lru-memoizer fires from a detached `setImmediate`.
20
+ () => void 0
21
+ );
22
+ });
23
+ }
24
+ };
25
+ });
26
+ const lruMemoizerChannelIntegration = defineIntegration(_lruMemoizerChannelIntegration);
27
+
28
+ export { lruMemoizerChannelIntegration };
29
+ //# sourceMappingURL=lru-memoizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru-memoizer.js","sources":["../../../../src/integrations/tracing-channel/lru-memoizer.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn } from '@sentry/core';\nimport { debug, defineIntegration, waitForTracingChannelBinding } from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Same name as the OTel integration by design — when enabled, the OTel\n// 'LruMemoizer' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'LruMemoizer' as const;\n\ninterface LruMemoizerLoadContext {\n arguments: unknown[];\n}\n\nconst _lruMemoizerChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`[orchestrion:lru-memoizer] subscribing to channel \"${CHANNELS.LRU_MEMOIZER_LOAD}\"`);\n\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<LruMemoizerLoadContext>(CHANNELS.LRU_MEMOIZER_LOAD),\n // We only want the helper's caller-context restore for the callback lru-memoizer fires from a detached `setImmediate`.\n () => undefined,\n );\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * EXPERIMENTAL — orchestrion-driven lru-memoizer integration. Subscribes to\n * `orchestrion:lru-memoizer:load` (injected into `lru-memoizer/lib/async.js`'s\n * `memoizedFunction`). Creates no spans; only re-runs the memoized callback with the\n * caller's scope. Requires the orchestrion runtime hook or bundler plugin.\n */\nexport const lruMemoizerChannelIntegration = defineIntegration(_lruMemoizerChannelIntegration);\n"],"names":[],"mappings":";;;;;;AASA,MAAM,gBAAA,GAAmB,aAAA;AAMzB,MAAM,kCAAkC,MAAM;AAC5C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAAC,mBAAmB,cAAA,EAAgB;AACtC,QAAA;AAAA,MACF;AAEA,MAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,CAAA,mDAAA,EAAsD,QAAA,CAAS,iBAAiB,CAAA,CAAA,CAAG,CAAA;AAE5G,MAAA,4BAAA,CAA6B,MAAM;AACjC,QAAA,wBAAA;AAAA,UACE,kBAAA,CAAmB,cAAA,CAAuC,QAAA,CAAS,iBAAiB,CAAA;AAAA;AAAA,UAEpF,MAAM;AAAA,SACR;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAA,CAAA;AAQO,MAAM,6BAAA,GAAgC,kBAAkB,8BAA8B;;;;"}
@@ -1,7 +1,8 @@
1
- import * as dc from 'node:diagnostics_channel';
2
- import { defineIntegration, debug, SPAN_STATUS_ERROR, bindScopeToEmitter, startInactiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getCurrentScope, withScope } from '@sentry/core';
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+ import { defineIntegration, debug, waitForTracingChannelBinding, getCurrentScope, startInactiveSpan, SPAN_KIND, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, bindScopeToEmitter } from '@sentry/core';
3
3
  import { DEBUG_BUILD } from '../../debug-build.js';
4
4
  import { CHANNELS } from '../../orchestrion/channels.js';
5
+ import { bindTracingChannelToSpan } from '../../tracing-channel.js';
5
6
 
6
7
  const INTEGRATION_NAME = "Mysql";
7
8
  const ATTR_DB_SYSTEM = "db.system";
@@ -15,92 +16,54 @@ const _mysqlChannelIntegration = (() => {
15
16
  return {
16
17
  name: INTEGRATION_NAME,
17
18
  setupOnce() {
19
+ if (!diagnosticsChannel.tracingChannel) {
20
+ return;
21
+ }
18
22
  DEBUG_BUILD && debug.log(`[orchestrion:mysql] subscribing to channel "${CHANNELS.MYSQL_QUERY}"`);
19
- const queryCh = dc.tracingChannel(CHANNELS.MYSQL_QUERY);
20
- const spans = /* @__PURE__ */ new WeakMap();
21
- const parentScopes = /* @__PURE__ */ new WeakMap();
22
- queryCh.subscribe({
23
- start(rawCtx) {
24
- const ctx = rawCtx;
25
- const sql = extractSql(ctx.arguments[0]);
26
- const { host, port, database, user } = getConnectionConfig(ctx.self);
27
- const portNumber = typeof port === "string" ? parseInt(port, 10) : port;
28
- const portIsNumber = typeof portNumber === "number" && !isNaN(portNumber);
29
- const span = startInactiveSpan({
30
- name: sql ?? "mysql.query",
31
- op: "db",
32
- attributes: {
33
- [ATTR_DB_SYSTEM]: "mysql",
34
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.db.orchestrion.mysql",
35
- [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, portIsNumber ? portNumber : void 0, database),
36
- ...database ? { [ATTR_DB_NAME]: database } : {},
37
- ...user ? { [ATTR_DB_USER]: user } : {},
38
- ...sql ? { [ATTR_DB_STATEMENT]: sql } : {},
39
- ...host ? { [ATTR_NET_PEER_NAME]: host } : {},
40
- ...portIsNumber ? { [ATTR_NET_PEER_PORT]: portNumber } : {}
41
- }
42
- });
43
- spans.set(rawCtx, span);
44
- const scope = getCurrentScope();
45
- parentScopes.set(rawCtx, scope);
46
- if (ctx.arguments.length > 0) {
47
- const cbIdx = ctx.arguments.length - 1;
48
- const orchestrionWrappedCb = ctx.arguments[cbIdx];
49
- if (typeof orchestrionWrappedCb === "function") {
50
- const wrapped = orchestrionWrappedCb;
51
- ctx.arguments[cbIdx] = function(...args) {
52
- return withScope(scope, () => wrapped.apply(this, args));
53
- };
54
- }
55
- }
56
- },
57
- end(rawCtx) {
58
- const ctx = rawCtx;
59
- if (ctx.error !== void 0) {
60
- finishSpan(rawCtx);
61
- return;
62
- }
63
- const result = ctx.result;
64
- if (result && typeof result === "object" && hasOnMethod(result)) {
65
- const span = spans.get(rawCtx);
66
- if (!span) return;
67
- const parentScope = parentScopes.get(rawCtx);
68
- if (parentScope) {
69
- bindScopeToEmitter(result, parentScope);
70
- }
71
- result.on("error", (err) => {
72
- span.setStatus({
73
- code: SPAN_STATUS_ERROR,
74
- message: err instanceof Error ? err.message : "unknown_error"
75
- });
76
- finishSpan(rawCtx);
23
+ waitForTracingChannelBinding(() => {
24
+ bindTracingChannelToSpan(
25
+ diagnosticsChannel.tracingChannel(CHANNELS.MYSQL_QUERY),
26
+ (data) => {
27
+ const sql = extractSql(data.arguments[0]);
28
+ const { host, port, database, user } = getConnectionConfig(data.self);
29
+ const portNumber = typeof port === "string" ? parseInt(port, 10) : port;
30
+ const portIsNumber = typeof portNumber === "number" && !isNaN(portNumber);
31
+ data._sentryCallerScope = getCurrentScope();
32
+ return startInactiveSpan({
33
+ name: sql ?? "mysql.query",
34
+ kind: SPAN_KIND.CLIENT,
35
+ op: "db",
36
+ attributes: {
37
+ [ATTR_DB_SYSTEM]: "mysql",
38
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.db.orchestrion.mysql",
39
+ [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, portIsNumber ? portNumber : void 0, database),
40
+ ...database ? { [ATTR_DB_NAME]: database } : {},
41
+ ...user ? { [ATTR_DB_USER]: user } : {},
42
+ ...sql ? { [ATTR_DB_STATEMENT]: sql } : {},
43
+ ...host ? { [ATTR_NET_PEER_NAME]: host } : {},
44
+ ...portIsNumber ? { [ATTR_NET_PEER_PORT]: portNumber } : {}
45
+ }
77
46
  });
78
- result.on("end", () => finishSpan(rawCtx));
79
- return;
47
+ },
48
+ {
49
+ // No-callback `query(sql)` returns a streamable `Query` emitter as `result`; it settles on the
50
+ // emitter's `'end'`/`'error'`, not the channel, so defer ending to those.
51
+ deferSpanEnd({ data, end }) {
52
+ const result = data.result;
53
+ if (!result || typeof result !== "object" || !hasOnMethod(result)) {
54
+ return false;
55
+ }
56
+ const callerScope = data._sentryCallerScope;
57
+ if (callerScope) {
58
+ bindScopeToEmitter(result, callerScope);
59
+ }
60
+ result.on("error", (err) => end(err));
61
+ result.on("end", () => end());
62
+ return true;
63
+ }
80
64
  }
81
- },
82
- error(rawCtx) {
83
- const ctx = rawCtx;
84
- const span = spans.get(rawCtx);
85
- if (!span) return;
86
- span.setStatus({
87
- code: SPAN_STATUS_ERROR,
88
- message: ctx.error instanceof Error ? ctx.error.message : "unknown_error"
89
- });
90
- },
91
- asyncStart() {
92
- },
93
- asyncEnd(rawCtx) {
94
- finishSpan(rawCtx);
95
- }
65
+ );
96
66
  });
97
- function finishSpan(rawCtx) {
98
- const span = spans.get(rawCtx);
99
- if (!span) return;
100
- span.end();
101
- spans.delete(rawCtx);
102
- parentScopes.delete(rawCtx);
103
- }
104
67
  }
105
68
  };
106
69
  });
@@ -1 +1 @@
1
- {"version":3,"file":"mysql.js","sources":["../../../../src/integrations/tracing-channel/mysql.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, Scope, Span } from '@sentry/core';\nimport {\n bindScopeToEmitter,\n debug,\n defineIntegration,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n withScope,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\n\n// NOTE: this uses the same name as the OTel integration by design.\n// When enabled, OTel 'Mysql' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Mysql';\n\n// OpenTelemetry \"OLD\" db/net semantic-conventions. We inline them rather than\n// importing `@opentelemetry/semantic-conventions` to keep this integration's\n// dependency surface free of OTel — orchestrion's whole point is to step away\n// from the OTel auto-instrumentation stack.\n//\n// We emit the OLD conventions to match `@opentelemetry/instrumentation-mysql`'s\n// default (it only emits the stable `db.system.name` / `db.query.text` set when\n// `OTEL_SEMCONV_STABILITY_OPT_IN=database` is opted into) and the rest of the\n// Sentry JS SDK, whose `inferDbSpanData` processor renames spans based on\n// `db.statement`.\nconst ATTR_DB_SYSTEM = 'db.system';\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\nconst ATTR_DB_NAME = 'db.name';\nconst ATTR_DB_USER = 'db.user';\nconst ATTR_DB_STATEMENT = 'db.statement';\nconst ATTR_NET_PEER_NAME = 'net.peer.name';\nconst ATTR_NET_PEER_PORT = 'net.peer.port';\n\n/**\n * The shape orchestrion's wrapCallback transform attaches to the tracing-channel\n * `context` object. Documented here rather than imported because orchestrion's\n * runtime doesn't export it — see `node_modules/@apm-js-collab/code-transformer/lib/transforms.js`.\n *\n * `arguments` is the *live* args array passed to the wrapped function: orchestrion\n * splices the user's callback out and inserts its own wrapper at the same index\n * before publishing `start`. The `start` hook re-wraps that entry to restore the\n * caller's scope across mysql's async callback dispatch (see below).\n */\ninterface MysqlQueryChannelContext {\n arguments: unknown[];\n self?: MysqlConnection;\n moduleVersion?: string;\n result?: unknown;\n error?: unknown;\n}\n\ninterface MysqlConnectionConfig {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n // Pool connections nest the real config one level deeper.\n connectionConfig?: MysqlConnectionConfig;\n}\n\ninterface MysqlConnection {\n config?: MysqlConnectionConfig;\n}\n\nconst _mysqlChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n DEBUG_BUILD && debug.log(`[orchestrion:mysql] subscribing to channel \"${CHANNELS.MYSQL_QUERY}\"`);\n const queryCh = diagnosticsChannel.tracingChannel(CHANNELS.MYSQL_QUERY);\n\n // Orchestrion creates one `context` object per call, shared across all\n // lifecycle hooks. We key both maps off that identity; `WeakMap` so an\n // unfinished path can't leak its entries.\n const spans = new WeakMap<object, Span>();\n // The scope active when the query was issued, consumed in `end` to bind\n // the streamed `Query` emitter's listeners to it.\n const parentScopes = new WeakMap<object, Scope>();\n\n // `subscribe()` requires all five lifecycle hooks. The orchestrion\n // `wrapAuto` transform fires events in one of four orders depending on\n // call shape:\n // - sync throw : start → error → end\n // (NO asyncEnd)\n // - async-callback error : start → end → error →\n // asyncStart → asyncEnd\n // - async-callback success : start → end → asyncStart →\n // asyncEnd\n // - no-callback (streamable Query) : start → end\n // (ctx.result is the Query\n // emitter, no async events)\n //\n // Where the span closes depends on the path: `asyncEnd` for callbacks (so\n // it spans the full round-trip + callback), or `end` for the sync-throw\n // and streamable paths. The `end` hook tells those apart via `ctx.error`\n // / `ctx.result` — see there.\n queryCh.subscribe({\n start(rawCtx) {\n const ctx = rawCtx as MysqlQueryChannelContext;\n const sql = extractSql(ctx.arguments[0]);\n const { host, port, database, user } = getConnectionConfig(ctx.self);\n const portNumber = typeof port === 'string' ? parseInt(port, 10) : port;\n const portIsNumber = typeof portNumber === 'number' && !isNaN(portNumber);\n\n const span = startInactiveSpan({\n name: sql ?? 'mysql.query',\n op: 'db',\n attributes: {\n [ATTR_DB_SYSTEM]: 'mysql',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.orchestrion.mysql',\n [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, portIsNumber ? portNumber : undefined, database),\n ...(database ? { [ATTR_DB_NAME]: database } : {}),\n ...(user ? { [ATTR_DB_USER]: user } : {}),\n ...(sql ? { [ATTR_DB_STATEMENT]: sql } : {}),\n ...(host ? { [ATTR_NET_PEER_NAME]: host } : {}),\n ...(portIsNumber ? { [ATTR_NET_PEER_PORT]: portNumber } : {}),\n },\n });\n spans.set(rawCtx, span);\n\n // Capture the scope while we're still synchronously inside the\n // caller's `connection.query` call. mysql v2 drains callbacks and\n // emits streamed-query events from its socket data handler, where the\n // AsyncLocalStorage store backing the active span no longer reflects\n // the caller's context — and `asyncStart`/`asyncEnd` fire from that\n // same lost context, so capturing has to happen now.\n const scope = getCurrentScope();\n parentScopes.set(rawCtx, scope);\n\n // Callback path: orchestrion has spliced the user's callback out of\n // `ctx.arguments` and put its own wrapper (`__apm$wrappedCb`) at the\n // same index. Re-wrap it so the callback — and any nested\n // `connection.query(...)` — runs with the captured scope active.\n if (ctx.arguments.length > 0) {\n const cbIdx = ctx.arguments.length - 1;\n const orchestrionWrappedCb = ctx.arguments[cbIdx];\n if (typeof orchestrionWrappedCb === 'function') {\n const wrapped = orchestrionWrappedCb as (...a: unknown[]) => unknown;\n ctx.arguments[cbIdx] = function (this: unknown, ...args: unknown[]): unknown {\n return withScope(scope, () => wrapped.apply(this, args));\n };\n }\n }\n },\n\n end(rawCtx) {\n const ctx = rawCtx as MysqlQueryChannelContext;\n\n // Sync throw: `end` fires AFTER `error` (both inside the wrapper's\n // `try/catch/finally`), so `ctx.error` is already set. Close the\n // span now since no `asyncEnd` will fire.\n if (ctx.error !== undefined) {\n finishSpan(rawCtx);\n return;\n }\n\n // No-callback (streamable Query) path: orchestrion's `wrapPromise`\n // stores the synchronous return value on `ctx.result` and never\n // fires `asyncStart`/`asyncEnd`. The returned `Query` is an\n // `EventEmitter` that emits `'end'` on success and `'error'` on\n // failure — hook those to close the span.\n // Note: a streamed span never finishes if the connection is destroyed\n // mid-flight — mysql then emits neither `'end'` nor `'error'`, so the\n // span is dropped (the `WeakMap` still prevents a leak). Closing this\n // needs connection-level hooks the per-query context doesn't expose.\n const result = ctx.result;\n if (result && typeof result === 'object' && hasOnMethod(result)) {\n const span = spans.get(rawCtx);\n if (!span) return;\n\n // Bind the captured scope to the streamed `Query` emitter: its\n // `'end'`/`'error'`/`'fields'`/… events fire from mysql's socket\n // handler with the caller's context lost, so without this a span\n // started in a user's stream listener would begin a fresh root trace\n // instead of nesting under the parent. `bindScopeToEmitter` patches\n // `on`/`addListener`/… so listeners added after `query()` returns\n // inherit the scope (like OTel's `context.bind`).\n const parentScope = parentScopes.get(rawCtx);\n if (parentScope) {\n bindScopeToEmitter(result, parentScope);\n }\n\n result.on('error', err => {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: err instanceof Error ? err.message : 'unknown_error',\n });\n // Defensive: end the span here too in case `'end'` never fires\n // (e.g. abrupt socket destruction). `finishSpan` is idempotent —\n // `spans.delete` makes the subsequent `'end'` listener a no-op.\n finishSpan(rawCtx);\n });\n result.on('end', () => finishSpan(rawCtx));\n return;\n }\n\n // Callback path: `asyncEnd` will close the span. Nothing to do here.\n },\n\n error(rawCtx) {\n const ctx = rawCtx as MysqlQueryChannelContext;\n const span = spans.get(rawCtx);\n if (!span) return;\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: ctx.error instanceof Error ? ctx.error.message : 'unknown_error',\n });\n },\n\n asyncStart() {\n // No-op: we end on `asyncEnd` so the span covers the full callback duration.\n },\n\n asyncEnd(rawCtx) {\n finishSpan(rawCtx);\n },\n });\n\n function finishSpan(rawCtx: object): void {\n const span = spans.get(rawCtx);\n if (!span) return;\n span.end();\n spans.delete(rawCtx);\n parentScopes.delete(rawCtx);\n }\n },\n };\n}) satisfies IntegrationFn;\n\nfunction hasOnMethod(obj: object): obj is { on: (event: string, listener: (arg?: unknown) => void) => unknown } {\n return 'on' in obj && typeof (obj as { on?: unknown }).on === 'function';\n}\n\nfunction extractSql(firstArg: unknown): string | undefined {\n if (typeof firstArg === 'string') {\n return firstArg;\n }\n if (firstArg && typeof firstArg === 'object' && 'sql' in firstArg) {\n const sql = (firstArg as { sql?: unknown }).sql;\n return typeof sql === 'string' ? sql : undefined;\n }\n return undefined;\n}\n\nfunction getConnectionConfig(connection: MysqlConnection | undefined): {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n} {\n // Pool connections nest the real config under `.connectionConfig`; single\n // connections expose it directly. Matches `@opentelemetry/instrumentation-mysql`.\n const config = connection?.config?.connectionConfig ?? connection?.config ?? {};\n return {\n host: config.host,\n port: config.port,\n database: config.database,\n user: config.user,\n };\n}\n\nfunction getJDBCString(host: string | undefined, port: number | undefined, database: string | undefined): string {\n let s = `jdbc:mysql://${host || 'localhost'}`;\n if (typeof port === 'number') {\n s += `:${port}`;\n }\n if (database) {\n s += `/${database}`;\n }\n return s;\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven mysql integration.\n *\n * Subscribes to the `orchestrion:mysql:query` diagnostics_channel that the\n * orchestrion code transform injects into `mysql/lib/Connection.js`'s\n * `Connection.prototype.query`. Requires the orchestrion runtime hook or\n * bundler plugin to be active — wire that up via `_experimentalSetupOrchestrion`.\n */\nexport const mysqlChannelIntegration = defineIntegration(_mysqlChannelIntegration);\n"],"names":["diagnosticsChannel"],"mappings":";;;;;AAiBA,MAAM,gBAAA,GAAmB,OAAA;AAYzB,MAAM,cAAA,GAAiB,WAAA;AACvB,MAAM,yBAAA,GAA4B,sBAAA;AAClC,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,iBAAA,GAAoB,cAAA;AAC1B,MAAM,kBAAA,GAAqB,eAAA;AAC3B,MAAM,kBAAA,GAAqB,eAAA;AAiC3B,MAAM,4BAA4B,MAAM;AACtC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,CAAA,4CAAA,EAA+C,QAAA,CAAS,WAAW,CAAA,CAAA,CAAG,CAAA;AAC/F,MAAA,MAAM,OAAA,GAAUA,EAAA,CAAmB,cAAA,CAAe,QAAA,CAAS,WAAW,CAAA;AAKtE,MAAA,MAAM,KAAA,uBAAY,OAAA,EAAsB;AAGxC,MAAA,MAAM,YAAA,uBAAmB,OAAA,EAAuB;AAmBhD,MAAA,OAAA,CAAQ,SAAA,CAAU;AAAA,QAChB,MAAM,MAAA,EAAQ;AACZ,UAAA,MAAM,GAAA,GAAM,MAAA;AACZ,UAAA,MAAM,GAAA,GAAM,UAAA,CAAW,GAAA,CAAI,SAAA,CAAU,CAAC,CAAC,CAAA;AACvC,UAAA,MAAM,EAAE,MAAM,IAAA,EAAM,QAAA,EAAU,MAAK,GAAI,mBAAA,CAAoB,IAAI,IAAI,CAAA;AACnE,UAAA,MAAM,aAAa,OAAO,IAAA,KAAS,WAAW,QAAA,CA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AAA,EAK3B;AAGA,EAAA,MAAM,SAAS,UAAA,EAAY,MAAA,EAAQ,gBAAA,IAAoB,UAAA,EAAY,UAAU,EAAC;AAC9E,EAAA,OAAO;AAAA,IACL,MAAM,MAAA,CAAO,IAAA;AAAA,IACb,MAAM,MAAA,CAAO,IAAA;AAAA,IACb,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,MAAM,MAAA,CAAO;AAAA,GACf;AACF;AAEA,SAAS,aAAA,CAAc,IAAA,EAA0B,IAAA,EAA0B,QAAA,EAAsC;AAC/G,EAAA,IAAI,CAAA,GAAI,CAAA,aAAA,EAAgB,IAAA,IAAQ,WAAW,CAAA,CAAA;AAC3C,EAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,IAAA,CAAA,IAAK,IAAI,IAAI,CAAA,CAAA;AAAA,EACf;AACA,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,CAAA,IAAK,IAAI,QAAQ,CAAA,CAAA;AAAA,EACnB;AACA,EAAA,OAAO,CAAA;AACT;AAUO,MAAM,uBAAA,GAA0B,kBAAkB,wBAAwB;;;;"}
1
+ {"version":3,"file":"mysql.js","sources":["../../../../src/integrations/tracing-channel/mysql.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, Scope } from '@sentry/core';\nimport {\n bindScopeToEmitter,\n debug,\n defineIntegration,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// NOTE: this uses the same name as the OTel integration by design.\n// When enabled, OTel 'Mysql' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Mysql' as const;\n\n// OTel \"OLD\" db/net semantic-conventions, inlined to keep this integration free of OTel deps. Matches\n// `@opentelemetry/instrumentation-mysql`'s default and the SDK's `inferDbSpanData` (which renames spans\n// off `db.statement`).\nconst ATTR_DB_SYSTEM = 'db.system';\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\nconst ATTR_DB_NAME = 'db.name';\nconst ATTR_DB_USER = 'db.user';\nconst ATTR_DB_STATEMENT = 'db.statement';\nconst ATTR_NET_PEER_NAME = 'net.peer.name';\nconst ATTR_NET_PEER_PORT = 'net.peer.port';\n\n/**\n * The shape orchestrion's transform attaches to the tracing-channel `context` object. Documented here\n * rather than imported because orchestrion's runtime doesn't export it.\n */\ninterface MysqlQueryChannelContext {\n // The live args array passed to the wrapped `connection.query` call; `arguments[0]` is the SQL.\n arguments: unknown[];\n self?: MysqlConnection;\n moduleVersion?: string;\n result?: unknown;\n error?: unknown;\n // The caller's scope, captured at `start` and replayed onto the streamed `Query` emitter (see below).\n _sentryCallerScope?: Scope;\n}\n\ninterface MysqlConnectionConfig {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n // Pool connections nest the real config one level deeper.\n connectionConfig?: MysqlConnectionConfig;\n}\n\ninterface MysqlConnection {\n config?: MysqlConnectionConfig;\n}\n\nconst _mysqlChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`[orchestrion:mysql] subscribing to channel \"${CHANNELS.MYSQL_QUERY}\"`);\n\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<MysqlQueryChannelContext>(CHANNELS.MYSQL_QUERY),\n data => {\n const sql = extractSql(data.arguments[0]);\n const { host, port, database, user } = getConnectionConfig(data.self);\n const portNumber = typeof port === 'string' ? parseInt(port, 10) : port;\n const portIsNumber = typeof portNumber === 'number' && !isNaN(portNumber);\n\n // For the streamed path: mysql emits the `Query` emitter's events from its socket data\n // handler with the caller's context lost. `deferSpanEnd` replays this scope onto the emitter.\n data._sentryCallerScope = getCurrentScope();\n\n return startInactiveSpan({\n name: sql ?? 'mysql.query',\n kind: SPAN_KIND.CLIENT,\n op: 'db',\n attributes: {\n [ATTR_DB_SYSTEM]: 'mysql',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.orchestrion.mysql',\n [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, portIsNumber ? portNumber : undefined, database),\n ...(database ? { [ATTR_DB_NAME]: database } : {}),\n ...(user ? { [ATTR_DB_USER]: user } : {}),\n ...(sql ? { [ATTR_DB_STATEMENT]: sql } : {}),\n ...(host ? { [ATTR_NET_PEER_NAME]: host } : {}),\n ...(portIsNumber ? { [ATTR_NET_PEER_PORT]: portNumber } : {}),\n },\n });\n },\n {\n // No-callback `query(sql)` returns a streamable `Query` emitter as `result`; it settles on the\n // emitter's `'end'`/`'error'`, not the channel, so defer ending to those.\n deferSpanEnd({ data, end }) {\n const result = data.result;\n if (!result || typeof result !== 'object' || !hasOnMethod(result)) {\n return false;\n }\n\n // Replay the caller's scope so user listeners on the emitter nest under it, not a new trace.\n const callerScope = data._sentryCallerScope;\n if (callerScope) {\n bindScopeToEmitter(result, callerScope);\n }\n\n result.on('error', err => end(err));\n result.on('end', () => end());\n\n return true;\n },\n },\n );\n });\n },\n };\n}) satisfies IntegrationFn;\n\nfunction hasOnMethod(obj: object): obj is { on: (event: string, listener: (arg?: unknown) => void) => unknown } {\n return 'on' in obj && typeof (obj as { on?: unknown }).on === 'function';\n}\n\nfunction extractSql(firstArg: unknown): string | undefined {\n if (typeof firstArg === 'string') {\n return firstArg;\n }\n if (firstArg && typeof firstArg === 'object' && 'sql' in firstArg) {\n const sql = (firstArg as { sql?: unknown }).sql;\n return typeof sql === 'string' ? sql : undefined;\n }\n return undefined;\n}\n\nfunction getConnectionConfig(connection: MysqlConnection | undefined): {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n} {\n // Pool connections nest the real config under `.connectionConfig`; single\n // connections expose it directly. Matches `@opentelemetry/instrumentation-mysql`.\n const config = connection?.config?.connectionConfig ?? connection?.config ?? {};\n return {\n host: config.host,\n port: config.port,\n database: config.database,\n user: config.user,\n };\n}\n\nfunction getJDBCString(host: string | undefined, port: number | undefined, database: string | undefined): string {\n let s = `jdbc:mysql://${host || 'localhost'}`;\n if (typeof port === 'number') {\n s += `:${port}`;\n }\n if (database) {\n s += `/${database}`;\n }\n return s;\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven mysql integration.\n *\n * Subscribes to the `orchestrion:mysql:query` diagnostics_channel that the\n * orchestrion code transform injects into `mysql/lib/Connection.js`'s\n * `Connection.prototype.query`. Requires the orchestrion runtime hook or\n * bundler plugin to be active — wire that up via `_experimentalSetupOrchestrion`.\n */\nexport const mysqlChannelIntegration = defineIntegration(_mysqlChannelIntegration);\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,gBAAA,GAAmB,OAAA;AAKzB,MAAM,cAAA,GAAiB,WAAA;AACvB,MAAM,yBAAA,GAA4B,sBAAA;AAClC,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,iBAAA,GAAoB,cAAA;AAC1B,MAAM,kBAAA,GAAqB,eAAA;AAC3B,MAAM,kBAAA,GAAqB,eAAA;AA8B3B,MAAM,4BAA4B,MAAM;AACtC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAAC,mBAAmB,cAAA,EAAgB;AACtC,QAAA;AAAA,MACF;AAEA,MAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,CAAA,4CAAA,EAA+C,QAAA,CAAS,WAAW,CAAA,CAAA,CAAG,CAAA;AAE/F,MAAA,4BAAA,CAA6B,MAAM;AACjC,QAAA,wBAAA;AAAA,UACE,kBAAA,CAAmB,cAAA,CAAyC,QAAA,CAAS,WAAW,CAAA;AAAA,UAChF,CAAA,IAAA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,IACb,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,MAAM,MAAA,CAAO;AAAA,GACf;AACF;AAEA,SAAS,aAAA,CAAc,IAAA,EAA0B,IAAA,EAA0B,QAAA,EAAsC;AAC/G,EAAA,IAAI,CAAA,GAAI,CAAA,aAAA,EAAgB,IAAA,IAAQ,WAAW,CAAA,CAAA;AAC3C,EAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,IAAA,CAAA,IAAK,IAAI,IAAI,CAAA,CAAA;AAAA,EACf;AACA,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,CAAA,IAAK,IAAI,QAAQ,CAAA,CAAA;AAAA,EACnB;AACA,EAAA,OAAO,CAAA;AACT;AAUO,MAAM,uBAAA,GAA0B,kBAAkB,wBAAwB;;;;"}
@@ -0,0 +1,81 @@
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+ import { defineIntegration, waitForTracingChannelBinding, debug, _INTERNAL_shouldSkipAiProviderWrapping, resolveAIRecordingOptions, shouldEnableTruncation, extractOpenAiRequestAttributes, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startInactiveSpan, addOpenAiRequestAttributes, addOpenAiResponseAttributes, instrumentOpenAiStream } from '@sentry/core';
3
+ import { DEBUG_BUILD } from '../../debug-build.js';
4
+ import { CHANNELS } from '../../orchestrion/channels.js';
5
+ import { bindTracingChannelToSpan } from '../../tracing-channel.js';
6
+
7
+ const INTEGRATION_NAME = "OpenAI";
8
+ const ORIGIN = "auto.ai.orchestrion.openai";
9
+ const INSTRUMENTED_CHANNELS = [
10
+ { channel: CHANNELS.OPENAI_CHAT, operation: "chat" },
11
+ { channel: CHANNELS.OPENAI_RESPONSES, operation: "chat" },
12
+ { channel: CHANNELS.OPENAI_EMBEDDINGS, operation: "embeddings" },
13
+ { channel: CHANNELS.OPENAI_CONVERSATIONS, operation: "chat" }
14
+ ];
15
+ let subscribed = false;
16
+ const _openaiChannelIntegration = ((options = {}) => {
17
+ return {
18
+ name: INTEGRATION_NAME,
19
+ setupOnce() {
20
+ if (!diagnosticsChannel.tracingChannel || subscribed) {
21
+ return;
22
+ }
23
+ subscribed = true;
24
+ waitForTracingChannelBinding(() => {
25
+ for (const { channel, operation } of INSTRUMENTED_CHANNELS) {
26
+ DEBUG_BUILD && debug.log(`[orchestrion:openai] subscribing to channel "${channel}"`);
27
+ bindTracingChannelToSpan(
28
+ diagnosticsChannel.tracingChannel(channel),
29
+ (data) => createGenAiSpan(data, operation, options),
30
+ {
31
+ beforeSpanEnd: (span, data) => {
32
+ addOpenAiResponseAttributes(span, data.result, resolveAIRecordingOptions(options).recordOutputs);
33
+ },
34
+ // Streaming: the result is a `Stream` consumed later, so instrument it and let it end the span.
35
+ deferSpanEnd: ({ span, data }) => wrapStreamResult(span, data, options)
36
+ }
37
+ );
38
+ }
39
+ });
40
+ }
41
+ };
42
+ });
43
+ function createGenAiSpan(data, operation, options) {
44
+ if (_INTERNAL_shouldSkipAiProviderWrapping(INTEGRATION_NAME)) {
45
+ return void 0;
46
+ }
47
+ const args = data.arguments ?? [];
48
+ const params = args[0];
49
+ const { recordInputs } = resolveAIRecordingOptions(options);
50
+ const enableTruncation = shouldEnableTruncation(options.enableTruncation);
51
+ const attributes = extractOpenAiRequestAttributes(args, operation);
52
+ attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = ORIGIN;
53
+ const model = params?.model || "unknown";
54
+ const span = startInactiveSpan({
55
+ name: `${operation} ${model}`,
56
+ op: `gen_ai.${operation}`,
57
+ attributes
58
+ });
59
+ if (recordInputs && params) {
60
+ addOpenAiRequestAttributes(span, params, operation, enableTruncation);
61
+ }
62
+ return span;
63
+ }
64
+ function isAsyncIterable(value) {
65
+ return !!value && typeof value[Symbol.asyncIterator] === "function";
66
+ }
67
+ function wrapStreamResult(span, data, options) {
68
+ const result = data.result;
69
+ if (!isAsyncIterable(result)) {
70
+ return false;
71
+ }
72
+ const { recordOutputs } = resolveAIRecordingOptions(options);
73
+ const iterate = result[Symbol.asyncIterator].bind(result);
74
+ const instrumented = instrumentOpenAiStream({ [Symbol.asyncIterator]: iterate }, span, recordOutputs ?? false);
75
+ result[Symbol.asyncIterator] = () => instrumented;
76
+ return true;
77
+ }
78
+ const openaiChannelIntegration = defineIntegration(_openaiChannelIntegration);
79
+
80
+ export { openaiChannelIntegration };
81
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sources":["../../../../src/integrations/tracing-channel/openai.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, OpenAiOptions, Span, SpanAttributeValue } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n addOpenAiRequestAttributes,\n addOpenAiResponseAttributes,\n debug,\n defineIntegration,\n extractOpenAiRequestAttributes,\n instrumentOpenAiStream,\n resolveAIRecordingOptions,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n shouldEnableTruncation,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Same name as the OTel integration by design: when enabled, the OTel 'OpenAI'\n// integration is dropped from the default set (see the Node opt-in loader).\nconst INTEGRATION_NAME = 'OpenAI' as const;\n\n// Distinct from the proxy's `auto.ai.openai` so spans from the orchestrion path\n// are attributable separately from the OTel/proxy one.\nconst ORIGIN = 'auto.ai.orchestrion.openai';\n\n// Each instrumented `create` method maps to the gen_ai operation its span reports.\nconst INSTRUMENTED_CHANNELS = [\n { channel: CHANNELS.OPENAI_CHAT, operation: 'chat' },\n { channel: CHANNELS.OPENAI_RESPONSES, operation: 'chat' },\n { channel: CHANNELS.OPENAI_EMBEDDINGS, operation: 'embeddings' },\n { channel: CHANNELS.OPENAI_CONVERSATIONS, operation: 'chat' },\n] as const;\n\n/**\n * The context object orchestrion shares across the tracing-channel lifecycle hooks: `arguments` is the\n * live args array passed to `Completions.create(body, options)`, and Node's `tracingChannel` attaches\n * `result` when the returned promise settles.\n */\ninterface OpenAiChatChannelContext {\n arguments: unknown[];\n result?: unknown;\n}\n\nlet subscribed = false;\n\nconst _openaiChannelIntegration = ((options: OpenAiOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19, and a second `init()` would double-subscribe.\n if (!diagnosticsChannel.tracingChannel || subscribed) {\n return;\n }\n subscribed = true;\n\n // `bindTracingChannelToSpan` needs the async-context binding that `initOpenTelemetry()` registers\n // after `setupOnce` runs, so wait for it before subscribing.\n waitForTracingChannelBinding(() => {\n for (const { channel, operation } of INSTRUMENTED_CHANNELS) {\n DEBUG_BUILD && debug.log(`[orchestrion:openai] subscribing to channel \"${channel}\"`);\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<OpenAiChatChannelContext>(channel),\n data => createGenAiSpan(data, operation, options),\n {\n beforeSpanEnd: (span, data) => {\n addOpenAiResponseAttributes(span, data.result, resolveAIRecordingOptions(options).recordOutputs);\n },\n // Streaming: the result is a `Stream` consumed later, so instrument it and let it end the span.\n deferSpanEnd: ({ span, data }) => wrapStreamResult(span, data, options),\n },\n );\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Build the span for an instrumented `create` call.\n * Returning `undefined` opts the payload out so no span is opened.\n */\nfunction createGenAiSpan(data: OpenAiChatChannelContext, operation: string, options: OpenAiOptions): Span | undefined {\n // langchain drives the openai SDK itself and instruments at its own layer; skip here to avoid double spans.\n if (_INTERNAL_shouldSkipAiProviderWrapping(INTEGRATION_NAME)) {\n return undefined;\n }\n\n const args = data.arguments ?? [];\n const params = args[0] as Record<string, unknown> | undefined;\n\n const { recordInputs } = resolveAIRecordingOptions(options);\n const enableTruncation = shouldEnableTruncation(options.enableTruncation);\n\n const attributes = extractOpenAiRequestAttributes(args, operation);\n attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = ORIGIN;\n const model = (params?.model as string) || 'unknown';\n\n const span = startInactiveSpan({\n name: `${operation} ${model}`,\n op: `gen_ai.${operation}`,\n attributes: attributes as Record<string, SpanAttributeValue>,\n });\n\n if (recordInputs && params) {\n addOpenAiRequestAttributes(span, params, operation, enableTruncation);\n }\n\n return span;\n}\n\ntype AsyncIterableStream = { [Symbol.asyncIterator]: () => AsyncIterator<unknown> };\n\nfunction isAsyncIterable(value: unknown): value is AsyncIterableStream {\n return !!value && typeof (value as AsyncIterableStream)[Symbol.asyncIterator] === 'function';\n}\n\n/**\n * For a streaming `create({ stream: true })` the result is a `Stream` the caller consumes later. We can't\n * swap what `create` returns, but the `Stream` in `data.result` is the same instance the caller holds and\n * `asyncEnd` fires before the caller iterates — so we patch its async iterator in place to run through\n * `instrumentOpenAiStream`, which accumulates the streamed attributes and ends the span when iteration finishes.\n * Only a streaming call resolves to an async-iterable, so that check alone distinguishes it. Returns `true`\n * to hand span-ending ownership to `instrumentOpenAiStream`; `false` for non-streaming/errored results, which end\n * via the normal `beforeSpanEnd` path.\n */\nfunction wrapStreamResult(span: Span, data: OpenAiChatChannelContext, options: OpenAiOptions): boolean {\n const result = data.result;\n if (!isAsyncIterable(result)) {\n return false;\n }\n\n const { recordOutputs } = resolveAIRecordingOptions(options);\n const iterate = result[Symbol.asyncIterator].bind(result);\n const instrumented = instrumentOpenAiStream({ [Symbol.asyncIterator]: iterate }, span, recordOutputs ?? false);\n result[Symbol.asyncIterator] = () => instrumented;\n\n return true;\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven OpenAI integration. Subscribes to the `orchestrion:openai:*`\n * diagnostics_channels injected into `openai`'s `create` methods (chat completions, responses, embeddings,\n * conversations), so it requires the orchestrion runtime hook or bundler plugin.\n */\nexport const openaiChannelIntegration = defineIntegration(_openaiChannelIntegration);\n"],"names":[],"mappings":";;;;;;AAsBA,MAAM,gBAAA,GAAmB,QAAA;AAIzB,MAAM,MAAA,GAAS,4BA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A,EAAgC,OAAA,EAAiC;AACrG,EAAA,MAAM,SAAS,IAAA,CAAK,MAAA;AACpB,EAAA,IAAI,CAAC,eAAA,CAAgB,MAAM,CAAA,EAAG;AAC5B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,aAAA,EAAc,GAAI,yBAAA,CAA0B,OAAO,CAAA;AAC3D,EAAA,MAAM,UAAU,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA,CAAE,KAAK,MAAM,CAAA;AACxD,EAAA,MAAM,YAAA,GAAe,sBAAA,CAAuB,EAAE,CAAC,MAAA,CAAO,aAAa,GAAG,OAAA,EAAQ,EAAG,IAAA,EAAM,aAAA,IAAiB,KAAK,CAAA;AAC7G,EAAA,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA,GAAI,MAAM,YAAA;AAErC,EAAA,OAAO,IAAA;AACT;AAOO,MAAM,wBAAA,GAA2B,kBAAkB,yBAAyB;;;;"}
@@ -0,0 +1,168 @@
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+ import { defineIntegration, waitForTracingChannelBinding, debug, getActiveSpan, getCurrentScope, startInactiveSpan, SPAN_KIND, bindScopeToEmitter, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
3
+ import { DEBUG_BUILD } from '../../debug-build.js';
4
+ import { CHANNELS } from '../../orchestrion/channels.js';
5
+ import { bindTracingChannelToSpan } from '../../tracing-channel.js';
6
+
7
+ const INTEGRATION_NAME = "Postgres";
8
+ const ORIGIN = "auto.db.orchestrion.postgres";
9
+ const ATTR_DB_SYSTEM = "db.system";
10
+ const ATTR_DB_NAME = "db.name";
11
+ const ATTR_DB_CONNECTION_STRING = "db.connection_string";
12
+ const ATTR_DB_USER = "db.user";
13
+ const ATTR_DB_STATEMENT = "db.statement";
14
+ const ATTR_NET_PEER_NAME = "net.peer.name";
15
+ const ATTR_NET_PEER_PORT = "net.peer.port";
16
+ const ATTR_PG_PLAN = "db.postgresql.plan";
17
+ const ATTR_PG_IDLE_TIMEOUT = "db.postgresql.idle.timeout.millis";
18
+ const ATTR_PG_MAX_CLIENT = "db.postgresql.max.client";
19
+ const DB_SYSTEM_POSTGRESQL = "postgresql";
20
+ const SPAN_QUERY_FALLBACK = "pg.query";
21
+ const SPAN_CONNECT = "pg.connect";
22
+ const SPAN_POOL_CONNECT = "pg-pool.connect";
23
+ const _postgresChannelIntegration = ((options = {}) => {
24
+ return {
25
+ name: INTEGRATION_NAME,
26
+ setupOnce() {
27
+ if (!diagnosticsChannel.tracingChannel) {
28
+ return;
29
+ }
30
+ waitForTracingChannelBinding(() => {
31
+ subscribeQueryLikeChannel(CHANNELS.PG_QUERY, querySpanOptions, { deferStreamedResult: true });
32
+ if (!options.ignoreConnectSpans) {
33
+ subscribeQueryLikeChannel(CHANNELS.PG_CONNECT, connectSpanOptions);
34
+ subscribeQueryLikeChannel(CHANNELS.PGPOOL_CONNECT, poolConnectSpanOptions);
35
+ }
36
+ });
37
+ }
38
+ };
39
+ });
40
+ function subscribeQueryLikeChannel(channelName, getSpanOptions, { deferStreamedResult = false } = {}) {
41
+ DEBUG_BUILD && debug.log(`[orchestrion:pg] subscribing to channel "${channelName}"`);
42
+ bindTracingChannelToSpan(
43
+ diagnosticsChannel.tracingChannel(channelName),
44
+ (data) => {
45
+ if (!getActiveSpan()) {
46
+ return void 0;
47
+ }
48
+ data._sentryCallerScope = getCurrentScope();
49
+ return startInactiveSpan({ ...getSpanOptions(data), kind: SPAN_KIND.CLIENT });
50
+ },
51
+ // `connect`/`pool-connect` resolve with a persistent `Client` (itself an
52
+ // `EventEmitter`), which is NOT a streamed result. Deferring their span
53
+ // to that emitter's `'end'`/`'error'` would keep it open for the whole
54
+ // connection lifetime, so it never ends in time and is dropped. Only
55
+ // `query` can return a streamable `Submittable`, so only it defers.
56
+ deferStreamedResult ? {
57
+ // Streamable `Submittable` (e.g. `client.query(new Query())`)
58
+ // returns an emitter that orchestrion stores on `ctx.result` while
59
+ // firing no async events; the query isn't done until the emitter
60
+ // emits `'end'`/`'error'`. Defer ending to those events for that
61
+ // path; the callback, promise, and sync-throw paths carry no
62
+ // emitter, so the helper ends the span as usual.
63
+ deferSpanEnd({ data, end }) {
64
+ const result = data.result;
65
+ if (!result || typeof result !== "object" || !hasOnMethod(result)) {
66
+ return false;
67
+ }
68
+ const callerScope = data._sentryCallerScope;
69
+ if (callerScope) {
70
+ bindScopeToEmitter(result, callerScope);
71
+ }
72
+ result.on("error", (err) => end(err));
73
+ result.on("end", () => end());
74
+ return true;
75
+ }
76
+ } : void 0
77
+ );
78
+ }
79
+ function querySpanOptions(ctx) {
80
+ const params = ctx.self?.connectionParameters ?? {};
81
+ const queryConfig = extractQueryConfig(ctx.arguments);
82
+ return {
83
+ // The description is the SQL statement
84
+ name: queryConfig?.text ?? SPAN_QUERY_FALLBACK,
85
+ op: "db",
86
+ attributes: {
87
+ ...getConnectionAttributes(params),
88
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
89
+ [ATTR_DB_STATEMENT]: queryConfig?.text || void 0,
90
+ [ATTR_PG_PLAN]: typeof queryConfig?.name === "string" ? queryConfig.name : void 0
91
+ }
92
+ };
93
+ }
94
+ function connectSpanOptions(ctx) {
95
+ const params = ctx.self?.connectionParameters ?? {};
96
+ return { name: SPAN_CONNECT, op: "db", attributes: getConnectionAttributes(params) };
97
+ }
98
+ function poolConnectSpanOptions(ctx) {
99
+ const opts = ctx.self?.options ?? {};
100
+ return { name: SPAN_POOL_CONNECT, op: "db", attributes: getPoolConnectionAttributes(opts) };
101
+ }
102
+ function hasOnMethod(obj) {
103
+ return "on" in obj && typeof obj.on === "function";
104
+ }
105
+ function extractQueryConfig(args) {
106
+ const arg0 = args[0];
107
+ if (typeof arg0 === "string") {
108
+ return { text: arg0 };
109
+ }
110
+ if (arg0 && typeof arg0 === "object" && typeof arg0.text === "string") {
111
+ const obj = arg0;
112
+ return { text: obj.text, name: obj.name };
113
+ }
114
+ return void 0;
115
+ }
116
+ function getConnectionAttributes(params) {
117
+ return {
118
+ [ATTR_DB_SYSTEM]: DB_SYSTEM_POSTGRESQL,
119
+ [ATTR_DB_CONNECTION_STRING]: getConnectionString(params),
120
+ [ATTR_DB_NAME]: params.database,
121
+ [ATTR_DB_USER]: params.user,
122
+ [ATTR_NET_PEER_NAME]: params.host,
123
+ [ATTR_NET_PEER_PORT]: Number.isInteger(params.port) ? params.port : void 0
124
+ };
125
+ }
126
+ function getPoolConnectionAttributes(opts) {
127
+ let url;
128
+ try {
129
+ url = opts.connectionString ? new URL(opts.connectionString) : void 0;
130
+ } catch {
131
+ url = void 0;
132
+ }
133
+ const database = url?.pathname.slice(1) || opts.database;
134
+ const host = url?.hostname || opts.host;
135
+ const port = Number(url?.port) || (Number.isInteger(opts.port) ? opts.port : void 0);
136
+ const user = url?.username || opts.user;
137
+ return {
138
+ [ATTR_DB_SYSTEM]: DB_SYSTEM_POSTGRESQL,
139
+ [ATTR_DB_CONNECTION_STRING]: getConnectionString(opts),
140
+ [ATTR_PG_IDLE_TIMEOUT]: opts.idleTimeoutMillis,
141
+ [ATTR_PG_MAX_CLIENT]: opts.max,
142
+ [ATTR_DB_NAME]: database,
143
+ [ATTR_NET_PEER_PORT]: port,
144
+ // these two come from a url parse and slice, can be ''
145
+ [ATTR_NET_PEER_NAME]: host || void 0,
146
+ [ATTR_DB_USER]: user || void 0
147
+ };
148
+ }
149
+ function getConnectionString(params) {
150
+ if (params.connectionString) {
151
+ try {
152
+ const url = new URL(params.connectionString);
153
+ url.username = "";
154
+ url.password = "";
155
+ return url.toString();
156
+ } catch {
157
+ return "postgresql://localhost:5432/";
158
+ }
159
+ }
160
+ const host = params.host || "localhost";
161
+ const port = params.port || 5432;
162
+ const database = params.database || "";
163
+ return `postgresql://${host}:${port}/${database}`;
164
+ }
165
+ const postgresChannelIntegration = defineIntegration(_postgresChannelIntegration);
166
+
167
+ export { postgresChannelIntegration };
168
+ //# sourceMappingURL=postgres.js.map