@sentry/server-utils 10.64.0 → 10.65.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 (279) hide show
  1. package/build/cjs/graphql/graphql-dc-subscriber.js +125 -0
  2. package/build/cjs/graphql/graphql-dc-subscriber.js.map +1 -0
  3. package/build/cjs/graphql/index.js +23 -0
  4. package/build/cjs/graphql/index.js.map +1 -0
  5. package/build/cjs/graphql/utils.js +86 -0
  6. package/build/cjs/graphql/utils.js.map +1 -0
  7. package/build/cjs/index.js +10 -11
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/integrations/tracing-channel/amqplib.js +420 -0
  10. package/build/cjs/integrations/tracing-channel/amqplib.js.map +1 -0
  11. package/build/cjs/integrations/tracing-channel/express/index.js +24 -0
  12. package/build/cjs/integrations/tracing-channel/express/index.js.map +1 -0
  13. package/build/cjs/integrations/tracing-channel/express/instrumentation.js +173 -0
  14. package/build/cjs/integrations/tracing-channel/express/instrumentation.js.map +1 -0
  15. package/build/cjs/integrations/tracing-channel/express/route.js +76 -0
  16. package/build/cjs/integrations/tracing-channel/express/route.js.map +1 -0
  17. package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js +1 -1
  18. package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js.map +1 -1
  19. package/build/cjs/integrations/tracing-channel/google-genai.js +96 -0
  20. package/build/cjs/integrations/tracing-channel/google-genai.js.map +1 -0
  21. package/build/cjs/integrations/tracing-channel/graphql/constants.js +26 -0
  22. package/build/cjs/integrations/tracing-channel/graphql/constants.js.map +1 -0
  23. package/build/cjs/integrations/tracing-channel/graphql/index.js +66 -0
  24. package/build/cjs/integrations/tracing-channel/graphql/index.js.map +1 -0
  25. package/build/cjs/integrations/tracing-channel/graphql/resolvers.js +168 -0
  26. package/build/cjs/integrations/tracing-channel/graphql/resolvers.js.map +1 -0
  27. package/build/cjs/integrations/tracing-channel/graphql/spans.js +102 -0
  28. package/build/cjs/integrations/tracing-channel/graphql/spans.js.map +1 -0
  29. package/build/cjs/integrations/tracing-channel/ioredis.js +14 -14
  30. package/build/cjs/integrations/tracing-channel/ioredis.js.map +1 -1
  31. package/build/cjs/integrations/tracing-channel/mysql.js +1 -1
  32. package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
  33. package/build/cjs/integrations/tracing-channel/openai.js.map +1 -1
  34. package/build/cjs/integrations/tracing-channel/postgres-js.js +191 -0
  35. package/build/cjs/integrations/tracing-channel/postgres-js.js.map +1 -0
  36. package/build/cjs/integrations/tracing-channel/postgres.js +5 -5
  37. package/build/cjs/integrations/tracing-channel/postgres.js.map +1 -1
  38. package/build/cjs/integrations/tracing-channel/redis.js +227 -0
  39. package/build/cjs/integrations/tracing-channel/redis.js.map +1 -0
  40. package/build/cjs/integrations/tracing-channel/vercel-ai.js +2 -2
  41. package/build/cjs/integrations/tracing-channel/vercel-ai.js.map +1 -1
  42. package/build/cjs/mongoose/mongoose-dc-subscriber.js +1 -1
  43. package/build/cjs/mongoose/mongoose-dc-subscriber.js.map +1 -1
  44. package/build/cjs/mysql2/index.js +23 -0
  45. package/build/cjs/mysql2/index.js.map +1 -0
  46. package/build/cjs/mysql2/mysql2-dc-subscriber.js +68 -0
  47. package/build/cjs/mysql2/mysql2-dc-subscriber.js.map +1 -0
  48. package/build/cjs/orchestrion/channels.js +13 -1
  49. package/build/cjs/orchestrion/channels.js.map +1 -1
  50. package/build/cjs/orchestrion/config/amqplib.js +81 -0
  51. package/build/cjs/orchestrion/config/amqplib.js.map +1 -0
  52. package/build/cjs/orchestrion/config/express.js +76 -0
  53. package/build/cjs/orchestrion/config/express.js.map +1 -0
  54. package/build/cjs/orchestrion/config/google-genai.js +38 -0
  55. package/build/cjs/orchestrion/config/google-genai.js.map +1 -0
  56. package/build/cjs/orchestrion/config/graphql.js +28 -0
  57. package/build/cjs/orchestrion/config/graphql.js.map +1 -0
  58. package/build/cjs/orchestrion/config/index.js +15 -2
  59. package/build/cjs/orchestrion/config/index.js.map +1 -1
  60. package/build/cjs/orchestrion/config/postgres.js +50 -0
  61. package/build/cjs/orchestrion/config/postgres.js.map +1 -0
  62. package/build/cjs/orchestrion/config/redis.js +76 -0
  63. package/build/cjs/orchestrion/config/redis.js.map +1 -0
  64. package/build/cjs/orchestrion/config/vercel-ai.js +18 -14
  65. package/build/cjs/orchestrion/config/vercel-ai.js.map +1 -1
  66. package/build/cjs/orchestrion/index.js +18 -1
  67. package/build/cjs/orchestrion/index.js.map +1 -1
  68. package/build/cjs/redis/index.js +23 -0
  69. package/build/cjs/redis/index.js.map +1 -0
  70. package/build/cjs/redis/redis-dc-subscriber.js +23 -35
  71. package/build/cjs/redis/redis-dc-subscriber.js.map +1 -1
  72. package/build/cjs/tracing-channel.js +7 -6
  73. package/build/cjs/tracing-channel.js.map +1 -1
  74. package/build/cjs/vercel-ai/util.js +123 -0
  75. package/build/cjs/vercel-ai/util.js.map +1 -0
  76. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +138 -74
  77. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  78. package/build/cjs/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.js → vercel-ai-orchestrion-subscriber.js} +153 -23
  79. package/build/cjs/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -0
  80. package/build/esm/graphql/graphql-dc-subscriber.js +118 -0
  81. package/build/esm/graphql/graphql-dc-subscriber.js.map +1 -0
  82. package/build/esm/graphql/index.js +21 -0
  83. package/build/esm/graphql/index.js.map +1 -0
  84. package/build/esm/graphql/utils.js +81 -0
  85. package/build/esm/graphql/utils.js.map +1 -0
  86. package/build/esm/index.js +3 -1
  87. package/build/esm/index.js.map +1 -1
  88. package/build/esm/integrations/tracing-channel/amqplib.js +418 -0
  89. package/build/esm/integrations/tracing-channel/amqplib.js.map +1 -0
  90. package/build/esm/integrations/tracing-channel/anthropic.js +1 -1
  91. package/build/esm/integrations/tracing-channel/express/index.js +22 -0
  92. package/build/esm/integrations/tracing-channel/express/index.js.map +1 -0
  93. package/build/esm/integrations/tracing-channel/express/instrumentation.js +171 -0
  94. package/build/esm/integrations/tracing-channel/express/instrumentation.js.map +1 -0
  95. package/build/esm/integrations/tracing-channel/express/route.js +68 -0
  96. package/build/esm/integrations/tracing-channel/express/route.js.map +1 -0
  97. package/build/esm/integrations/tracing-channel/fastify/instrumentation.js +2 -2
  98. package/build/esm/integrations/tracing-channel/fastify/instrumentation.js.map +1 -1
  99. package/build/esm/integrations/tracing-channel/google-genai.js +94 -0
  100. package/build/esm/integrations/tracing-channel/google-genai.js.map +1 -0
  101. package/build/esm/integrations/tracing-channel/graphql/constants.js +14 -0
  102. package/build/esm/integrations/tracing-channel/graphql/constants.js.map +1 -0
  103. package/build/esm/integrations/tracing-channel/graphql/index.js +63 -0
  104. package/build/esm/integrations/tracing-channel/graphql/index.js.map +1 -0
  105. package/build/esm/integrations/tracing-channel/graphql/resolvers.js +164 -0
  106. package/build/esm/integrations/tracing-channel/graphql/resolvers.js.map +1 -0
  107. package/build/esm/integrations/tracing-channel/graphql/spans.js +96 -0
  108. package/build/esm/integrations/tracing-channel/graphql/spans.js.map +1 -0
  109. package/build/esm/integrations/tracing-channel/ioredis.js +15 -15
  110. package/build/esm/integrations/tracing-channel/ioredis.js.map +1 -1
  111. package/build/esm/integrations/tracing-channel/mysql.js +2 -2
  112. package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
  113. package/build/esm/integrations/tracing-channel/openai.js +1 -1
  114. package/build/esm/integrations/tracing-channel/openai.js.map +1 -1
  115. package/build/esm/integrations/tracing-channel/postgres-js.js +189 -0
  116. package/build/esm/integrations/tracing-channel/postgres-js.js.map +1 -0
  117. package/build/esm/integrations/tracing-channel/postgres.js +6 -6
  118. package/build/esm/integrations/tracing-channel/postgres.js.map +1 -1
  119. package/build/esm/integrations/tracing-channel/redis.js +225 -0
  120. package/build/esm/integrations/tracing-channel/redis.js.map +1 -0
  121. package/build/esm/integrations/tracing-channel/vercel-ai.js +1 -1
  122. package/build/esm/integrations/tracing-channel/vercel-ai.js.map +1 -1
  123. package/build/esm/mongoose/mongoose-dc-subscriber.js +2 -2
  124. package/build/esm/mongoose/mongoose-dc-subscriber.js.map +1 -1
  125. package/build/esm/mysql2/index.js +21 -0
  126. package/build/esm/mysql2/index.js.map +1 -0
  127. package/build/esm/mysql2/mysql2-dc-subscriber.js +62 -0
  128. package/build/esm/mysql2/mysql2-dc-subscriber.js.map +1 -0
  129. package/build/esm/orchestrion/channels.js +13 -1
  130. package/build/esm/orchestrion/channels.js.map +1 -1
  131. package/build/esm/orchestrion/config/amqplib.js +78 -0
  132. package/build/esm/orchestrion/config/amqplib.js.map +1 -0
  133. package/build/esm/orchestrion/config/express.js +73 -0
  134. package/build/esm/orchestrion/config/express.js.map +1 -0
  135. package/build/esm/orchestrion/config/google-genai.js +35 -0
  136. package/build/esm/orchestrion/config/google-genai.js.map +1 -0
  137. package/build/esm/orchestrion/config/graphql.js +25 -0
  138. package/build/esm/orchestrion/config/graphql.js.map +1 -0
  139. package/build/esm/orchestrion/config/index.js +15 -2
  140. package/build/esm/orchestrion/config/index.js.map +1 -1
  141. package/build/esm/orchestrion/config/postgres.js +47 -0
  142. package/build/esm/orchestrion/config/postgres.js.map +1 -0
  143. package/build/esm/orchestrion/config/redis.js +73 -0
  144. package/build/esm/orchestrion/config/redis.js.map +1 -0
  145. package/build/esm/orchestrion/config/vercel-ai.js +18 -14
  146. package/build/esm/orchestrion/config/vercel-ai.js.map +1 -1
  147. package/build/esm/orchestrion/index.js +14 -2
  148. package/build/esm/orchestrion/index.js.map +1 -1
  149. package/build/esm/package.json +1 -1
  150. package/build/esm/redis/index.js +21 -0
  151. package/build/esm/redis/index.js.map +1 -0
  152. package/build/esm/redis/redis-dc-subscriber.js +24 -36
  153. package/build/esm/redis/redis-dc-subscriber.js.map +1 -1
  154. package/build/esm/tracing-channel.js +8 -7
  155. package/build/esm/tracing-channel.js.map +1 -1
  156. package/build/esm/vercel-ai/util.js +116 -0
  157. package/build/esm/vercel-ai/util.js.map +1 -0
  158. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +112 -50
  159. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  160. package/build/esm/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.js → vercel-ai-orchestrion-subscriber.js} +153 -23
  161. package/build/esm/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -0
  162. package/build/types/graphql/graphql-dc-subscriber.d.ts +94 -0
  163. package/build/types/graphql/graphql-dc-subscriber.d.ts.map +1 -0
  164. package/build/types/graphql/index.d.ts +12 -0
  165. package/build/types/graphql/index.d.ts.map +1 -0
  166. package/build/types/graphql/utils.d.ts +40 -0
  167. package/build/types/graphql/utils.d.ts.map +1 -0
  168. package/build/types/index.d.ts +4 -2
  169. package/build/types/index.d.ts.map +1 -1
  170. package/build/types/integrations/tracing-channel/amqplib.d.ts +11 -0
  171. package/build/types/integrations/tracing-channel/amqplib.d.ts.map +1 -0
  172. package/build/types/integrations/tracing-channel/express/index.d.ts +18 -0
  173. package/build/types/integrations/tracing-channel/express/index.d.ts.map +1 -0
  174. package/build/types/integrations/tracing-channel/express/instrumentation.d.ts +4 -0
  175. package/build/types/integrations/tracing-channel/express/instrumentation.d.ts.map +1 -0
  176. package/build/types/integrations/tracing-channel/express/route.d.ts +28 -0
  177. package/build/types/integrations/tracing-channel/express/route.d.ts.map +1 -0
  178. package/build/types/integrations/tracing-channel/express/types.d.ts +64 -0
  179. package/build/types/integrations/tracing-channel/express/types.d.ts.map +1 -0
  180. package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts.map +1 -1
  181. package/build/types/integrations/tracing-channel/google-genai.d.ts +12 -0
  182. package/build/types/integrations/tracing-channel/google-genai.d.ts.map +1 -0
  183. package/build/types/integrations/tracing-channel/graphql/constants.d.ts +12 -0
  184. package/build/types/integrations/tracing-channel/graphql/constants.d.ts.map +1 -0
  185. package/build/types/integrations/tracing-channel/graphql/graphql-types.d.ts +135 -0
  186. package/build/types/integrations/tracing-channel/graphql/graphql-types.d.ts.map +1 -0
  187. package/build/types/integrations/tracing-channel/graphql/index.d.ts +28 -0
  188. package/build/types/integrations/tracing-channel/graphql/index.d.ts.map +1 -0
  189. package/build/types/integrations/tracing-channel/graphql/resolvers.d.ts +13 -0
  190. package/build/types/integrations/tracing-channel/graphql/resolvers.d.ts.map +1 -0
  191. package/build/types/integrations/tracing-channel/graphql/spans.d.ts +17 -0
  192. package/build/types/integrations/tracing-channel/graphql/spans.d.ts.map +1 -0
  193. package/build/types/integrations/tracing-channel/graphql/types.d.ts +25 -0
  194. package/build/types/integrations/tracing-channel/graphql/types.d.ts.map +1 -0
  195. package/build/types/integrations/tracing-channel/ioredis.d.ts.map +1 -1
  196. package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
  197. package/build/types/integrations/tracing-channel/openai.d.ts.map +1 -1
  198. package/build/types/integrations/tracing-channel/postgres-js.d.ts +26 -0
  199. package/build/types/integrations/tracing-channel/postgres-js.d.ts.map +1 -0
  200. package/build/types/integrations/tracing-channel/postgres.d.ts.map +1 -1
  201. package/build/types/integrations/tracing-channel/redis.d.ts +16 -0
  202. package/build/types/integrations/tracing-channel/redis.d.ts.map +1 -0
  203. package/build/types/integrations/tracing-channel/vercel-ai.d.ts +1 -1
  204. package/build/types/mongoose/mongoose-dc-subscriber.d.ts.map +1 -1
  205. package/build/types/mysql2/index.d.ts +11 -0
  206. package/build/types/mysql2/index.d.ts.map +1 -0
  207. package/build/types/mysql2/mysql2-dc-subscriber.d.ts +59 -0
  208. package/build/types/mysql2/mysql2-dc-subscriber.d.ts.map +1 -0
  209. package/build/types/orchestrion/channels.d.ts +34 -0
  210. package/build/types/orchestrion/channels.d.ts.map +1 -1
  211. package/build/types/orchestrion/config/amqplib.d.ts +66 -0
  212. package/build/types/orchestrion/config/amqplib.d.ts.map +1 -0
  213. package/build/types/orchestrion/config/express.d.ts +32 -0
  214. package/build/types/orchestrion/config/express.d.ts.map +1 -0
  215. package/build/types/orchestrion/config/google-genai.d.ts +30 -0
  216. package/build/types/orchestrion/config/google-genai.d.ts.map +1 -0
  217. package/build/types/orchestrion/config/graphql.d.ts +29 -0
  218. package/build/types/orchestrion/config/graphql.d.ts.map +1 -0
  219. package/build/types/orchestrion/config/index.d.ts.map +1 -1
  220. package/build/types/orchestrion/config/postgres.d.ts +9 -0
  221. package/build/types/orchestrion/config/postgres.d.ts.map +1 -0
  222. package/build/types/orchestrion/config/redis.d.ts +37 -0
  223. package/build/types/orchestrion/config/redis.d.ts.map +1 -0
  224. package/build/types/orchestrion/config/vercel-ai.d.ts +1 -0
  225. package/build/types/orchestrion/config/vercel-ai.d.ts.map +1 -1
  226. package/build/types/orchestrion/index.d.ts +31 -4
  227. package/build/types/orchestrion/index.d.ts.map +1 -1
  228. package/build/types/redis/index.d.ts +18 -0
  229. package/build/types/redis/index.d.ts.map +1 -0
  230. package/build/types/redis/redis-dc-subscriber.d.ts +0 -5
  231. package/build/types/redis/redis-dc-subscriber.d.ts.map +1 -1
  232. package/build/types/tracing-channel.d.ts +5 -0
  233. package/build/types/tracing-channel.d.ts.map +1 -1
  234. package/build/types/vercel-ai/util.d.ts +32 -0
  235. package/build/types/vercel-ai/util.d.ts.map +1 -0
  236. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +6 -2
  237. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  238. package/build/types/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.d.ts → vercel-ai-orchestrion-subscriber.d.ts} +1 -1
  239. package/build/types/vercel-ai/vercel-ai-orchestrion-subscriber.d.ts.map +1 -0
  240. package/build/types-ts3.8/graphql/graphql-dc-subscriber.d.ts +94 -0
  241. package/build/types-ts3.8/graphql/index.d.ts +12 -0
  242. package/build/types-ts3.8/graphql/utils.d.ts +40 -0
  243. package/build/types-ts3.8/index.d.ts +4 -2
  244. package/build/types-ts3.8/integrations/tracing-channel/amqplib.d.ts +11 -0
  245. package/build/types-ts3.8/integrations/tracing-channel/express/index.d.ts +18 -0
  246. package/build/types-ts3.8/integrations/tracing-channel/express/instrumentation.d.ts +4 -0
  247. package/build/types-ts3.8/integrations/tracing-channel/express/route.d.ts +28 -0
  248. package/build/types-ts3.8/integrations/tracing-channel/express/types.d.ts +64 -0
  249. package/build/types-ts3.8/integrations/tracing-channel/google-genai.d.ts +12 -0
  250. package/build/types-ts3.8/integrations/tracing-channel/graphql/constants.d.ts +12 -0
  251. package/build/types-ts3.8/integrations/tracing-channel/graphql/graphql-types.d.ts +135 -0
  252. package/build/types-ts3.8/integrations/tracing-channel/graphql/index.d.ts +30 -0
  253. package/build/types-ts3.8/integrations/tracing-channel/graphql/resolvers.d.ts +13 -0
  254. package/build/types-ts3.8/integrations/tracing-channel/graphql/spans.d.ts +17 -0
  255. package/build/types-ts3.8/integrations/tracing-channel/graphql/types.d.ts +25 -0
  256. package/build/types-ts3.8/integrations/tracing-channel/postgres-js.d.ts +26 -0
  257. package/build/types-ts3.8/integrations/tracing-channel/redis.d.ts +16 -0
  258. package/build/types-ts3.8/integrations/tracing-channel/vercel-ai.d.ts +1 -1
  259. package/build/types-ts3.8/mysql2/index.d.ts +11 -0
  260. package/build/types-ts3.8/mysql2/mysql2-dc-subscriber.d.ts +59 -0
  261. package/build/types-ts3.8/orchestrion/channels.d.ts +34 -0
  262. package/build/types-ts3.8/orchestrion/config/amqplib.d.ts +66 -0
  263. package/build/types-ts3.8/orchestrion/config/express.d.ts +32 -0
  264. package/build/types-ts3.8/orchestrion/config/google-genai.d.ts +30 -0
  265. package/build/types-ts3.8/orchestrion/config/graphql.d.ts +29 -0
  266. package/build/types-ts3.8/orchestrion/config/postgres.d.ts +9 -0
  267. package/build/types-ts3.8/orchestrion/config/redis.d.ts +37 -0
  268. package/build/types-ts3.8/orchestrion/config/vercel-ai.d.ts +1 -0
  269. package/build/types-ts3.8/orchestrion/index.d.ts +33 -4
  270. package/build/types-ts3.8/redis/index.d.ts +18 -0
  271. package/build/types-ts3.8/redis/redis-dc-subscriber.d.ts +0 -5
  272. package/build/types-ts3.8/tracing-channel.d.ts +5 -0
  273. package/build/types-ts3.8/vercel-ai/util.d.ts +32 -0
  274. package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +6 -2
  275. package/build/types-ts3.8/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.d.ts → vercel-ai-orchestrion-subscriber.d.ts} +1 -1
  276. package/package.json +2 -2
  277. package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +0 -1
  278. package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +0 -1
  279. package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts.map +0 -1
@@ -0,0 +1,63 @@
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+ import { defineIntegration, waitForTracingChannelBinding, debug, extendIntegration } from '@sentry/core';
3
+ import { DEBUG_BUILD } from '../../../debug-build.js';
4
+ import { graphqlIntegration } from '../../../graphql/index.js';
5
+ import { CHANNELS } from '../../../orchestrion/channels.js';
6
+ import { bindTracingChannelToSpan } from '../../../tracing-channel.js';
7
+ import { startParseSpan, finalizeValidateSpan, startValidateSpan, finalizeExecuteSpan, startExecuteSpan } from './spans.js';
8
+
9
+ const INTEGRATION_NAME = "Graphql";
10
+ function getOptionsWithDefaults(options) {
11
+ return {
12
+ ignoreResolveSpans: options.ignoreResolveSpans !== false,
13
+ ignoreTrivialResolveSpans: options.ignoreTrivialResolveSpans !== false,
14
+ useOperationNameForRootSpan: options.useOperationNameForRootSpan !== false
15
+ };
16
+ }
17
+ function safe(fn) {
18
+ try {
19
+ return fn();
20
+ } catch (error) {
21
+ DEBUG_BUILD && debug.warn("[orchestrion:graphql] error building span", error);
22
+ return void 0;
23
+ }
24
+ }
25
+ const _graphqlChannelIntegration = ((options = {}) => {
26
+ const config = getOptionsWithDefaults(options);
27
+ const getConfig = () => config;
28
+ return {
29
+ name: INTEGRATION_NAME,
30
+ setupOnce() {
31
+ if (!diagnosticsChannel.tracingChannel) {
32
+ return;
33
+ }
34
+ waitForTracingChannelBinding(() => {
35
+ bindTracingChannelToSpan(
36
+ diagnosticsChannel.tracingChannel(CHANNELS.GRAPHQL_PARSE),
37
+ () => safe(() => startParseSpan())
38
+ );
39
+ bindTracingChannelToSpan(
40
+ diagnosticsChannel.tracingChannel(CHANNELS.GRAPHQL_VALIDATE),
41
+ (data) => safe(() => startValidateSpan(data.arguments[1])),
42
+ { beforeSpanEnd: (span, data) => void safe(() => finalizeValidateSpan(span, data.result)) }
43
+ );
44
+ bindTracingChannelToSpan(
45
+ diagnosticsChannel.tracingChannel(CHANNELS.GRAPHQL_EXECUTE),
46
+ (data) => safe(() => startExecuteSpan(data.arguments, data.self, config, getConfig)),
47
+ { beforeSpanEnd: (span, data) => void safe(() => finalizeExecuteSpan(span, data.result)) }
48
+ );
49
+ });
50
+ }
51
+ };
52
+ });
53
+ const graphqlChannelIntegration = defineIntegration(_graphqlChannelIntegration);
54
+ const graphqlDiagnosticsChannelIntegration = (options) => {
55
+ const orchestrion = graphqlChannelIntegration(options);
56
+ return extendIntegration(graphqlIntegration(options), {
57
+ name: INTEGRATION_NAME,
58
+ setupOnce: () => orchestrion.setupOnce?.()
59
+ });
60
+ };
61
+
62
+ export { graphqlChannelIntegration, graphqlDiagnosticsChannelIntegration };
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing-channel/graphql/index.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn } from '@sentry/core';\nimport { debug, defineIntegration, extendIntegration, waitForTracingChannelBinding } from '@sentry/core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { graphqlIntegration as graphqlNativeIntegration } from '../../../graphql';\nimport type { GraphqlDiagnosticChannelsOptions } from '../../../graphql/graphql-dc-subscriber';\nimport { CHANNELS } from '../../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../../tracing-channel';\nimport {\n finalizeExecuteSpan,\n finalizeValidateSpan,\n startExecuteSpan,\n startParseSpan,\n startValidateSpan,\n} from './spans';\nimport type { GraphqlResolvedConfig } from './types';\n\n// Same name as the OTel/native integration by design, so enabling injection swaps this in for it.\nconst INTEGRATION_NAME = 'Graphql' as const;\n\n// The context orchestrion's transform attaches to each channel: `arguments` is the live args of the\n// wrapped call, `result` the settled return value.\ninterface GraphqlChannelContext {\n arguments: unknown[];\n self?: unknown;\n result?: unknown;\n error?: unknown;\n}\n\nfunction getOptionsWithDefaults(options: GraphqlDiagnosticChannelsOptions): GraphqlResolvedConfig {\n return {\n ignoreResolveSpans: options.ignoreResolveSpans !== false,\n ignoreTrivialResolveSpans: options.ignoreTrivialResolveSpans !== false,\n useOperationNameForRootSpan: options.useOperationNameForRootSpan !== false,\n };\n}\n\n/**\n * Runs a span-building callback so a throw inside it can never break the user's graphql call: these\n * run inside the `tracingChannel(...).trace*` machinery wrapping the real function (as the `getSpan`\n * producer / `beforeSpanEnd` handler), where an unguarded throw would propagate into the traced call.\n */\nfunction safe<T>(fn: () => T): T | undefined {\n try {\n return fn();\n } catch (error) {\n DEBUG_BUILD && debug.warn('[orchestrion:graphql] error building span', error);\n return undefined;\n }\n}\n\nconst _graphqlChannelIntegration = ((options: GraphqlDiagnosticChannelsOptions = {}) => {\n const config = getOptionsWithDefaults(options);\n const getConfig = (): GraphqlResolvedConfig => config;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(diagnosticsChannel.tracingChannel<GraphqlChannelContext>(CHANNELS.GRAPHQL_PARSE), () =>\n safe(() => startParseSpan()),\n );\n\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<GraphqlChannelContext>(CHANNELS.GRAPHQL_VALIDATE),\n data => safe(() => startValidateSpan(data.arguments[1])),\n { beforeSpanEnd: (span, data) => void safe(() => finalizeValidateSpan(span, data.result)) },\n );\n\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<GraphqlChannelContext>(CHANNELS.GRAPHQL_EXECUTE),\n data => safe(() => startExecuteSpan(data.arguments, data.self, config, getConfig)),\n { beforeSpanEnd: (span, data) => void safe(() => finalizeExecuteSpan(span, data.result)) },\n );\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * EXPERIMENTAL — orchestrion-driven graphql integration for graphql v14–16 (v17 publishes native\n * `diagnostics_channel` events handled by `@sentry/server-utils`'s graphql integration instead).\n *\n * Subscribes to the `orchestrion:graphql:{parse,validate,execute}` channels the orchestrion code\n * transform injects into `graphql`'s `language/parser.js`, `validation/validate.js` and\n * `execution/execute.js`, emitting spans identical to the native path. Requires the orchestrion\n * runtime hook or bundler plugin — wire it up via `experimentalUseDiagnosticsChannelInjection()`.\n *\n * @experimental\n */\nexport const graphqlChannelIntegration = defineIntegration(_graphqlChannelIntegration);\n\n/**\n * The complete graphql diagnostics-channel integration: the native subscriber (graphql v17) composed\n * with the orchestrion subscriber (v14–16), so opting into injection instruments every supported\n * version via diagnostics channels without the OTel patcher. Reuses the OTel `Graphql` name so\n * enabling injection swaps this in for it.\n */\nexport const graphqlDiagnosticsChannelIntegration = (options?: GraphqlDiagnosticChannelsOptions) => {\n const orchestrion = graphqlChannelIntegration(options);\n return extendIntegration(graphqlNativeIntegration(options), {\n name: INTEGRATION_NAME,\n setupOnce: () => orchestrion.setupOnce?.(),\n });\n};\n"],"names":["graphqlNativeIntegration"],"mappings":";;;;;;;;AAkBA,MAAM,gBAAA,GAAmB,SAAA;AAWzB,SAAS,uBAAuB,OAAA,EAAkE;AAChG,EAAA,OAAO;AAAA,IACL,kBAAA,EAAoB,QAAQ,kBAAA,KAAuB,KAAA;AAAA,IACnD,yBAAA,EAA2B,QAAQ,yBAAA,KAA8B,KAAA;AAAA,IACjE,2BAAA,EAA6B,QAAQ,2BA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IAAA,EAAM,MAAA,EAAQ,SAAS,CAAC,CAAA;AAAA,UACjF,EAAE,aAAA,EAAe,CAAC,IAAA,EAAM,IAAA,KAAS,KAAK,IAAA,CAAK,MAAM,mBAAA,CAAoB,IAAA,EAAM,IAAA,CAAK,MAAM,CAAC,CAAA;AAAE,SAC3F;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAA,CAAA;AAaO,MAAM,yBAAA,GAA4B,kBAAkB,0BAA0B;AAQ9E,MAAM,oCAAA,GAAuC,CAAC,OAAA,KAA+C;AAClG,EAAA,MAAM,WAAA,GAAc,0BAA0B,OAAO,CAAA;AACrD,EAAA,OAAO,iBAAA,CAAkBA,kBAAA,CAAyB,OAAO,CAAA,EAAG;AAAA,IAC1D,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,EAAW,MAAM,WAAA,CAAY,SAAA;AAAY,GAC1C,CAAA;AACH;;;;"}
@@ -0,0 +1,164 @@
1
+ import { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';
2
+ import { isObjectLike, withActiveSpan, SPAN_STATUS_ERROR, startInactiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
3
+ import { GRAPHQL_PATCHED_SYMBOL, GRAPHQL_DATA_SYMBOL, GRAPHQL_PARENT_NAME, GRAPHQL_FIELD_TYPE, GRAPHQL_FIELD_PATH, GRAPHQL_FIELD_NAME, ORIGIN, SPAN_NAME_RESOLVE } from './constants.js';
4
+
5
+ function isPromise(value) {
6
+ return typeof value?.then === "function";
7
+ }
8
+ function wrapFields(type, getConfig) {
9
+ if (!type || type[GRAPHQL_PATCHED_SYMBOL]) {
10
+ return;
11
+ }
12
+ type[GRAPHQL_PATCHED_SYMBOL] = true;
13
+ const fields = type.getFields();
14
+ Object.keys(fields).forEach((key) => {
15
+ const field = fields[key];
16
+ if (!field) {
17
+ return;
18
+ }
19
+ if (field.resolve) {
20
+ field.resolve = wrapFieldResolver(getConfig, field.resolve);
21
+ }
22
+ if (field.type) {
23
+ for (const unwrappedType of unwrapType(field.type)) {
24
+ wrapFields(unwrappedType, getConfig);
25
+ }
26
+ }
27
+ });
28
+ }
29
+ function wrapFieldResolver(getConfig, fieldResolver, isDefaultResolver = false) {
30
+ if (typeof fieldResolver !== "function" || fieldResolver[GRAPHQL_PATCHED_SYMBOL]) {
31
+ return fieldResolver;
32
+ }
33
+ function wrappedFieldResolver(source, args, rawContextValue, info) {
34
+ if (!fieldResolver) {
35
+ return void 0;
36
+ }
37
+ const contextValue = rawContextValue ?? {};
38
+ const config = getConfig();
39
+ if (config.ignoreTrivialResolveSpans && isDefaultResolver && (isObjectLike(source) || typeof source === "function")) {
40
+ const property = source[info.fieldName];
41
+ if (typeof property !== "function") {
42
+ return fieldResolver.call(this, source, args, contextValue, info);
43
+ }
44
+ }
45
+ if (!contextValue[GRAPHQL_DATA_SYMBOL]) {
46
+ return fieldResolver.call(this, source, args, contextValue, info);
47
+ }
48
+ const path = pathToArray(info.path);
49
+ const { field, spanAdded } = createFieldIfNotExists(contextValue, info, path);
50
+ const span = field.span;
51
+ return withActiveSpan(span, () => {
52
+ try {
53
+ const res = fieldResolver.call(this, source, args, contextValue, info);
54
+ if (isPromise(res)) {
55
+ return res.then(
56
+ (r) => {
57
+ endResolveSpan(span, spanAdded);
58
+ return r;
59
+ },
60
+ (err) => {
61
+ endResolveSpan(span, spanAdded, err);
62
+ throw err;
63
+ }
64
+ );
65
+ }
66
+ endResolveSpan(span, spanAdded);
67
+ return res;
68
+ } catch (err) {
69
+ endResolveSpan(span, spanAdded, err);
70
+ throw err;
71
+ }
72
+ });
73
+ }
74
+ wrappedFieldResolver[GRAPHQL_PATCHED_SYMBOL] = true;
75
+ return wrappedFieldResolver;
76
+ }
77
+ function endResolveSpan(span, shouldEndSpan, error) {
78
+ if (!shouldEndSpan) {
79
+ return;
80
+ }
81
+ if (error) {
82
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });
83
+ }
84
+ span.end();
85
+ }
86
+ function createFieldIfNotExists(contextValue, info, path) {
87
+ const existing = getField(contextValue, path);
88
+ if (existing) {
89
+ return { field: existing, spanAdded: false };
90
+ }
91
+ const field = { span: createResolverSpan(info, path, getParentFieldSpan(contextValue, path)) };
92
+ addField(contextValue, path, field);
93
+ return { field, spanAdded: true };
94
+ }
95
+ function createResolverSpan(info, path, parentSpan) {
96
+ const attributes = {
97
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
98
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,
99
+ [GRAPHQL_FIELD_NAME]: info.fieldName,
100
+ [GRAPHQL_FIELD_PATH]: path.join("."),
101
+ [GRAPHQL_FIELD_TYPE]: info.returnType.toString(),
102
+ [GRAPHQL_PARENT_NAME]: info.parentType.name
103
+ };
104
+ return startInactiveSpan({ name: `${SPAN_NAME_RESOLVE} ${path.join(".")}`, attributes, parentSpan });
105
+ }
106
+ function addField(contextValue, path, field) {
107
+ const data = contextValue[GRAPHQL_DATA_SYMBOL];
108
+ if (data) {
109
+ data.fields[path.join(".")] = field;
110
+ }
111
+ }
112
+ function getField(contextValue, path) {
113
+ return contextValue[GRAPHQL_DATA_SYMBOL]?.fields[path.join(".")];
114
+ }
115
+ function getParentFieldSpan(contextValue, path) {
116
+ for (let i = path.length - 1; i > 0; i--) {
117
+ const field = getField(contextValue, path.slice(0, i));
118
+ if (field) {
119
+ return field.span;
120
+ }
121
+ }
122
+ return contextValue[GRAPHQL_DATA_SYMBOL]?.span;
123
+ }
124
+ function pathToArray(path) {
125
+ const flattened = [];
126
+ let curr = path;
127
+ while (curr) {
128
+ flattened.push(String(curr.key));
129
+ curr = curr.prev;
130
+ }
131
+ return flattened.reverse();
132
+ }
133
+ function unwrapType(type) {
134
+ if ("ofType" in type && type.ofType) {
135
+ return unwrapType(type.ofType);
136
+ }
137
+ if (isGraphQLUnionType(type)) {
138
+ return type.getTypes();
139
+ }
140
+ if (isGraphQLObjectType(type)) {
141
+ return [type];
142
+ }
143
+ return [];
144
+ }
145
+ function isGraphQLUnionType(type) {
146
+ return "getTypes" in type && typeof type.getTypes === "function";
147
+ }
148
+ function isGraphQLObjectType(type) {
149
+ return "getFields" in type && typeof type.getFields === "function";
150
+ }
151
+ function getOperation(document, operationName) {
152
+ const definitions = document?.definitions;
153
+ if (!definitions || !Array.isArray(definitions)) {
154
+ return void 0;
155
+ }
156
+ const isOperation = (def) => !!def?.operation && ["query", "mutation", "subscription"].indexOf(def.operation) !== -1;
157
+ if (operationName) {
158
+ return definitions.filter(isOperation).find((def) => operationName === def?.name?.value);
159
+ }
160
+ return definitions.find(isOperation);
161
+ }
162
+
163
+ export { getOperation, wrapFieldResolver, wrapFields };
164
+ //# sourceMappingURL=resolvers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvers.js","sources":["../../../../../src/integrations/tracing-channel/graphql/resolvers.ts"],"sourcesContent":["/*\n * Resolver-span wrapping for the orchestrion graphql path. graphql v14–16 publishes no per-field\n * `resolve` channel (unlike v17's native one), so the schema's field resolvers are swapped for\n * span-creating proxies under the execute channel's `start` (the \"consumer trick\" — the transform\n * can't target user resolvers, but `execute` receives the schema, so we mutate it before the wrapped\n * call runs). Resolver spans use the same origin/op/field attributes as the native subscriber.\n */\n\nimport { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n isObjectLike,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n GRAPHQL_DATA_SYMBOL,\n GRAPHQL_FIELD_NAME,\n GRAPHQL_FIELD_PATH,\n GRAPHQL_FIELD_TYPE,\n GRAPHQL_PARENT_NAME,\n GRAPHQL_PATCHED_SYMBOL,\n ORIGIN,\n SPAN_NAME_RESOLVE,\n} from './constants';\nimport type {\n DefinitionNode,\n DocumentNode,\n GraphQLFieldResolver,\n GraphQLObjectType,\n GraphQLOutputType,\n GraphQLPath,\n GraphQLResolveInfo,\n GraphQLType,\n GraphQLUnionType,\n GraphqlResolvedConfig,\n Maybe,\n ObjectWithGraphQLData,\n Patched,\n} from './types';\n\nfunction isPromise(value: unknown): value is Promise<unknown> {\n return typeof (value as { then?: unknown } | undefined)?.then === 'function';\n}\n\n/**\n * Walks the query/mutation type tree and swaps each field's `resolve` for a span-creating proxy.\n * Idempotent per type via {@link GRAPHQL_PATCHED_SYMBOL}.\n */\nexport function wrapFields(type: Maybe<GraphQLObjectType & Patched>, getConfig: () => GraphqlResolvedConfig): void {\n if (!type || type[GRAPHQL_PATCHED_SYMBOL]) {\n return;\n }\n\n type[GRAPHQL_PATCHED_SYMBOL] = true;\n const fields = type.getFields();\n\n Object.keys(fields).forEach(key => {\n const field = fields[key];\n if (!field) {\n return;\n }\n\n if (field.resolve) {\n field.resolve = wrapFieldResolver(getConfig, field.resolve);\n }\n\n if (field.type) {\n for (const unwrappedType of unwrapType(field.type)) {\n wrapFields(unwrappedType, getConfig);\n }\n }\n });\n}\n\nexport function wrapFieldResolver(\n getConfig: () => GraphqlResolvedConfig,\n fieldResolver: Maybe<GraphQLFieldResolver & Patched>,\n isDefaultResolver = false,\n): GraphQLFieldResolver & Patched {\n // Return the resolver untouched if it isn't a function or is already a wrapped one — the wrapper we\n // return is marked with `GRAPHQL_PATCHED_SYMBOL` below precisely so it can be detected here. (The\n // guard must test the incoming `fieldResolver`, not the freshly-hoisted `wrappedFieldResolver`.)\n if (typeof fieldResolver !== 'function' || fieldResolver[GRAPHQL_PATCHED_SYMBOL]) {\n return fieldResolver as GraphQLFieldResolver;\n }\n\n function wrappedFieldResolver(\n this: unknown,\n source: unknown,\n args: unknown,\n rawContextValue: unknown,\n info: GraphQLResolveInfo,\n ): unknown {\n if (!fieldResolver) {\n return undefined;\n }\n\n const contextValue = (rawContextValue ?? {}) as ObjectWithGraphQLData;\n const config = getConfig();\n\n // Mirror graphql's own \"trivial resolver\" check: a default resolver that just reads a\n // non-function property is not worth a span.\n if (\n config.ignoreTrivialResolveSpans &&\n isDefaultResolver &&\n (isObjectLike(source) || typeof source === 'function')\n ) {\n const property = (source as Record<string, unknown>)[info.fieldName];\n if (typeof property !== 'function') {\n return fieldResolver.call(this, source, args, contextValue, info);\n }\n }\n\n if (!contextValue[GRAPHQL_DATA_SYMBOL]) {\n return fieldResolver.call(this, source, args, contextValue, info);\n }\n\n const path = pathToArray(info.path);\n const { field, spanAdded } = createFieldIfNotExists(contextValue, info, path);\n const span = field.span;\n\n return withActiveSpan(span, () => {\n try {\n const res = fieldResolver.call(this, source, args, contextValue, info);\n if (isPromise(res)) {\n return res.then(\n r => {\n endResolveSpan(span, spanAdded);\n return r;\n },\n (err: Error) => {\n endResolveSpan(span, spanAdded, err);\n throw err;\n },\n );\n }\n endResolveSpan(span, spanAdded);\n return res;\n } catch (err) {\n endResolveSpan(span, spanAdded, err as Error);\n throw err;\n }\n });\n }\n\n (wrappedFieldResolver as Patched)[GRAPHQL_PATCHED_SYMBOL] = true;\n return wrappedFieldResolver;\n}\n\nfunction endResolveSpan(span: Span, shouldEndSpan: boolean, error?: Error): void {\n if (!shouldEndSpan) {\n return;\n }\n if (error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });\n }\n span.end();\n}\n\nfunction createFieldIfNotExists(\n contextValue: ObjectWithGraphQLData,\n info: GraphQLResolveInfo,\n path: string[],\n): { field: { span: Span }; spanAdded: boolean } {\n const existing = getField(contextValue, path);\n if (existing) {\n return { field: existing, spanAdded: false };\n }\n\n const field = { span: createResolverSpan(info, path, getParentFieldSpan(contextValue, path)) };\n addField(contextValue, path, field);\n return { field, spanAdded: true };\n}\n\nfunction createResolverSpan(info: GraphQLResolveInfo, path: string[], parentSpan?: Span): Span {\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_FIELD_NAME]: info.fieldName,\n [GRAPHQL_FIELD_PATH]: path.join('.'),\n [GRAPHQL_FIELD_TYPE]: info.returnType.toString(),\n [GRAPHQL_PARENT_NAME]: info.parentType.name,\n };\n\n return startInactiveSpan({ name: `${SPAN_NAME_RESOLVE} ${path.join('.')}`, attributes, parentSpan });\n}\n\nfunction addField(contextValue: ObjectWithGraphQLData, path: string[], field: { span: Span }): void {\n const data = contextValue[GRAPHQL_DATA_SYMBOL];\n if (data) {\n data.fields[path.join('.')] = field;\n }\n}\n\nfunction getField(contextValue: ObjectWithGraphQLData, path: string[]): { span: Span } | undefined {\n return contextValue[GRAPHQL_DATA_SYMBOL]?.fields[path.join('.')];\n}\n\nfunction getParentFieldSpan(contextValue: ObjectWithGraphQLData, path: string[]): Span | undefined {\n for (let i = path.length - 1; i > 0; i--) {\n const field = getField(contextValue, path.slice(0, i));\n if (field) {\n return field.span;\n }\n }\n return contextValue[GRAPHQL_DATA_SYMBOL]?.span;\n}\n\nfunction pathToArray(path: GraphQLPath): string[] {\n const flattened: string[] = [];\n let curr: GraphQLPath | undefined = path;\n while (curr) {\n flattened.push(String(curr.key));\n curr = curr.prev;\n }\n return flattened.reverse();\n}\n\nfunction unwrapType(type: GraphQLOutputType): readonly (GraphQLObjectType & Patched)[] {\n // The structural index signature widens `ofType` to `unknown`, so narrow it back explicitly.\n if ('ofType' in type && type.ofType) {\n return unwrapType(type.ofType as GraphQLOutputType);\n }\n if (isGraphQLUnionType(type)) {\n return type.getTypes();\n }\n if (isGraphQLObjectType(type)) {\n return [type];\n }\n return [];\n}\n\nfunction isGraphQLUnionType(type: GraphQLType): type is GraphQLUnionType {\n return 'getTypes' in type && typeof type.getTypes === 'function';\n}\n\nfunction isGraphQLObjectType(type: GraphQLType): type is GraphQLObjectType {\n return 'getFields' in type && typeof (type as GraphQLObjectType).getFields === 'function';\n}\n\n/**\n * Returns the operation definition for `operationName` (or the first operation) from a parsed\n * document, or `undefined` for schema documents / when no operation is present.\n */\nexport function getOperation(document: DocumentNode, operationName?: Maybe<string>): DefinitionNode | undefined {\n const definitions: readonly DefinitionNode[] | undefined = document?.definitions;\n if (!definitions || !Array.isArray(definitions)) {\n return undefined;\n }\n\n const isOperation = (def: DefinitionNode): boolean =>\n !!def?.operation && ['query', 'mutation', 'subscription'].indexOf(def.operation) !== -1;\n\n if (operationName) {\n return definitions.filter(isOperation).find((def: DefinitionNode) => operationName === def?.name?.value);\n }\n return definitions.find(isOperation);\n}\n"],"names":[],"mappings":";;;;AA4CA,SAAS,UAAU,KAAA,EAA2C;AAC5D,EAAA,OAAO,OAAQ,OAA0C,IAAA,KAAS,UAAA;AACpE;AAMO,SAAS,UAAA,CAAW,MAA0C,SAAA,EAA8C;AACjH,EAAA,IAAI,CAAC,IAAA,IAAQ,IAAA,CAAK,sBAAsB,CAAA,EAAG;AACzC,IAAA;AAAA,EACF;AAEA,EAAA,IAAA,CAAK,sBAAsB,CAAA,GAAI,IAAA;AAC/B,EAAA,MAAM,MAAA,GAAS,KAAK,SAAA,EAAU;AAE9B,EAAA,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAAE,OAAA,CAAQ,CAAA,GAAA,KAAO;AACjC,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA;AAAA,IACF;AAEA,IAAA,IAAI,MAAM,OAAA,EAAS;AACjB,MAAA,KAAA,CAAM,OAAA,GAAU,iBAAA,CAAkB,SAAA,EAAW,KAAA,CAAM,OAAO,CAAA;AAAA,IAC5D;AAEA,IAAA,IAAI,MAAM,IAAA,EAAM;AACd,MAAA,KAAA,MAAW,aAAA,IAAiB,UAAA,CAAW,KAAA,CAAM,IAAI,CAAA,EAAG;AAClD,QAAA,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AQ,OAAO,IAAA,CAAK,QAAA,KAAa,UAAA;AACxD;AAEA,SAAS,oBAAoB,IAAA,EAA8C;AACzE,EAAA,OAAO,WAAA,IAAe,IAAA,IAAQ,OAAQ,IAAA,CAA2B,SAAA,KAAc,UAAA;AACjF;AAMO,SAAS,YAAA,CAAa,UAAwB,aAAA,EAA2D;AAC9G,EAAA,MAAM,cAAqD,QAAA,EAAU,WAAA;AACrE,EAAA,IAAI,CAAC,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC/C,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,WAAA,GAAc,CAAC,GAAA,KACnB,CAAC,CAAC,GAAA,EAAK,SAAA,IAAa,CAAC,OAAA,EAAS,YAAY,cAAc,CAAA,CAAE,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA,KAAM,EAAA;AAEvF,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,OAAO,WAAA,CAAY,MAAA,CAAO,WAAW,CAAA,CAAE,IAAA,CAAK,CAAC,GAAA,KAAwB,aAAA,KAAkB,GAAA,EAAK,IAAA,EAAM,KAAK,CAAA;AAAA,EACzG;AACA,EAAA,OAAO,WAAA,CAAY,KAAK,WAAW,CAAA;AACrC;;;;"}
@@ -0,0 +1,96 @@
1
+ import { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';
2
+ import { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';
3
+ import { startInactiveSpan, SPAN_STATUS_ERROR, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
4
+ import { redactGraphqlDocument, hasResultErrors, getOperationSpanName, renameRootSpanWithOperation } from '../../../graphql/utils.js';
5
+ import { ORIGIN, SPAN_NAME_PARSE, SPAN_NAME_VALIDATE, GRAPHQL_DATA_SYMBOL, SPAN_NAME_EXECUTE } from './constants.js';
6
+ import { wrapFieldResolver, wrapFields, getOperation } from './resolvers.js';
7
+
8
+ const BASE_ATTRIBUTES = {
9
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
10
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP
11
+ };
12
+ function startParseSpan() {
13
+ return startInactiveSpan({ name: SPAN_NAME_PARSE, attributes: { ...BASE_ATTRIBUTES } });
14
+ }
15
+ function startValidateSpan(documentAST) {
16
+ return startInactiveSpan({
17
+ name: SPAN_NAME_VALIDATE,
18
+ attributes: { ...BASE_ATTRIBUTES, [GRAPHQL_DOCUMENT]: redactGraphqlDocument(documentAST) }
19
+ });
20
+ }
21
+ function finalizeValidateSpan(span, result) {
22
+ if (Array.isArray(result) && result.length > 0) {
23
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: "invalid_argument" });
24
+ }
25
+ }
26
+ function normalizeExecuteArgs(argsArray) {
27
+ if (argsArray.length >= 2) {
28
+ return {
29
+ schema: argsArray[0 /* SCHEMA */],
30
+ document: argsArray[1 /* DOCUMENT */],
31
+ contextValue: argsArray[3 /* CONTEXT_VALUE */] ?? {},
32
+ operationName: argsArray[5 /* OPERATION_NAME */],
33
+ fieldResolver: argsArray[6 /* FIELD_RESOLVER */],
34
+ writeBack: (contextValue, fieldResolver) => {
35
+ argsArray[3 /* CONTEXT_VALUE */] = contextValue;
36
+ argsArray[6 /* FIELD_RESOLVER */] = fieldResolver;
37
+ }
38
+ };
39
+ }
40
+ const obj = argsArray[0] ?? {};
41
+ return {
42
+ schema: obj.schema,
43
+ document: obj.document,
44
+ contextValue: obj.contextValue ?? {},
45
+ operationName: obj.operationName,
46
+ fieldResolver: obj.fieldResolver,
47
+ writeBack: (contextValue, fieldResolver) => {
48
+ obj.contextValue = contextValue;
49
+ obj.fieldResolver = fieldResolver;
50
+ }
51
+ };
52
+ }
53
+ function startExecuteSpan(argsArray, self, config, getConfig) {
54
+ const args = normalizeExecuteArgs(argsArray);
55
+ const { schema, document } = args;
56
+ let { contextValue, fieldResolver } = args;
57
+ const alreadyInstrumented = !!contextValue[GRAPHQL_DATA_SYMBOL];
58
+ if (!config.ignoreResolveSpans && !alreadyInstrumented) {
59
+ const isUsingDefaultResolver = fieldResolver == null;
60
+ const defaultFieldResolver = self?.defaultFieldResolver;
61
+ const fieldResolverForExecute = fieldResolver ?? defaultFieldResolver;
62
+ if (fieldResolverForExecute) {
63
+ fieldResolver = wrapFieldResolver(getConfig, fieldResolverForExecute, isUsingDefaultResolver);
64
+ }
65
+ if (schema) {
66
+ wrapFields(schema.getQueryType(), getConfig);
67
+ wrapFields(schema.getMutationType(), getConfig);
68
+ }
69
+ }
70
+ const operation = getOperation(document, args.operationName);
71
+ const operationType = operation?.operation;
72
+ const operationName = operation?.name?.value ?? args.operationName ?? void 0;
73
+ const span = startInactiveSpan({
74
+ name: getOperationSpanName(operationType, operationName || void 0, SPAN_NAME_EXECUTE),
75
+ attributes: {
76
+ ...BASE_ATTRIBUTES,
77
+ [GRAPHQL_OPERATION_TYPE]: operationType,
78
+ [GRAPHQL_OPERATION_NAME]: operationName || void 0,
79
+ [GRAPHQL_DOCUMENT]: redactGraphqlDocument(document)
80
+ }
81
+ });
82
+ if (config.useOperationNameForRootSpan && operationType) {
83
+ renameRootSpanWithOperation(span, operationType, operationName || void 0);
84
+ }
85
+ contextValue[GRAPHQL_DATA_SYMBOL] = { source: document, span, fields: {} };
86
+ args.writeBack(contextValue, fieldResolver);
87
+ return span;
88
+ }
89
+ function finalizeExecuteSpan(span, result) {
90
+ if (hasResultErrors(result)) {
91
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
92
+ }
93
+ }
94
+
95
+ export { finalizeExecuteSpan, finalizeValidateSpan, startExecuteSpan, startParseSpan, startValidateSpan };
96
+ //# sourceMappingURL=spans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spans.js","sources":["../../../../../src/integrations/tracing-channel/graphql/spans.ts"],"sourcesContent":["/*\n * Span builders for the orchestrion graphql channels (v14–16). They emit the same spans as the native\n * `diagnostics_channel` subscriber (`../../../graphql/graphql-dc-subscriber.ts`, graphql >= 17) by\n * reusing its `utils` and conventions — only the data source differs: here the payloads are the raw\n * arguments of the injected `parse`/`validate`/`execute` calls rather than graphql's native events.\n */\n\nimport { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';\nimport { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';\nimport type { Span } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { GraphqlDocumentNode } from '../../../graphql/utils';\nimport {\n getOperationSpanName,\n hasResultErrors,\n redactGraphqlDocument,\n renameRootSpanWithOperation,\n} from '../../../graphql/utils';\nimport { GRAPHQL_DATA_SYMBOL, ORIGIN, SPAN_NAME_EXECUTE, SPAN_NAME_PARSE, SPAN_NAME_VALIDATE } from './constants';\nimport { getOperation, wrapFields, wrapFieldResolver } from './resolvers';\nimport type {\n DocumentNode,\n GraphQLFieldResolver,\n GraphQLSchema,\n GraphqlResolvedConfig,\n Maybe,\n ObjectWithGraphQLData,\n} from './types';\n\nconst BASE_ATTRIBUTES = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n} as const;\n\nexport function startParseSpan(): Span {\n return startInactiveSpan({ name: SPAN_NAME_PARSE, attributes: { ...BASE_ATTRIBUTES } });\n}\n\n/** `documentAST` is the 2nd argument to `validate(schema, documentAST, …)`. */\nexport function startValidateSpan(documentAST: unknown): Span {\n return startInactiveSpan({\n name: SPAN_NAME_VALIDATE,\n attributes: { ...BASE_ATTRIBUTES, [GRAPHQL_DOCUMENT]: redactGraphqlDocument(documentAST as GraphqlDocumentNode) },\n });\n}\n\n/** `result` is validation's return value: a (possibly empty) array of errors. */\nexport function finalizeValidateSpan(span: Span, result: unknown): void {\n if (Array.isArray(result) && result.length > 0) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'invalid_argument' });\n }\n}\n\n/** Positional slots of a `graphql.execute(schema, document, …)` call (v14/v15 legacy signature). */\nconst enum ExecuteArg {\n SCHEMA = 0,\n DOCUMENT = 1,\n CONTEXT_VALUE = 3,\n OPERATION_NAME = 5,\n FIELD_RESOLVER = 6,\n}\n\ninterface NormalizedExecuteArgs {\n schema?: GraphQLSchema;\n document?: DocumentNode;\n contextValue: ObjectWithGraphQLData;\n operationName?: Maybe<string>;\n fieldResolver?: Maybe<GraphQLFieldResolver>;\n /** Writes `contextValue`/`fieldResolver` mutations back to the live channel `arguments`. */\n writeBack: (contextValue: ObjectWithGraphQLData, fieldResolver: Maybe<GraphQLFieldResolver>) => void;\n}\n\n/**\n * `execute` accepts either a single `ExecutionArgs` object (modern callers, always in v16) or\n * positional args (v14/v15). Both are normalized here; `writeBack` puts mutations onto the correct\n * slot so they reach the real call.\n */\nfunction normalizeExecuteArgs(argsArray: unknown[]): NormalizedExecuteArgs {\n if (argsArray.length >= 2) {\n return {\n schema: argsArray[ExecuteArg.SCHEMA] as GraphQLSchema | undefined,\n document: argsArray[ExecuteArg.DOCUMENT] as DocumentNode | undefined,\n contextValue: (argsArray[ExecuteArg.CONTEXT_VALUE] ?? {}) as ObjectWithGraphQLData,\n operationName: argsArray[ExecuteArg.OPERATION_NAME] as Maybe<string>,\n fieldResolver: argsArray[ExecuteArg.FIELD_RESOLVER] as Maybe<GraphQLFieldResolver>,\n writeBack: (contextValue, fieldResolver) => {\n argsArray[ExecuteArg.CONTEXT_VALUE] = contextValue;\n argsArray[ExecuteArg.FIELD_RESOLVER] = fieldResolver;\n },\n };\n }\n\n const obj = (argsArray[0] ?? {}) as {\n schema?: GraphQLSchema;\n document?: DocumentNode;\n contextValue?: unknown;\n operationName?: Maybe<string>;\n fieldResolver?: Maybe<GraphQLFieldResolver>;\n };\n return {\n schema: obj.schema,\n document: obj.document,\n contextValue: (obj.contextValue ?? {}) as ObjectWithGraphQLData,\n operationName: obj.operationName,\n fieldResolver: obj.fieldResolver,\n writeBack: (contextValue, fieldResolver) => {\n obj.contextValue = contextValue;\n obj.fieldResolver = fieldResolver;\n },\n };\n}\n\n/**\n * Opens the execute span and, unless resolver spans are disabled, swaps the schema's field resolvers\n * (and the default field resolver) for span-creating proxies — mutating the live `arguments` in place\n * so the wrapped `execute` call runs with them. Always returns a span; the caller guards against\n * throws (see `safe` in `index.ts`).\n */\nexport function startExecuteSpan(\n argsArray: unknown[],\n self: unknown,\n config: GraphqlResolvedConfig,\n getConfig: () => GraphqlResolvedConfig,\n): Span {\n const args = normalizeExecuteArgs(argsArray);\n const { schema, document } = args;\n let { contextValue, fieldResolver } = args;\n\n // Skip resolver wrapping when disabled or when a parent execute already set up this context\n // (nested execute reusing the same contextValue).\n const alreadyInstrumented = !!contextValue[GRAPHQL_DATA_SYMBOL];\n if (!config.ignoreResolveSpans && !alreadyInstrumented) {\n const isUsingDefaultResolver = fieldResolver == null;\n const defaultFieldResolver = (self as { defaultFieldResolver?: GraphQLFieldResolver } | undefined)\n ?.defaultFieldResolver;\n const fieldResolverForExecute = fieldResolver ?? defaultFieldResolver;\n if (fieldResolverForExecute) {\n fieldResolver = wrapFieldResolver(getConfig, fieldResolverForExecute, isUsingDefaultResolver);\n }\n\n if (schema) {\n wrapFields(schema.getQueryType(), getConfig);\n wrapFields(schema.getMutationType(), getConfig);\n }\n }\n\n // v14–16 channels carry only the raw args, so derive the operation from the document (native v17\n // provides `operationType`/`operationName` on the event directly).\n const operation = getOperation(document as DocumentNode, args.operationName);\n const operationType = operation?.operation;\n const operationName = operation?.name?.value ?? args.operationName ?? undefined;\n\n const span = startInactiveSpan({\n name: getOperationSpanName(operationType, operationName || undefined, SPAN_NAME_EXECUTE),\n attributes: {\n ...BASE_ATTRIBUTES,\n [GRAPHQL_OPERATION_TYPE]: operationType,\n [GRAPHQL_OPERATION_NAME]: operationName || undefined,\n [GRAPHQL_DOCUMENT]: redactGraphqlDocument(document as GraphqlDocumentNode | undefined),\n },\n });\n\n if (config.useOperationNameForRootSpan && operationType) {\n renameRootSpanWithOperation(span, operationType, operationName || undefined);\n }\n\n // The resolver proxies read the execute span (and their own bookkeeping) off this symbol.\n contextValue[GRAPHQL_DATA_SYMBOL] = { source: document, span, fields: {} };\n args.writeBack(contextValue, fieldResolver);\n\n return span;\n}\n\n/** `result` is the settled `ExecutionResult`; GraphQL errors surface on `result.errors`, not a throw. */\nexport function finalizeExecuteSpan(span: Span, result: unknown): void {\n if (hasResultErrors(result)) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n}\n"],"names":[],"mappings":";;;;;;;AAkCA,MAAM,eAAA,GAAkB;AAAA,EACtB,CAAC,gCAAgC,GAAG,MAAA;AAAA,EACpC,CAAC,4BAA4B,GAAG;AAClC,CAAA;AAEO,SAAS,cAAA,GAAuB;AACrC,EAAA,OAAO,iBAAA,CAAkB,EAAE,IAAA,EAAM,eAAA,EAAiB,YAAY,EAAE,GAAG,eAAA,EAAgB,EAAG,CAAA;AACxF;AAGO,SAAS,kBAAkB,WAAA,EAA4B;AAC5D,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,IAAA,EAAM,kBAAA;AAAA,IACN,UAAA,EAAY,EAAE,GAAG,eAAA,EAAiB,CAAC,gBAAgB,GAAG,qBAAA,CAAsB,WAAkC,CAAA;AAAE,GACjH,CAAA;AACH;AAGO,SAAS,oBAAA,CAAqB,MAAY,MAAA,EAAuB;AACtE,EAAA,IAAI,MAAM,OAAA,CAAQ,MAAM,CAAA,IAAK,MAAA,CAAO,SAAS,CAAA,EAAG;AAC9C,IAAA,IAAA,CAAK,UAAU,EA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A,CAAO,+BAA+B,aAAA,EAAe;AACvD,IAAA,2BAAA,CAA4B,IAAA,EAAM,aAAA,EAAe,aAAA,IAAiB,MAAS,CAAA;AAAA,EAC7E;AAGA,EAAA,YAAA,CAAa,mBAAmB,IAAI,EAAE,MAAA,EAAQ,UAAU,IAAA,EAAM,MAAA,EAAQ,EAAC,EAAE;AACzE,EAAA,IAAA,CAAK,SAAA,CAAU,cAAc,aAAa,CAAA;AAE1C,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,mBAAA,CAAoB,MAAY,MAAA,EAAuB;AACrE,EAAA,IAAI,eAAA,CAAgB,MAAM,CAAA,EAAG;AAC3B,IAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,iBAAA,EAAmB,OAAA,EAAS,kBAAkB,CAAA;AAAA,EACvE;AACF;;;;"}
@@ -1,6 +1,6 @@
1
1
  import * as diagnosticsChannel from 'node:diagnostics_channel';
2
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';
3
+ import { defineIntegration, debug, waitForTracingChannelBinding, startInactiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
4
4
  import { DEBUG_BUILD } from '../../debug-build.js';
5
5
  import { CHANNELS } from '../../orchestrion/channels.js';
6
6
  import { defaultDbStatementSerializer } from '../../redis/redis-statement-serializer.js';
@@ -40,9 +40,6 @@ const _ioredisChannelIntegration = ((options = {}) => {
40
40
  bindTracingChannelToSpan(
41
41
  commandChannel,
42
42
  (data) => {
43
- if (!getActiveSpan()) {
44
- return void 0;
45
- }
46
43
  const command = data.arguments?.[0];
47
44
  if (!command || typeof command !== "object") {
48
45
  return void 0;
@@ -56,6 +53,8 @@ const _ioredisChannelIntegration = ((options = {}) => {
56
53
  });
57
54
  },
58
55
  {
56
+ // ioredis' `requireParentSpan` default: only create a span under an active span.
57
+ requiresParentSpan: true,
59
58
  beforeSpanEnd(span, data) {
60
59
  if ("error" in data || !responseHook) {
61
60
  return;
@@ -67,17 +66,18 @@ const _ioredisChannelIntegration = ((options = {}) => {
67
66
  }
68
67
  }
69
68
  );
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
- });
69
+ bindTracingChannelToSpan(
70
+ connectChannel,
71
+ (data) => {
72
+ const { host, port } = getConnectionOptions(data.self);
73
+ return startInactiveSpan({
74
+ name: "connect",
75
+ op: "db",
76
+ attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: "connect" }
77
+ });
78
+ },
79
+ { requiresParentSpan: true }
80
+ );
81
81
  });
82
82
  }
83
83
  };
@@ -1 +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,GAAmB,SAAA;AAEzB,MAAM,MAAA,GAAS,2BAAA;AAGf,MAAM,yBAAA,GAA4B,sBAAA;AA4BlC,SAAS,qBAAqB,IAAA,EAAqE;AACjG,EAAA,OAAO,EAAE,MAAM,IAAA,EAAM,OAAA,EAAS,MAAM,IAAA,EAAM,IAAA,EAAM,SAAS,IAAA,EAAK;AAChE;AAEA,SAAS,oBAAA,CAAqB,MAA0B,IAAA,EAAmD;AACzG,EAAA,OAAO;AAAA,IACL,CAAC,SAAS,GAAG,OAAA;AAAA,IACb,CAAC,yBAAyB,GAAG,CAAA,QAAA,EAAW,IAAI,IAAI,IAAI,CAAA,CAAA;AAAA,IACpD,CAAC,aAAa,GAAG,IAAA;AAAA,IACjB,CAAC,aAAa,GAAG,IAAA;AAAA,IACjB,CAAC,gCAAgC,GAAG;AAAA,GACtC;AACF;AAEA,MAAM,0BAAA,IAA8B,CAAC,OAAA,GAA4C,EAAC,KAAM;AACtF,EAAA,MAAM,eAAe,OAAA,CAAQ,YAAA;AAE7B,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,IACE,KAAA,CAAM,IAAI,CAAA,sCAAA,EAAyC,QAAA,CAAS,eAAe,CAAA,GAAA,EAAM,QAAA,CAAS,eAAe,CAAA,CAAA,CAAG,CAAA;AAE9G,MAAA,MAAM,iBAAiB,kBAAA,CAAmB,cAAA;AAAA,QACxC,QAAA,CAAS;AAAA,OACX;AACA,MAAA,MAAM,iB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UAAA,IAAI,CAAC,eAAc,EAAG;AACpB,YAAA,OAAO,MAAA;AAAA,UACT;AACA,UAAA,MAAM,EAAE,IAAA,EAAM,IAAA,EAAK,GAAI,oBAAA,CAAqB,KAAK,IAAI,CAAA;AACrD,UAAA,OAAO,iBAAA,CAAkB;AAAA,YACvB,IAAA,EAAM,SAAA;AAAA,YACN,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;;;;"}
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 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 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 // ioredis' `requireParentSpan` default: only create a span under an active span.\n requiresParentSpan: true,\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(\n connectChannel,\n data => {\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 { requiresParentSpan: true },\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":";;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,SAAA;AAEzB,MAAM,MAAA,GAAS,2BAAA;AAGf,MAAM,yBAAA,GAA4B,sBAAA;AA4BlC,SAAS,qBAAqB,IAAA,EAAqE;AACjG,EAAA,OAAO,EAAE,MAAM,IAAA,EAAM,OAAA,EAAS,MAAM,IAAA,EAAM,IAAA,EAAM,SAAS,IAAA,EAAK;AAChE;AAEA,SAAS,oBAAA,CAAqB,MAA0B,IAAA,EAAmD;AACzG,EAAA,OAAO;AAAA,IACL,CAAC,SAAS,GAAG,OAAA;AAAA,IACb,CAAC,yBAAyB,GAAG,CAAA,QAAA,EAAW,IAAI,IAAI,IAAI,CAAA,CAAA;AAAA,IACpD,CAAC,aAAa,GAAG,IAAA;AAAA,IACjB,CAAC,aAAa,GAAG,IAAA;AAAA,IACjB,CAAC,gCAAgC,GAAG;AAAA,GACtC;AACF;AAEA,MAAM,0BAAA,IAA8B,CAAC,OAAA,GAA4C,EAAC,KAAM;AACtF,EAAA,MAAM,eAAe,OAAA,CAAQ,YAAA;AAE7B,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,IACE,KAAA,CAAM,IAAI,CAAA,sCAAA,EAAyC,QAAA,CAAS,eAAe,CAAA,GAAA,EAAM,QAAA,CAAS,eAAe,CAAA,CAAA,CAAG,CAAA;AAE9G,MAAA,MAAM,iBAAiB,kBAAA,CAAmB,cA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;AAAA,UACA,CAAA,IAAA,KAAQ;AACN,YAAA,MAAM,EAAE,IAAA,EAAM,IAAA,EAAK,GAAI,oBAAA,CAAqB,KAAK,IAAI,CAAA;AACrD,YAAA,OAAO,iBAAA,CAAkB;AAAA,cACvB,IAAA,EAAM,SAAA;AAAA,cACN,EAAA,EAAI,IAAA;AAAA,cACJ,UAAA,EAAY,EAAE,GAAG,oBAAA,CAAqB,IAAA,EAAM,IAAI,CAAA,EAAG,CAAC,YAAY,GAAG,SAAA;AAAU,aAC9E,CAAA;AAAA,UACH,CAAA;AAAA,UACA,EAAE,oBAAoB,IAAA;AAAK,SAC7B;AAAA,MACF,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;;;;"}
@@ -1,5 +1,5 @@
1
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';
2
+ import { defineIntegration, debug, waitForTracingChannelBinding, bindScopeToEmitter, getCurrentScope, startInactiveSpan, SPAN_KIND, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, isObjectLike } from '@sentry/core';
3
3
  import { DEBUG_BUILD } from '../../debug-build.js';
4
4
  import { CHANNELS } from '../../orchestrion/channels.js';
5
5
  import { bindTracingChannelToSpan } from '../../tracing-channel.js';
@@ -74,7 +74,7 @@ function extractSql(firstArg) {
74
74
  if (typeof firstArg === "string") {
75
75
  return firstArg;
76
76
  }
77
- if (firstArg && typeof firstArg === "object" && "sql" in firstArg) {
77
+ if (isObjectLike(firstArg) && "sql" in firstArg) {
78
78
  const sql = firstArg.sql;
79
79
  return typeof sql === "string" ? sql : void 0;
80
80
  }
@@ -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 } 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 = defineI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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 isObjectLike,\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 (isObjectLike(firstArg) && '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":";;;;;;AAmBA,MAAM,gBAAA,GAAmB,OAAA;AAKzB,MAAM,cAAA,GAAiB,WAAA;AACvB,MAAM,yBAAA,GAA4B,sBAAA;AAClC,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,YA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AAA,EAAuC;AACzD,EAAA,IAAI,OAAO,aAAa,QAAA,EAAU;AAChC,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI,YAAA,CAAa,QAAQ,CAAA,IAAK,KAAA,IAAS,QAAA,EAAU;AAC/C,IAAA,MAAM,MAAO,QAAA,CAA+B,GAAA;AAC5C,IAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,MAAA;AAAA,EACzC;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,oBAAoB,UAAA,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,5 +1,5 @@
1
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';
2
+ import { defineIntegration, waitForTracingChannelBinding, debug, addOpenAiResponseAttributes, resolveAIRecordingOptions, instrumentOpenAiStream, _INTERNAL_shouldSkipAiProviderWrapping, shouldEnableTruncation, extractOpenAiRequestAttributes, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startInactiveSpan, addOpenAiRequestAttributes } from '@sentry/core';
3
3
  import { DEBUG_BUILD } from '../../debug-build.js';
4
4
  import { CHANNELS } from '../../orchestrion/channels.js';
5
5
  import { bindTracingChannelToSpan } from '../../tracing-channel.js';
@@ -1 +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,4BAAA;AAGf,MAAM,qBAAA,GAAwB;AAAA,EAC5B,EAAE,OAAA,EAAS,QAAA,CAAS,WAAA,EAAa,WAAW,MAAA,EAAO;AAAA,EACnD,EAAE,OAAA,EAAS,QAAA,CAAS,gBAAA,EAAkB,WAAW,MAAA,EAAO;AAAA,EACxD,EAAE,OAAA,EAAS,QAAA,CAAS,iBAAA,EAAmB,WAAW,YAAA,EAAa;AAAA,EAC/D,EAAE,OAAA,EAAS,QAAA,CAAS,oBAAA,EAAsB,WAAW,MAAA;AACvD,CAAA;AAYA,IAAI,UAAA,GAAa,KAAA;AAEjB,MAAM,yBAAA,IAA6B,CAAC,OAAA,GAAyB,EAAC,KAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAAC,kBAAA,CAAmB,cAAA,IAAkB,UAAA,EAAY;AACpD,QAAA;AAAA,MACF;AACA,MAAA,UAAA,GAAa,IAAA;AAIb,MAAA,4BAAA,CAA6B,MAAM;AACjC,QAAA,KAAA,MAAW,EAAE,OAAA,EAAS,SAAA,EAAU,IAAK,qBAAA,EAAuB;AAC1D,UAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,CAAA,6CAAA,EAAgD,OAAO,CAAA,CAAA,CAAG,CAAA;AACnF,UAAA,wBAAA;AAAA,YACE,kBAAA,CAAmB,eAAyC,OAAO,CAAA;AAAA,YACnE,CAAA,IAAA,KAAQ,eAAA,CAAgB,IAAA,EAAM,SAAA,EAAW,OAAO,CAAA;AAAA,YAChD;AAAA,cACE,aAAA,EAAe,CAAC,IAAA,EAAM,IAAA,KAAS;AAC7B,gBAAA,2BAAA,CAA4B,MAAM,IAAA,CAAK,M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AA,EAA8C;AACrE,EAAA,OAAO,CAAC,CAAC,KAAA,IAAS,OAAQ,KAAA,CAA8B,MAAA,CAAO,aAAa,CAAA,KAAM,UAAA;AACpF;AAWA,SAAS,gBAAA,CAAiB,IAAA,EAAY,IAAA,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;;;;"}
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 // When another provider (e.g. LangChain) is driving the SDK, it records the spans itself and marks this\n // provider as skipped; 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,4BAAA;AAGf,MAAM,qBAAA,GAAwB;AAAA,EAC5B,EAAE,OAAA,EAAS,QAAA,CAAS,WAAA,EAAa,WAAW,MAAA,EAAO;AAAA,EACnD,EAAE,OAAA,EAAS,QAAA,CAAS,gBAAA,EAAkB,WAAW,MAAA,EAAO;AAAA,EACxD,EAAE,OAAA,EAAS,QAAA,CAAS,iBAAA,EAAmB,WAAW,YAAA,EAAa;AAAA,EAC/D,EAAE,OAAA,EAAS,QAAA,CAAS,oBAAA,EAAsB,WAAW,MAAA;AACvD,CAAA;AAYA,IAAI,UAAA,GAAa,KAAA;AAEjB,MAAM,yBAAA,IAA6B,CAAC,OAAA,GAAyB,EAAC,KAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAAC,kBAAA,CAAmB,cAAA,IAAkB,UAAA,EAAY;AACpD,QAAA;AAAA,MACF;AACA,MAAA,UAAA,GAAa,IAAA;AAIb,MAAA,4BAAA,CAA6B,MAAM;AACjC,QAAA,KAAA,MAAW,EAAE,OAAA,EAAS,SAAA,EAAU,IAAK,qBAAA,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