@sentry/server-utils 10.65.0 → 10.66.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 (301) hide show
  1. package/build/cjs/graphql/graphql-dc-subscriber.js +2 -4
  2. package/build/cjs/graphql/graphql-dc-subscriber.js.map +1 -1
  3. package/build/cjs/graphql/utils.js +7 -1
  4. package/build/cjs/graphql/utils.js.map +1 -1
  5. package/build/cjs/index.js +11 -8
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/cjs/integrations/tracing-channel/dataloader.js +95 -0
  8. package/build/cjs/integrations/tracing-channel/dataloader.js.map +1 -0
  9. package/build/cjs/integrations/tracing-channel/generic-pool.js +34 -0
  10. package/build/cjs/integrations/tracing-channel/generic-pool.js.map +1 -0
  11. package/build/cjs/integrations/tracing-channel/graphql/spans.js +2 -2
  12. package/build/cjs/integrations/tracing-channel/graphql/spans.js.map +1 -1
  13. package/build/cjs/integrations/tracing-channel/ioredis.js +29 -26
  14. package/build/cjs/integrations/tracing-channel/ioredis.js.map +1 -1
  15. package/build/cjs/integrations/tracing-channel/kafkajs/consumer.js +71 -0
  16. package/build/cjs/integrations/tracing-channel/kafkajs/consumer.js.map +1 -0
  17. package/build/cjs/integrations/tracing-channel/kafkajs/index.js +70 -0
  18. package/build/cjs/integrations/tracing-channel/kafkajs/index.js.map +1 -0
  19. package/build/cjs/integrations/tracing-channel/kafkajs/semconv.js +22 -0
  20. package/build/cjs/integrations/tracing-channel/kafkajs/semconv.js.map +1 -0
  21. package/build/cjs/integrations/tracing-channel/kafkajs/spans.js +119 -0
  22. package/build/cjs/integrations/tracing-channel/kafkajs/spans.js.map +1 -0
  23. package/build/cjs/integrations/tracing-channel/knex.js +188 -0
  24. package/build/cjs/integrations/tracing-channel/knex.js.map +1 -0
  25. package/build/cjs/integrations/tracing-channel/mysql2.js +83 -0
  26. package/build/cjs/integrations/tracing-channel/mysql2.js.map +1 -0
  27. package/build/cjs/orchestrion/bundler/esbuild.js +11 -0
  28. package/build/cjs/orchestrion/bundler/esbuild.js.map +1 -0
  29. package/build/cjs/orchestrion/bundler/options.js +15 -0
  30. package/build/cjs/orchestrion/bundler/options.js.map +1 -0
  31. package/build/cjs/orchestrion/bundler/rollup.js +11 -0
  32. package/build/cjs/orchestrion/bundler/rollup.js.map +1 -0
  33. package/build/cjs/orchestrion/bundler/vite.js +4 -21
  34. package/build/cjs/orchestrion/bundler/vite.js.map +1 -1
  35. package/build/cjs/orchestrion/bundler/webpack.js +32 -0
  36. package/build/cjs/orchestrion/bundler/webpack.js.map +1 -0
  37. package/build/cjs/orchestrion/channels.js +50 -20
  38. package/build/cjs/orchestrion/channels.js.map +1 -1
  39. package/build/cjs/orchestrion/config/dataloader.js +53 -0
  40. package/build/cjs/orchestrion/config/dataloader.js.map +1 -0
  41. package/build/cjs/orchestrion/config/firebase.js +8 -0
  42. package/build/cjs/orchestrion/config/firebase.js.map +1 -0
  43. package/build/cjs/orchestrion/config/generic-pool.js +21 -0
  44. package/build/cjs/orchestrion/config/generic-pool.js.map +1 -0
  45. package/build/cjs/orchestrion/config/index.js +55 -23
  46. package/build/cjs/orchestrion/config/index.js.map +1 -1
  47. package/build/cjs/orchestrion/config/kafkajs.js +30 -0
  48. package/build/cjs/orchestrion/config/kafkajs.js.map +1 -0
  49. package/build/cjs/orchestrion/config/knex.js +43 -0
  50. package/build/cjs/orchestrion/config/knex.js.map +1 -0
  51. package/build/cjs/orchestrion/config/langchain.js +8 -0
  52. package/build/cjs/orchestrion/config/langchain.js.map +1 -0
  53. package/build/cjs/orchestrion/config/langgraph.js +8 -0
  54. package/build/cjs/orchestrion/config/langgraph.js.map +1 -0
  55. package/build/cjs/orchestrion/config/mongodb.js +8 -0
  56. package/build/cjs/orchestrion/config/mongodb.js.map +1 -0
  57. package/build/cjs/orchestrion/config/mongoose.js +8 -0
  58. package/build/cjs/orchestrion/config/mongoose.js.map +1 -0
  59. package/build/cjs/orchestrion/config/mysql2.js +32 -0
  60. package/build/cjs/orchestrion/config/mysql2.js.map +1 -0
  61. package/build/cjs/orchestrion/config/nestjs.js +122 -0
  62. package/build/cjs/orchestrion/config/nestjs.js.map +1 -0
  63. package/build/cjs/orchestrion/config/prisma.js +8 -0
  64. package/build/cjs/orchestrion/config/prisma.js.map +1 -0
  65. package/build/cjs/orchestrion/config/react-router.js +8 -0
  66. package/build/cjs/orchestrion/config/react-router.js.map +1 -0
  67. package/build/cjs/orchestrion/config/remix.js +8 -0
  68. package/build/cjs/orchestrion/config/remix.js.map +1 -0
  69. package/build/cjs/orchestrion/config/tedious.js +8 -0
  70. package/build/cjs/orchestrion/config/tedious.js.map +1 -0
  71. package/build/cjs/orchestrion/detect.js +12 -11
  72. package/build/cjs/orchestrion/detect.js.map +1 -1
  73. package/build/cjs/orchestrion/index.js +16 -1
  74. package/build/cjs/orchestrion/index.js.map +1 -1
  75. package/build/cjs/orchestrion/runtime/register.js +25 -14
  76. package/build/cjs/orchestrion/runtime/register.js.map +1 -1
  77. package/build/cjs/prisma/global.js +14 -0
  78. package/build/cjs/prisma/global.js.map +1 -0
  79. package/build/cjs/prisma/index.js +27 -0
  80. package/build/cjs/prisma/index.js.map +1 -0
  81. package/build/cjs/prisma/tracing-helper.js +211 -0
  82. package/build/cjs/prisma/tracing-helper.js.map +1 -0
  83. package/build/cjs/vercel-ai/util.js +0 -11
  84. package/build/cjs/vercel-ai/util.js.map +1 -1
  85. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +9 -9
  86. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  87. package/build/esm/graphql/graphql-dc-subscriber.js +3 -5
  88. package/build/esm/graphql/graphql-dc-subscriber.js.map +1 -1
  89. package/build/esm/graphql/utils.js +8 -2
  90. package/build/esm/graphql/utils.js.map +1 -1
  91. package/build/esm/index.js +1 -0
  92. package/build/esm/index.js.map +1 -1
  93. package/build/esm/integrations/tracing-channel/dataloader.js +93 -0
  94. package/build/esm/integrations/tracing-channel/dataloader.js.map +1 -0
  95. package/build/esm/integrations/tracing-channel/generic-pool.js +32 -0
  96. package/build/esm/integrations/tracing-channel/generic-pool.js.map +1 -0
  97. package/build/esm/integrations/tracing-channel/graphql/spans.js +3 -3
  98. package/build/esm/integrations/tracing-channel/graphql/spans.js.map +1 -1
  99. package/build/esm/integrations/tracing-channel/ioredis.js +29 -27
  100. package/build/esm/integrations/tracing-channel/ioredis.js.map +1 -1
  101. package/build/esm/integrations/tracing-channel/kafkajs/consumer.js +67 -0
  102. package/build/esm/integrations/tracing-channel/kafkajs/consumer.js.map +1 -0
  103. package/build/esm/integrations/tracing-channel/kafkajs/index.js +68 -0
  104. package/build/esm/integrations/tracing-channel/kafkajs/index.js.map +1 -0
  105. package/build/esm/integrations/tracing-channel/kafkajs/semconv.js +12 -0
  106. package/build/esm/integrations/tracing-channel/kafkajs/semconv.js.map +1 -0
  107. package/build/esm/integrations/tracing-channel/kafkajs/spans.js +112 -0
  108. package/build/esm/integrations/tracing-channel/kafkajs/spans.js.map +1 -0
  109. package/build/esm/integrations/tracing-channel/knex.js +186 -0
  110. package/build/esm/integrations/tracing-channel/knex.js.map +1 -0
  111. package/build/esm/integrations/tracing-channel/mysql2.js +81 -0
  112. package/build/esm/integrations/tracing-channel/mysql2.js.map +1 -0
  113. package/build/esm/orchestrion/bundler/esbuild.js +9 -0
  114. package/build/esm/orchestrion/bundler/esbuild.js.map +1 -0
  115. package/build/esm/orchestrion/bundler/options.js +13 -0
  116. package/build/esm/orchestrion/bundler/options.js.map +1 -0
  117. package/build/esm/orchestrion/bundler/rollup.js +9 -0
  118. package/build/esm/orchestrion/bundler/rollup.js.map +1 -0
  119. package/build/esm/orchestrion/bundler/vite.js +5 -22
  120. package/build/esm/orchestrion/bundler/vite.js.map +1 -1
  121. package/build/esm/orchestrion/bundler/webpack.js +27 -0
  122. package/build/esm/orchestrion/bundler/webpack.js.map +1 -0
  123. package/build/esm/orchestrion/channels.js +50 -20
  124. package/build/esm/orchestrion/channels.js.map +1 -1
  125. package/build/esm/orchestrion/config/dataloader.js +50 -0
  126. package/build/esm/orchestrion/config/dataloader.js.map +1 -0
  127. package/build/esm/orchestrion/config/firebase.js +5 -0
  128. package/build/esm/orchestrion/config/firebase.js.map +1 -0
  129. package/build/esm/orchestrion/config/generic-pool.js +18 -0
  130. package/build/esm/orchestrion/config/generic-pool.js.map +1 -0
  131. package/build/esm/orchestrion/config/index.js +55 -24
  132. package/build/esm/orchestrion/config/index.js.map +1 -1
  133. package/build/esm/orchestrion/config/kafkajs.js +27 -0
  134. package/build/esm/orchestrion/config/kafkajs.js.map +1 -0
  135. package/build/esm/orchestrion/config/knex.js +40 -0
  136. package/build/esm/orchestrion/config/knex.js.map +1 -0
  137. package/build/esm/orchestrion/config/langchain.js +5 -0
  138. package/build/esm/orchestrion/config/langchain.js.map +1 -0
  139. package/build/esm/orchestrion/config/langgraph.js +5 -0
  140. package/build/esm/orchestrion/config/langgraph.js.map +1 -0
  141. package/build/esm/orchestrion/config/mongodb.js +5 -0
  142. package/build/esm/orchestrion/config/mongodb.js.map +1 -0
  143. package/build/esm/orchestrion/config/mongoose.js +5 -0
  144. package/build/esm/orchestrion/config/mongoose.js.map +1 -0
  145. package/build/esm/orchestrion/config/mysql2.js +29 -0
  146. package/build/esm/orchestrion/config/mysql2.js.map +1 -0
  147. package/build/esm/orchestrion/config/nestjs.js +119 -0
  148. package/build/esm/orchestrion/config/nestjs.js.map +1 -0
  149. package/build/esm/orchestrion/config/prisma.js +5 -0
  150. package/build/esm/orchestrion/config/prisma.js.map +1 -0
  151. package/build/esm/orchestrion/config/react-router.js +5 -0
  152. package/build/esm/orchestrion/config/react-router.js.map +1 -0
  153. package/build/esm/orchestrion/config/remix.js +5 -0
  154. package/build/esm/orchestrion/config/remix.js.map +1 -0
  155. package/build/esm/orchestrion/config/tedious.js +5 -0
  156. package/build/esm/orchestrion/config/tedious.js.map +1 -0
  157. package/build/esm/orchestrion/detect.js +13 -12
  158. package/build/esm/orchestrion/detect.js.map +1 -1
  159. package/build/esm/orchestrion/index.js +11 -2
  160. package/build/esm/orchestrion/index.js.map +1 -1
  161. package/build/esm/orchestrion/runtime/register.js +27 -16
  162. package/build/esm/orchestrion/runtime/register.js.map +1 -1
  163. package/build/esm/package.json +1 -1
  164. package/build/esm/prisma/global.js +12 -0
  165. package/build/esm/prisma/global.js.map +1 -0
  166. package/build/esm/prisma/index.js +24 -0
  167. package/build/esm/prisma/index.js.map +1 -0
  168. package/build/esm/prisma/tracing-helper.js +209 -0
  169. package/build/esm/prisma/tracing-helper.js.map +1 -0
  170. package/build/esm/vercel-ai/util.js +1 -11
  171. package/build/esm/vercel-ai/util.js.map +1 -1
  172. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +11 -11
  173. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  174. package/build/types/graphql/utils.d.ts +2 -6
  175. package/build/types/graphql/utils.d.ts.map +1 -1
  176. package/build/types/index.d.ts +2 -0
  177. package/build/types/index.d.ts.map +1 -1
  178. package/build/types/integrations/tracing-channel/dataloader.d.ts +11 -0
  179. package/build/types/integrations/tracing-channel/dataloader.d.ts.map +1 -0
  180. package/build/types/integrations/tracing-channel/generic-pool.d.ts +10 -0
  181. package/build/types/integrations/tracing-channel/generic-pool.d.ts.map +1 -0
  182. package/build/types/integrations/tracing-channel/ioredis.d.ts +20 -0
  183. package/build/types/integrations/tracing-channel/ioredis.d.ts.map +1 -1
  184. package/build/types/integrations/tracing-channel/kafkajs/consumer.d.ts +8 -0
  185. package/build/types/integrations/tracing-channel/kafkajs/consumer.d.ts.map +1 -0
  186. package/build/types/integrations/tracing-channel/kafkajs/index.d.ts +17 -0
  187. package/build/types/integrations/tracing-channel/kafkajs/index.d.ts.map +1 -0
  188. package/build/types/integrations/tracing-channel/kafkajs/semconv.d.ts +10 -0
  189. package/build/types/integrations/tracing-channel/kafkajs/semconv.d.ts.map +1 -0
  190. package/build/types/integrations/tracing-channel/kafkajs/spans.d.ts +38 -0
  191. package/build/types/integrations/tracing-channel/kafkajs/spans.d.ts.map +1 -0
  192. package/build/types/integrations/tracing-channel/kafkajs/types.d.ts +40 -0
  193. package/build/types/integrations/tracing-channel/kafkajs/types.d.ts.map +1 -0
  194. package/build/types/integrations/tracing-channel/knex.d.ts +11 -0
  195. package/build/types/integrations/tracing-channel/knex.d.ts.map +1 -0
  196. package/build/types/integrations/tracing-channel/mysql2.d.ts +15 -0
  197. package/build/types/integrations/tracing-channel/mysql2.d.ts.map +1 -0
  198. package/build/types/orchestrion/bundler/esbuild.d.ts +21 -0
  199. package/build/types/orchestrion/bundler/esbuild.d.ts.map +1 -0
  200. package/build/types/orchestrion/bundler/options.d.ts +19 -0
  201. package/build/types/orchestrion/bundler/options.d.ts.map +1 -0
  202. package/build/types/orchestrion/bundler/rollup.d.ts +17 -0
  203. package/build/types/orchestrion/bundler/rollup.d.ts.map +1 -0
  204. package/build/types/orchestrion/bundler/vite.d.ts +4 -17
  205. package/build/types/orchestrion/bundler/vite.d.ts.map +1 -1
  206. package/build/types/orchestrion/bundler/webpack.d.ts +19 -0
  207. package/build/types/orchestrion/bundler/webpack.d.ts.map +1 -0
  208. package/build/types/orchestrion/channels.d.ts +64 -37
  209. package/build/types/orchestrion/channels.d.ts.map +1 -1
  210. package/build/types/orchestrion/config/dataloader.d.ts +46 -0
  211. package/build/types/orchestrion/config/dataloader.d.ts.map +1 -0
  212. package/build/types/orchestrion/config/firebase.d.ts +4 -0
  213. package/build/types/orchestrion/config/firebase.d.ts.map +1 -0
  214. package/build/types/orchestrion/config/generic-pool.d.ts +31 -0
  215. package/build/types/orchestrion/config/generic-pool.d.ts.map +1 -0
  216. package/build/types/orchestrion/config/index.d.ts +18 -5
  217. package/build/types/orchestrion/config/index.d.ts.map +1 -1
  218. package/build/types/orchestrion/config/kafkajs.d.ts +17 -0
  219. package/build/types/orchestrion/config/kafkajs.d.ts.map +1 -0
  220. package/build/types/orchestrion/config/knex.d.ts +9 -0
  221. package/build/types/orchestrion/config/knex.d.ts.map +1 -0
  222. package/build/types/orchestrion/config/langchain.d.ts +4 -0
  223. package/build/types/orchestrion/config/langchain.d.ts.map +1 -0
  224. package/build/types/orchestrion/config/langgraph.d.ts +4 -0
  225. package/build/types/orchestrion/config/langgraph.d.ts.map +1 -0
  226. package/build/types/orchestrion/config/mongodb.d.ts +4 -0
  227. package/build/types/orchestrion/config/mongodb.d.ts.map +1 -0
  228. package/build/types/orchestrion/config/mongoose.d.ts +4 -0
  229. package/build/types/orchestrion/config/mongoose.d.ts.map +1 -0
  230. package/build/types/orchestrion/config/mysql2.d.ts +18 -0
  231. package/build/types/orchestrion/config/mysql2.d.ts.map +1 -0
  232. package/build/types/orchestrion/config/nestjs.d.ts +24 -0
  233. package/build/types/orchestrion/config/nestjs.d.ts.map +1 -0
  234. package/build/types/orchestrion/config/prisma.d.ts +4 -0
  235. package/build/types/orchestrion/config/prisma.d.ts.map +1 -0
  236. package/build/types/orchestrion/config/react-router.d.ts +4 -0
  237. package/build/types/orchestrion/config/react-router.d.ts.map +1 -0
  238. package/build/types/orchestrion/config/remix.d.ts +4 -0
  239. package/build/types/orchestrion/config/remix.d.ts.map +1 -0
  240. package/build/types/orchestrion/config/tedious.d.ts +4 -0
  241. package/build/types/orchestrion/config/tedious.d.ts.map +1 -0
  242. package/build/types/orchestrion/detect.d.ts +3 -10
  243. package/build/types/orchestrion/detect.d.ts.map +1 -1
  244. package/build/types/orchestrion/index.d.ts +25 -1
  245. package/build/types/orchestrion/index.d.ts.map +1 -1
  246. package/build/types/orchestrion/runtime/register.d.ts +11 -9
  247. package/build/types/orchestrion/runtime/register.d.ts.map +1 -1
  248. package/build/types/prisma/global.d.ts +5 -0
  249. package/build/types/prisma/global.d.ts.map +1 -0
  250. package/build/types/prisma/index.d.ts +45 -0
  251. package/build/types/prisma/index.d.ts.map +1 -0
  252. package/build/types/prisma/tracing-helper.d.ts +46 -0
  253. package/build/types/prisma/tracing-helper.d.ts.map +1 -0
  254. package/build/types/prisma/types.d.ts +37 -0
  255. package/build/types/prisma/types.d.ts.map +1 -0
  256. package/build/types/vercel-ai/util.d.ts +0 -2
  257. package/build/types/vercel-ai/util.d.ts.map +1 -1
  258. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  259. package/build/types-ts3.8/graphql/utils.d.ts +2 -6
  260. package/build/types-ts3.8/index.d.ts +2 -0
  261. package/build/types-ts3.8/integrations/tracing-channel/dataloader.d.ts +11 -0
  262. package/build/types-ts3.8/integrations/tracing-channel/generic-pool.d.ts +10 -0
  263. package/build/types-ts3.8/integrations/tracing-channel/ioredis.d.ts +20 -0
  264. package/build/types-ts3.8/integrations/tracing-channel/kafkajs/consumer.d.ts +8 -0
  265. package/build/types-ts3.8/integrations/tracing-channel/kafkajs/index.d.ts +17 -0
  266. package/build/types-ts3.8/integrations/tracing-channel/kafkajs/semconv.d.ts +10 -0
  267. package/build/types-ts3.8/integrations/tracing-channel/kafkajs/spans.d.ts +38 -0
  268. package/build/types-ts3.8/integrations/tracing-channel/kafkajs/types.d.ts +40 -0
  269. package/build/types-ts3.8/integrations/tracing-channel/knex.d.ts +11 -0
  270. package/build/types-ts3.8/integrations/tracing-channel/mysql2.d.ts +15 -0
  271. package/build/types-ts3.8/orchestrion/bundler/esbuild.d.ts +21 -0
  272. package/build/types-ts3.8/orchestrion/bundler/options.d.ts +19 -0
  273. package/build/types-ts3.8/orchestrion/bundler/rollup.d.ts +17 -0
  274. package/build/types-ts3.8/orchestrion/bundler/vite.d.ts +4 -17
  275. package/build/types-ts3.8/orchestrion/bundler/webpack.d.ts +19 -0
  276. package/build/types-ts3.8/orchestrion/channels.d.ts +64 -37
  277. package/build/types-ts3.8/orchestrion/config/dataloader.d.ts +46 -0
  278. package/build/types-ts3.8/orchestrion/config/firebase.d.ts +4 -0
  279. package/build/types-ts3.8/orchestrion/config/generic-pool.d.ts +31 -0
  280. package/build/types-ts3.8/orchestrion/config/index.d.ts +18 -5
  281. package/build/types-ts3.8/orchestrion/config/kafkajs.d.ts +17 -0
  282. package/build/types-ts3.8/orchestrion/config/knex.d.ts +9 -0
  283. package/build/types-ts3.8/orchestrion/config/langchain.d.ts +4 -0
  284. package/build/types-ts3.8/orchestrion/config/langgraph.d.ts +4 -0
  285. package/build/types-ts3.8/orchestrion/config/mongodb.d.ts +4 -0
  286. package/build/types-ts3.8/orchestrion/config/mongoose.d.ts +4 -0
  287. package/build/types-ts3.8/orchestrion/config/mysql2.d.ts +18 -0
  288. package/build/types-ts3.8/orchestrion/config/nestjs.d.ts +24 -0
  289. package/build/types-ts3.8/orchestrion/config/prisma.d.ts +4 -0
  290. package/build/types-ts3.8/orchestrion/config/react-router.d.ts +4 -0
  291. package/build/types-ts3.8/orchestrion/config/remix.d.ts +4 -0
  292. package/build/types-ts3.8/orchestrion/config/tedious.d.ts +4 -0
  293. package/build/types-ts3.8/orchestrion/detect.d.ts +3 -10
  294. package/build/types-ts3.8/orchestrion/index.d.ts +25 -1
  295. package/build/types-ts3.8/orchestrion/runtime/register.d.ts +11 -9
  296. package/build/types-ts3.8/prisma/global.d.ts +5 -0
  297. package/build/types-ts3.8/prisma/index.d.ts +45 -0
  298. package/build/types-ts3.8/prisma/tracing-helper.d.ts +52 -0
  299. package/build/types-ts3.8/prisma/types.d.ts +40 -0
  300. package/build/types-ts3.8/vercel-ai/util.d.ts +0 -2
  301. package/package.json +41 -8
@@ -6,33 +6,43 @@ const node_url = require('node:url');
6
6
  const debugBuild = require('../../debug-build.js');
7
7
  const index = require('../config/index.js');
8
8
 
9
- function registerDiagnosticsChannelInjection() {
10
- const g = globalThis.__SENTRY_ORCHESTRION__ ?? (globalThis.__SENTRY_ORCHESTRION__ = {});
11
- if (g.runtime || g.bundler) {
9
+ function hasStableSyncModuleHooks(denoVersionString) {
10
+ const parseVersion = (v) => v.split(".").map((n) => parseInt(n, 10));
11
+ const nodeVersion = parseVersion(process.versions.node ?? "0.0.0");
12
+ const denoVersion = parseVersion(denoVersionString ?? "0.0.0");
13
+ return (nodeVersion[0] ?? 0) > 25 || nodeVersion[0] === 25 && (nodeVersion[1] ?? 0) >= 1 || nodeVersion[0] === 24 && (nodeVersion[1] ?? 0) >= 13 || (denoVersion[0] ?? 0) > 2 || denoVersion[0] === 2 && (denoVersion[1] ?? 0) >= 8;
14
+ }
15
+ function registerDiagnosticsChannelInjection(options) {
16
+ if (core.GLOBAL_OBJ?.__SENTRY_ORCHESTRION__?.runtime) {
12
17
  return;
13
18
  }
14
19
  const globalAny = globalThis;
15
- const parseVersion = (v) => v.split(".").map((n) => parseInt(n, 10));
16
- const nodeVersion = parseVersion(process.versions.node ?? "0.0.0");
17
- const denoVersion = parseVersion(globalAny.Deno?.version?.deno ?? "0.0.0");
18
- const stableSyncHooks = (nodeVersion[0] ?? 0) > 25 || nodeVersion[0] === 25 && (nodeVersion[1] ?? 0) >= 1 || nodeVersion[0] === 24 && (nodeVersion[1] ?? 0) >= 13 || (denoVersion[0] ?? 0) > 2 || denoVersion[0] === 2 && (denoVersion[1] ?? 0) >= 8;
20
+ const stableSyncHooks = hasStableSyncModuleHooks(globalAny.Deno?.version?.deno);
21
+ let thisModuleUrl;
22
+ thisModuleUrl = node_url.pathToFileURL(__filename).href;
19
23
  let nodeRequire;
20
24
  nodeRequire = require;
25
+ const tracingHooksDir = options?.tracingHooksDir;
26
+ const requireFromHooksDir = tracingHooksDir ? Module.createRequire(thisModuleUrl) : void 0;
21
27
  const mod = Module;
22
28
  try {
23
29
  if (typeof mod.registerHooks === "function" && stableSyncHooks) {
24
- const { initialize, resolve, load } = nodeRequire("@apm-js-collab/tracing-hooks/hook-sync.mjs");
30
+ const { initialize, resolve, load, setDiagnosticsHook } = requireFromHooksDir ? requireFromHooksDir(`${tracingHooksDir}/hook-sync.mjs`) : nodeRequire("@apm-js-collab/tracing-hooks/hook-sync.mjs");
31
+ setDiagnosticsHook((event) => {
32
+ core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__ || {};
33
+ core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime = core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime || [];
34
+ core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime.push(event.moduleName);
35
+ });
25
36
  initialize({ instrumentations: index.SENTRY_INSTRUMENTATIONS });
26
37
  mod.registerHooks({ resolve, load });
27
38
  debugBuild.DEBUG_BUILD && core.debug.log("[orchestrion] registered diagnostics-channel injection via Module.registerHooks()");
28
39
  } else if (typeof mod.register === "function" && !globalAny.Bun && !globalAny.Deno) {
29
- let parentURL;
30
- parentURL = node_url.pathToFileURL(__filename).href;
31
- mod.register("@apm-js-collab/tracing-hooks/hook.mjs", {
32
- parentURL,
40
+ const hookSpecifier = tracingHooksDir ? node_url.pathToFileURL(`${tracingHooksDir}/hook.mjs`).href : "@apm-js-collab/tracing-hooks/hook.mjs";
41
+ mod.register(hookSpecifier, {
42
+ parentURL: thisModuleUrl,
33
43
  data: { instrumentations: index.SENTRY_INSTRUMENTATIONS }
34
44
  });
35
- const ModulePatch = nodeRequire("@apm-js-collab/tracing-hooks");
45
+ const ModulePatch = requireFromHooksDir && tracingHooksDir ? requireFromHooksDir(tracingHooksDir) : nodeRequire("@apm-js-collab/tracing-hooks");
36
46
  new ModulePatch({ instrumentations: index.SENTRY_INSTRUMENTATIONS }).patch();
37
47
  debugBuild.DEBUG_BUILD && core.debug.log("[orchestrion] registered diagnostics-channel injection via Module.register()");
38
48
  } else {
@@ -46,7 +56,8 @@ function registerDiagnosticsChannelInjection() {
46
56
  );
47
57
  return;
48
58
  }
49
- g.runtime = true;
59
+ core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__ || {};
60
+ core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime = core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime || [];
50
61
  }
51
62
 
52
63
  exports.registerDiagnosticsChannelInjection = registerDiagnosticsChannelInjection;
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","sources":["../../../../src/orchestrion/runtime/register.ts"],"sourcesContent":["import { debug } from '@sentry/core';\nimport { createRequire } from 'node:module';\nimport * as Module from 'node:module';\nimport { pathToFileURL } from 'node:url';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { SENTRY_INSTRUMENTATIONS } from '../config';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __SENTRY_ORCHESTRION__: { runtime?: boolean; bundler?: boolean } | undefined;\n}\n\n/**\n * Synchronously register the diagnostics-channel injection module hooks.\n *\n * This is the single source of truth for the registration logic. It is used by:\n * - `Sentry.init()` (the Node SDK calls it directly — that's why this module\n * must be CJS-compatible / dual-built, so it can be `require()`d synchronously\n * before the app's `import`s resolve), and\n * - `import-hook.mjs`, the side-effecting `--import` entry, which just calls it.\n *\n * Libraries imported *after* this call publish the `tracingChannel` events that\n * the channel-based integrations subscribe to.\n *\n * Idempotent via `globalThis.__SENTRY_ORCHESTRION__` — a no-op if the runtime\n * `--import` hook or a bundler plugin already injected the channels.\n */\nexport function registerDiagnosticsChannelInjection(): void {\n const g = (globalThis.__SENTRY_ORCHESTRION__ ??= {});\n\n // Already injected (runtime --import hook or bundler plugin) — nothing to do.\n if (g.runtime || g.bundler) {\n return;\n }\n\n const globalAny = globalThis as { Bun?: unknown; Deno?: { version?: { deno?: string } } };\n const parseVersion = (v: string): number[] => v.split('.').map(n => parseInt(n, 10));\n const nodeVersion = parseVersion(process.versions.node ?? '0.0.0');\n const denoVersion = parseVersion(globalAny.Deno?.version?.deno ?? '0.0.0');\n // `Module.registerHooks` only became stable in Node 24.13 / 25.1 and Deno 2.8.\n const stableSyncHooks =\n (nodeVersion[0] ?? 0) > 25 ||\n (nodeVersion[0] === 25 && (nodeVersion[1] ?? 0) >= 1) ||\n (nodeVersion[0] === 24 && (nodeVersion[1] ?? 0) >= 13) ||\n (denoVersion[0] ?? 0) > 2 ||\n (denoVersion[0] === 2 && (denoVersion[1] ?? 0) >= 8);\n\n let nodeRequire: (specifier: string) => unknown;\n /*! rollup-include-cjs-only */\n nodeRequire = require;\n /*! rollup-include-cjs-only-end */\n /*! rollup-include-esm-only */\n nodeRequire = createRequire(import.meta.url);\n /*! rollup-include-esm-only-end */\n\n // `Module.registerHooks` / `Module.register` are newer than the @types/node\n // we build against, hence the cast.\n const mod = Module as unknown as {\n registerHooks?: (hooks: unknown) => void;\n register?: (specifier: string, options: unknown) => void;\n };\n\n // runs both at `--import` time and (synchronously) inside `Sentry.init()`,\n // so an unguarded throw would either abort startup or make `init()` throw.\n // On any failure (e.g. dep resolution, `require(esm)` / Node-compat\n // incompatibility) we warn (DEBUG only) and continue without channel\n // injection\n try {\n if (typeof mod.registerHooks === 'function' && stableSyncHooks) {\n // Sync hooks cover CJS and ESM, no separate `_compile` patch needed.\n // We require() the module here so that we can synchronously load it,\n // including from a CommonJS Sentry build, without bundlers pulling in.\n // All versions in stableSyncHooks support this.\n const { initialize, resolve, load } = nodeRequire('@apm-js-collab/tracing-hooks/hook-sync.mjs') as {\n initialize: (opts: { instrumentations: unknown }) => void;\n resolve: unknown;\n load: unknown;\n };\n initialize({ instrumentations: SENTRY_INSTRUMENTATIONS });\n mod.registerHooks({ resolve, load });\n DEBUG_BUILD && debug.log('[orchestrion] registered diagnostics-channel injection via Module.registerHooks()');\n } else if (typeof mod.register === 'function' && !globalAny.Bun && !globalAny.Deno) {\n // `Module.register` + the `_compile` patch is Node 18.19–24.12 / 25.0\n // path. Bun/Deno are excluded: they don't support this combination and\n // must use the stable `registerHooks` path above (or none at all).\n let parentURL: string;\n /*! rollup-include-cjs-only */\n parentURL = pathToFileURL(__filename).href;\n /*! rollup-include-cjs-only-end */\n /*! rollup-include-esm-only */\n parentURL = import.meta.url;\n /*! rollup-include-esm-only-end */\n\n mod.register('@apm-js-collab/tracing-hooks/hook.mjs', {\n parentURL,\n data: { instrumentations: SENTRY_INSTRUMENTATIONS },\n });\n\n // ALSO patch `Module.prototype._compile` for the CJS side: when an ESM\n // file `import`s a CJS package, the package's internal `require()` calls\n // are resolved through the CJS machinery and never reach the ESM\n // register hook, so without this patch the file we want to instrument\n // loads untransformed.\n const ModulePatch = nodeRequire('@apm-js-collab/tracing-hooks') as new (opts: { instrumentations: unknown }) => {\n patch: () => void;\n };\n new ModulePatch({ instrumentations: SENTRY_INSTRUMENTATIONS }).patch();\n DEBUG_BUILD && debug.log('[orchestrion] registered diagnostics-channel injection via Module.register()');\n } else {\n DEBUG_BUILD &&\n debug.warn('[Sentry] No available Node API to register diagnostics-channel injection hooks; skipping.');\n return;\n }\n } catch (error) {\n DEBUG_BUILD &&\n debug.warn(\n '[Sentry] Failed to register diagnostics-channel injection hooks; channel-based integrations ' +\n 'will not record spans.',\n error,\n );\n return;\n }\n\n g.runtime = true;\n}\n"],"names":["SENTRY_INSTRUMENTATIONS","DEBUG_BUILD","debug","pathToFileURL"],"mappings":";;;;;;;;AA2BO,SAAS,mCAAA,GAA4C;AAC1D,EAAA,MAAM,CAAA,GAAK,UAAA,CAAW,sBAAA,KAAX,UAAA,CAAW,yBAA2B,EAAC,CAAA;AAGlD,EAAA,IAAI,CAAA,CAAE,OAAA,IAAW,CAAA,CAAE,OAAA,EAAS;AAC1B,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,SAAA,GAAY,UAAA;AAClB,EAAA,MAAM,YAAA,GAAe,CAAC,CAAA,KAAwB,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,CAAI,CAAA,CAAA,KAAK,QAAA,CAAS,CAAA,EAAG,EAAE,CAAC,CAAA;AACnF,EAAA,MAAM,WAAA,GAAc,YAAA,CAAa,OAAA,CAAQ,QAAA,CAAS,QAAQ,OAAO,CAAA;AACjE,EAAA,MAAM,cAAc,YAAA,CAAa,SAAA,CAAU,IAAA,EAAM,OAAA,EAAS,QAAQ,OAAO,CAAA;AAEzE,EAAA,MAAM,mBACH,WAAA,CAAY,CAAC,CAAA,IAAK,CAAA,IAAK,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,IAAA,WAAY,CAAA,EAAA,kBAAwBA,6BAAE,EAAA,CAAA,CAAA,KAAA,EAAA;AAAA,MACtCC,sBAAA,IAAAC,UAAA,CAAA,GAAA,CAAA,8EAAA,CAAA;AAAA,IAAA,CAAA,MACA;AACA,MAAAD,sBAAA,IAAYC,UAAA,CAAA,IAAY,CAAA,2FAAA,CAAA;AAAA,MACxB;AAEA,IAAA;AAAsD,EAAA,CAAA,CAAA,OACpD,KAAA,EAAA;AAAA,IAAAD,sBACM,IAAEC,UAAA,CAAA,IAAA;AAA0C,MACpD,oHAAC;AAOD,MAAA;AAGA,KAAA;AACA,IAAA;AAAuG,EAAA;AAEvG,EAAA,CAAA,CAAA,OAAA,GAAA,IAAA;AAEA;;;;"}
1
+ {"version":3,"file":"register.js","sources":["../../../../src/orchestrion/runtime/register.ts"],"sourcesContent":["import { debug, GLOBAL_OBJ } from '@sentry/core';\nimport { createRequire } from 'node:module';\nimport * as Module from 'node:module';\nimport { pathToFileURL } from 'node:url';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { SENTRY_INSTRUMENTATIONS } from '../config';\nimport type { InstrumentationConfig } from '@apm-js-collab/code-transformer';\nimport type { register } from 'node:module';\n\ntype TracingHooksSync = {\n initialize: (opts: { instrumentations: InstrumentationConfig[] }) => void;\n resolve: Function;\n load: Function;\n setDiagnosticsHook: (callback: (event: { url: string; moduleName: string; error: Error }) => void) => void;\n};\n\ntype NodeModule = {\n registerHooks?: (options: unknown) => { deregister: () => void };\n register?: typeof register;\n};\n\nexport interface RegisterDiagnosticsChannelInjectionOptions {\n /**\n * Absolute directory of the `@apm-js-collab/tracing-hooks` package (forward slashes).\n *\n * Needed when SDK code is bundled into an app's server build: the default bare-specifier\n * require then resolves from the emitted chunk, which fails under isolated installs (pnpm).\n * Framework SDKs (e.g. `@sentry/nextjs`) resolve the package at build time and pass its\n * location here; it is loaded through an opaque `createRequire` that bundlers can't trace.\n */\n tracingHooksDir?: string;\n}\n\n/** `Module.registerHooks` only became stable in Node 24.13 / 25.1 and Deno 2.8. */\nfunction hasStableSyncModuleHooks(denoVersionString: string | undefined): boolean {\n const parseVersion = (v: string): number[] => v.split('.').map(n => parseInt(n, 10));\n const nodeVersion = parseVersion(process.versions.node ?? '0.0.0');\n const denoVersion = parseVersion(denoVersionString ?? '0.0.0');\n return (\n (nodeVersion[0] ?? 0) > 25 ||\n (nodeVersion[0] === 25 && (nodeVersion[1] ?? 0) >= 1) ||\n (nodeVersion[0] === 24 && (nodeVersion[1] ?? 0) >= 13) ||\n (denoVersion[0] ?? 0) > 2 ||\n (denoVersion[0] === 2 && (denoVersion[1] ?? 0) >= 8)\n );\n}\n\n/**\n * Synchronously register the diagnostics-channel injection module hooks.\n *\n * This is the single source of truth for the registration logic. It is used by:\n * - `Sentry.init()` (the Node SDK calls it directly — that's why this module\n * must be CJS-compatible / dual-built, so it can be `require()`d synchronously\n * before the app's `import`s resolve), and\n * - `import-hook.mjs`, the side-effecting `--import` entry, which just calls it.\n *\n * Libraries imported *after* this call publish the `tracingChannel` events that\n * the channel-based integrations subscribe to.\n */\nexport function registerDiagnosticsChannelInjection(options?: RegisterDiagnosticsChannelInjectionOptions): void {\n if (GLOBAL_OBJ?.__SENTRY_ORCHESTRION__?.runtime) {\n return;\n }\n\n const globalAny = globalThis as { Bun?: unknown; Deno?: { version?: { deno?: string } } };\n const stableSyncHooks = hasStableSyncModuleHooks(globalAny.Deno?.version?.deno);\n\n let thisModuleUrl: string;\n /*! rollup-include-cjs-only */\n thisModuleUrl = pathToFileURL(__filename).href;\n /*! rollup-include-cjs-only-end */\n /*! rollup-include-esm-only */\n thisModuleUrl = import.meta.url;\n /*! rollup-include-esm-only-end */\n\n // Default: bare specifiers via a plain (aliased) `require`, so bundlers see and resolve them\n // like any other dependency. Override: with `tracingHooksDir`, absolute paths are loaded through\n // `createRequire`, which bundlers leave as a true runtime require — they must not statically\n // resolve these (Turbopack fails the build on an absolute request, and the machinery breaks when\n // bundled anyway). `createRequire` rather than ignore-comments because webpack only honors\n // `webpackIgnore` on `import()`, not `require()` (it compiles the call to a broken module stub).\n let nodeRequire: (specifier: string) => unknown;\n /*! rollup-include-cjs-only */\n nodeRequire = require;\n /*! rollup-include-cjs-only-end */\n /*! rollup-include-esm-only */\n nodeRequire = createRequire(import.meta.url);\n /*! rollup-include-esm-only-end */\n\n const tracingHooksDir = options?.tracingHooksDir;\n const requireFromHooksDir = tracingHooksDir ? createRequire(thisModuleUrl) : undefined;\n\n // `Module.registerHooks` / `Module.register` are newer than the @types/node\n // we build against, hence the cast.\n const mod = Module as NodeModule;\n\n // runs both at `--import` time and (synchronously) inside `Sentry.init()`,\n // so an unguarded throw would either abort startup or make `init()` throw.\n // On any failure (e.g. dep resolution, `require(esm)` / Node-compat\n // incompatibility) we warn (DEBUG only) and continue without channel\n // injection\n try {\n if (typeof mod.registerHooks === 'function' && stableSyncHooks) {\n // Sync hooks cover CJS and ESM, no separate `_compile` patch needed.\n // We require() the module here so that we can synchronously load it,\n // including from a CommonJS Sentry build, without bundlers pulling in.\n // All versions in stableSyncHooks support this.\n const { initialize, resolve, load, setDiagnosticsHook } = (\n requireFromHooksDir\n ? requireFromHooksDir(`${tracingHooksDir}/hook-sync.mjs`)\n : nodeRequire('@apm-js-collab/tracing-hooks/hook-sync.mjs')\n ) as TracingHooksSync;\n\n setDiagnosticsHook(event => {\n GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ || {};\n GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime = GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime || [];\n GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime.push(event.moduleName);\n });\n\n initialize({ instrumentations: SENTRY_INSTRUMENTATIONS });\n mod.registerHooks({ resolve, load });\n DEBUG_BUILD && debug.log('[orchestrion] registered diagnostics-channel injection via Module.registerHooks()');\n } else if (typeof mod.register === 'function' && !globalAny.Bun && !globalAny.Deno) {\n // `Module.register` + the `_compile` patch is Node 18.19–24.12 / 25.0\n // path. Bun/Deno are excluded: they don't support this combination and\n // must use the stable `registerHooks` path above (or none at all).\n // `Module.register` resolves ESM-style: a bare package specifier is resolved against\n // `parentURL`, but a filesystem path (the `tracingHooksDir` override) is not a valid ESM\n // specifier and must be passed as a file:// URL.\n const hookSpecifier = tracingHooksDir\n ? pathToFileURL(`${tracingHooksDir}/hook.mjs`).href\n : '@apm-js-collab/tracing-hooks/hook.mjs';\n mod.register(hookSpecifier, {\n parentURL: thisModuleUrl,\n data: { instrumentations: SENTRY_INSTRUMENTATIONS },\n });\n\n // ALSO patch `Module.prototype._compile` for the CJS side: when an ESM\n // file `import`s a CJS package, the package's internal `require()` calls\n // are resolved through the CJS machinery and never reach the ESM\n // register hook, so without this patch the file we want to instrument\n // loads untransformed.\n const ModulePatch = (\n requireFromHooksDir && tracingHooksDir\n ? requireFromHooksDir(tracingHooksDir)\n : nodeRequire('@apm-js-collab/tracing-hooks')\n ) as new (opts: { instrumentations: unknown }) => {\n patch: () => void;\n };\n new ModulePatch({ instrumentations: SENTRY_INSTRUMENTATIONS }).patch();\n DEBUG_BUILD && debug.log('[orchestrion] registered diagnostics-channel injection via Module.register()');\n } else {\n DEBUG_BUILD &&\n debug.warn('[Sentry] No available Node API to register diagnostics-channel injection hooks; skipping.');\n return;\n }\n } catch (error) {\n DEBUG_BUILD &&\n debug.warn(\n '[Sentry] Failed to register diagnostics-channel injection hooks; channel-based integrations ' +\n 'will not record spans.',\n error,\n );\n return;\n }\n\n GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ || {};\n GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime = GLOBAL_OBJ.__SENTRY_ORCHESTRION__.runtime || [];\n}\n"],"names":["GLOBAL_OBJ","pathToFileURL","createRequire","SENTRY_INSTRUMENTATIONS","DEBUG_BUILD","debug"],"mappings":";;;;;;;;AAkCA,SAAS,yBAAyB,iBAAA,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BAAiC;AAC5C,OAAA,CAAA;AAA+D,MACjE,MAAC,WAAA,GAAA,mBAAA,IAAA,eAAA,GAAA,mBAAA,CAAA,eAAA,CAAA,GAAA,WAAA,CAAA,8BAAA,CAAA;AAED,MAAA,IAAA,WAAa,CAAA,EAAA,gBAAkB,EAAAA,6BAAyB,EAAA,CAAA,CAAA,KAAA,EAAA;AACxD,MAAAC,sBAAI,IAAAC,UAAgB,CAAA,GAAA,CAAA,8EAAe,CAAA;AACnC,IAAA,CAAA,MAAA;AAA4G,MAC9GD,sBAAW,IAAAC,UAAW,CAAA,IAAA,CAAA,2FAA8D,CAAA;AAOlF,MAAA;AAGA,IAAA;AAA4B,EAAA,CAAA,CAAA,OAC1B,KAAA,EAAA;AAAW,IAAAD,sBACL,IAAEC,UAAA,CAAA,IAAA;AAA0C,MACpD,oHAAC;AAOD,MAAA;AAOA,KAAA;AACA,IAAA;AAAuG,EAAA;AAEvG,EAAAL,eAAA,CAAA,sBACa,GAAAA,eAAA,CAAA,sBAAA,IAAA,EAAA;AACb,EAAAA,eAAA,CAAA,sBAAA,CAAA,OAAA,GAAAA,eAAA,CAAA,sBAAA,CAAA,OAAA,IAAA,EAAA;AAAA;;;;"}
@@ -0,0 +1,14 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const majorVersion = "7";
4
+ const GLOBAL_INSTRUMENTATION_KEY = "PRISMA_INSTRUMENTATION";
5
+ const GLOBAL_VERSIONED_INSTRUMENTATION_KEY = `V${majorVersion}_PRISMA_INSTRUMENTATION`;
6
+ const globalThisWithPrismaInstrumentation = globalThis;
7
+ function setGlobalTracingHelper(helper) {
8
+ const globalValue = { helper };
9
+ globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY] = globalValue;
10
+ globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY] = globalValue;
11
+ }
12
+
13
+ exports.setGlobalTracingHelper = setGlobalTracingHelper;
14
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","sources":["../../../src/prisma/global.ts"],"sourcesContent":["/*\n * Copyright Prisma\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/prisma/prisma/tree/b6feea5565ec577545a79547d24273ccdd11b4c7/packages/instrumentation-contract\n * - Upstream version: @prisma/instrumentation-contract@7.8.0\n * - Replaced `import packageJson from '../package.json'` with hardcoded major version\n */\n\nimport type { PrismaInstrumentationGlobalValue, TracingHelper } from './types';\n\nconst majorVersion = '7';\n\nconst GLOBAL_INSTRUMENTATION_KEY = 'PRISMA_INSTRUMENTATION';\nconst GLOBAL_VERSIONED_INSTRUMENTATION_KEY = `V${majorVersion}_PRISMA_INSTRUMENTATION` as const;\n\ntype GlobalThisWithPrismaInstrumentation = typeof globalThis & {\n [GLOBAL_INSTRUMENTATION_KEY]?: PrismaInstrumentationGlobalValue;\n} & {\n [K in typeof GLOBAL_VERSIONED_INSTRUMENTATION_KEY]?: PrismaInstrumentationGlobalValue;\n};\n\nconst globalThisWithPrismaInstrumentation = globalThis as GlobalThisWithPrismaInstrumentation;\n\nexport function getGlobalTracingHelper(): TracingHelper | undefined {\n const versionedGlobal = globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY];\n\n if (versionedGlobal?.helper) {\n return versionedGlobal.helper;\n }\n\n const fallbackGlobal = globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY];\n\n return fallbackGlobal?.helper;\n}\n\nexport function setGlobalTracingHelper(helper: TracingHelper): void {\n const globalValue: PrismaInstrumentationGlobalValue = { helper };\n\n globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY] = globalValue;\n globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY] = globalValue;\n}\n\nexport function clearGlobalTracingHelper(): void {\n globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY] = undefined;\n globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY] = undefined;\n}\n"],"names":[],"mappings":";;AAYA,MAAM,YAAA,GAAe,GAAA;AAErB,MAAM,0BAAA,GAA6B,wBAAA;AACnC,MAAM,oCAAA,GAAuC,IAAI,YAAY,CAAA,uBAAA,CAAA;AAQ7D,MAAM,mCAAA,GAAsC,UAAA;AAcrC,SAAS,uBAAuB,MAAA,EAA6B;AAClE,EAAA,MAAM,WAAA,GAAgD,EAAE,MAAA,EAAO;AAE/D,EAAA,mCAAA,CAAoC,oCAAoC,CAAA,GAAI,WAAA;AAC5E,EAAA,mCAAA,CAAoC,0BAA0B,CAAA,GAAI,WAAA;AACpE;;;;"}
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+ const global = require('./global.js');
5
+ const tracingHelper = require('./tracing-helper.js');
6
+
7
+ const INTEGRATION_NAME = "Prisma";
8
+ function instrumentPrisma(options) {
9
+ global.setGlobalTracingHelper(
10
+ new tracingHelper.ActiveTracingHelper({
11
+ ignoreSpanTypes: options?.instrumentationConfig?.ignoreSpanTypes ?? []
12
+ })
13
+ );
14
+ }
15
+ const _prismaIntegration = ((options) => {
16
+ return {
17
+ name: INTEGRATION_NAME,
18
+ setupOnce() {
19
+ instrumentPrisma(options);
20
+ }
21
+ };
22
+ });
23
+ const prismaIntegration = core.defineIntegration(_prismaIntegration);
24
+
25
+ exports.instrumentPrisma = instrumentPrisma;
26
+ exports.prismaIntegration = prismaIntegration;
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/prisma/index.ts"],"sourcesContent":["import type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { setGlobalTracingHelper } from './global';\nimport { ActiveTracingHelper } from './tracing-helper';\n\nconst INTEGRATION_NAME = 'Prisma' as const;\n\nexport interface PrismaInstrumentationConfig {\n /**\n * Span types that should not be traced. Matched against the full span name (e.g. `prisma:client:operation`),\n * either exactly (string) or by pattern (RegExp).\n */\n ignoreSpanTypes?: (string | RegExp)[];\n}\n\nexport interface PrismaOptions {\n /**\n * @deprecated This is no longer used, v5 works out of the box.\n */\n prismaInstrumentation?: unknown;\n /**\n * Configuration for the Prisma tracing helper.\n */\n instrumentationConfig?: PrismaInstrumentationConfig;\n}\n\n/**\n * Sets up the global Prisma tracing helper that Prisma looks up on `globalThis` to emit tracing data.\n *\n * Prisma reads `globalThis.PRISMA_INSTRUMENTATION` (and its versioned variant) to find a \"TracingHelper\"\n * which it uses internally to create spans, so it can produce tracing data without depending on\n * OpenTelemetry. The helper we install here mints spans through Sentry's span APIs. A single helper\n * serves both Prisma v5 (which calls `createEngineSpan`) and v6/v7 (which call `dispatchEngineSpans`),\n * so it doesn't blow up on version mismatches.\n */\nexport function instrumentPrisma(options?: PrismaOptions): void {\n setGlobalTracingHelper(\n new ActiveTracingHelper({\n ignoreSpanTypes: options?.instrumentationConfig?.ignoreSpanTypes ?? [],\n }),\n );\n}\n\nconst _prismaIntegration = ((options?: PrismaOptions) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPrisma(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [prisma](https://www.npmjs.com/package/prisma) library.\n * For more information, see the [`prismaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/).\n *\n * NOTE: This integration works out of the box with Prisma v6, and v7.\n * On Prisma versions prior to v6, add `previewFeatures = [\"tracing\"]` to the client generator block of your Prisma schema:\n *\n * ```\n * generator client {\n * provider = \"prisma-client-js\"\n * previewFeatures = [\"tracing\"]\n * }\n * ```\n */\nexport const prismaIntegration = defineIntegration(_prismaIntegration);\n"],"names":["setGlobalTracingHelper","ActiveTracingHelper","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,gBAAA,GAAmB,QAAA;AA8BlB,SAAS,iBAAiB,OAAA,EAA+B;AAC9D,EAAAA,6BAAA;AAAA,IACE,IAAIC,iCAAA,CAAoB;AAAA,MACtB,eAAA,EAAiB,OAAA,EAAS,qBAAA,EAAuB,eAAA,IAAmB;AAAC,KACtE;AAAA,GACH;AACF;AAEA,MAAM,kBAAA,IAAsB,CAAC,OAAA,KAA4B;AACvD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,gBAAA,CAAiB,OAAO,CAAA;AAAA,IAC1B;AAAA,GACF;AACF,CAAA,CAAA;AAgBO,MAAM,iBAAA,GAAoBC,uBAAkB,kBAAkB;;;;;"}
@@ -0,0 +1,211 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+ const debugBuild = require('../debug-build.js');
5
+ const attributes = require('@sentry/conventions/attributes');
6
+
7
+ const showAllTraces = (() => {
8
+ try {
9
+ return process.env.PRISMA_SHOW_ALL_TRACES === "true";
10
+ } catch {
11
+ return false;
12
+ }
13
+ })();
14
+ const nonSampledTraceParent = `00-10-10-00`;
15
+ const PRISMA_ORIGIN = "auto.db.otel.prisma";
16
+ const MAX_TRACKED_PRISMA_SPANS = 1e3;
17
+ const prismaSpanRegistry = new core.LRUMap(MAX_TRACKED_PRISMA_SPANS);
18
+ const pendingEngineSpans = [];
19
+ function registerPrismaSpan(id, span) {
20
+ prismaSpanRegistry.set(id, span);
21
+ }
22
+ function buildSpanAttributes(name, attributes$1) {
23
+ const merged = {
24
+ ...attributes$1,
25
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRISMA_ORIGIN
26
+ };
27
+ if (name === "prisma:engine:db_query" && merged[attributes.DB_SYSTEM] == null) {
28
+ merged[attributes.DB_SYSTEM] = "prisma";
29
+ }
30
+ return merged;
31
+ }
32
+ function buildSpanName(name, attributes) {
33
+ const queryText = attributes["db.query.text"];
34
+ if ((name === "prisma:engine:db_query" || name === "prisma:client:db_query") && typeof queryText === "string") {
35
+ return queryText;
36
+ }
37
+ return name;
38
+ }
39
+ function createResolvedEngineSpans() {
40
+ let createdSpan = true;
41
+ while (createdSpan) {
42
+ createdSpan = false;
43
+ for (let i = pendingEngineSpans.length - 1; i >= 0; i--) {
44
+ const engineSpan = pendingEngineSpans[i];
45
+ const parentSpan = prismaSpanRegistry.get(engineSpan.parent_span_id);
46
+ if (!parentSpan) {
47
+ continue;
48
+ }
49
+ const attributes = buildSpanAttributes(engineSpan.name, engineSpan.attributes);
50
+ const span = core.startInactiveSpan({
51
+ name: buildSpanName(engineSpan.name, attributes),
52
+ attributes,
53
+ kind: engineSpan.kind === "client" ? core.SPAN_KIND.CLIENT : core.SPAN_KIND.INTERNAL,
54
+ startTime: engineSpan.start_time,
55
+ parentSpan
56
+ });
57
+ registerPrismaSpan(engineSpan.span_id, span);
58
+ if (engineSpan.links) {
59
+ span.addLinks(
60
+ engineSpan.links.flatMap((link) => {
61
+ const linkedSpan = prismaSpanRegistry.get(link.span_id);
62
+ return linkedSpan ? [{ context: linkedSpan.spanContext() }] : [];
63
+ })
64
+ );
65
+ }
66
+ span.end(engineSpan.end_time);
67
+ pendingEngineSpans.splice(i, 1);
68
+ createdSpan = true;
69
+ }
70
+ }
71
+ }
72
+ class ActiveTracingHelper {
73
+ constructor({ ignoreSpanTypes }) {
74
+ this.ignoreSpanTypes = ignoreSpanTypes;
75
+ }
76
+ isEnabled() {
77
+ return true;
78
+ }
79
+ getTraceParent(span) {
80
+ const spanContext = (span ?? core.getActiveSpan())?.spanContext();
81
+ if (spanContext) {
82
+ return `00-${spanContext.traceId}-${spanContext.spanId}-0${spanContext.traceFlags}`;
83
+ }
84
+ return nonSampledTraceParent;
85
+ }
86
+ dispatchEngineSpans(spans) {
87
+ const linkIds = /* @__PURE__ */ new Map();
88
+ const roots = spans.filter((span) => span.parentId === null);
89
+ for (const root of roots) {
90
+ dispatchEngineSpan(root, spans, linkIds, this.ignoreSpanTypes);
91
+ }
92
+ }
93
+ /**
94
+ * Prisma v5 broke the tracing helper interface with the v6 major, replacing `createEngineSpan` with
95
+ * `dispatchEngineSpans`. We implement the v6/v7 interface (`dispatchEngineSpans`) but also keep this
96
+ * v5-only method so the same helper doesn't blow up in Prisma 5 users' faces, minting v5 engine spans
97
+ * through Sentry's span APIs instead of crashing.
98
+ */
99
+ createEngineSpan(engineSpanEvent) {
100
+ pendingEngineSpans.push(...engineSpanEvent.spans);
101
+ createResolvedEngineSpans();
102
+ const overflow = pendingEngineSpans.length - MAX_TRACKED_PRISMA_SPANS;
103
+ if (overflow > 0) {
104
+ debugBuild.DEBUG_BUILD && core.debug.log(`[Prisma] Dropping ${overflow} unresolved v5 engine span(s) whose parent was never registered.`);
105
+ pendingEngineSpans.splice(0, overflow);
106
+ }
107
+ }
108
+ getActiveContext() {
109
+ return core.getActiveSpan();
110
+ }
111
+ runInChildSpan(nameOrOptions, callback) {
112
+ const options = typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
113
+ if (options.internal && !showAllTraces) {
114
+ return callback();
115
+ }
116
+ const name = `prisma:client:${options.name}`;
117
+ if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {
118
+ return callback();
119
+ }
120
+ const parentSpan = core.getActiveSpan();
121
+ const attributes = buildSpanAttributes(name, options.attributes);
122
+ const spanOptions = {
123
+ name: buildSpanName(name, attributes),
124
+ attributes,
125
+ kind: options.kind,
126
+ links: options.links,
127
+ startTime: options.startTime,
128
+ parentSpan
129
+ };
130
+ if (options.active === false) {
131
+ const span = core.startInactiveSpan(spanOptions);
132
+ registerPrismaSpan(span.spanContext().spanId, span);
133
+ return endSpan(span, () => callback(span, parentSpan));
134
+ }
135
+ return core.startSpanManual(spanOptions, (span) => {
136
+ registerPrismaSpan(span.spanContext().spanId, span);
137
+ return endSpan(span, () => callback(span, parentSpan));
138
+ });
139
+ }
140
+ }
141
+ function dispatchEngineSpan(engineSpan, allSpans, linkIds, ignoreSpanTypes) {
142
+ if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) {
143
+ return;
144
+ }
145
+ const attributes = buildSpanAttributes(engineSpan.name, engineSpan.attributes);
146
+ core.startSpanManual(
147
+ {
148
+ name: buildSpanName(engineSpan.name, attributes),
149
+ attributes,
150
+ kind: engineSpan.kind === "client" ? core.SPAN_KIND.CLIENT : core.SPAN_KIND.INTERNAL,
151
+ startTime: engineSpan.startTime
152
+ },
153
+ (span) => {
154
+ linkIds.set(engineSpan.id, span.spanContext().spanId);
155
+ if (engineSpan.links) {
156
+ span.addLinks(
157
+ engineSpan.links.flatMap((link) => {
158
+ const linkedId = linkIds.get(link);
159
+ if (!linkedId) {
160
+ return [];
161
+ }
162
+ return {
163
+ context: {
164
+ spanId: linkedId,
165
+ traceId: span.spanContext().traceId,
166
+ traceFlags: span.spanContext().traceFlags
167
+ }
168
+ };
169
+ })
170
+ );
171
+ }
172
+ const children = allSpans.filter((s) => s.parentId === engineSpan.id);
173
+ for (const child of children) {
174
+ dispatchEngineSpan(child, allSpans, linkIds, ignoreSpanTypes);
175
+ }
176
+ span.end(engineSpan.endTime);
177
+ }
178
+ );
179
+ }
180
+ function endSpan(span, run) {
181
+ let result;
182
+ try {
183
+ result = run();
184
+ } catch (reason) {
185
+ span.end();
186
+ throw reason;
187
+ }
188
+ if (isPromiseLike(result)) {
189
+ return result.then(
190
+ (value) => {
191
+ span.end();
192
+ return value;
193
+ },
194
+ (reason) => {
195
+ span.end();
196
+ throw reason;
197
+ }
198
+ );
199
+ }
200
+ span.end();
201
+ return result;
202
+ }
203
+ function isPromiseLike(value) {
204
+ return value != null && typeof value["then"] === "function";
205
+ }
206
+ function shouldIgnoreSpan(spanName, ignoreSpanTypes) {
207
+ return ignoreSpanTypes.some((pattern) => typeof pattern === "string" ? pattern === spanName : pattern.test(spanName));
208
+ }
209
+
210
+ exports.ActiveTracingHelper = ActiveTracingHelper;
211
+ //# sourceMappingURL=tracing-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-helper.js","sources":["../../../src/prisma/tracing-helper.ts"],"sourcesContent":["/*\n * Copyright Prisma\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/prisma/prisma/tree/b6feea5565ec577545a79547d24273ccdd11b4c7/packages/instrumentation\n * - Upstream version: @prisma/instrumentation@7.8.0\n * - Replaced `@prisma/instrumentation-contract` imports with local vendored types\n * - Span creation uses Sentry's span APIs (`startSpanManual` / `startInactiveSpan`) instead of the OTel tracer\n * - Span creation sets the Sentry origin, renames `db_query` spans to their SQL text, and backfills\n * `db.system` for older Prisma versions\n * - Added a `createEngineSpan` method so a single helper serves both Prisma v5 (which calls\n * `createEngineSpan`) and v6/v7 (which call `dispatchEngineSpans`)\n */\n\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n LRUMap,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n startSpanManual,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { EngineSpan, ExtendedSpanOptions, SpanCallback, TracingHelper } from './types';\nimport { DB_SYSTEM } from '@sentry/conventions/attributes';\n\n// Reading `process.env` can throw in runtimes that gate env access (e.g. Deno without `--allow-env`)\n// and `process` may be absent altogether (edge runtimes), so this degrades to `false` in those cases.\nconst showAllTraces = ((): boolean => {\n try {\n return process.env.PRISMA_SHOW_ALL_TRACES === 'true';\n } catch {\n return false;\n }\n})();\n\nconst nonSampledTraceParent = `00-10-10-00`;\n\nconst PRISMA_ORIGIN = 'auto.db.otel.prisma';\n\ntype Options = {\n ignoreSpanTypes: (string | RegExp)[];\n};\n\n// Vendored in from @prisma/instrumentation v5:\ntype V5EngineSpanEvent = {\n span: boolean;\n spans: V5EngineSpan[];\n};\n\ntype V5EngineSpanKind = 'client' | 'internal';\n\ntype V5EngineSpan = {\n span: boolean;\n name: string;\n trace_id: string;\n span_id: string;\n parent_span_id: string;\n start_time: [number, number];\n end_time: [number, number];\n attributes?: Record<string, string>;\n links?: { trace_id: string; span_id: string }[];\n kind: V5EngineSpanKind;\n};\n\n// Prisma v5 dispatches engine spans (`prisma:engine:*`, which carry the SQL `db.statement`) one batch\n// at a time, out of order, and detached from the active span, naming their parent only by id: a span\n// references either a client span (by the Sentry span id Prisma learned via `getTraceParent`) or a\n// sibling engine span (by the engine's own id), and a batch may not contain the parent it references.\n// By the time the engine reports them the client span may already have ended, so `getActiveSpan()`\n// can't be used to find it. `prismaSpanRegistry` maps span ids to their Sentry span, and an engine\n// span whose parent isn't registered yet waits in `pendingEngineSpans` until a later batch registers it.\nconst MAX_TRACKED_PRISMA_SPANS = 1000;\nconst prismaSpanRegistry = new LRUMap<string, Span>(MAX_TRACKED_PRISMA_SPANS);\nconst pendingEngineSpans: V5EngineSpan[] = [];\n\n/** Register a span so v5 engine spans can later resolve it as a parent by the id Prisma reports it under. */\nfunction registerPrismaSpan(id: string, span: Span): void {\n prismaSpanRegistry.set(id, span);\n}\n\n/**\n * Older Prisma versions emit `prisma:engine:db_query` spans without a `db.system`, so it's backfilled here.\n */\nfunction buildSpanAttributes(name: string, attributes: Record<string, unknown> | undefined): SpanAttributes {\n const merged: SpanAttributes = {\n ...(attributes as SpanAttributes | undefined),\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRISMA_ORIGIN,\n };\n\n // oxlint-disable-next-line typescript/no-deprecated\n if (name === 'prisma:engine:db_query' && merged[DB_SYSTEM] == null) {\n // oxlint-disable-next-line typescript/no-deprecated\n merged[DB_SYSTEM] = 'prisma';\n }\n\n return merged;\n}\n\n/**\n * Db query spans are named after their SQL text (e.g. `SELECT * FROM \"User\"`) rather than the generic\n * engine name. v5/v6 emit `prisma:engine:db_query`; v7 inlined the engine and emits `prisma:client:db_query`.\n */\nfunction buildSpanName(name: string, attributes: SpanAttributes): string {\n const queryText = attributes['db.query.text'];\n if ((name === 'prisma:engine:db_query' || name === 'prisma:client:db_query') && typeof queryText === 'string') {\n return queryText;\n }\n return name;\n}\n\n/**\n * Create every pending v5 engine span whose parent is now registered, repeating until no further span\n * resolves (so a child queued before its parent is created once the parent arrives in a later batch).\n * Each span is created under its resolved parent and registered by its engine id so its own children\n * can find it; origin, the `prisma:engine:db_query` to SQL rename, and the `db.system` backfill are\n * applied here, exactly as for v6/v7 engine spans.\n */\nfunction createResolvedEngineSpans(): void {\n // Terminates: `createdSpan` is only set true right after a `splice`, so every pass that keeps the\n // loop going strictly shrinks the finite `pendingEngineSpans`; a pass that resolves nothing exits.\n let createdSpan = true;\n while (createdSpan) {\n createdSpan = false;\n for (let i = pendingEngineSpans.length - 1; i >= 0; i--) {\n const engineSpan = pendingEngineSpans[i]!;\n const parentSpan = prismaSpanRegistry.get(engineSpan.parent_span_id);\n if (!parentSpan) {\n continue;\n }\n\n const attributes = buildSpanAttributes(engineSpan.name, engineSpan.attributes);\n const span = startInactiveSpan({\n name: buildSpanName(engineSpan.name, attributes),\n attributes,\n kind: engineSpan.kind === 'client' ? SPAN_KIND.CLIENT : SPAN_KIND.INTERNAL,\n startTime: engineSpan.start_time,\n parentSpan,\n });\n registerPrismaSpan(engineSpan.span_id, span);\n\n // Engine links reference other engine spans by their engine id; re-point them at the Sentry spans\n // we minted (mirroring v6/v7's `dispatchEngineSpan`). Links must be added before the span ends,\n // since the SentryTracerProvider seals spans on end. Links to spans we haven't created are dropped.\n if (engineSpan.links) {\n span.addLinks(\n engineSpan.links.flatMap(link => {\n const linkedSpan = prismaSpanRegistry.get(link.span_id);\n return linkedSpan ? [{ context: linkedSpan.spanContext() }] : [];\n }),\n );\n }\n\n span.end(engineSpan.end_time);\n\n pendingEngineSpans.splice(i, 1);\n createdSpan = true;\n }\n }\n}\n\n/**\n * This satisifes the TracingHelper interface for Prisma v5 and v6/v7.\n */\nexport class ActiveTracingHelper implements TracingHelper {\n private ignoreSpanTypes: (string | RegExp)[];\n\n public constructor({ ignoreSpanTypes }: Options) {\n this.ignoreSpanTypes = ignoreSpanTypes;\n }\n\n public isEnabled(): boolean {\n return true;\n }\n\n public getTraceParent(span?: Span): string {\n const spanContext = (span ?? getActiveSpan())?.spanContext();\n if (spanContext) {\n return `00-${spanContext.traceId}-${spanContext.spanId}-0${spanContext.traceFlags}`;\n }\n return nonSampledTraceParent;\n }\n\n public dispatchEngineSpans(spans: EngineSpan[]): void {\n const linkIds = new Map<string, string>();\n const roots = spans.filter(span => span.parentId === null);\n\n for (const root of roots) {\n dispatchEngineSpan(root, spans, linkIds, this.ignoreSpanTypes);\n }\n }\n\n /**\n * Prisma v5 broke the tracing helper interface with the v6 major, replacing `createEngineSpan` with\n * `dispatchEngineSpans`. We implement the v6/v7 interface (`dispatchEngineSpans`) but also keep this\n * v5-only method so the same helper doesn't blow up in Prisma 5 users' faces, minting v5 engine spans\n * through Sentry's span APIs instead of crashing.\n */\n public createEngineSpan(engineSpanEvent: V5EngineSpanEvent): void {\n pendingEngineSpans.push(...engineSpanEvent.spans);\n\n // Resolve before capping so a span is only ever dropped after a full resolution attempt, never\n // before it had a chance to find its parent. What remains are orphans whose parent was never\n // registered (e.g. evicted from the registry under sustained load); cap that backlog so it can't\n // grow without bound.\n createResolvedEngineSpans();\n\n const overflow = pendingEngineSpans.length - MAX_TRACKED_PRISMA_SPANS;\n if (overflow > 0) {\n DEBUG_BUILD &&\n debug.log(`[Prisma] Dropping ${overflow} unresolved v5 engine span(s) whose parent was never registered.`);\n pendingEngineSpans.splice(0, overflow);\n }\n }\n\n public getActiveContext(): Span | undefined {\n return getActiveSpan();\n }\n\n public runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R {\n const options: ExtendedSpanOptions = typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;\n\n if (options.internal && !showAllTraces) {\n return callback();\n }\n\n const name = `prisma:client:${options.name}`;\n\n if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {\n return callback();\n }\n\n const parentSpan = getActiveSpan();\n\n const attributes = buildSpanAttributes(name, options.attributes as Record<string, unknown> | undefined);\n const spanOptions = {\n name: buildSpanName(name, attributes),\n attributes,\n kind: options.kind,\n links: options.links,\n startTime: options.startTime,\n parentSpan,\n };\n\n if (options.active === false) {\n const span = startInactiveSpan(spanOptions);\n // Register the client span so a v5 engine span (dispatched later, detached) can resolve it as a\n // parent by the Sentry span id Prisma reported via `getTraceParent` (see `createResolvedEngineSpans`).\n registerPrismaSpan(span.spanContext().spanId, span);\n return endSpan(span, () => callback(span, parentSpan));\n }\n\n return startSpanManual(spanOptions, span => {\n registerPrismaSpan(span.spanContext().spanId, span);\n return endSpan(span, () => callback(span, parentSpan));\n });\n }\n}\n\nfunction dispatchEngineSpan(\n engineSpan: EngineSpan,\n allSpans: EngineSpan[],\n linkIds: Map<string, string>,\n ignoreSpanTypes: (string | RegExp)[],\n): void {\n if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) {\n return;\n }\n\n const attributes = buildSpanAttributes(engineSpan.name, engineSpan.attributes);\n\n startSpanManual(\n {\n name: buildSpanName(engineSpan.name, attributes),\n attributes,\n kind: engineSpan.kind === 'client' ? SPAN_KIND.CLIENT : SPAN_KIND.INTERNAL,\n startTime: engineSpan.startTime,\n },\n span => {\n linkIds.set(engineSpan.id, span.spanContext().spanId);\n\n if (engineSpan.links) {\n span.addLinks(\n engineSpan.links.flatMap(link => {\n const linkedId = linkIds.get(link);\n if (!linkedId) {\n return [];\n }\n return {\n context: {\n spanId: linkedId,\n traceId: span.spanContext().traceId,\n traceFlags: span.spanContext().traceFlags,\n },\n };\n }),\n );\n }\n\n const children = allSpans.filter(s => s.parentId === engineSpan.id);\n for (const child of children) {\n dispatchEngineSpan(child, allSpans, linkIds, ignoreSpanTypes);\n }\n\n span.end(engineSpan.endTime);\n },\n );\n}\n\nfunction endSpan<T>(span: Span, run: () => T): T {\n let result: T;\n try {\n result = run();\n } catch (reason) {\n span.end();\n throw reason;\n }\n\n if (isPromiseLike(result)) {\n return result.then(\n value => {\n span.end();\n return value;\n },\n reason => {\n span.end();\n throw reason;\n },\n ) as T;\n }\n span.end();\n return result;\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return value != null && typeof (value as Record<string, unknown>)['then'] === 'function';\n}\n\nfunction shouldIgnoreSpan(spanName: string, ignoreSpanTypes: (string | RegExp)[]): boolean {\n return ignoreSpanTypes.some(pattern => (typeof pattern === 'string' ? pattern === spanName : pattern.test(spanName)));\n}\n"],"names":["LRUMap","attributes","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","DB_SYSTEM","startInactiveSpan","SPAN_KIND","getActiveSpan","DEBUG_BUILD","debug","startSpanManual"],"mappings":";;;;;;AA+BA,MAAM,iBAAiB,MAAe;AACpC,EAAA,IAAI;AACF,IAAA,OAAO,OAAA,CAAQ,IAAI,sBAAA,KAA2B,MAAA;AAAA,EAChD,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF,CAAA,GAAG;AAEH,MAAM,qBAAA,GAAwB,CAAA,WAAA,CAAA;AAE9B,MAAM,aAAA,GAAgB,qBAAA;AAkCtB,MAAM,wBAAA,GAA2B,GAAA;AACjC,MAAM,kBAAA,GAAqB,IAAIA,WAAA,CAAqB,wBAAwB,CAAA;AAC5E,MAAM,qBAAqC,EAAC;AAG5C,SAAS,kBAAA,CAAmB,IAAY,IAAA,EAAkB;AACxD,EAAA,kBAAA,CAAmB,GAAA,CAAI,IAAI,IAAI,CAAA;AACjC;AAKA,SAAS,mBAAA,CAAoB,MAAcC,YAAA,EAAiE;AAC1G,EAAA,MAAM,MAAA,GAAyB;AAAA,IAC7B,GAAIA,YAAA;AAAA,IACJ,CAACC,qCAAgC,GAAG;AAAA,GACtC;AAGA,EAAA,IAAI,IAAA,KAAS,wBAAA,IAA4B,MAAA,CAAOC,oBAAS,KAAK,IAAA,EAAM;AAElE,IAAA,MAAA,CAAOA,oBAAS,CAAA,GA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KAAS;AACP,QAAA,IAAA,CAAK,GAAA,EAAI;AACT,QAAA,OAAO,KAAA;AAAA,MACT,CAAA;AAAA,MACA,CAAA,MAAA,KAAU;AACR,QAAA,IAAA,CAAK,GAAA,EAAI;AACT,QAAA,MAAM,MAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,IAAA,CAAK,GAAA,EAAI;AACT,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,cAAc,KAAA,EAA+C;AACpE,EAAA,OAAO,KAAA,IAAS,IAAA,IAAQ,OAAQ,KAAA,CAAkC,MAAM,CAAA,KAAM,UAAA;AAChF;AAEA,SAAS,gBAAA,CAAiB,UAAkB,eAAA,EAA+C;AACzF,EAAA,OAAO,eAAA,CAAgB,IAAA,CAAK,CAAA,OAAA,KAAY,OAAO,OAAA,KAAY,QAAA,GAAW,OAAA,KAAY,QAAA,GAAW,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAE,CAAA;AACtH;;;;"}
@@ -11,16 +11,6 @@ function asNumber(value) {
11
11
  function sum(a, b) {
12
12
  return a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
13
13
  }
14
- function safeStringify(value) {
15
- if (typeof value === "string") {
16
- return value;
17
- }
18
- try {
19
- return JSON.stringify(value);
20
- } catch {
21
- return "[unserializable]";
22
- }
23
- }
24
14
  function isReadableStream(value) {
25
15
  return core.isObjectLike(value) && typeof value.pipeThrough === "function" && typeof value.getReader === "function";
26
16
  }
@@ -117,7 +107,6 @@ function accumulateChunk(state, chunk) {
117
107
  exports.asNumber = asNumber;
118
108
  exports.asString = asString;
119
109
  exports.isReadableStream = isReadableStream;
120
- exports.safeStringify = safeStringify;
121
110
  exports.sum = sum;
122
111
  exports.tapModelCallStream = tapModelCallStream;
123
112
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sources":["../../../src/vercel-ai/util.ts"],"sourcesContent":["/** Shared, state-free helpers for the Vercel AI (`ai`) channel subscribers, plus the streamed model-call tap. */\n\nimport { isObjectLike } from '@sentry/core';\n\n/** Narrow to a string, or `undefined` for anything else. */\nexport function asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\n/** Narrow to a finite number, or `undefined` for anything else (including `NaN`). */\nexport function asNumber(value: unknown): number | undefined {\n return typeof value === 'number' && !isNaN(value) ? value : undefined;\n}\n\n/** Add two optional numbers, treating a missing operand as `0` but returning `undefined` when both are absent. */\nexport function sum(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);\n}\n\n/** Stringify a value, passing strings through and falling back to a placeholder on circular/unserializable input. */\nexport function safeStringify(value: unknown): string {\n if (typeof value === 'string') {\n return value;\n }\n try {\n return JSON.stringify(value);\n } catch {\n return '[unserializable]';\n }\n}\n\n/*\n * Streaming support for the `ai:telemetry` tracing channel.\n *\n * For a streamed model call (`doStream`) the SDK resolves the `languageModelCall` channel promise as\n * soon as it hands back the *unconsumed* stream — so `result.stream` is a `ReadableStream` and the\n * final usage / finish reason / output only arrive later, as the stream is drained (they ride the\n * stream's own `finish`/`text-delta`/`tool-call` chunks, never the channel context). The SDK\n * deliberately leaves `result` undefined on the `streamText`/`step` contexts and exposes the stream\n * only on the model call, expecting consumers to tap it themselves.\n * @see https://github.com/vercel/ai/pull/15660 (discussion: \"tee off and aggregate ourselves\")\n *\n * We replace `result.stream` with a passthrough that forwards every chunk untouched (so the SDK's own\n * consumption is unaffected) while accumulating the data we need, then hand the aggregate back once the\n * stream settles so the model-call span can be enriched and ended out-of-band.\n */\n\n/** The subset of a streamed provider chunk we read. Unknown chunk types are forwarded and ignored. */\ninterface StreamChunk {\n type?: unknown;\n delta?: unknown;\n // v4 text-delta chunks carry the text on `textDelta`; v5+ uses `delta`.\n textDelta?: unknown;\n id?: unknown;\n modelId?: unknown;\n toolCallId?: unknown;\n toolName?: unknown;\n input?: unknown;\n args?: unknown;\n finishReason?: unknown;\n usage?: unknown;\n providerMetadata?: unknown;\n error?: unknown;\n}\n\n/** The aggregate handed back once a streamed model call finishes, in the shape `enrichSpanOnEnd` expects. */\nexport interface StreamedModelCallResult {\n text?: string;\n toolCalls: Array<Record<string, unknown>>;\n usage?: unknown;\n finishReason?: unknown;\n responseId?: string;\n responseModel?: string;\n providerMetadata?: unknown;\n}\n\n/** A minimal structural check — the streamed model call exposes a web `ReadableStream` on `result.stream`. */\nexport function isReadableStream(value: unknown): value is ReadableStream<unknown> {\n return (\n isObjectLike(value) &&\n typeof (value as { pipeThrough?: unknown }).pipeThrough === 'function' &&\n typeof (value as { getReader?: unknown }).getReader === 'function'\n );\n}\n\n/**\n * Wrap a streamed model call's `ReadableStream` so its chunks are observed as the SDK consumes them,\n * without altering what the SDK sees. Returns a replacement stream to swap onto `result.stream`.\n *\n * `onFinal` runs exactly once when the stream drains cleanly; `onError` runs exactly once if it errors\n * or is cancelled. Reading one source chunk per `pull` preserves the SDK's backpressure. The\n * `try/catch` around every read guarantees the owning span is always ended — a leaked open span on a\n * mid-stream failure would be worse than a slightly-less-enriched one.\n */\nexport function tapModelCallStream(\n stream: ReadableStream<unknown>,\n onFinal: (result: StreamedModelCallResult) => void,\n onError: (error: unknown) => void,\n): ReadableStream<unknown> {\n const reader = stream.getReader();\n const state: StreamedModelCallResult = { toolCalls: [] };\n let text = '';\n let settled = false;\n\n const finalize = (): void => {\n if (settled) {\n return;\n }\n settled = true;\n if (text) {\n state.text = text;\n }\n onFinal(state);\n };\n\n const fail = (error: unknown): void => {\n if (settled) {\n return;\n }\n settled = true;\n onError(error);\n };\n\n return new ReadableStream<unknown>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n finalize();\n controller.close();\n\n return;\n }\n text += accumulateChunk(state, value) ?? '';\n controller.enqueue(value);\n } catch (error) {\n fail(error);\n controller.error(error);\n }\n },\n cancel(reason) {\n // Consumer stopped reading early (e.g. a `break` out of `for await`); close out the span with\n // whatever we have rather than leave it open. A non-error reason is a deliberate stop, not a failure.\n finalize();\n\n return reader.cancel(reason);\n },\n });\n}\n\n/**\n * Fold a single streamed chunk into the running aggregate. Returns any text delta so the caller can\n * accumulate it (kept out of `state` until the end to avoid re-joining on every chunk).\n */\nfunction accumulateChunk(state: StreamedModelCallResult, chunk: unknown): string | undefined {\n if (!isObjectLike(chunk)) {\n return undefined;\n }\n const {\n type,\n delta,\n textDelta,\n id,\n modelId,\n toolCallId,\n toolName,\n input,\n args,\n finishReason,\n usage,\n providerMetadata,\n } = chunk as StreamChunk;\n\n switch (type) {\n case 'text-delta': {\n const textChunk = delta ?? textDelta;\n return typeof textChunk === 'string' ? textChunk : undefined;\n }\n case 'tool-call':\n state.toolCalls.push({ toolCallId, toolName, input: input ?? args });\n\n return undefined;\n case 'response-metadata':\n if (typeof id === 'string') {\n state.responseId = id;\n }\n if (typeof modelId === 'string') {\n state.responseModel = modelId;\n }\n\n return undefined;\n case 'finish':\n state.finishReason = finishReason;\n state.usage = usage;\n if (providerMetadata !== undefined) {\n state.providerMetadata = providerMetadata;\n }\n\n return undefined;\n default:\n return undefined;\n }\n}\n"],"names":["isObjectLike"],"mappings":";;;;AAKO,SAAS,SAAS,KAAA,EAAoC;AAC3D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,MAAA;AAC7C;AAGO,SAAS,SAAS,KAAA,EAAoC;AAC3D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,KAAK,IAAI,KAAA,GAAQ,MAAA;AAC9D;AAGO,SAAS,GAAA,CAAI,GAAuB,CAAA,EAA2C;AACpF,EAAA,OAAO,MAAM,MAAA,IAAa,CAAA,KAAM,SAAY,MAAA,GAAA,CAAa,CAAA,IAAK,MAAM,CAAA,IAAK,CAAA,CAAA;AAC3E;AAGO,SAAS,cAAc,KAAA,EAAwB;AACpD,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,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,MAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,QAAA,KAAA,CAAM,aAAA,GAAgB,OAAA;AAAA,MACxB;AAEA,MAAA,OAAO,MAAA;AAAA,IACT,KAAK,QAAA;AACH,MAAA,KAAA,CAAM,YAAA,GAAe,YAAA;AACrB,MAAA,KAAA,CAAM,KAAA,GAAQ,KAAA;AACd,MAAA,IAAI,qBAAqB,MAAA,EAAW;AAClC,QAAA,KAAA,CAAM,gBAAA,GAAmB,gBAAA;AAAA,MAC3B;AAEA,MAAA,OAAO,MAAA;AAAA,IACT;AACE,MAAA,OAAO,MAAA;AAAA;AAEb;;;;;;;;;"}
1
+ {"version":3,"file":"util.js","sources":["../../../src/vercel-ai/util.ts"],"sourcesContent":["/** Shared, state-free helpers for the Vercel AI (`ai`) channel subscribers, plus the streamed model-call tap. */\n\nimport { isObjectLike } from '@sentry/core';\n\n/** Narrow to a string, or `undefined` for anything else. */\nexport function asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\n/** Narrow to a finite number, or `undefined` for anything else (including `NaN`). */\nexport function asNumber(value: unknown): number | undefined {\n return typeof value === 'number' && !isNaN(value) ? value : undefined;\n}\n\n/** Add two optional numbers, treating a missing operand as `0` but returning `undefined` when both are absent. */\nexport function sum(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);\n}\n\n/*\n * Streaming support for the `ai:telemetry` tracing channel.\n *\n * For a streamed model call (`doStream`) the SDK resolves the `languageModelCall` channel promise as\n * soon as it hands back the *unconsumed* stream — so `result.stream` is a `ReadableStream` and the\n * final usage / finish reason / output only arrive later, as the stream is drained (they ride the\n * stream's own `finish`/`text-delta`/`tool-call` chunks, never the channel context). The SDK\n * deliberately leaves `result` undefined on the `streamText`/`step` contexts and exposes the stream\n * only on the model call, expecting consumers to tap it themselves.\n * @see https://github.com/vercel/ai/pull/15660 (discussion: \"tee off and aggregate ourselves\")\n *\n * We replace `result.stream` with a passthrough that forwards every chunk untouched (so the SDK's own\n * consumption is unaffected) while accumulating the data we need, then hand the aggregate back once the\n * stream settles so the model-call span can be enriched and ended out-of-band.\n */\n\n/** The subset of a streamed provider chunk we read. Unknown chunk types are forwarded and ignored. */\ninterface StreamChunk {\n type?: unknown;\n delta?: unknown;\n // v4 text-delta chunks carry the text on `textDelta`; v5+ uses `delta`.\n textDelta?: unknown;\n id?: unknown;\n modelId?: unknown;\n toolCallId?: unknown;\n toolName?: unknown;\n input?: unknown;\n args?: unknown;\n finishReason?: unknown;\n usage?: unknown;\n providerMetadata?: unknown;\n error?: unknown;\n}\n\n/** The aggregate handed back once a streamed model call finishes, in the shape `enrichSpanOnEnd` expects. */\nexport interface StreamedModelCallResult {\n text?: string;\n toolCalls: Array<Record<string, unknown>>;\n usage?: unknown;\n finishReason?: unknown;\n responseId?: string;\n responseModel?: string;\n providerMetadata?: unknown;\n}\n\n/** A minimal structural check — the streamed model call exposes a web `ReadableStream` on `result.stream`. */\nexport function isReadableStream(value: unknown): value is ReadableStream<unknown> {\n return (\n isObjectLike(value) &&\n typeof (value as { pipeThrough?: unknown }).pipeThrough === 'function' &&\n typeof (value as { getReader?: unknown }).getReader === 'function'\n );\n}\n\n/**\n * Wrap a streamed model call's `ReadableStream` so its chunks are observed as the SDK consumes them,\n * without altering what the SDK sees. Returns a replacement stream to swap onto `result.stream`.\n *\n * `onFinal` runs exactly once when the stream drains cleanly; `onError` runs exactly once if it errors\n * or is cancelled. Reading one source chunk per `pull` preserves the SDK's backpressure. The\n * `try/catch` around every read guarantees the owning span is always ended — a leaked open span on a\n * mid-stream failure would be worse than a slightly-less-enriched one.\n */\nexport function tapModelCallStream(\n stream: ReadableStream<unknown>,\n onFinal: (result: StreamedModelCallResult) => void,\n onError: (error: unknown) => void,\n): ReadableStream<unknown> {\n const reader = stream.getReader();\n const state: StreamedModelCallResult = { toolCalls: [] };\n let text = '';\n let settled = false;\n\n const finalize = (): void => {\n if (settled) {\n return;\n }\n settled = true;\n if (text) {\n state.text = text;\n }\n onFinal(state);\n };\n\n const fail = (error: unknown): void => {\n if (settled) {\n return;\n }\n settled = true;\n onError(error);\n };\n\n return new ReadableStream<unknown>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n finalize();\n controller.close();\n\n return;\n }\n text += accumulateChunk(state, value) ?? '';\n controller.enqueue(value);\n } catch (error) {\n fail(error);\n controller.error(error);\n }\n },\n cancel(reason) {\n // Consumer stopped reading early (e.g. a `break` out of `for await`); close out the span with\n // whatever we have rather than leave it open. A non-error reason is a deliberate stop, not a failure.\n finalize();\n\n return reader.cancel(reason);\n },\n });\n}\n\n/**\n * Fold a single streamed chunk into the running aggregate. Returns any text delta so the caller can\n * accumulate it (kept out of `state` until the end to avoid re-joining on every chunk).\n */\nfunction accumulateChunk(state: StreamedModelCallResult, chunk: unknown): string | undefined {\n if (!isObjectLike(chunk)) {\n return undefined;\n }\n const {\n type,\n delta,\n textDelta,\n id,\n modelId,\n toolCallId,\n toolName,\n input,\n args,\n finishReason,\n usage,\n providerMetadata,\n } = chunk as StreamChunk;\n\n switch (type) {\n case 'text-delta': {\n const textChunk = delta ?? textDelta;\n return typeof textChunk === 'string' ? textChunk : undefined;\n }\n case 'tool-call':\n state.toolCalls.push({ toolCallId, toolName, input: input ?? args });\n\n return undefined;\n case 'response-metadata':\n if (typeof id === 'string') {\n state.responseId = id;\n }\n if (typeof modelId === 'string') {\n state.responseModel = modelId;\n }\n\n return undefined;\n case 'finish':\n state.finishReason = finishReason;\n state.usage = usage;\n if (providerMetadata !== undefined) {\n state.providerMetadata = providerMetadata;\n }\n\n return undefined;\n default:\n return undefined;\n }\n}\n"],"names":["isObjectLike"],"mappings":";;;;AAKO,SAAS,SAAS,KAAA,EAAoC;AAC3D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,MAAA;AAC7C;AAGO,SAAS,SAAS,KAAA,EAAoC;AAC3D,EAAA,OAAO,OAAO,KAAA,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K,mBAAA;AACH,MAAA,IAAI,OAAO,OAAO,QAAA,EAAU;AAC1B,QAAA,KAAA,CAAM,UAAA,GAAa,EAAA;AAAA,MACrB;AACA,MAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,QAAA,KAAA,CAAM,aAAA,GAAgB,OAAA;AAAA,MACxB;AAEA,MAAA,OAAO,MAAA;AAAA,IACT,KAAK,QAAA;AACH,MAAA,KAAA,CAAM,YAAA,GAAe,YAAA;AACrB,MAAA,KAAA,CAAM,KAAA,GAAQ,KAAA;AACd,MAAA,IAAI,qBAAqB,MAAA,EAAW;AAClC,QAAA,KAAA,CAAM,gBAAA,GAAmB,gBAAA;AAAA,MAC3B;AAEA,MAAA,OAAO,MAAA;AAAA,IACT;AACE,MAAA,OAAO,MAAA;AAAA;AAEb;;;;;;;;"}
@@ -194,7 +194,7 @@ function createSpanFromMessage(data, channelOptions) {
194
194
  const input = type === "embedMany" ? event.values : event.value;
195
195
  return startGenAiSpan(GEN_AI_EMBEDDINGS_OPERATION, modelId, {
196
196
  ...baseAttributes,
197
- ...recordInputs && input !== void 0 ? { [attributes.GEN_AI_EMBEDDINGS_INPUT]: util.safeStringify(input) } : {}
197
+ ...recordInputs && input !== void 0 ? { [attributes.GEN_AI_EMBEDDINGS_INPUT]: core.stringify(input) } : {}
198
198
  });
199
199
  }
200
200
  case "rerank":
@@ -235,7 +235,7 @@ function buildModelCallSpan(event, baseAttributes, recordInputs, enableTruncatio
235
235
  ...baseAttributes,
236
236
  [VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,
237
237
  ...recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {},
238
- ...recordInputs && Array.isArray(event.tools) ? { [attributes.GEN_AI_REQUEST_AVAILABLE_TOOLS]: util.safeStringify(event.tools) } : {}
238
+ ...recordInputs && Array.isArray(event.tools) ? { [attributes.GEN_AI_REQUEST_AVAILABLE_TOOLS]: core.stringify(event.tools) } : {}
239
239
  });
240
240
  }
241
241
  function buildToolSpan(event, recordInputs) {
@@ -250,7 +250,7 @@ function buildToolSpan(event, recordInputs) {
250
250
  ...toolName ? { [attributes.GEN_AI_TOOL_NAME]: toolName } : {},
251
251
  ...toolCallId ? { [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: toolCallId } : {},
252
252
  ...description ? { [GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE]: description } : {},
253
- ...recordInputs && toolInput !== void 0 ? { [attributes.GEN_AI_TOOL_INPUT]: util.safeStringify(toolInput) } : {}
253
+ ...recordInputs && toolInput !== void 0 ? { [attributes.GEN_AI_TOOL_INPUT]: core.stringify(toolInput) } : {}
254
254
  });
255
255
  }
256
256
  function enrichSpanOnEnd(span, data, channelOptions) {
@@ -261,7 +261,7 @@ function enrichSpanOnEnd(span, data, channelOptions) {
261
261
  const { recordOutputs } = getRecordingOptions(data.event, channelOptions);
262
262
  if (type === "executeTool") {
263
263
  if (recordOutputs) {
264
- span.setAttribute(attributes.GEN_AI_TOOL_OUTPUT, util.safeStringify(result.output ?? result));
264
+ span.setAttribute(attributes.GEN_AI_TOOL_OUTPUT, core.stringify(result.output ?? result));
265
265
  }
266
266
  const output = core.isObjectLike(result.output) ? result.output : void 0;
267
267
  if (output?.type === "tool-error") {
@@ -286,7 +286,7 @@ function enrichSpanOnEnd(span, data, channelOptions) {
286
286
  }
287
287
  const finishReason = getFinishReason(result);
288
288
  if (finishReason && type === "languageModelCall") {
289
- span.setAttribute(attributes.GEN_AI_RESPONSE_FINISH_REASONS, util.safeStringify([finishReason]));
289
+ span.setAttribute(attributes.GEN_AI_RESPONSE_FINISH_REASONS, core.stringify([finishReason]));
290
290
  }
291
291
  const response = core.isObjectLike(result.response) ? result.response : void 0;
292
292
  const responseId = util.asString(response?.id) ?? util.asString(result.responseId);
@@ -328,7 +328,7 @@ function buildOutputMessages(parts, finishReason) {
328
328
  if (!parts.length) {
329
329
  return void 0;
330
330
  }
331
- return util.safeStringify([{ role: "assistant", parts, finish_reason: normalizeFinishReason(finishReason) }]);
331
+ return core.stringify([{ role: "assistant", parts, finish_reason: normalizeFinishReason(finishReason) }]);
332
332
  }
333
333
  function toolCallPart(toolCall) {
334
334
  const args = toolCall.input ?? toolCall.args;
@@ -336,7 +336,7 @@ function toolCallPart(toolCall) {
336
336
  type: "tool_call",
337
337
  id: util.asString(toolCall.toolCallId),
338
338
  name: util.asString(toolCall.toolName),
339
- arguments: typeof args === "string" ? args : util.safeStringify(args ?? {})
339
+ arguments: typeof args === "string" ? args : core.stringify(args ?? {})
340
340
  };
341
341
  }
342
342
  function partsFromContent(content) {
@@ -413,11 +413,11 @@ function buildInputMessageAttributes(event, enableTruncation) {
413
413
  const attributes$1 = {};
414
414
  const instructions = util.asString(event.instructions);
415
415
  if (instructions) {
416
- attributes$1[core.GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE] = util.safeStringify([{ type: "text", content: instructions }]);
416
+ attributes$1[core.GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE] = core.stringify([{ type: "text", content: instructions }]);
417
417
  }
418
418
  const messages = event.messages ?? event.prompt;
419
419
  if (messages !== void 0) {
420
- attributes$1[attributes.GEN_AI_INPUT_MESSAGES] = enableTruncation ? core.getTruncatedJsonString(messages) : util.safeStringify(messages);
420
+ attributes$1[attributes.GEN_AI_INPUT_MESSAGES] = enableTruncation ? core.getTruncatedJsonString(messages) : core.stringify(messages);
421
421
  attributes$1[core.GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE] = Array.isArray(messages) ? messages.length : 1;
422
422
  }
423
423
  return attributes$1;