@sentry/node 10.62.0 → 10.63.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 (308) hide show
  1. package/build/cjs/integrations/featureFlagShims/launchDarkly.js.map +1 -1
  2. package/build/cjs/integrations/featureFlagShims/openFeature.js.map +1 -1
  3. package/build/cjs/integrations/featureFlagShims/statsig.js.map +1 -1
  4. package/build/cjs/integrations/featureFlagShims/unleash.js.map +1 -1
  5. package/build/cjs/integrations/fs/index.js.map +1 -1
  6. package/build/cjs/integrations/http.js.map +1 -1
  7. package/build/cjs/integrations/node-fetch/index.js +7 -49
  8. package/build/cjs/integrations/node-fetch/index.js.map +1 -1
  9. package/build/cjs/integrations/node-fetch/undici-instrumentation.js +266 -0
  10. package/build/cjs/integrations/node-fetch/undici-instrumentation.js.map +1 -0
  11. package/build/cjs/integrations/tracing/amqplib/index.js.map +1 -1
  12. package/build/cjs/integrations/tracing/connect/index.js.map +1 -1
  13. package/build/cjs/integrations/tracing/dataloader/index.js.map +1 -1
  14. package/build/cjs/integrations/tracing/express.js.map +1 -1
  15. package/build/cjs/integrations/tracing/fastify/index.js +7 -103
  16. package/build/cjs/integrations/tracing/fastify/index.js.map +1 -1
  17. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +2 -3
  18. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -1
  19. package/build/cjs/integrations/tracing/firebase/firebase.js.map +1 -1
  20. package/build/cjs/integrations/tracing/genericPool/index.js.map +1 -1
  21. package/build/cjs/integrations/tracing/graphql/index.js.map +1 -1
  22. package/build/cjs/integrations/tracing/hapi/index.js.map +1 -1
  23. package/build/cjs/integrations/tracing/hono/index.js.map +1 -1
  24. package/build/cjs/integrations/tracing/index.js +0 -1
  25. package/build/cjs/integrations/tracing/index.js.map +1 -1
  26. package/build/cjs/integrations/tracing/kafka/index.js.map +1 -1
  27. package/build/cjs/integrations/tracing/knex/index.js.map +1 -1
  28. package/build/cjs/integrations/tracing/koa/index.js.map +1 -1
  29. package/build/cjs/integrations/tracing/lrumemoizer/index.js.map +1 -1
  30. package/build/cjs/integrations/tracing/lrumemoizer/vendored/instrumentation.js +4 -2
  31. package/build/cjs/integrations/tracing/lrumemoizer/vendored/instrumentation.js.map +1 -1
  32. package/build/cjs/integrations/tracing/mongo/index.js.map +1 -1
  33. package/build/cjs/integrations/tracing/mongoose/index.js.map +1 -1
  34. package/build/cjs/integrations/tracing/mysql/index.js.map +1 -1
  35. package/build/cjs/integrations/tracing/mysql/vendored/instrumentation.js +34 -128
  36. package/build/cjs/integrations/tracing/mysql/vendored/instrumentation.js.map +1 -1
  37. package/build/cjs/integrations/tracing/mysql/vendored/semconv.js +0 -2
  38. package/build/cjs/integrations/tracing/mysql/vendored/semconv.js.map +1 -1
  39. package/build/cjs/integrations/tracing/mysql/vendored/utils.js +2 -27
  40. package/build/cjs/integrations/tracing/mysql/vendored/utils.js.map +1 -1
  41. package/build/cjs/integrations/tracing/mysql2/index.js.map +1 -1
  42. package/build/cjs/integrations/tracing/postgres/index.js.map +1 -1
  43. package/build/cjs/integrations/tracing/postgresjs.js.map +1 -1
  44. package/build/cjs/integrations/tracing/prisma/index.js +1 -10
  45. package/build/cjs/integrations/tracing/prisma/index.js.map +1 -1
  46. package/build/cjs/integrations/tracing/prisma/vendored/active-tracing-helper.js +83 -57
  47. package/build/cjs/integrations/tracing/prisma/vendored/active-tracing-helper.js.map +1 -1
  48. package/build/cjs/integrations/tracing/prisma/vendored/constants.js.map +1 -1
  49. package/build/cjs/integrations/tracing/prisma/vendored/global.js +2 -2
  50. package/build/cjs/integrations/tracing/prisma/vendored/global.js.map +1 -1
  51. package/build/cjs/integrations/tracing/prisma/vendored/instrumentation.js +1 -6
  52. package/build/cjs/integrations/tracing/prisma/vendored/instrumentation.js.map +1 -1
  53. package/build/cjs/integrations/tracing/redis/index.js +3 -3
  54. package/build/cjs/integrations/tracing/redis/index.js.map +1 -1
  55. package/build/cjs/integrations/tracing/tedious/index.js.map +1 -1
  56. package/build/cjs/integrations/tracing/vercelai/constants.js.map +1 -1
  57. package/build/cjs/integrations/tracing/vercelai/index.js +2 -4
  58. package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -1
  59. package/build/cjs/sdk/diagnosticsChannelInjection.js.map +1 -1
  60. package/build/cjs/sdk/experimentalUseDiagnosticsChannelInjection.js +8 -6
  61. package/build/cjs/sdk/experimentalUseDiagnosticsChannelInjection.js.map +1 -1
  62. package/build/esm/integrations/featureFlagShims/launchDarkly.js.map +1 -1
  63. package/build/esm/integrations/featureFlagShims/openFeature.js.map +1 -1
  64. package/build/esm/integrations/featureFlagShims/statsig.js.map +1 -1
  65. package/build/esm/integrations/featureFlagShims/unleash.js.map +1 -1
  66. package/build/esm/integrations/fs/index.js.map +1 -1
  67. package/build/esm/integrations/http.js.map +1 -1
  68. package/build/esm/integrations/node-fetch/index.js +9 -50
  69. package/build/esm/integrations/node-fetch/index.js.map +1 -1
  70. package/build/esm/integrations/node-fetch/undici-instrumentation.js +264 -0
  71. package/build/esm/integrations/node-fetch/undici-instrumentation.js.map +1 -0
  72. package/build/esm/integrations/tracing/amqplib/index.js.map +1 -1
  73. package/build/esm/integrations/tracing/connect/index.js.map +1 -1
  74. package/build/esm/integrations/tracing/dataloader/index.js.map +1 -1
  75. package/build/esm/integrations/tracing/express.js.map +1 -1
  76. package/build/esm/integrations/tracing/fastify/index.js +8 -103
  77. package/build/esm/integrations/tracing/fastify/index.js.map +1 -1
  78. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +3 -4
  79. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -1
  80. package/build/esm/integrations/tracing/firebase/firebase.js.map +1 -1
  81. package/build/esm/integrations/tracing/genericPool/index.js.map +1 -1
  82. package/build/esm/integrations/tracing/graphql/index.js.map +1 -1
  83. package/build/esm/integrations/tracing/hapi/index.js.map +1 -1
  84. package/build/esm/integrations/tracing/hono/index.js.map +1 -1
  85. package/build/esm/integrations/tracing/index.js +1 -2
  86. package/build/esm/integrations/tracing/index.js.map +1 -1
  87. package/build/esm/integrations/tracing/kafka/index.js.map +1 -1
  88. package/build/esm/integrations/tracing/knex/index.js.map +1 -1
  89. package/build/esm/integrations/tracing/koa/index.js.map +1 -1
  90. package/build/esm/integrations/tracing/lrumemoizer/index.js.map +1 -1
  91. package/build/esm/integrations/tracing/lrumemoizer/vendored/instrumentation.js +5 -3
  92. package/build/esm/integrations/tracing/lrumemoizer/vendored/instrumentation.js.map +1 -1
  93. package/build/esm/integrations/tracing/mongo/index.js.map +1 -1
  94. package/build/esm/integrations/tracing/mongoose/index.js.map +1 -1
  95. package/build/esm/integrations/tracing/mysql/index.js.map +1 -1
  96. package/build/esm/integrations/tracing/mysql/vendored/instrumentation.js +37 -131
  97. package/build/esm/integrations/tracing/mysql/vendored/instrumentation.js.map +1 -1
  98. package/build/esm/integrations/tracing/mysql/vendored/semconv.js +1 -2
  99. package/build/esm/integrations/tracing/mysql/vendored/semconv.js.map +1 -1
  100. package/build/esm/integrations/tracing/mysql/vendored/utils.js +3 -25
  101. package/build/esm/integrations/tracing/mysql/vendored/utils.js.map +1 -1
  102. package/build/esm/integrations/tracing/mysql2/index.js.map +1 -1
  103. package/build/esm/integrations/tracing/postgres/index.js.map +1 -1
  104. package/build/esm/integrations/tracing/postgresjs.js.map +1 -1
  105. package/build/esm/integrations/tracing/prisma/index.js +2 -11
  106. package/build/esm/integrations/tracing/prisma/index.js.map +1 -1
  107. package/build/esm/integrations/tracing/prisma/vendored/active-tracing-helper.js +83 -57
  108. package/build/esm/integrations/tracing/prisma/vendored/active-tracing-helper.js.map +1 -1
  109. package/build/esm/integrations/tracing/prisma/vendored/constants.js.map +1 -1
  110. package/build/esm/integrations/tracing/prisma/vendored/global.js +2 -2
  111. package/build/esm/integrations/tracing/prisma/vendored/global.js.map +1 -1
  112. package/build/esm/integrations/tracing/prisma/vendored/instrumentation.js +1 -6
  113. package/build/esm/integrations/tracing/prisma/vendored/instrumentation.js.map +1 -1
  114. package/build/esm/integrations/tracing/redis/index.js +4 -4
  115. package/build/esm/integrations/tracing/redis/index.js.map +1 -1
  116. package/build/esm/integrations/tracing/tedious/index.js.map +1 -1
  117. package/build/esm/integrations/tracing/vercelai/constants.js.map +1 -1
  118. package/build/esm/integrations/tracing/vercelai/index.js +3 -5
  119. package/build/esm/integrations/tracing/vercelai/index.js.map +1 -1
  120. package/build/esm/package.json +1 -1
  121. package/build/esm/sdk/diagnosticsChannelInjection.js.map +1 -1
  122. package/build/esm/sdk/experimentalUseDiagnosticsChannelInjection.js +9 -7
  123. package/build/esm/sdk/experimentalUseDiagnosticsChannelInjection.js.map +1 -1
  124. package/build/types/integrations/featureFlagShims/launchDarkly.d.ts +3 -1
  125. package/build/types/integrations/featureFlagShims/launchDarkly.d.ts.map +1 -1
  126. package/build/types/integrations/featureFlagShims/openFeature.d.ts +3 -1
  127. package/build/types/integrations/featureFlagShims/openFeature.d.ts.map +1 -1
  128. package/build/types/integrations/featureFlagShims/statsig.d.ts +3 -1
  129. package/build/types/integrations/featureFlagShims/statsig.d.ts.map +1 -1
  130. package/build/types/integrations/featureFlagShims/unleash.d.ts +3 -1
  131. package/build/types/integrations/featureFlagShims/unleash.d.ts.map +1 -1
  132. package/build/types/integrations/fs/index.d.ts +3 -1
  133. package/build/types/integrations/fs/index.d.ts.map +1 -1
  134. package/build/types/integrations/http.d.ts +3 -1
  135. package/build/types/integrations/http.d.ts.map +1 -1
  136. package/build/types/integrations/node-fetch/index.d.ts +4 -35
  137. package/build/types/integrations/node-fetch/index.d.ts.map +1 -1
  138. package/build/types/integrations/node-fetch/types.d.ts +96 -0
  139. package/build/types/integrations/node-fetch/types.d.ts.map +1 -0
  140. package/build/types/integrations/node-fetch/undici-instrumentation.d.ts +14 -0
  141. package/build/types/integrations/node-fetch/undici-instrumentation.d.ts.map +1 -0
  142. package/build/types/integrations/tracing/amqplib/index.d.ts +3 -1
  143. package/build/types/integrations/tracing/amqplib/index.d.ts.map +1 -1
  144. package/build/types/integrations/tracing/anthropic-ai/index.d.ts +3 -1
  145. package/build/types/integrations/tracing/anthropic-ai/index.d.ts.map +1 -1
  146. package/build/types/integrations/tracing/connect/index.d.ts +3 -1
  147. package/build/types/integrations/tracing/connect/index.d.ts.map +1 -1
  148. package/build/types/integrations/tracing/dataloader/index.d.ts +3 -1
  149. package/build/types/integrations/tracing/dataloader/index.d.ts.map +1 -1
  150. package/build/types/integrations/tracing/express.d.ts +3 -1
  151. package/build/types/integrations/tracing/express.d.ts.map +1 -1
  152. package/build/types/integrations/tracing/fastify/index.d.ts +6 -6
  153. package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -1
  154. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts.map +1 -1
  155. package/build/types/integrations/tracing/firebase/firebase.d.ts +3 -1
  156. package/build/types/integrations/tracing/firebase/firebase.d.ts.map +1 -1
  157. package/build/types/integrations/tracing/genericPool/index.d.ts +3 -1
  158. package/build/types/integrations/tracing/genericPool/index.d.ts.map +1 -1
  159. package/build/types/integrations/tracing/google-genai/index.d.ts +3 -1
  160. package/build/types/integrations/tracing/google-genai/index.d.ts.map +1 -1
  161. package/build/types/integrations/tracing/graphql/index.d.ts +3 -1
  162. package/build/types/integrations/tracing/graphql/index.d.ts.map +1 -1
  163. package/build/types/integrations/tracing/hapi/index.d.ts +3 -1
  164. package/build/types/integrations/tracing/hapi/index.d.ts.map +1 -1
  165. package/build/types/integrations/tracing/hono/index.d.ts +3 -1
  166. package/build/types/integrations/tracing/hono/index.d.ts.map +1 -1
  167. package/build/types/integrations/tracing/index.d.ts.map +1 -1
  168. package/build/types/integrations/tracing/kafka/index.d.ts +3 -1
  169. package/build/types/integrations/tracing/kafka/index.d.ts.map +1 -1
  170. package/build/types/integrations/tracing/knex/index.d.ts +3 -1
  171. package/build/types/integrations/tracing/knex/index.d.ts.map +1 -1
  172. package/build/types/integrations/tracing/koa/index.d.ts +3 -1
  173. package/build/types/integrations/tracing/koa/index.d.ts.map +1 -1
  174. package/build/types/integrations/tracing/langchain/index.d.ts +3 -1
  175. package/build/types/integrations/tracing/langchain/index.d.ts.map +1 -1
  176. package/build/types/integrations/tracing/langgraph/index.d.ts +3 -1
  177. package/build/types/integrations/tracing/langgraph/index.d.ts.map +1 -1
  178. package/build/types/integrations/tracing/lrumemoizer/index.d.ts +3 -1
  179. package/build/types/integrations/tracing/lrumemoizer/index.d.ts.map +1 -1
  180. package/build/types/integrations/tracing/lrumemoizer/vendored/instrumentation.d.ts.map +1 -1
  181. package/build/types/integrations/tracing/mongo/index.d.ts +3 -1
  182. package/build/types/integrations/tracing/mongo/index.d.ts.map +1 -1
  183. package/build/types/integrations/tracing/mongoose/index.d.ts +3 -1
  184. package/build/types/integrations/tracing/mongoose/index.d.ts.map +1 -1
  185. package/build/types/integrations/tracing/mysql/index.d.ts +3 -1
  186. package/build/types/integrations/tracing/mysql/index.d.ts.map +1 -1
  187. package/build/types/integrations/tracing/mysql/vendored/instrumentation.d.ts +3 -17
  188. package/build/types/integrations/tracing/mysql/vendored/instrumentation.d.ts.map +1 -1
  189. package/build/types/integrations/tracing/mysql/vendored/mysql-types.d.ts +16 -16
  190. package/build/types/integrations/tracing/mysql/vendored/mysql-types.d.ts.map +1 -1
  191. package/build/types/integrations/tracing/mysql/vendored/semconv.d.ts +0 -8
  192. package/build/types/integrations/tracing/mysql/vendored/semconv.d.ts.map +1 -1
  193. package/build/types/integrations/tracing/mysql/vendored/utils.d.ts +6 -9
  194. package/build/types/integrations/tracing/mysql/vendored/utils.d.ts.map +1 -1
  195. package/build/types/integrations/tracing/mysql2/index.d.ts +3 -1
  196. package/build/types/integrations/tracing/mysql2/index.d.ts.map +1 -1
  197. package/build/types/integrations/tracing/openai/index.d.ts +3 -1
  198. package/build/types/integrations/tracing/openai/index.d.ts.map +1 -1
  199. package/build/types/integrations/tracing/postgres/index.d.ts +3 -1
  200. package/build/types/integrations/tracing/postgres/index.d.ts.map +1 -1
  201. package/build/types/integrations/tracing/postgresjs.d.ts +3 -1
  202. package/build/types/integrations/tracing/postgresjs.d.ts.map +1 -1
  203. package/build/types/integrations/tracing/prisma/index.d.ts +5 -21
  204. package/build/types/integrations/tracing/prisma/index.d.ts.map +1 -1
  205. package/build/types/integrations/tracing/prisma/vendored/active-tracing-helper.d.ts +5 -7
  206. package/build/types/integrations/tracing/prisma/vendored/active-tracing-helper.d.ts.map +1 -1
  207. package/build/types/integrations/tracing/prisma/vendored/constants.d.ts.map +1 -1
  208. package/build/types/integrations/tracing/prisma/vendored/global.d.ts.map +1 -1
  209. package/build/types/integrations/tracing/prisma/vendored/instrumentation.d.ts +2 -4
  210. package/build/types/integrations/tracing/prisma/vendored/instrumentation.d.ts.map +1 -1
  211. package/build/types/integrations/tracing/prisma/vendored/types.d.ts +5 -23
  212. package/build/types/integrations/tracing/prisma/vendored/types.d.ts.map +1 -1
  213. package/build/types/integrations/tracing/redis/index.d.ts +4 -2
  214. package/build/types/integrations/tracing/redis/index.d.ts.map +1 -1
  215. package/build/types/integrations/tracing/tedious/index.d.ts +3 -1
  216. package/build/types/integrations/tracing/tedious/index.d.ts.map +1 -1
  217. package/build/types/integrations/tracing/vercelai/constants.d.ts +1 -1
  218. package/build/types/integrations/tracing/vercelai/constants.d.ts.map +1 -1
  219. package/build/types/integrations/tracing/vercelai/index.d.ts +3 -1
  220. package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -1
  221. package/build/types/sdk/diagnosticsChannelInjection.d.ts +1 -1
  222. package/build/types/sdk/diagnosticsChannelInjection.d.ts.map +1 -1
  223. package/build/types/sdk/experimentalUseDiagnosticsChannelInjection.d.ts.map +1 -1
  224. package/build/types-ts3.8/integrations/featureFlagShims/launchDarkly.d.ts +3 -1
  225. package/build/types-ts3.8/integrations/featureFlagShims/openFeature.d.ts +3 -1
  226. package/build/types-ts3.8/integrations/featureFlagShims/statsig.d.ts +3 -1
  227. package/build/types-ts3.8/integrations/featureFlagShims/unleash.d.ts +3 -1
  228. package/build/types-ts3.8/integrations/fs/index.d.ts +3 -1
  229. package/build/types-ts3.8/integrations/http.d.ts +3 -1
  230. package/build/types-ts3.8/integrations/node-fetch/index.d.ts +4 -35
  231. package/build/types-ts3.8/integrations/node-fetch/types.d.ts +96 -0
  232. package/build/types-ts3.8/integrations/node-fetch/undici-instrumentation.d.ts +14 -0
  233. package/build/types-ts3.8/integrations/tracing/amqplib/index.d.ts +3 -1
  234. package/build/types-ts3.8/integrations/tracing/anthropic-ai/index.d.ts +3 -1
  235. package/build/types-ts3.8/integrations/tracing/connect/index.d.ts +3 -1
  236. package/build/types-ts3.8/integrations/tracing/dataloader/index.d.ts +3 -1
  237. package/build/types-ts3.8/integrations/tracing/express.d.ts +3 -1
  238. package/build/types-ts3.8/integrations/tracing/fastify/index.d.ts +6 -6
  239. package/build/types-ts3.8/integrations/tracing/firebase/firebase.d.ts +3 -1
  240. package/build/types-ts3.8/integrations/tracing/genericPool/index.d.ts +3 -1
  241. package/build/types-ts3.8/integrations/tracing/google-genai/index.d.ts +3 -1
  242. package/build/types-ts3.8/integrations/tracing/graphql/index.d.ts +3 -1
  243. package/build/types-ts3.8/integrations/tracing/hapi/index.d.ts +3 -1
  244. package/build/types-ts3.8/integrations/tracing/hono/index.d.ts +3 -1
  245. package/build/types-ts3.8/integrations/tracing/kafka/index.d.ts +3 -1
  246. package/build/types-ts3.8/integrations/tracing/knex/index.d.ts +3 -1
  247. package/build/types-ts3.8/integrations/tracing/koa/index.d.ts +3 -1
  248. package/build/types-ts3.8/integrations/tracing/langchain/index.d.ts +3 -1
  249. package/build/types-ts3.8/integrations/tracing/langgraph/index.d.ts +3 -1
  250. package/build/types-ts3.8/integrations/tracing/lrumemoizer/index.d.ts +3 -1
  251. package/build/types-ts3.8/integrations/tracing/mongo/index.d.ts +3 -1
  252. package/build/types-ts3.8/integrations/tracing/mongoose/index.d.ts +3 -1
  253. package/build/types-ts3.8/integrations/tracing/mysql/index.d.ts +3 -1
  254. package/build/types-ts3.8/integrations/tracing/mysql/vendored/instrumentation.d.ts +3 -17
  255. package/build/types-ts3.8/integrations/tracing/mysql/vendored/mysql-types.d.ts +16 -16
  256. package/build/types-ts3.8/integrations/tracing/mysql/vendored/semconv.d.ts +0 -8
  257. package/build/types-ts3.8/integrations/tracing/mysql/vendored/utils.d.ts +6 -9
  258. package/build/types-ts3.8/integrations/tracing/mysql2/index.d.ts +3 -1
  259. package/build/types-ts3.8/integrations/tracing/openai/index.d.ts +3 -1
  260. package/build/types-ts3.8/integrations/tracing/postgres/index.d.ts +3 -1
  261. package/build/types-ts3.8/integrations/tracing/postgresjs.d.ts +3 -1
  262. package/build/types-ts3.8/integrations/tracing/prisma/index.d.ts +5 -21
  263. package/build/types-ts3.8/integrations/tracing/prisma/vendored/active-tracing-helper.d.ts +5 -7
  264. package/build/types-ts3.8/integrations/tracing/prisma/vendored/instrumentation.d.ts +2 -4
  265. package/build/types-ts3.8/integrations/tracing/prisma/vendored/types.d.ts +5 -23
  266. package/build/types-ts3.8/integrations/tracing/redis/index.d.ts +4 -2
  267. package/build/types-ts3.8/integrations/tracing/tedious/index.d.ts +3 -1
  268. package/build/types-ts3.8/integrations/tracing/vercelai/constants.d.ts +1 -1
  269. package/build/types-ts3.8/integrations/tracing/vercelai/index.d.ts +3 -1
  270. package/build/types-ts3.8/sdk/diagnosticsChannelInjection.d.ts +1 -1
  271. package/package.json +6 -5
  272. package/build/cjs/integrations/node-fetch/vendored/semconv.js +0 -28
  273. package/build/cjs/integrations/node-fetch/vendored/semconv.js.map +0 -1
  274. package/build/cjs/integrations/node-fetch/vendored/undici.js +0 -302
  275. package/build/cjs/integrations/node-fetch/vendored/undici.js.map +0 -1
  276. package/build/cjs/integrations/tracing/fastify/vendored/instrumentation.js +0 -387
  277. package/build/cjs/integrations/tracing/fastify/vendored/instrumentation.js.map +0 -1
  278. package/build/cjs/integrations/tracing/mysql/vendored/AttributeNames.js +0 -9
  279. package/build/cjs/integrations/tracing/mysql/vendored/AttributeNames.js.map +0 -1
  280. package/build/esm/integrations/node-fetch/vendored/semconv.js +0 -15
  281. package/build/esm/integrations/node-fetch/vendored/semconv.js.map +0 -1
  282. package/build/esm/integrations/node-fetch/vendored/undici.js +0 -300
  283. package/build/esm/integrations/node-fetch/vendored/undici.js.map +0 -1
  284. package/build/esm/integrations/tracing/fastify/vendored/instrumentation.js +0 -385
  285. package/build/esm/integrations/tracing/fastify/vendored/instrumentation.js.map +0 -1
  286. package/build/esm/integrations/tracing/mysql/vendored/AttributeNames.js +0 -7
  287. package/build/esm/integrations/tracing/mysql/vendored/AttributeNames.js.map +0 -1
  288. package/build/types/integrations/node-fetch/vendored/internal-types.d.ts +0 -25
  289. package/build/types/integrations/node-fetch/vendored/internal-types.d.ts.map +0 -1
  290. package/build/types/integrations/node-fetch/vendored/semconv.d.ts +0 -13
  291. package/build/types/integrations/node-fetch/vendored/semconv.d.ts.map +0 -1
  292. package/build/types/integrations/node-fetch/vendored/types.d.ts +0 -60
  293. package/build/types/integrations/node-fetch/vendored/types.d.ts.map +0 -1
  294. package/build/types/integrations/node-fetch/vendored/undici.d.ts +0 -21
  295. package/build/types/integrations/node-fetch/vendored/undici.d.ts.map +0 -1
  296. package/build/types/integrations/tracing/fastify/vendored/instrumentation.d.ts +0 -27
  297. package/build/types/integrations/tracing/fastify/vendored/instrumentation.d.ts.map +0 -1
  298. package/build/types/integrations/tracing/mysql/vendored/AttributeNames.d.ts +0 -4
  299. package/build/types/integrations/tracing/mysql/vendored/AttributeNames.d.ts.map +0 -1
  300. package/build/types/integrations/tracing/mysql/vendored/types.d.ts +0 -9
  301. package/build/types/integrations/tracing/mysql/vendored/types.d.ts.map +0 -1
  302. package/build/types-ts3.8/integrations/node-fetch/vendored/internal-types.d.ts +0 -25
  303. package/build/types-ts3.8/integrations/node-fetch/vendored/semconv.d.ts +0 -13
  304. package/build/types-ts3.8/integrations/node-fetch/vendored/types.d.ts +0 -60
  305. package/build/types-ts3.8/integrations/node-fetch/vendored/undici.d.ts +0 -21
  306. package/build/types-ts3.8/integrations/tracing/fastify/vendored/instrumentation.d.ts +0 -27
  307. package/build/types-ts3.8/integrations/tracing/mysql/vendored/AttributeNames.d.ts +0 -4
  308. package/build/types-ts3.8/integrations/tracing/mysql/vendored/types.d.ts +0 -9
@@ -1 +1 @@
1
- {"version":3,"file":"postgresjs.js","sources":["../../../../src/integrations/tracing/postgresjs.ts"],"sourcesContent":["// Instrumentation for https://github.com/porsager/postgres\n\nimport { context, trace } from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from './InstrumentationNodeModuleFile';\nimport {\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_RESPONSE_STATUS_CODE,\n ATTR_DB_SYSTEM_NAME,\n ATTR_ERROR_TYPE,\n} from '@opentelemetry/semantic-conventions';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n debug,\n defineIntegration,\n instrumentPostgresJsSql,\n replaceExports,\n SDK_VERSION,\n SPAN_STATUS_ERROR,\n startSpanManual,\n} from '@sentry/core';\nimport { addOriginToSpan, generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../debug-build';\n\nconst INTEGRATION_NAME = 'PostgresJs';\nconst SUPPORTED_VERSIONS = ['>=3.0.0 <4'];\nconst SQL_OPERATION_REGEX = /^(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER)/i;\n\ntype PostgresConnectionContext = {\n ATTR_DB_NAMESPACE?: string; // Database name\n ATTR_SERVER_ADDRESS?: string; // Hostname or IP address of the database server\n ATTR_SERVER_PORT?: string; // Port number of the database server\n};\n\n// Marker to track if a query was created from an instrumented sql instance\n// This prevents double-spanning when both wrapper and prototype patches are active\nconst QUERY_FROM_INSTRUMENTED_SQL = Symbol.for('sentry.query.from.instrumented.sql');\n\ntype PostgresJsInstrumentationConfig = InstrumentationConfig & {\n /**\n * Whether to require a parent span for the instrumentation.\n * If set to true, the instrumentation will only create spans if there is a parent span\n * available in the current scope.\n * @default true\n */\n requireParentSpan?: boolean;\n /**\n * Hook to modify the span before it is started.\n * This can be used to set additional attributes or modify the span in any way.\n */\n requestHook?: (span: Span, sanitizedSqlQuery: string, postgresConnectionContext?: PostgresConnectionContext) => void;\n};\n\nexport const instrumentPostgresJs = generateInstrumentOnce(\n INTEGRATION_NAME,\n (options?: PostgresJsInstrumentationConfig) =>\n new PostgresJsInstrumentation({\n requireParentSpan: options?.requireParentSpan ?? true,\n requestHook: options?.requestHook,\n }),\n);\n\n/**\n * Instrumentation for the [postgres](https://www.npmjs.com/package/postgres) library.\n * This instrumentation captures postgresjs queries and their attributes.\n *\n * Uses internal Sentry patching patterns to support both CommonJS and ESM environments.\n */\nexport class PostgresJsInstrumentation extends InstrumentationBase<PostgresJsInstrumentationConfig> {\n public constructor(config: PostgresJsInstrumentationConfig) {\n super('sentry-postgres-js', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by patching the postgres module.\n * Uses two complementary approaches:\n * 1. Main function wrapper: instruments sql instances created AFTER instrumentation is set up (CJS + ESM)\n * 2. Query.prototype patch: fallback for sql instances created BEFORE instrumentation (CJS only)\n */\n public init(): InstrumentationNodeModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'postgres',\n SUPPORTED_VERSIONS,\n exports => {\n try {\n return this._patchPostgres(exports);\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch postgres module:', e);\n return exports;\n }\n },\n exports => exports,\n );\n\n // Add fallback Query.prototype patching for pre-existing sql instances (CJS only)\n // This catches queries from sql instances created before Sentry was initialized\n ['src', 'cf/src', 'cjs/src'].forEach(path => {\n module.files.push(\n new InstrumentationNodeModuleFile(\n `postgres/${path}/query.js`,\n SUPPORTED_VERSIONS,\n this._patchQueryPrototype.bind(this),\n this._unpatchQueryPrototype.bind(this),\n ),\n );\n });\n\n return module;\n }\n\n /**\n * Patches the postgres module by wrapping the main export function.\n * This intercepts the creation of sql instances and instruments them.\n */\n private _patchPostgres(exports: { [key: string]: unknown }): { [key: string]: unknown } {\n // In CJS: exports is the function itself\n // In ESM: exports.default is the function\n const isFunction = typeof exports === 'function';\n const Original = isFunction ? exports : exports.default;\n\n if (typeof Original !== 'function') {\n DEBUG_BUILD && debug.warn('postgres module does not export a function. Skipping instrumentation.');\n return exports;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n\n const WrappedPostgres = function (this: unknown, ...args: unknown[]): unknown {\n const sql = Reflect.construct(Original as (...args: unknown[]) => unknown, args);\n\n // Validate that construction succeeded and returned a valid function object\n if (!sql || typeof sql !== 'function') {\n DEBUG_BUILD && debug.warn('postgres() did not return a valid instance');\n return sql;\n }\n\n // Delegate to the portable instrumentation from @sentry/core\n const config = self.getConfig();\n return instrumentPostgresJsSql(sql, {\n requireParentSpan: config.requireParentSpan,\n requestHook: config.requestHook,\n });\n };\n\n Object.setPrototypeOf(WrappedPostgres, Original);\n Object.setPrototypeOf(WrappedPostgres.prototype, (Original as { prototype: object }).prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedPostgres, key, descriptor);\n }\n }\n }\n\n // For CJS: the exports object IS the function, so return the wrapped function\n // For ESM: replace the default export\n if (isFunction) {\n return WrappedPostgres as unknown as { [key: string]: unknown };\n } else {\n replaceExports(exports, 'default', WrappedPostgres);\n return exports;\n }\n }\n\n /**\n * Determines whether a span should be created based on the current context.\n * If `requireParentSpan` is set to true in the configuration, a span will\n * only be created if there is a parent span available.\n */\n private _shouldCreateSpans(): boolean {\n const config = this.getConfig();\n const hasParentSpan = trace.getSpan(context.active()) !== undefined;\n return hasParentSpan || !config.requireParentSpan;\n }\n\n /**\n * Extracts DB operation name from SQL query and sets it on the span.\n */\n private _setOperationName(span: Span, sanitizedQuery: string | undefined, command?: string): void {\n if (command) {\n span.setAttribute(ATTR_DB_OPERATION_NAME, command);\n return;\n }\n // Fallback: extract operation from the SQL query\n const operationMatch = sanitizedQuery?.match(SQL_OPERATION_REGEX);\n if (operationMatch?.[1]) {\n span.setAttribute(ATTR_DB_OPERATION_NAME, operationMatch[1].toUpperCase());\n }\n }\n\n /**\n * Reconstructs the full SQL query from template strings with PostgreSQL placeholders.\n *\n * For sql`SELECT * FROM users WHERE id = ${123} AND name = ${'foo'}`:\n * strings = [\"SELECT * FROM users WHERE id = \", \" AND name = \", \"\"]\n * returns: \"SELECT * FROM users WHERE id = $1 AND name = $2\"\n */\n private _reconstructQuery(strings: string[] | undefined): string | undefined {\n if (!strings?.length) {\n return undefined;\n }\n if (strings.length === 1) {\n return strings[0] || undefined;\n }\n // Join template parts with PostgreSQL placeholders ($1, $2, etc.)\n return strings.reduce((acc, str, i) => (i === 0 ? str : `${acc}$${i}${str}`), '');\n }\n\n /**\n * Sanitize SQL query as per the OTEL semantic conventions\n * https://opentelemetry.io/docs/specs/semconv/database/database-spans/#sanitization-of-dbquerytext\n *\n * PostgreSQL $n placeholders are preserved per OTEL spec - they're parameterized queries,\n * not sensitive literals. Only actual values (strings, numbers, booleans) are sanitized.\n */\n private _sanitizeSqlQuery(sqlQuery: string | undefined): string {\n if (!sqlQuery) {\n return 'Unknown SQL Query';\n }\n\n return (\n sqlQuery\n // Remove comments first (they may contain newlines and extra spaces)\n .replace(/--.*$/gm, '') // Single line comments (multiline mode)\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Multi-line comments\n .replace(/;\\s*$/, '') // Remove trailing semicolons\n // Collapse whitespace to a single space (after removing comments)\n .replace(/\\s+/g, ' ')\n .trim() // Remove extra spaces and trim\n // Sanitize hex/binary literals before string literals\n .replace(/\\bX'[0-9A-Fa-f]*'/gi, '?') // Hex string literals\n .replace(/\\bB'[01]*'/gi, '?') // Binary string literals\n // Sanitize string literals (handles escaped quotes)\n .replace(/'(?:[^']|'')*'/g, '?')\n // Sanitize hex numbers\n .replace(/\\b0x[0-9A-Fa-f]+/gi, '?')\n // Sanitize boolean literals\n .replace(/\\b(?:TRUE|FALSE)\\b/gi, '?')\n // Sanitize numeric literals (preserve $n placeholders via negative lookbehind)\n .replace(/-?\\b\\d+\\.?\\d*[eE][+-]?\\d+\\b/g, '?') // Scientific notation\n .replace(/-?\\b\\d+\\.\\d+\\b/g, '?') // Decimals\n .replace(/-?\\.\\d+\\b/g, '?') // Decimals starting with dot\n .replace(/(?<!\\$)-?\\b\\d+\\b/g, '?') // Integers (NOT $n placeholders)\n // Collapse IN clauses for cardinality (both ? and $n variants)\n .replace(/\\bIN\\b\\s*\\(\\s*\\?(?:\\s*,\\s*\\?)*\\s*\\)/gi, 'IN (?)')\n .replace(/\\bIN\\b\\s*\\(\\s*\\$\\d+(?:\\s*,\\s*\\$\\d+)*\\s*\\)/gi, 'IN ($?)')\n );\n }\n\n /**\n * Fallback patch for Query.prototype.handle to instrument queries from pre-existing sql instances.\n * This catches queries from sql instances created BEFORE Sentry was initialized (CJS only).\n *\n * Note: Queries from pre-existing instances won't have connection context (database, host, port)\n * because the sql instance wasn't created through our instrumented wrapper.\n */\n private _patchQueryPrototype(moduleExports: {\n Query: {\n prototype: {\n handle: ((...args: unknown[]) => Promise<unknown>) & {\n __sentry_original__?: (...args: unknown[]) => Promise<unknown>;\n };\n };\n };\n }): typeof moduleExports {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n const originalHandle = moduleExports.Query.prototype.handle;\n\n moduleExports.Query.prototype.handle = async function (\n this: {\n resolve: unknown;\n reject: unknown;\n strings?: string[];\n executed?: boolean;\n },\n ...args: unknown[]\n ): Promise<unknown> {\n // Skip if this query came from an instrumented sql instance (already handled by wrapper),\n // or if handle() was already called (postgres.js calls handle() from then/catch/finally —\n // only the first call executes SQL, subsequent calls are no-ops).\n if (this.executed || (this as Record<symbol, unknown>)[QUERY_FROM_INSTRUMENTED_SQL]) {\n return originalHandle.apply(this, args);\n }\n\n // Skip if we shouldn't create spans\n if (!self._shouldCreateSpans()) {\n return originalHandle.apply(this, args);\n }\n\n const fullQuery = self._reconstructQuery(this.strings);\n const sanitizedSqlQuery = self._sanitizeSqlQuery(fullQuery);\n\n return startSpanManual(\n {\n name: sanitizedSqlQuery || 'postgresjs.query',\n op: 'db',\n },\n (span: Span) => {\n addOriginToSpan(span, 'auto.db.postgresjs');\n\n span.setAttributes({\n [ATTR_DB_SYSTEM_NAME]: 'postgres',\n [ATTR_DB_QUERY_TEXT]: sanitizedSqlQuery,\n });\n\n // Note: No connection context available for pre-existing instances\n // because the sql instance wasn't created through our instrumented wrapper\n\n const config = self.getConfig();\n const { requestHook } = config;\n if (requestHook) {\n safeExecuteInTheMiddle(\n () => requestHook(span, sanitizedSqlQuery, undefined),\n e => {\n if (e) {\n span.setAttribute('sentry.hook.error', 'requestHook failed');\n DEBUG_BUILD && debug.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, e);\n }\n },\n true,\n );\n }\n\n // Wrap resolve to end span on success\n const originalResolve = this.resolve;\n this.resolve = new Proxy(originalResolve as (...args: unknown[]) => unknown, {\n apply: (resolveTarget, resolveThisArg, resolveArgs: [{ command?: string }]) => {\n try {\n self._setOperationName(span, sanitizedSqlQuery, resolveArgs?.[0]?.command);\n span.end();\n } catch (e) {\n DEBUG_BUILD && debug.error('Error ending span in resolve callback:', e);\n }\n return Reflect.apply(resolveTarget, resolveThisArg, resolveArgs);\n },\n });\n\n // Wrap reject to end span on error\n const originalReject = this.reject;\n this.reject = new Proxy(originalReject as (...args: unknown[]) => unknown, {\n apply: (rejectTarget, rejectThisArg, rejectArgs: { message?: string; code?: string; name?: string }[]) => {\n try {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: rejectArgs?.[0]?.message || 'unknown_error',\n });\n span.setAttribute(ATTR_DB_RESPONSE_STATUS_CODE, rejectArgs?.[0]?.code || 'unknown');\n span.setAttribute(ATTR_ERROR_TYPE, rejectArgs?.[0]?.name || 'unknown');\n self._setOperationName(span, sanitizedSqlQuery);\n span.end();\n } catch (e) {\n DEBUG_BUILD && debug.error('Error ending span in reject callback:', e);\n }\n return Reflect.apply(rejectTarget, rejectThisArg, rejectArgs);\n },\n });\n\n try {\n return originalHandle.apply(this, args);\n } catch (e) {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: e instanceof Error ? e.message : 'unknown_error',\n });\n span.end();\n throw e;\n }\n },\n );\n };\n\n // Store original for unpatch - must be set on the NEW patched function\n moduleExports.Query.prototype.handle.__sentry_original__ = originalHandle;\n\n return moduleExports;\n }\n\n /**\n * Restores the original Query.prototype.handle method.\n */\n private _unpatchQueryPrototype(moduleExports: {\n Query: {\n prototype: {\n handle: ((...args: unknown[]) => Promise<unknown>) & {\n __sentry_original__?: (...args: unknown[]) => Promise<unknown>;\n };\n };\n };\n }): typeof moduleExports {\n if (moduleExports.Query.prototype.handle.__sentry_original__) {\n moduleExports.Query.prototype.handle = moduleExports.Query.prototype.handle.__sentry_original__;\n }\n return moduleExports;\n }\n}\n\nconst _postgresJsIntegration = ((options?: PostgresJsInstrumentationConfig) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPostgresJs(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [postgres](https://www.npmjs.com/package/postgres) library.\n *\n * For more information, see the [`postgresIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/postgres/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.postgresJsIntegration()],\n * });\n * ```\n */\n\nexport const postgresJsIntegration = defineIntegration(_postgresJsIntegration);\n"],"names":["generateInstrumentOnce","InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","DEBUG_BUILD","debug","InstrumentationNodeModuleFile","instrumentPostgresJsSql","replaceExports","trace","context","ATTR_DB_OPERATION_NAME","startSpanManual","addOriginToSpan","ATTR_DB_SYSTEM_NAME","ATTR_DB_QUERY_TEXT","safeExecuteInTheMiddle","SPAN_STATUS_ERROR","ATTR_DB_RESPONSE_STATUS_CODE","ATTR_ERROR_TYPE","defineIntegration"],"mappings":";;;;;;;;;;AA8BA,MAAM,gBAAA,GAAmB,YAAA;AACzB,MAAM,kBAAA,GAAqB,CAAC,YAAY,CAAA;AACxC,MAAM,mBAAA,GAAsB,mDAAA;AAU5B,MAAM,2BAAA,mBAA8B,MAAA,CAAO,GAAA,CAAI,oCAAoC,CAAA;AAiB5E,MAAM,oBAAA,GAAuBA,+BAAA;AAAA,EAClC,gBAAA;AAAA,EACA,CAAC,OAAA,KACC,IAAI,yBAAA,CAA0B;AAAA,IAC5B,iBAAA,EAAmB,SAAS,iBAAA,IAAqB,IAAA;AAAA,IACjD,aAAa,OAAA,EAAS;AAAA,GACvB;AACL;AAQO,MAAM,kCAAkCC,mCAAA,CAAqD;AAAA,EAC3F,YAAY,MAAA,EAAyC;AAC1D,IAAA,KAAA,CAAM,oBAAA,EAAsBC,kBAAa,MAAM,CAAA;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,IAAA,GAA4C;AACjD,IAAA,MAAM,SAAS,IAAIC,mDAAA;AAAA,MACjB,UAAA;AAAA,MACA,kBAAA;AAAA,MACA,CAAA,OAAA,KAAW;AACT,QAAA,IAAI;AACF,UAAA,OAAO,IAAA,CAAK,eAAe,OAAO,CAAA;AAAA,QACpC,SAAS,CAAA,EAAG;AACV,UAAAC,sBAAA,IAAeC,UAAA,CAAM,KAAA,CAAM,kCAAA,EAAoC,CAAC,CAAA;AAChE,UAAA,OAAO,OAAA;AAAA,QACT;AAAA,MACF,CAAA;AAAA,MACA,CAAA,OAAA,KAAW;AAAA,KACb;AAIA,IAAA,CAAC,KAAA,EAAO,QAAA,EAAU,SAAS,CAAA,CAAE,QAAQ,CAAA,IAAA,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AAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKQ,uBAAuB,aAAA,EAQN;AACvB,IAAA,IAAI,aAAA,CAAc,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,mBAAA,EAAqB;AAC5D,MAAA,aAAA,CAAc,MAAM,SAAA,CAAU,MAAA,GAAS,aAAA,CAAc,KAAA,CAAM,UAAU,MAAA,CAAO,mBAAA;AAAA,IAC9E;AACA,IAAA,OAAO,aAAA;AAAA,EACT;AACF;AAEA,MAAM,sBAAA,IAA0B,CAAC,OAAA,KAA8C;AAC7E,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,oBAAA,CAAqB,OAAO,CAAA;AAAA,IAC9B;AAAA,GACF;AACF,CAAA,CAAA;AAiBO,MAAM,qBAAA,GAAwBG,uBAAkB,sBAAsB;;;;;;"}
1
+ {"version":3,"file":"postgresjs.js","sources":["../../../../src/integrations/tracing/postgresjs.ts"],"sourcesContent":["// Instrumentation for https://github.com/porsager/postgres\n\nimport { context, trace } from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from './InstrumentationNodeModuleFile';\nimport {\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_RESPONSE_STATUS_CODE,\n ATTR_DB_SYSTEM_NAME,\n ATTR_ERROR_TYPE,\n} from '@opentelemetry/semantic-conventions';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n debug,\n defineIntegration,\n instrumentPostgresJsSql,\n replaceExports,\n SDK_VERSION,\n SPAN_STATUS_ERROR,\n startSpanManual,\n} from '@sentry/core';\nimport { addOriginToSpan, generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../debug-build';\n\nconst INTEGRATION_NAME = 'PostgresJs' as const;\nconst SUPPORTED_VERSIONS = ['>=3.0.0 <4'];\nconst SQL_OPERATION_REGEX = /^(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER)/i;\n\ntype PostgresConnectionContext = {\n ATTR_DB_NAMESPACE?: string; // Database name\n ATTR_SERVER_ADDRESS?: string; // Hostname or IP address of the database server\n ATTR_SERVER_PORT?: string; // Port number of the database server\n};\n\n// Marker to track if a query was created from an instrumented sql instance\n// This prevents double-spanning when both wrapper and prototype patches are active\nconst QUERY_FROM_INSTRUMENTED_SQL = Symbol.for('sentry.query.from.instrumented.sql');\n\ntype PostgresJsInstrumentationConfig = InstrumentationConfig & {\n /**\n * Whether to require a parent span for the instrumentation.\n * If set to true, the instrumentation will only create spans if there is a parent span\n * available in the current scope.\n * @default true\n */\n requireParentSpan?: boolean;\n /**\n * Hook to modify the span before it is started.\n * This can be used to set additional attributes or modify the span in any way.\n */\n requestHook?: (span: Span, sanitizedSqlQuery: string, postgresConnectionContext?: PostgresConnectionContext) => void;\n};\n\nexport const instrumentPostgresJs = generateInstrumentOnce(\n INTEGRATION_NAME,\n (options?: PostgresJsInstrumentationConfig) =>\n new PostgresJsInstrumentation({\n requireParentSpan: options?.requireParentSpan ?? true,\n requestHook: options?.requestHook,\n }),\n);\n\n/**\n * Instrumentation for the [postgres](https://www.npmjs.com/package/postgres) library.\n * This instrumentation captures postgresjs queries and their attributes.\n *\n * Uses internal Sentry patching patterns to support both CommonJS and ESM environments.\n */\nexport class PostgresJsInstrumentation extends InstrumentationBase<PostgresJsInstrumentationConfig> {\n public constructor(config: PostgresJsInstrumentationConfig) {\n super('sentry-postgres-js', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by patching the postgres module.\n * Uses two complementary approaches:\n * 1. Main function wrapper: instruments sql instances created AFTER instrumentation is set up (CJS + ESM)\n * 2. Query.prototype patch: fallback for sql instances created BEFORE instrumentation (CJS only)\n */\n public init(): InstrumentationNodeModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'postgres',\n SUPPORTED_VERSIONS,\n exports => {\n try {\n return this._patchPostgres(exports);\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch postgres module:', e);\n return exports;\n }\n },\n exports => exports,\n );\n\n // Add fallback Query.prototype patching for pre-existing sql instances (CJS only)\n // This catches queries from sql instances created before Sentry was initialized\n ['src', 'cf/src', 'cjs/src'].forEach(path => {\n module.files.push(\n new InstrumentationNodeModuleFile(\n `postgres/${path}/query.js`,\n SUPPORTED_VERSIONS,\n this._patchQueryPrototype.bind(this),\n this._unpatchQueryPrototype.bind(this),\n ),\n );\n });\n\n return module;\n }\n\n /**\n * Patches the postgres module by wrapping the main export function.\n * This intercepts the creation of sql instances and instruments them.\n */\n private _patchPostgres(exports: { [key: string]: unknown }): { [key: string]: unknown } {\n // In CJS: exports is the function itself\n // In ESM: exports.default is the function\n const isFunction = typeof exports === 'function';\n const Original = isFunction ? exports : exports.default;\n\n if (typeof Original !== 'function') {\n DEBUG_BUILD && debug.warn('postgres module does not export a function. Skipping instrumentation.');\n return exports;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n\n const WrappedPostgres = function (this: unknown, ...args: unknown[]): unknown {\n const sql = Reflect.construct(Original as (...args: unknown[]) => unknown, args);\n\n // Validate that construction succeeded and returned a valid function object\n if (!sql || typeof sql !== 'function') {\n DEBUG_BUILD && debug.warn('postgres() did not return a valid instance');\n return sql;\n }\n\n // Delegate to the portable instrumentation from @sentry/core\n const config = self.getConfig();\n return instrumentPostgresJsSql(sql, {\n requireParentSpan: config.requireParentSpan,\n requestHook: config.requestHook,\n });\n };\n\n Object.setPrototypeOf(WrappedPostgres, Original);\n Object.setPrototypeOf(WrappedPostgres.prototype, (Original as { prototype: object }).prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedPostgres, key, descriptor);\n }\n }\n }\n\n // For CJS: the exports object IS the function, so return the wrapped function\n // For ESM: replace the default export\n if (isFunction) {\n return WrappedPostgres as unknown as { [key: string]: unknown };\n } else {\n replaceExports(exports, 'default', WrappedPostgres);\n return exports;\n }\n }\n\n /**\n * Determines whether a span should be created based on the current context.\n * If `requireParentSpan` is set to true in the configuration, a span will\n * only be created if there is a parent span available.\n */\n private _shouldCreateSpans(): boolean {\n const config = this.getConfig();\n const hasParentSpan = trace.getSpan(context.active()) !== undefined;\n return hasParentSpan || !config.requireParentSpan;\n }\n\n /**\n * Extracts DB operation name from SQL query and sets it on the span.\n */\n private _setOperationName(span: Span, sanitizedQuery: string | undefined, command?: string): void {\n if (command) {\n span.setAttribute(ATTR_DB_OPERATION_NAME, command);\n return;\n }\n // Fallback: extract operation from the SQL query\n const operationMatch = sanitizedQuery?.match(SQL_OPERATION_REGEX);\n if (operationMatch?.[1]) {\n span.setAttribute(ATTR_DB_OPERATION_NAME, operationMatch[1].toUpperCase());\n }\n }\n\n /**\n * Reconstructs the full SQL query from template strings with PostgreSQL placeholders.\n *\n * For sql`SELECT * FROM users WHERE id = ${123} AND name = ${'foo'}`:\n * strings = [\"SELECT * FROM users WHERE id = \", \" AND name = \", \"\"]\n * returns: \"SELECT * FROM users WHERE id = $1 AND name = $2\"\n */\n private _reconstructQuery(strings: string[] | undefined): string | undefined {\n if (!strings?.length) {\n return undefined;\n }\n if (strings.length === 1) {\n return strings[0] || undefined;\n }\n // Join template parts with PostgreSQL placeholders ($1, $2, etc.)\n return strings.reduce((acc, str, i) => (i === 0 ? str : `${acc}$${i}${str}`), '');\n }\n\n /**\n * Sanitize SQL query as per the OTEL semantic conventions\n * https://opentelemetry.io/docs/specs/semconv/database/database-spans/#sanitization-of-dbquerytext\n *\n * PostgreSQL $n placeholders are preserved per OTEL spec - they're parameterized queries,\n * not sensitive literals. Only actual values (strings, numbers, booleans) are sanitized.\n */\n private _sanitizeSqlQuery(sqlQuery: string | undefined): string {\n if (!sqlQuery) {\n return 'Unknown SQL Query';\n }\n\n return (\n sqlQuery\n // Remove comments first (they may contain newlines and extra spaces)\n .replace(/--.*$/gm, '') // Single line comments (multiline mode)\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Multi-line comments\n .replace(/;\\s*$/, '') // Remove trailing semicolons\n // Collapse whitespace to a single space (after removing comments)\n .replace(/\\s+/g, ' ')\n .trim() // Remove extra spaces and trim\n // Sanitize hex/binary literals before string literals\n .replace(/\\bX'[0-9A-Fa-f]*'/gi, '?') // Hex string literals\n .replace(/\\bB'[01]*'/gi, '?') // Binary string literals\n // Sanitize string literals (handles escaped quotes)\n .replace(/'(?:[^']|'')*'/g, '?')\n // Sanitize hex numbers\n .replace(/\\b0x[0-9A-Fa-f]+/gi, '?')\n // Sanitize boolean literals\n .replace(/\\b(?:TRUE|FALSE)\\b/gi, '?')\n // Sanitize numeric literals (preserve $n placeholders via negative lookbehind)\n .replace(/-?\\b\\d+\\.?\\d*[eE][+-]?\\d+\\b/g, '?') // Scientific notation\n .replace(/-?\\b\\d+\\.\\d+\\b/g, '?') // Decimals\n .replace(/-?\\.\\d+\\b/g, '?') // Decimals starting with dot\n .replace(/(?<!\\$)-?\\b\\d+\\b/g, '?') // Integers (NOT $n placeholders)\n // Collapse IN clauses for cardinality (both ? and $n variants)\n .replace(/\\bIN\\b\\s*\\(\\s*\\?(?:\\s*,\\s*\\?)*\\s*\\)/gi, 'IN (?)')\n .replace(/\\bIN\\b\\s*\\(\\s*\\$\\d+(?:\\s*,\\s*\\$\\d+)*\\s*\\)/gi, 'IN ($?)')\n );\n }\n\n /**\n * Fallback patch for Query.prototype.handle to instrument queries from pre-existing sql instances.\n * This catches queries from sql instances created BEFORE Sentry was initialized (CJS only).\n *\n * Note: Queries from pre-existing instances won't have connection context (database, host, port)\n * because the sql instance wasn't created through our instrumented wrapper.\n */\n private _patchQueryPrototype(moduleExports: {\n Query: {\n prototype: {\n handle: ((...args: unknown[]) => Promise<unknown>) & {\n __sentry_original__?: (...args: unknown[]) => Promise<unknown>;\n };\n };\n };\n }): typeof moduleExports {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n const originalHandle = moduleExports.Query.prototype.handle;\n\n moduleExports.Query.prototype.handle = async function (\n this: {\n resolve: unknown;\n reject: unknown;\n strings?: string[];\n executed?: boolean;\n },\n ...args: unknown[]\n ): Promise<unknown> {\n // Skip if this query came from an instrumented sql instance (already handled by wrapper),\n // or if handle() was already called (postgres.js calls handle() from then/catch/finally —\n // only the first call executes SQL, subsequent calls are no-ops).\n if (this.executed || (this as Record<symbol, unknown>)[QUERY_FROM_INSTRUMENTED_SQL]) {\n return originalHandle.apply(this, args);\n }\n\n // Skip if we shouldn't create spans\n if (!self._shouldCreateSpans()) {\n return originalHandle.apply(this, args);\n }\n\n const fullQuery = self._reconstructQuery(this.strings);\n const sanitizedSqlQuery = self._sanitizeSqlQuery(fullQuery);\n\n return startSpanManual(\n {\n name: sanitizedSqlQuery || 'postgresjs.query',\n op: 'db',\n },\n (span: Span) => {\n addOriginToSpan(span, 'auto.db.postgresjs');\n\n span.setAttributes({\n [ATTR_DB_SYSTEM_NAME]: 'postgres',\n [ATTR_DB_QUERY_TEXT]: sanitizedSqlQuery,\n });\n\n // Note: No connection context available for pre-existing instances\n // because the sql instance wasn't created through our instrumented wrapper\n\n const config = self.getConfig();\n const { requestHook } = config;\n if (requestHook) {\n safeExecuteInTheMiddle(\n () => requestHook(span, sanitizedSqlQuery, undefined),\n e => {\n if (e) {\n span.setAttribute('sentry.hook.error', 'requestHook failed');\n DEBUG_BUILD && debug.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, e);\n }\n },\n true,\n );\n }\n\n // Wrap resolve to end span on success\n const originalResolve = this.resolve;\n this.resolve = new Proxy(originalResolve as (...args: unknown[]) => unknown, {\n apply: (resolveTarget, resolveThisArg, resolveArgs: [{ command?: string }]) => {\n try {\n self._setOperationName(span, sanitizedSqlQuery, resolveArgs?.[0]?.command);\n span.end();\n } catch (e) {\n DEBUG_BUILD && debug.error('Error ending span in resolve callback:', e);\n }\n return Reflect.apply(resolveTarget, resolveThisArg, resolveArgs);\n },\n });\n\n // Wrap reject to end span on error\n const originalReject = this.reject;\n this.reject = new Proxy(originalReject as (...args: unknown[]) => unknown, {\n apply: (rejectTarget, rejectThisArg, rejectArgs: { message?: string; code?: string; name?: string }[]) => {\n try {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: rejectArgs?.[0]?.message || 'unknown_error',\n });\n span.setAttribute(ATTR_DB_RESPONSE_STATUS_CODE, rejectArgs?.[0]?.code || 'unknown');\n span.setAttribute(ATTR_ERROR_TYPE, rejectArgs?.[0]?.name || 'unknown');\n self._setOperationName(span, sanitizedSqlQuery);\n span.end();\n } catch (e) {\n DEBUG_BUILD && debug.error('Error ending span in reject callback:', e);\n }\n return Reflect.apply(rejectTarget, rejectThisArg, rejectArgs);\n },\n });\n\n try {\n return originalHandle.apply(this, args);\n } catch (e) {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: e instanceof Error ? e.message : 'unknown_error',\n });\n span.end();\n throw e;\n }\n },\n );\n };\n\n // Store original for unpatch - must be set on the NEW patched function\n moduleExports.Query.prototype.handle.__sentry_original__ = originalHandle;\n\n return moduleExports;\n }\n\n /**\n * Restores the original Query.prototype.handle method.\n */\n private _unpatchQueryPrototype(moduleExports: {\n Query: {\n prototype: {\n handle: ((...args: unknown[]) => Promise<unknown>) & {\n __sentry_original__?: (...args: unknown[]) => Promise<unknown>;\n };\n };\n };\n }): typeof moduleExports {\n if (moduleExports.Query.prototype.handle.__sentry_original__) {\n moduleExports.Query.prototype.handle = moduleExports.Query.prototype.handle.__sentry_original__;\n }\n return moduleExports;\n }\n}\n\nconst _postgresJsIntegration = ((options?: PostgresJsInstrumentationConfig) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPostgresJs(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [postgres](https://www.npmjs.com/package/postgres) library.\n *\n * For more information, see the [`postgresIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/postgres/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.postgresJsIntegration()],\n * });\n * ```\n */\n\nexport const postgresJsIntegration = defineIntegration(_postgresJsIntegration);\n"],"names":["generateInstrumentOnce","InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","DEBUG_BUILD","debug","InstrumentationNodeModuleFile","instrumentPostgresJsSql","replaceExports","trace","context","ATTR_DB_OPERATION_NAME","startSpanManual","addOriginToSpan","ATTR_DB_SYSTEM_NAME","ATTR_DB_QUERY_TEXT","safeExecuteInTheMiddle","SPAN_STATUS_ERROR","ATTR_DB_RESPONSE_STATUS_CODE","ATTR_ERROR_TYPE","defineIntegration"],"mappings":";;;;;;;;;;AA8BA,MAAM,gBAAA,GAAmB,YAAA;AACzB,MAAM,kBAAA,GAAqB,CAAC,YAAY,CAAA;AACxC,MAAM,mBAAA,GAAsB,mDAAA;AAU5B,MAAM,2BAAA,mBAA8B,MAAA,CAAO,GAAA,CAAI,oCAAoC,CAAA;AAiB5E,MAAM,oBAAA,GAAuBA,+BAAA;AAAA,EAClC,gBAAA;AAAA,EACA,CAAC,OAAA,KACC,IAAI,yBAAA,CAA0B;AAAA,IAC5B,iBAAA,EAAmB,SAAS,iBAAA,IAAqB,IAAA;AAAA,IACjD,aAAa,OAAA,EAAS;AAAA,GACvB;AACL;AAQO,MAAM,kCAAkCC,mCAAA,CAAqD;AAAA,EAC3F,YAAY,MAAA,EAAyC;AAC1D,IAAA,KAAA,CAAM,oBAAA,EAAsBC,kBAAa,MAAM,CAAA;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,IAAA,GAA4C;AACjD,IAAA,MAAM,SAAS,IAAIC,mDAAA;AAAA,MACjB,UAA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,UACxC,SAAS,CAAA,EAAG;AACV,YAAA,IAAA,CAAK,SAAA,CAAU;AAAA,cACb,IAAA,EAAMY,sBAAA;AAAA,cACN,OAAA,EAAS,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU;AAAA,aAC3C,CAAA;AACD,YAAA,IAAA,CAAK,GAAA,EAAI;AACT,YAAA,MAAM,CAAA;AAAA,UACR;AAAA,QACF;AAAA,OACF;AAAA,IACF,CAAA;AAGA,IAAA,aAAA,CAAc,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,mBAAA,GAAsB,cAAA;AAE3D,IAAA,OAAO,aAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKQ,uBAAuB,aAAA,EAQN;AACvB,IAAA,IAAI,aAAA,CAAc,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,mBAAA,EAAqB;AAC5D,MAAA,aAAA,CAAc,MAAM,SAAA,CAAU,MAAA,GAAS,aAAA,CAAc,KAAA,CAAM,UAAU,MAAA,CAAO,mBAAA;AAAA,IAC9E;AACA,IAAA,OAAO,aAAA;AAAA,EACT;AACF;AAEA,MAAM,sBAAA,IAA0B,CAAC,OAAA,KAA8C;AAC7E,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,oBAAA,CAAqB,OAAO,CAAA;AAAA,IAC9B;AAAA,GACF;AACF,CAAA,CAAA;AAiBO,MAAM,qBAAA,GAAwBG,uBAAkB,sBAAsB;;;;;;"}
@@ -35,7 +35,7 @@ class SentryPrismaInteropInstrumentation extends instrumentation.PrismaInstrumen
35
35
  }
36
36
  try {
37
37
  engineSpanEvent.spans.forEach((engineSpan) => {
38
- const kind = engineSpanKindToOTELSpanKind(engineSpan.kind);
38
+ const kind = engineSpan.kind === "client" ? api.SpanKind.CLIENT : api.SpanKind.INTERNAL;
39
39
  const parentSpanId = engineSpan.parent_span_id;
40
40
  const spanId = engineSpan.span_id;
41
41
  const traceId = engineSpan.trace_id;
@@ -80,15 +80,6 @@ class SentryPrismaInteropInstrumentation extends instrumentation.PrismaInstrumen
80
80
  }
81
81
  }
82
82
  }
83
- function engineSpanKindToOTELSpanKind(engineSpanKind) {
84
- switch (engineSpanKind) {
85
- case "client":
86
- return api.SpanKind.CLIENT;
87
- case "internal":
88
- default:
89
- return api.SpanKind.INTERNAL;
90
- }
91
- }
92
83
  const instrumentPrisma = nodeCore.generateInstrumentOnce(INTEGRATION_NAME, (options) => {
93
84
  return new SentryPrismaInteropInstrumentation(options);
94
85
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/prisma/index.ts"],"sourcesContent":["import type { Link, Tracer } from '@opentelemetry/api';\nimport { context, SpanKind, trace, TraceFlags } from '@opentelemetry/api';\nimport type { Instrumentation } from '@opentelemetry/instrumentation';\nimport type { IdGenerator } from '@opentelemetry/sdk-trace-base';\nimport { consoleSandbox, defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { PrismaInstrumentation } from './vendored/instrumentation';\nimport type { PrismaV5TracingHelper } from './vendored/v5-tracing-helper';\nimport type { PrismaV6TracingHelper } from './vendored/v6-tracing-helper';\n\nconst INTEGRATION_NAME = 'Prisma';\n\ntype CompatibilityLayerTraceHelper = PrismaV5TracingHelper & PrismaV6TracingHelper;\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\nfunction isPrismaV6TracingHelper(helper: unknown): helper is PrismaV6TracingHelper {\n return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;\n}\n\nfunction getPrismaTracingHelper(): unknown | undefined {\n const prismaInstrumentationObject = (globalThis as Record<string, unknown>).PRISMA_INSTRUMENTATION;\n const prismaTracingHelper =\n prismaInstrumentationObject &&\n typeof prismaInstrumentationObject === 'object' &&\n 'helper' in prismaInstrumentationObject\n ? prismaInstrumentationObject.helper\n : undefined;\n\n return prismaTracingHelper;\n}\n\ntype TracerWithIdGenerator = Tracer & {\n _idGenerator?: IdGenerator;\n};\n\ninterface PrismaOptions {\n /**\n * @deprecated This is no longer used, v5 works out of the box.\n */\n prismaInstrumentation?: Instrumentation;\n /**\n * Configuration passed through to the {@link PrismaInstrumentation} constructor.\n */\n instrumentationConfig?: ConstructorParameters<typeof PrismaInstrumentation>[0];\n}\n\nclass SentryPrismaInteropInstrumentation extends PrismaInstrumentation {\n public constructor(options?: PrismaOptions) {\n super(options?.instrumentationConfig);\n }\n\n public enable(): void {\n super.enable();\n\n // The PrismaIntegration (super class) defines a global variable `global[\"PRISMA_INSTRUMENTATION\"]` when `enable()` is called. This global variable holds a \"TracingHelper\" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 5 with the v6 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.\n // Because we actually want to use the v6 instrumentation and not blow up in Prisma 5 user's faces, what we're doing here is backfilling the v5 method (`createEngineSpan`) with a noop so that no longer crashes when it attempts to call that function.\n const prismaTracingHelper = getPrismaTracingHelper();\n\n if (isPrismaV6TracingHelper(prismaTracingHelper)) {\n // Inspired & adjusted from https://github.com/prisma/prisma/tree/5.22.0/packages/instrumentation\n (prismaTracingHelper as CompatibilityLayerTraceHelper).createEngineSpan = (\n engineSpanEvent: V5EngineSpanEvent,\n ) => {\n const tracer = trace.getTracer('prismaV5Compatibility') as TracerWithIdGenerator;\n\n // Prisma v5 relies on being able to create spans with a specific span & trace ID\n // this is no longer possible in OTEL v2, there is no public API to do this anymore\n // So in order to kind of hack this possibility, we rely on the internal `_idGenerator` property\n // This is used to generate the random IDs, and we overwrite this temporarily to generate static IDs\n // This is flawed and may not work, e.g. if the code is bundled and the private property is renamed\n // in such cases, these spans will not be captured and some Prisma spans will be missing\n const initialIdGenerator = tracer._idGenerator;\n\n if (!initialIdGenerator) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Could not find _idGenerator on tracer, skipping Prisma v5 compatibility - some Prisma spans may be missing!',\n );\n });\n\n return;\n }\n\n try {\n engineSpanEvent.spans.forEach(engineSpan => {\n const kind = engineSpanKindToOTELSpanKind(engineSpan.kind);\n\n const parentSpanId = engineSpan.parent_span_id;\n const spanId = engineSpan.span_id;\n const traceId = engineSpan.trace_id;\n\n const links: Link[] | undefined = engineSpan.links?.map(link => {\n return {\n context: {\n traceId: link.trace_id,\n spanId: link.span_id,\n traceFlags: TraceFlags.SAMPLED,\n },\n };\n });\n\n const ctx = trace.setSpanContext(context.active(), {\n traceId,\n spanId: parentSpanId,\n traceFlags: TraceFlags.SAMPLED,\n });\n\n context.with(ctx, () => {\n const temporaryIdGenerator: IdGenerator = {\n generateTraceId: () => {\n return traceId;\n },\n generateSpanId: () => {\n return spanId;\n },\n };\n\n tracer._idGenerator = temporaryIdGenerator;\n\n const span = tracer.startSpan(engineSpan.name, {\n kind,\n links,\n startTime: engineSpan.start_time,\n attributes: engineSpan.attributes,\n });\n\n span.end(engineSpan.end_time);\n\n tracer._idGenerator = initialIdGenerator;\n });\n });\n } finally {\n // Ensure we always restore this at the end, even if something errors\n tracer._idGenerator = initialIdGenerator;\n }\n };\n }\n }\n}\n\nfunction engineSpanKindToOTELSpanKind(engineSpanKind: V5EngineSpanKind): SpanKind {\n switch (engineSpanKind) {\n case 'client':\n return SpanKind.CLIENT;\n case 'internal':\n default: // Other span kinds aren't currently supported\n return SpanKind.INTERNAL;\n }\n}\n\nexport const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATION_NAME, options => {\n return new SentryPrismaInteropInstrumentation(options);\n});\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: By default, this integration works with Prisma version 6.\n * To get performance instrumentation for other Prisma versions,\n * 1. Install the `@prisma/instrumentation` package with the desired version.\n * 1. Pass a `new PrismaInstrumentation()` instance as exported from `@prisma/instrumentation` to the `prismaInstrumentation` option of this integration:\n *\n * ```js\n * import { PrismaInstrumentation } from '@prisma/instrumentation'\n *\n * Sentry.init({\n * integrations: [\n * prismaIntegration({\n * // Override the default instrumentation that Sentry uses\n * prismaInstrumentation: new PrismaInstrumentation()\n * })\n * ]\n * })\n * ```\n *\n * The passed instrumentation instance will override the default instrumentation instance the integration would use, while the `prismaIntegration` will still ensure data compatibility for the various Prisma versions.\n * 1. Depending on your Prisma version (prior to version 6), 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((options?: PrismaOptions) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPrisma(options);\n },\n setup(client) {\n // If no tracing helper exists, we skip any work here\n // this means that prisma is not being used\n if (!getPrismaTracingHelper()) {\n return;\n }\n\n client.on('spanStart', span => {\n const spanJSON = spanToJSON(span);\n if (spanJSON.description?.startsWith('prisma:')) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.prisma');\n }\n\n // Make sure we use the query text as the span name, for ex. SELECT * FROM \"User\" WHERE \"id\" = $1.\n // v5/v6 emit `prisma:engine:db_query`; v7 inlined the engine and emits `prisma:client:db_query`.\n if (\n (spanJSON.description === 'prisma:engine:db_query' || spanJSON.description === 'prisma:client:db_query') &&\n spanJSON.data['db.query.text']\n ) {\n span.updateName(spanJSON.data['db.query.text'] as string);\n }\n\n // In Prisma v5.22+, the `db.system` attribute is automatically set\n // On older versions, this is missing, so we add it here\n if (spanJSON.description === 'prisma:engine:db_query' && !spanJSON.data['db.system']) {\n span.setAttribute('db.system', 'prisma');\n }\n });\n },\n };\n});\n"],"names":["PrismaInstrumentation","trace","consoleSandbox","TraceFlags","context","SpanKind","generateInstrumentOnce","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN"],"mappings":";;;;;;;AAUA,MAAM,gBAAA,GAAmB,QAAA;AAyBzB,SAAS,wBAAwB,MAAA,EAAkD;AACjF,EAAA,OAAO,CAAC,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,YAAY,qBAAA,IAAyB,MAAA;AAC5E;AAEA,SAAS,sBAAA,GAA8C;AACrD,EAAA,MAAM,8BAA+B,UAAA,CAAuC,sBAAA;AAC5E,EAAA,MAAM,mBAAA,GACJ,+BACA,OAAO,2BAAA,KAAgC,YACvC,QAAA,IAAY,2BAAA,GACR,4BAA4B,MAAA,GAC5B,MAAA;AAEN,EAAA,OAAO,mBAAA;AACT;AAiBA,MAAM,2CAA2CA,qCAAA,CAAsB;AAAA,EAC9D,YAAY,OAAA,EAAyB;AAC1C,IAAA,KAAA,CAAM,SAAS,qBAAqB,CAAA;AAAA,EACtC;AAAA,EAEO,MAAA,GAAe;AACpB,IAAA,KAAA,CAAM,MAAA,EAAO;AAIb,IAAA,MAAM,sBAAsB,sBAAA,EAAuB;AAEnD,IAAA,IAAI,uBAAA,CAAwB,mBAAmB,CAAA,EAAG;AAEhD,MAAC,mBAAA,CAAsD,gBAAA,GAAmB,CACxE,eAAA,KACG;AACH,QAAA,MAAM,MAAA,GAASC,SAAA,CAAM,SAAA,CAAU,uBAAuB,CAAA;AAQtD,QAAA,MAAM,qBAAqB,MAAA,CAAO,YAAA;AAElC,QAAA,IAAI,CAAC,kBAAA,EAAoB;AACvB,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AAAA,QAC3E;AAIA,QAAA,IAAA,CACG,QAAA,CAAS,gBAAgB,wBAAA,IAA4B,QAAA,CAAS,gBAAgB,wBAAA,KAC/E,QAAA,CAAS,IAAA,CAAK,eAAe,CAAA,EAC7B;AACA,UAAA,IAAA,CAAK,UAAA,CAAW,QAAA,CAAS,IAAA,CAAK,eAAe,CAAW,CAAA;AAAA,QAC1D;AAIA,QAAA,IAAI,SAAS,WAAA,KAAgB,wBAAA,IAA4B,CAAC,QAAA,CAAS,IAAA,CAAK,WAAW,CAAA,EAAG;AACpF,UAAA,IAAA,CAAK,YAAA,CAAa,aAAa,QAAQ,CAAA;AAAA,QACzC;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAC;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/prisma/index.ts"],"sourcesContent":["import type { Link, Tracer } from '@opentelemetry/api';\nimport { context, SpanKind, trace, TraceFlags } from '@opentelemetry/api';\nimport type { Instrumentation } from '@opentelemetry/instrumentation';\nimport type { IdGenerator } from '@opentelemetry/sdk-trace-base';\nimport { consoleSandbox, defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { PrismaInstrumentation } from './vendored/instrumentation';\nimport type { PrismaV5TracingHelper } from './vendored/v5-tracing-helper';\nimport type { PrismaV6TracingHelper } from './vendored/v6-tracing-helper';\n\nconst INTEGRATION_NAME = 'Prisma' as const;\n\ntype CompatibilityLayerTraceHelper = PrismaV5TracingHelper & PrismaV6TracingHelper;\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\nfunction isPrismaV6TracingHelper(helper: unknown): helper is PrismaV6TracingHelper {\n return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;\n}\n\nfunction getPrismaTracingHelper(): unknown | undefined {\n const prismaInstrumentationObject = (globalThis as Record<string, unknown>).PRISMA_INSTRUMENTATION;\n const prismaTracingHelper =\n prismaInstrumentationObject &&\n typeof prismaInstrumentationObject === 'object' &&\n 'helper' in prismaInstrumentationObject\n ? prismaInstrumentationObject.helper\n : undefined;\n\n return prismaTracingHelper;\n}\n\ntype TracerWithIdGenerator = Tracer & {\n _idGenerator?: IdGenerator;\n};\n\ninterface PrismaOptions {\n /**\n * @deprecated This is no longer used, v5 works out of the box.\n */\n prismaInstrumentation?: Instrumentation;\n /**\n * Configuration passed through to the {@link PrismaInstrumentation} constructor.\n */\n instrumentationConfig?: ConstructorParameters<typeof PrismaInstrumentation>[0];\n}\n\nclass SentryPrismaInteropInstrumentation extends PrismaInstrumentation {\n public constructor(options?: PrismaOptions) {\n super(options?.instrumentationConfig);\n }\n\n public enable(): void {\n super.enable();\n\n // The PrismaIntegration (super class) defines a global variable `global[\"PRISMA_INSTRUMENTATION\"]` when `enable()` is called. This global variable holds a \"TracingHelper\" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 5 with the v6 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.\n // Because we actually want to use the v6 instrumentation and not blow up in Prisma 5 user's faces, what we're doing here is backfilling the v5 method (`createEngineSpan`) with a noop so that no longer crashes when it attempts to call that function.\n const prismaTracingHelper = getPrismaTracingHelper();\n\n if (isPrismaV6TracingHelper(prismaTracingHelper)) {\n // Inspired & adjusted from https://github.com/prisma/prisma/tree/5.22.0/packages/instrumentation\n (prismaTracingHelper as CompatibilityLayerTraceHelper).createEngineSpan = (\n engineSpanEvent: V5EngineSpanEvent,\n ) => {\n const tracer = trace.getTracer('prismaV5Compatibility') as TracerWithIdGenerator;\n\n // Prisma v5 relies on being able to create spans with a specific span & trace ID\n // this is no longer possible in OTEL v2, there is no public API to do this anymore\n // So in order to kind of hack this possibility, we rely on the internal `_idGenerator` property\n // This is used to generate the random IDs, and we overwrite this temporarily to generate static IDs\n // This is flawed and may not work, e.g. if the code is bundled and the private property is renamed\n // in such cases, these spans will not be captured and some Prisma spans will be missing\n const initialIdGenerator = tracer._idGenerator;\n\n if (!initialIdGenerator) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Could not find _idGenerator on tracer, skipping Prisma v5 compatibility - some Prisma spans may be missing!',\n );\n });\n\n return;\n }\n\n try {\n engineSpanEvent.spans.forEach(engineSpan => {\n const kind = engineSpan.kind === 'client' ? SpanKind.CLIENT : SpanKind.INTERNAL;\n\n const parentSpanId = engineSpan.parent_span_id;\n const spanId = engineSpan.span_id;\n const traceId = engineSpan.trace_id;\n\n const links: Link[] | undefined = engineSpan.links?.map(link => {\n return {\n context: {\n traceId: link.trace_id,\n spanId: link.span_id,\n traceFlags: TraceFlags.SAMPLED,\n },\n };\n });\n\n const ctx = trace.setSpanContext(context.active(), {\n traceId,\n spanId: parentSpanId,\n traceFlags: TraceFlags.SAMPLED,\n });\n\n context.with(ctx, () => {\n const temporaryIdGenerator: IdGenerator = {\n generateTraceId: () => {\n return traceId;\n },\n generateSpanId: () => {\n return spanId;\n },\n };\n\n tracer._idGenerator = temporaryIdGenerator;\n\n const span = tracer.startSpan(engineSpan.name, {\n kind,\n links,\n startTime: engineSpan.start_time,\n attributes: engineSpan.attributes,\n });\n\n span.end(engineSpan.end_time);\n\n tracer._idGenerator = initialIdGenerator;\n });\n });\n } finally {\n // Ensure we always restore this at the end, even if something errors\n tracer._idGenerator = initialIdGenerator;\n }\n };\n }\n }\n}\n\nexport const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATION_NAME, options => {\n return new SentryPrismaInteropInstrumentation(options);\n});\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((options?: PrismaOptions) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPrisma(options);\n },\n setup(client) {\n // If no tracing helper exists, we skip any work here\n // this means that prisma is not being used\n if (!getPrismaTracingHelper()) {\n return;\n }\n\n // Prisma v5 engine spans are created via the `createEngineSpan` path above, which bypasses the\n // tracing helper, so this hook applies origin, the db_query rename, and the db.system backfill to\n // them. v6/v7 spans already get these from the helper; the guards are idempotent, so it's a no-op there.\n client.on('spanStart', span => {\n const spanJSON = spanToJSON(span);\n if (spanJSON.description?.startsWith('prisma:')) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.prisma');\n }\n\n // Make sure we use the query text as the span name, for ex. SELECT * FROM \"User\" WHERE \"id\" = $1.\n // v5/v6 emit `prisma:engine:db_query`; v7 inlined the engine and emits `prisma:client:db_query`.\n if (\n (spanJSON.description === 'prisma:engine:db_query' || spanJSON.description === 'prisma:client:db_query') &&\n spanJSON.data['db.query.text']\n ) {\n span.updateName(spanJSON.data['db.query.text'] as string);\n }\n\n // In Prisma v5.22+, the `db.system` attribute is automatically set\n // On older versions, this is missing, so we add it here\n if (spanJSON.description === 'prisma:engine:db_query' && !spanJSON.data['db.system']) {\n span.setAttribute('db.system', 'prisma');\n }\n });\n },\n };\n});\n"],"names":["PrismaInstrumentation","trace","consoleSandbox","SpanKind","TraceFlags","context","generateInstrum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;AACF,CAAC;;;;;"}
@@ -1,98 +1,124 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const api = require('@opentelemetry/api');
3
+ const core = require('@sentry/core');
4
4
 
5
5
  const showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === "true";
6
6
  const nonSampledTraceParent = `00-10-10-00`;
7
- function engineSpanKindToOtelSpanKind(engineSpanKind) {
8
- switch (engineSpanKind) {
9
- case "client":
10
- return api.SpanKind.CLIENT;
11
- case "internal":
12
- default:
13
- return api.SpanKind.INTERNAL;
7
+ const PRISMA_ORIGIN = "auto.db.otel.prisma";
8
+ function buildSpanAttributes(name, attributes) {
9
+ const merged = {
10
+ ...attributes,
11
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRISMA_ORIGIN
12
+ };
13
+ if (name === "prisma:engine:db_query" && merged["db.system"] == null) {
14
+ merged["db.system"] = "prisma";
15
+ }
16
+ return merged;
17
+ }
18
+ function buildSpanName(name, attributes) {
19
+ const queryText = attributes["db.query.text"];
20
+ if ((name === "prisma:engine:db_query" || name === "prisma:client:db_query") && typeof queryText === "string") {
21
+ return queryText;
14
22
  }
23
+ return name;
15
24
  }
16
25
  class ActiveTracingHelper {
17
- constructor({ tracerProvider, ignoreSpanTypes }) {
18
- this.tracerProvider = tracerProvider;
26
+ constructor({ ignoreSpanTypes }) {
19
27
  this.ignoreSpanTypes = ignoreSpanTypes;
20
28
  }
21
29
  isEnabled() {
22
30
  return true;
23
31
  }
24
- getTraceParent(context) {
25
- const span = api.trace.getSpanContext(context ?? api.context.active());
26
- if (span) {
27
- return `00-${span.traceId}-${span.spanId}-0${span.traceFlags}`;
32
+ getTraceParent(span) {
33
+ const spanContext = (span ?? core.getActiveSpan())?.spanContext();
34
+ if (spanContext) {
35
+ return `00-${spanContext.traceId}-${spanContext.spanId}-0${spanContext.traceFlags}`;
28
36
  }
29
37
  return nonSampledTraceParent;
30
38
  }
31
39
  dispatchEngineSpans(spans) {
32
- const tracer = this.tracerProvider.getTracer("prisma");
33
40
  const linkIds = /* @__PURE__ */ new Map();
34
41
  const roots = spans.filter((span) => span.parentId === null);
35
42
  for (const root of roots) {
36
- dispatchEngineSpan(tracer, root, spans, linkIds, this.ignoreSpanTypes);
43
+ dispatchEngineSpan(root, spans, linkIds, this.ignoreSpanTypes);
37
44
  }
38
45
  }
39
46
  getActiveContext() {
40
- return api.context.active();
47
+ return core.getActiveSpan();
41
48
  }
42
- runInChildSpan(options, callback) {
43
- if (typeof options === "string") {
44
- options = { name: options };
45
- }
49
+ runInChildSpan(nameOrOptions, callback) {
50
+ const options = typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
46
51
  if (options.internal && !showAllTraces) {
47
52
  return callback();
48
53
  }
49
- const tracer = this.tracerProvider.getTracer("prisma");
50
- const context = options.context ?? this.getActiveContext();
51
54
  const name = `prisma:client:${options.name}`;
52
55
  if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {
53
56
  return callback();
54
57
  }
58
+ const parentSpan = core.getActiveSpan();
59
+ const attributes = buildSpanAttributes(name, options.attributes);
60
+ const spanOptions = {
61
+ name: buildSpanName(name, attributes),
62
+ attributes,
63
+ kind: options.kind,
64
+ links: options.links,
65
+ startTime: options.startTime,
66
+ parentSpan
67
+ };
55
68
  if (options.active === false) {
56
- const span = tracer.startSpan(name, options, context);
57
- return endSpan(span, callback(span, context));
69
+ const span = core.startInactiveSpan(spanOptions);
70
+ return endSpan(span, () => callback(span, parentSpan));
58
71
  }
59
- return tracer.startActiveSpan(name, options, (span) => endSpan(span, callback(span, context)));
72
+ return core.startSpanManual(spanOptions, (span) => endSpan(span, () => callback(span, parentSpan)));
60
73
  }
61
74
  }
62
- function dispatchEngineSpan(tracer, engineSpan, allSpans, linkIds, ignoreSpanTypes) {
63
- if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) return;
64
- const spanOptions = {
65
- attributes: engineSpan.attributes,
66
- kind: engineSpanKindToOtelSpanKind(engineSpan.kind),
67
- startTime: engineSpan.startTime
68
- };
69
- tracer.startActiveSpan(engineSpan.name, spanOptions, (span) => {
70
- linkIds.set(engineSpan.id, span.spanContext().spanId);
71
- if (engineSpan.links) {
72
- span.addLinks(
73
- engineSpan.links.flatMap((link) => {
74
- const linkedId = linkIds.get(link);
75
- if (!linkedId) {
76
- return [];
77
- }
78
- return {
79
- context: {
80
- spanId: linkedId,
81
- traceId: span.spanContext().traceId,
82
- traceFlags: span.spanContext().traceFlags
75
+ function dispatchEngineSpan(engineSpan, allSpans, linkIds, ignoreSpanTypes) {
76
+ if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) {
77
+ return;
78
+ }
79
+ const attributes = buildSpanAttributes(engineSpan.name, engineSpan.attributes);
80
+ core.startSpanManual(
81
+ {
82
+ name: buildSpanName(engineSpan.name, attributes),
83
+ attributes,
84
+ kind: engineSpan.kind === "client" ? core.SPAN_KIND.CLIENT : core.SPAN_KIND.INTERNAL,
85
+ startTime: engineSpan.startTime
86
+ },
87
+ (span) => {
88
+ linkIds.set(engineSpan.id, span.spanContext().spanId);
89
+ if (engineSpan.links) {
90
+ span.addLinks(
91
+ engineSpan.links.flatMap((link) => {
92
+ const linkedId = linkIds.get(link);
93
+ if (!linkedId) {
94
+ return [];
83
95
  }
84
- };
85
- })
86
- );
87
- }
88
- const children = allSpans.filter((s) => s.parentId === engineSpan.id);
89
- for (const child of children) {
90
- dispatchEngineSpan(tracer, child, allSpans, linkIds, ignoreSpanTypes);
96
+ return {
97
+ context: {
98
+ spanId: linkedId,
99
+ traceId: span.spanContext().traceId,
100
+ traceFlags: span.spanContext().traceFlags
101
+ }
102
+ };
103
+ })
104
+ );
105
+ }
106
+ const children = allSpans.filter((s) => s.parentId === engineSpan.id);
107
+ for (const child of children) {
108
+ dispatchEngineSpan(child, allSpans, linkIds, ignoreSpanTypes);
109
+ }
110
+ span.end(engineSpan.endTime);
91
111
  }
92
- span.end(engineSpan.endTime);
93
- });
112
+ );
94
113
  }
95
- function endSpan(span, result) {
114
+ function endSpan(span, run) {
115
+ let result;
116
+ try {
117
+ result = run();
118
+ } catch (reason) {
119
+ span.end();
120
+ throw reason;
121
+ }
96
122
  if (isPromiseLike(result)) {
97
123
  return result.then(
98
124
  (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"active-tracing-helper.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/active-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 * - Minor TypeScript strictness adjustments for this repository's compiler settings\n */\n/* eslint-disable */\n\nimport {\n Attributes,\n Context,\n context as _context,\n Span,\n SpanKind,\n SpanOptions,\n trace,\n Tracer,\n TracerProvider,\n} from '@opentelemetry/api';\nimport type { EngineSpan, EngineSpanKind, ExtendedSpanOptions, SpanCallback, TracingHelper } from './types';\n\nconst showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === 'true';\n\nconst nonSampledTraceParent = `00-10-10-00`;\n\ntype Options = {\n tracerProvider: TracerProvider;\n ignoreSpanTypes: (string | RegExp)[];\n};\n\nfunction engineSpanKindToOtelSpanKind(engineSpanKind: EngineSpanKind): SpanKind {\n switch (engineSpanKind) {\n case 'client':\n return SpanKind.CLIENT;\n case 'internal':\n default:\n return SpanKind.INTERNAL;\n }\n}\n\nexport class ActiveTracingHelper implements TracingHelper {\n private tracerProvider: TracerProvider;\n private ignoreSpanTypes: (string | RegExp)[];\n\n constructor({ tracerProvider, ignoreSpanTypes }: Options) {\n this.tracerProvider = tracerProvider;\n this.ignoreSpanTypes = ignoreSpanTypes;\n }\n\n isEnabled(): boolean {\n return true;\n }\n\n getTraceParent(context?: Context | undefined): string {\n const span = trace.getSpanContext(context ?? _context.active());\n if (span) {\n return `00-${span.traceId}-${span.spanId}-0${span.traceFlags}`;\n }\n return nonSampledTraceParent;\n }\n\n dispatchEngineSpans(spans: EngineSpan[]): void {\n const tracer = this.tracerProvider.getTracer('prisma');\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(tracer, root, spans, linkIds, this.ignoreSpanTypes);\n }\n }\n\n getActiveContext(): Context | undefined {\n return _context.active();\n }\n\n runInChildSpan<R>(options: string | ExtendedSpanOptions, callback: SpanCallback<R>): R {\n if (typeof options === 'string') {\n options = { name: options };\n }\n\n if (options.internal && !showAllTraces) {\n return callback();\n }\n\n const tracer = this.tracerProvider.getTracer('prisma');\n const context = options.context ?? this.getActiveContext();\n const name = `prisma:client:${options.name}`;\n\n if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {\n return callback();\n }\n\n if (options.active === false) {\n const span = tracer.startSpan(name, options, context);\n return endSpan(span, callback(span, context));\n }\n\n return tracer.startActiveSpan(name, options, span => endSpan(span, callback(span, context)));\n }\n}\n\nfunction dispatchEngineSpan(\n tracer: Tracer,\n engineSpan: EngineSpan,\n allSpans: EngineSpan[],\n linkIds: Map<string, string>,\n ignoreSpanTypes: (string | RegExp)[],\n) {\n if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) return;\n\n const spanOptions = {\n attributes: engineSpan.attributes as Attributes,\n kind: engineSpanKindToOtelSpanKind(engineSpan.kind),\n startTime: engineSpan.startTime,\n } satisfies SpanOptions;\n\n tracer.startActiveSpan(engineSpan.name, spanOptions, 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(tracer, child, allSpans, linkIds, ignoreSpanTypes);\n }\n\n span.end(engineSpan.endTime);\n });\n}\n\nfunction endSpan<T>(span: Span, result: T): T {\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":["SpanKind","trace","_context"],"mappings":";;;;AAyBA,MAAM,aAAA,GAAgB,OAAA,CAAQ,GAAA,CAAI,sBAAA,KAA2B,MAAA;AAE7D,MAAM,qBAAA,GAAwB,CAAA,WAAA,CAAA;AAO9B,SAAS,6BAA6B,cAAA,EAA0C;AAC9E,EAAA,QAAQ,cAAA;AAAgB,IACtB,KAAK,QAAA;AACH,MAAA,OAAOA,YAAA,CAAS,MAAA;AAAA,IAClB,KAAK,UAAA;AAAA,IACL;AACE,MAAA,OAAOA,YAAA,CAAS,QAAA;AAAA;AAEtB;AAEO,MAAM,mBAAA,CAA6C;AAAA,EAIxD,WAAA,CAAY,EAAE,cAAA,EAAgB,eAAA,EAAgB,EAAY;AACxD,IAAA,IAAA,CAAK,cAAA,GAAiB,cAAA;AACtB,IAAA,IAAA,CAAK,eAAA,GAAkB,eAAA;AAAA,EACzB;AAAA,EAEA,SAAA,GAAqB;AACnB,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEA,eAAe,OAAA,EAAuC;AACpD,IAAA,MAAM,OAAOC,SAAA,CAAM,cAAA,CAAe,OAAA,IAAWC,WAAA,CAAS,QAAQ,CAAA;AAC9D,IAAA,IAAI,IAAA,EAAM;AACR,MAAA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AA,KAAY,QAAA,GAAW,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAE,CAAA;AACtH;;;;"}
1
+ {"version":3,"file":"active-tracing-helper.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/active-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 */\n\nimport type { Span, SpanAttributes, SpanKindValue, SpanLink } from '@sentry/core';\nimport {\n getActiveSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n startSpanManual,\n} from '@sentry/core';\nimport type { EngineSpan, ExtendedSpanOptions, SpanCallback, TracingHelper } from './types';\n\nconst showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === 'true';\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/**\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 if (name === 'prisma:engine:db_query' && merged['db.system'] == null) {\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\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 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 as SpanKindValue | undefined,\n links: options.links as SpanLink[] | undefined,\n startTime: options.startTime,\n parentSpan,\n };\n\n if (options.active === false) {\n const span = startInactiveSpan(spanOptions);\n return endSpan(span, () => callback(span, parentSpan));\n }\n\n return startSpanManual(spanOptions, span => endSpan(span, () => callback(span, parentSpan)));\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":["SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getActiveSpan","startInactiveSpan","startSpanManual","SPAN_KIND"],"mappings":";;;;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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;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/constants.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 `import packageJson from '../package.json'` with hardcoded values\n */\n/* eslint-disable */\n\nimport { SDK_VERSION } from '@sentry/core';\n\nexport const VERSION = SDK_VERSION;\n\nexport const NAME = '@sentry/instrumentation-prisma';\n\nexport const MODULE_NAME = '@prisma/client';\n\nexport const SUPPORTED_MODULE_VERSIONS = ['>=5.0.0'];\n"],"names":["SDK_VERSION"],"mappings":";;;;AAaO,MAAM,OAAA,GAAUA;AAEhB,MAAM,IAAA,GAAO;AAEb,MAAM,WAAA,GAAc;AAEpB,MAAM,yBAAA,GAA4B,CAAC,SAAS;;;;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/constants.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 `import packageJson from '../package.json'` with hardcoded values\n */\n\nimport { SDK_VERSION } from '@sentry/core';\n\nexport const VERSION = SDK_VERSION;\n\nexport const NAME = '@sentry/instrumentation-prisma';\n\nexport const MODULE_NAME = '@prisma/client';\n\nexport const SUPPORTED_MODULE_VERSIONS = ['>=5.0.0'];\n"],"names":["SDK_VERSION"],"mappings":";;;;AAYO,MAAM,OAAA,GAAUA;AAEhB,MAAM,IAAA,GAAO;AAEb,MAAM,WAAA,GAAc;AAEpB,MAAM,yBAAA,GAA4B,CAAC,SAAS;;;;;;;"}
@@ -18,8 +18,8 @@ function setGlobalTracingHelper(helper) {
18
18
  globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY] = globalValue;
19
19
  }
20
20
  function clearGlobalTracingHelper() {
21
- delete globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY];
22
- delete globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY];
21
+ globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY] = void 0;
22
+ globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY] = void 0;
23
23
  }
24
24
 
25
25
  exports.clearGlobalTracingHelper = clearGlobalTracingHelper;
@@ -1 +1 @@
1
- {"version":3,"file":"global.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/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/* eslint-disable */\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 delete globalThisWithPrismaInstrumentation[GLOBAL_VERSIONED_INSTRUMENTATION_KEY];\n delete globalThisWithPrismaInstrumentation[GLOBAL_INSTRUMENTATION_KEY];\n}\n"],"names":[],"mappings":";;AAaA,MAAM,YAAA,GAAe,GAAA;AAErB,MAAM,0BAAA,GAA6B,wBAAA;AACnC,MAAM,oCAAA,GAAuC,IAAI,YAAY,CAAA,uBAAA,CAAA;AAQ7D,MAAM,mCAAA,GAAsC,UAAA;AAErC,SAAS,sBAAA,GAAoD;AAClE,EAAA,MAAM,eAAA,GAAkB,oCAAoC,oCAAoC,CAAA;AAEhG,EAAA,IAAI,iBAAiB,MAAA,EAAQ;AAC3B,IAAA,OAAO,eAAA,CAAgB,MAAA;AAAA,EACzB;AAEA,EAAA,MAAM,cAAA,GAAiB,oCAAoC,0BAA0B,CAAA;AAErF,EAAA,OAAO,cAAA,EAAgB,MAAA;AACzB;AAEO,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;AAEO,SAAS,wBAAA,GAAiC;AAC/C,EAAA,OAAO,oCAAoC,oCAAoC,CAAA;AAC/E,EAAA,OAAO,oCAAoC,0BAA0B,CAAA;AACvE;;;;;;"}
1
+ {"version":3,"file":"global.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/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;AAErC,SAAS,sBAAA,GAAoD;AAClE,EAAA,MAAM,eAAA,GAAkB,oCAAoC,oCAAoC,CAAA;AAEhG,EAAA,IAAI,iBAAiB,MAAA,EAAQ;AAC3B,IAAA,OAAO,eAAA,CAAgB,MAAA;AAAA,EACzB;AAEA,EAAA,MAAM,cAAA,GAAiB,oCAAoC,0BAA0B,CAAA;AAErF,EAAA,OAAO,cAAA,EAAgB,MAAA;AACzB;AAEO,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;AAEO,SAAS,wBAAA,GAAiC;AAC/C,EAAA,mCAAA,CAAoC,oCAAoC,CAAA,GAAI,MAAA;AAC5E,EAAA,mCAAA,CAAoC,0BAA0B,CAAA,GAAI,MAAA;AACpE;;;;;;"}
@@ -1,18 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const api = require('@opentelemetry/api');
4
3
  const instrumentation = require('@opentelemetry/instrumentation');
5
- const global = require('./global.js');
6
4
  const activeTracingHelper = require('./active-tracing-helper.js');
7
5
  const constants = require('./constants.js');
6
+ const global = require('./global.js');
8
7
 
9
8
  class PrismaInstrumentation extends instrumentation.InstrumentationBase {
10
9
  constructor(config = {}) {
11
10
  super(constants.NAME, constants.VERSION, config);
12
11
  }
13
- setTracerProvider(tracerProvider) {
14
- this.tracerProvider = tracerProvider;
15
- }
16
12
  init() {
17
13
  const module = new instrumentation.InstrumentationNodeModuleDefinition(constants.MODULE_NAME, constants.SUPPORTED_MODULE_VERSIONS);
18
14
  return [module];
@@ -21,7 +17,6 @@ class PrismaInstrumentation extends instrumentation.InstrumentationBase {
21
17
  const config = this._config;
22
18
  global.setGlobalTracingHelper(
23
19
  new activeTracingHelper.ActiveTracingHelper({
24
- tracerProvider: this.tracerProvider ?? api.trace.getTracerProvider(),
25
20
  ignoreSpanTypes: config.ignoreSpanTypes ?? []
26
21
  })
27
22
  );
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/instrumentation.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 equivalents\n * - Replaced `import { VERSION, NAME, MODULE_NAME } from './constants'` with local vendored constants\n */\n/* eslint-disable */\n\nimport { trace, TracerProvider } from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport { clearGlobalTracingHelper, getGlobalTracingHelper, setGlobalTracingHelper } from './global';\n\nimport { ActiveTracingHelper } from './active-tracing-helper';\nimport { MODULE_NAME, NAME, SUPPORTED_MODULE_VERSIONS, VERSION } from './constants';\n\nexport interface PrismaInstrumentationConfig {\n ignoreSpanTypes?: (string | RegExp)[];\n}\n\ntype Config = PrismaInstrumentationConfig & InstrumentationConfig;\n\nexport class PrismaInstrumentation extends InstrumentationBase {\n private tracerProvider: TracerProvider | undefined;\n\n constructor(config: Config = {}) {\n super(NAME, VERSION, config);\n }\n\n setTracerProvider(tracerProvider: TracerProvider): void {\n this.tracerProvider = tracerProvider;\n }\n\n init() {\n const module = new InstrumentationNodeModuleDefinition(MODULE_NAME, SUPPORTED_MODULE_VERSIONS);\n\n return [module];\n }\n\n enable() {\n const config = this._config as Config;\n\n setGlobalTracingHelper(\n new ActiveTracingHelper({\n tracerProvider: this.tracerProvider ?? trace.getTracerProvider(),\n ignoreSpanTypes: config.ignoreSpanTypes ?? [],\n }),\n );\n }\n\n disable() {\n clearGlobalTracingHelper();\n }\n\n isEnabled() {\n return getGlobalTracingHelper() !== undefined;\n }\n}\n"],"names":["InstrumentationBase","NAME","VERSION","InstrumentationNodeModuleDefinition","MODULE_NAME","SUPPORTED_MODULE_VERSIONS","setGlobalTracingHelper","ActiveTracingHelper","trace","clearGlobalTracingHelper","getGlobalTracingHelper"],"mappings":";;;;;;;;AA6BO,MAAM,8BAA8BA,mCAAA,CAAoB;AAAA,EAG7D,WAAA,CAAY,MAAA,GAAiB,EAAC,EAAG;AAC/B,IAAA,KAAA,CAAMC,cAAA,EAAMC,mBAAS,MAAM,CAAA;AAAA,EAC7B;AAAA,EAEA,kBAAkB,cAAA,EAAsC;AACtD,IAAA,IAAA,CAAK,cAAA,GAAiB,cAAA;AAAA,EACxB;AAAA,EAEA,IAAA,GAAO;AACL,IAAA,MAAM,MAAA,GAAS,IAAIC,mDAAA,CAAoCC,qBAAA,EAAaC,mCAAyB,CAAA;AAE7F,IAAA,OAAO,CAAC,MAAM,CAAA;AAAA,EAChB;AAAA,EAEA,MAAA,GAAS;AACP,IAAA,MAAM,SAAS,IAAA,CAAK,OAAA;AAEpB,IAAAC,6BAAA;AAAA,MACE,IAAIC,uCAAA,CAAoB;AAAA,QACtB,cAAA,EAAgB,IAAA,CAAK,cAAA,IAAkBC,SAAA,CAAM,iBAAA,EAAkB;AAAA,QAC/D,eAAA,EAAiB,MAAA,CAAO,eAAA,IAAmB;AAAC,OAC7C;AAAA,KACH;AAAA,EACF;AAAA,EAEA,OAAA,GAAU;AACR,IAAAC,+BAAA,EAAyB;AAAA,EAC3B;AAAA,EAEA,SAAA,GAAY;AACV,IAAA,OAAOC,+BAAuB,KAAM,MAAA;AAAA,EACtC;AACF;;;;"}
1
+ {"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/prisma/vendored/instrumentation.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 equivalents\n * - Replaced `import { VERSION, NAME, MODULE_NAME } from './constants'` with local vendored constants\n * - Removed the unused `setTracerProvider`/`tracerProvider` members; spans are created through Sentry's\n * span APIs, which resolve the active client themselves\n */\n\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport { ActiveTracingHelper } from './active-tracing-helper';\nimport { MODULE_NAME, NAME, SUPPORTED_MODULE_VERSIONS, VERSION } from './constants';\nimport { clearGlobalTracingHelper, getGlobalTracingHelper, setGlobalTracingHelper } from './global';\n\nexport interface PrismaInstrumentationConfig {\n ignoreSpanTypes?: (string | RegExp)[];\n}\n\ntype Config = PrismaInstrumentationConfig & InstrumentationConfig;\n\nexport class PrismaInstrumentation extends InstrumentationBase {\n public constructor(config: Config = {}) {\n super(NAME, VERSION, config);\n }\n\n public init(): InstrumentationNodeModuleDefinition[] {\n const module = new InstrumentationNodeModuleDefinition(MODULE_NAME, SUPPORTED_MODULE_VERSIONS);\n\n return [module];\n }\n\n public enable(): void {\n const config = this._config as Config;\n\n setGlobalTracingHelper(\n new ActiveTracingHelper({\n ignoreSpanTypes: config.ignoreSpanTypes ?? [],\n }),\n );\n }\n\n public disable(): void {\n clearGlobalTracingHelper();\n }\n\n public isEnabled(): boolean {\n return getGlobalTracingHelper() !== undefined;\n }\n}\n"],"names":["InstrumentationBase","NAME","VERSION","InstrumentationNodeModuleDefinition","MODULE_NAME","SUPPORTED_MODULE_VERSIONS","setGlobalTracingHelper","ActiveTracingHelper","clearGlobalTracingHelper","getGlobalTracingHelper"],"mappings":";;;;;;;AAyBO,MAAM,8BAA8BA,mCAAA,CAAoB;AAAA,EACtD,WAAA,CAAY,MAAA,GAAiB,EAAC,EAAG;AACtC,IAAA,KAAA,CAAMC,cAAA,EAAMC,mBAAS,MAAM,CAAA;AAAA,EAC7B;AAAA,EAEO,IAAA,GAA8C;AACnD,IAAA,MAAM,MAAA,GAAS,IAAIC,mDAAA,CAAoCC,qBAAA,EAAaC,mCAAyB,CAAA;AAE7F,IAAA,OAAO,CAAC,MAAM,CAAA;AAAA,EAChB;AAAA,EAEO,MAAA,GAAe;AACpB,IAAA,MAAM,SAAS,IAAA,CAAK,OAAA;AAEpB,IAAAC,6BAAA;AAAA,MACE,IAAIC,uCAAA,CAAoB;AAAA,QACtB,eAAA,EAAiB,MAAA,CAAO,eAAA,IAAmB;AAAC,OAC7C;AAAA,KACH;AAAA,EACF;AAAA,EAEO,OAAA,GAAgB;AACrB,IAAAC,+BAAA,EAAyB;AAAA,EAC3B;AAAA,EAEO,SAAA,GAAqB;AAC1B,IAAA,OAAOC,+BAAuB,KAAM,MAAA;AAAA,EACtC;AACF;;;;"}
@@ -53,9 +53,9 @@ const instrumentRedis = Object.assign(
53
53
  instrumentIORedis();
54
54
  instrumentRedisModule();
55
55
  if (dc.tracingChannel) {
56
- void Promise.resolve().then(
57
- () => serverUtils.subscribeRedisDiagnosticChannels(dc.tracingChannel, cacheResponseHook)
58
- );
56
+ core.waitForTracingChannelBinding(() => {
57
+ serverUtils.subscribeRedisDiagnosticChannels(dc.tracingChannel, cacheResponseHook);
58
+ });
59
59
  }
60
60
  },
61
61
  { id: INTEGRATION_NAME }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/redis/index.ts"],"sourcesContent":["import type { IntegrationFn, Span } from '@sentry/core';\nimport {\n defineIntegration,\n SEMANTIC_ATTRIBUTE_CACHE_HIT,\n SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE,\n SEMANTIC_ATTRIBUTE_CACHE_KEY,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n truncate,\n} from '@sentry/core';\nimport * as dc from 'node:diagnostics_channel';\nimport { subscribeRedisDiagnosticChannels, type RedisTracingChannelFactory } from '@sentry/server-utils';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport type { IORedisCommandArgs } from '../../../utils/redisCache';\nimport {\n calculateCacheItemSize,\n GET_COMMANDS,\n getCacheKeySafely,\n getCacheOperation,\n isInCommands,\n shouldConsiderForCache,\n} from '../../../utils/redisCache';\nimport type { IORedisResponseCustomAttributeFunction } from './vendored/types';\nimport { IORedisInstrumentation } from './vendored/ioredis-instrumentation';\nimport { RedisInstrumentation } from './vendored/redis-instrumentation';\n\ninterface RedisOptions {\n /**\n * Define cache prefixes for cache keys that should be captured as a cache span.\n *\n * Setting this to, for example, `['user:']` will capture cache keys that start with `user:`.\n */\n cachePrefixes?: string[];\n /**\n * Maximum length of the cache key added to the span description. If the key exceeds this length, it will be truncated.\n *\n * Passing `0` will use the full cache key without truncation.\n *\n * By default, the full cache key is used.\n */\n maxCacheKeyLength?: number;\n}\n\nconst INTEGRATION_NAME = 'Redis';\n\n/* Only exported for testing purposes */\nexport let _redisOptions: RedisOptions = {};\n\n/* Only exported for testing purposes */\nexport const cacheResponseHook: IORedisResponseCustomAttributeFunction = (\n span: Span,\n redisCommand: string,\n cmdArgs: IORedisCommandArgs,\n response: unknown,\n) => {\n const safeKey = getCacheKeySafely(redisCommand, cmdArgs);\n const cacheOperation = getCacheOperation(redisCommand);\n\n if (\n !safeKey ||\n !cacheOperation ||\n !_redisOptions.cachePrefixes ||\n !shouldConsiderForCache(redisCommand, safeKey, _redisOptions.cachePrefixes)\n ) {\n // not relevant for cache\n return;\n }\n\n // otel/ioredis seems to be using the old standard, as there was a change to those params: https://github.com/open-telemetry/opentelemetry-specification/issues/3199\n // We are using params based on the docs: https://opentelemetry.io/docs/specs/semconv/attributes-registry/network/\n // Fall back to stable semconv attributes (server.address/server.port) when\n // old-semconv ones are absent, eg OTEL_SEMCONV_STABILITY_OPT_IN=database\n // set for node-redis v4/v5.\n const spanData = spanToJSON(span).data;\n const networkPeerAddress = spanData['net.peer.name'] ?? spanData['server.address'];\n const networkPeerPort = spanData['net.peer.port'] ?? spanData['server.port'];\n if (networkPeerPort && networkPeerAddress) {\n span.setAttributes({ 'network.peer.address': networkPeerAddress, 'network.peer.port': networkPeerPort });\n }\n\n const cacheItemSize = calculateCacheItemSize(response);\n\n if (cacheItemSize) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);\n }\n\n if (isInCommands(GET_COMMANDS, redisCommand) && cacheItemSize !== undefined) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, cacheItemSize > 0);\n }\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: cacheOperation,\n [SEMANTIC_ATTRIBUTE_CACHE_KEY]: safeKey,\n });\n\n // todo: change to string[] once EAP supports it\n const spanDescription = safeKey.join(', ');\n\n span.updateName(\n _redisOptions.maxCacheKeyLength ? truncate(spanDescription, _redisOptions.maxCacheKeyLength) : spanDescription,\n );\n};\n\nconst instrumentIORedis = generateInstrumentOnce(`${INTEGRATION_NAME}.IORedis`, () => {\n return new IORedisInstrumentation({\n responseHook: cacheResponseHook,\n });\n});\n\nconst instrumentRedisModule = generateInstrumentOnce(`${INTEGRATION_NAME}.Redis`, () => {\n return new RedisInstrumentation({\n responseHook: cacheResponseHook,\n });\n});\n\n/**\n * To be able to preload all Redis OTel instrumentations with just one ID\n * (\"Redis\"), all the instrumentations are generated in this one function\n */\nexport const instrumentRedis = Object.assign(\n (): void => {\n instrumentIORedis();\n instrumentRedisModule();\n // node-redis >= 5.12.0 and ioredis >= 5.11.0 publish via diagnostics_channel.\n // `bindTracingChannelToSpan` (inside the subscriber) makes the span the active\n // OTel context via `bindStore`, which needs the Sentry OTel context manager to\n // be registered — `initOpenTelemetry()` does that after integration `setupOnce`,\n // so defer to the next tick.\n // Check this here to ensure this does not fail at runtime for Node <= 18.18.0\n if (dc.tracingChannel) {\n void Promise.resolve().then(() =>\n subscribeRedisDiagnosticChannels(dc.tracingChannel as RedisTracingChannelFactory, cacheResponseHook),\n );\n }\n\n // todo: implement them gradually\n // new LegacyRedisInstrumentation({}),\n },\n { id: INTEGRATION_NAME },\n);\n\nconst _redisIntegration = ((options: RedisOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n _redisOptions = options;\n instrumentRedis();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [redis](https://www.npmjs.com/package/redis) and\n * [ioredis](https://www.npmjs.com/package/ioredis) libraries.\n *\n * For more information, see the [`redisIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/redis/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.redisIntegration()],\n * });\n * ```\n */\nexport const redisIntegration = defineIntegration(_redisIntegration);\n"],"names":["_redisOptions","getCacheKeySafely","getCacheOperation","shouldConsiderForCache","spanToJSON","calculateCacheItemSize","SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE","isInCommands","GET_COMMANDS","SEMANTIC_ATTRIBUTE_CACHE_HIT","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_CACHE_KEY","truncate","generateInstrumentOnce","IORedisInstrumentation","RedisInstrumentation","subscribeRedisDiagnosticChannels","defineIntegration"],"mappings":";;;;;;;;;;AA2CA,MAAM,gBAAA,GAAmB,OAAA;AAGdA,wBAA8B;AAGlC,MAAM,iBAAA,GAA4D,CACvE,IAAA,EACA,YAAA,EACA,SACA,QAAA,KACG;AACH,EAAA,MAAM,OAAA,GAAUC,4BAAA,CAAkB,YAAA,EAAc,OAAO,CAAA;AACvD,EAAA,MAAM,cAAA,GAAiBC,6BAAkB,YAAY,CAAA;AAErD,EAAA,IACE,CAAC,OAAA,IACD,CAAC,cAAA,IACD,CAACF,qBAAA,CAAc,aAAA,IACf,CAACG,iCAAA,CAAuB,YAAA,EAAc,OAAA,EAASH,qBAAA,CAAc,aAAa,CAAA,EAC1E;AAEA,IAAA;AAAA,EACF;AAOA,EAAA,MAAM,QAAA,GAAWI,eAAA,CAAW,IAAI,CAAA,CAAE,IAAA;AAClC,EAAA,MAAM,kBAAA,GAAqB,QAAA,CAAS,eAAe,CAAA,IAAK,SAAS,gBAAgB,CAAA;AACjF,EAAA,MAAM,eAAA,GAAkB,QAAA,CAAS,eAAe,CAAA,IAAK,SAAS,aAAa,CAAA;AAC3E,EAAA,IAAI,mBAAmB,kBAAA,EAAoB;AACzC,IAAA,IAAA,CAAK,cAAc,EAAE,sBAAA,EAAwB,kBAAA,EAAoB,mBAAA,EAAqB,iBAAiB,CAAA;AAAA,EACzG;AAEA,EAAA,MAAM,aAAA,GAAgBC,kCAAuB,QAAQ,CAAA;AAErD,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,IAAA,CAAK,YAAA,CAAaC,yCAAoC,aAAa,CAAA;AAAA,EACrE;AAEA,EAAA,IAAIC,uBAAA,CAAaC,uBAAA,EAAc,YAAY,CAAA,IAAK,kBAAkB,MAAA,E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ACN,SAAA,GAAY;AACV,MAAAhB,qBAAA,GAAgB,OAAA;AAChB,MAAA,eAAA,EAAgB;AAAA,IAClB;AAAA,GACF;AACF,CAAA,CAAA;AAiBO,MAAM,gBAAA,GAAmBiB,uBAAkB,iBAAiB;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/redis/index.ts"],"sourcesContent":["import type { IntegrationFn, Span } from '@sentry/core';\nimport {\n defineIntegration,\n SEMANTIC_ATTRIBUTE_CACHE_HIT,\n SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE,\n SEMANTIC_ATTRIBUTE_CACHE_KEY,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n truncate,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport * as dc from 'node:diagnostics_channel';\nimport { subscribeRedisDiagnosticChannels, type RedisTracingChannelFactory } from '@sentry/server-utils';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport type { IORedisCommandArgs } from '../../../utils/redisCache';\nimport {\n calculateCacheItemSize,\n GET_COMMANDS,\n getCacheKeySafely,\n getCacheOperation,\n isInCommands,\n shouldConsiderForCache,\n} from '../../../utils/redisCache';\nimport type { IORedisResponseCustomAttributeFunction } from './vendored/types';\nimport { IORedisInstrumentation } from './vendored/ioredis-instrumentation';\nimport { RedisInstrumentation } from './vendored/redis-instrumentation';\n\ninterface RedisOptions {\n /**\n * Define cache prefixes for cache keys that should be captured as a cache span.\n *\n * Setting this to, for example, `['user:']` will capture cache keys that start with `user:`.\n */\n cachePrefixes?: string[];\n /**\n * Maximum length of the cache key added to the span description. If the key exceeds this length, it will be truncated.\n *\n * Passing `0` will use the full cache key without truncation.\n *\n * By default, the full cache key is used.\n */\n maxCacheKeyLength?: number;\n}\n\nconst INTEGRATION_NAME = 'Redis' as const;\n\n/* Only exported for testing purposes */\nexport let _redisOptions: RedisOptions = {};\n\n/* Only exported for testing purposes */\nexport const cacheResponseHook: IORedisResponseCustomAttributeFunction = (\n span: Span,\n redisCommand: string,\n cmdArgs: IORedisCommandArgs,\n response: unknown,\n) => {\n const safeKey = getCacheKeySafely(redisCommand, cmdArgs);\n const cacheOperation = getCacheOperation(redisCommand);\n\n if (\n !safeKey ||\n !cacheOperation ||\n !_redisOptions.cachePrefixes ||\n !shouldConsiderForCache(redisCommand, safeKey, _redisOptions.cachePrefixes)\n ) {\n // not relevant for cache\n return;\n }\n\n // otel/ioredis seems to be using the old standard, as there was a change to those params: https://github.com/open-telemetry/opentelemetry-specification/issues/3199\n // We are using params based on the docs: https://opentelemetry.io/docs/specs/semconv/attributes-registry/network/\n // Fall back to stable semconv attributes (server.address/server.port) when\n // old-semconv ones are absent, eg OTEL_SEMCONV_STABILITY_OPT_IN=database\n // set for node-redis v4/v5.\n const spanData = spanToJSON(span).data;\n const networkPeerAddress = spanData['net.peer.name'] ?? spanData['server.address'];\n const networkPeerPort = spanData['net.peer.port'] ?? spanData['server.port'];\n if (networkPeerPort && networkPeerAddress) {\n span.setAttributes({ 'network.peer.address': networkPeerAddress, 'network.peer.port': networkPeerPort });\n }\n\n const cacheItemSize = calculateCacheItemSize(response);\n\n if (cacheItemSize) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);\n }\n\n if (isInCommands(GET_COMMANDS, redisCommand) && cacheItemSize !== undefined) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, cacheItemSize > 0);\n }\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: cacheOperation,\n [SEMANTIC_ATTRIBUTE_CACHE_KEY]: safeKey,\n });\n\n // todo: change to string[] once EAP supports it\n const spanDescription = safeKey.join(', ');\n\n span.updateName(\n _redisOptions.maxCacheKeyLength ? truncate(spanDescription, _redisOptions.maxCacheKeyLength) : spanDescription,\n );\n};\n\nconst instrumentIORedis = generateInstrumentOnce(`${INTEGRATION_NAME}.IORedis`, () => {\n return new IORedisInstrumentation({\n responseHook: cacheResponseHook,\n });\n});\n\nconst instrumentRedisModule = generateInstrumentOnce(`${INTEGRATION_NAME}.Redis`, () => {\n return new RedisInstrumentation({\n responseHook: cacheResponseHook,\n });\n});\n\n/**\n * To be able to preload all Redis OTel instrumentations with just one ID\n * (\"Redis\"), all the instrumentations are generated in this one function\n */\nexport const instrumentRedis = Object.assign(\n (): void => {\n instrumentIORedis();\n instrumentRedisModule();\n // node-redis >= 5.12.0 and ioredis >= 5.11.0 publish via diagnostics_channel.\n // `bindTracingChannelToSpan` (inside the subscriber) makes the span the active\n // OTel context via `bindStore`, which needs the Sentry OTel context manager to\n // be registered — `initOpenTelemetry()` does that after integration `setupOnce`,\n // so defer to the next tick.\n // Check this here to ensure this does not fail at runtime for Node <= 18.18.0\n if (dc.tracingChannel) {\n waitForTracingChannelBinding(() => {\n subscribeRedisDiagnosticChannels(dc.tracingChannel as RedisTracingChannelFactory, cacheResponseHook);\n });\n }\n\n // todo: implement them gradually\n // new LegacyRedisInstrumentation({}),\n },\n { id: INTEGRATION_NAME },\n);\n\nconst _redisIntegration = ((options: RedisOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n _redisOptions = options;\n instrumentRedis();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [redis](https://www.npmjs.com/package/redis) and\n * [ioredis](https://www.npmjs.com/package/ioredis) libraries.\n *\n * For more information, see the [`redisIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/redis/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.redisIntegration()],\n * });\n * ```\n */\nexport const redisIntegration = defineIntegration(_redisIntegration);\n"],"names":["_redisOptions","getCacheKeySafely","getCacheOperation","shouldConsiderForCache","spanToJSON","calculateCacheItemSize","SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE","isInCommands","GET_COMMANDS","SEMANTIC_ATTRIBUTE_CACHE_HIT","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_CACHE_KEY","truncate","generateInstrumentOnce","IORedisInstrumentation","RedisInstrumentation","waitForTracingChannelBinding","subscribeRedisDiagnosticChannels","defineIntegration"],"mappings":";;;;;;;;;;AA4CA,MAAM,gBAAA,GAAmB,OAAA;AAGdA,wBAA8B;AAGlC,MAAM,iBAAA,GAA4D,CACvE,IAAA,EACA,YAAA,EACA,SACA,QAAA,KACG;AACH,EAAA,MAAM,OAAA,GAAUC,4BAAA,CAAkB,YAAA,EAAc,OAAO,CAAA;AACvD,EAAA,MAAM,cAAA,GAAiBC,6BAAkB,YAAY,CAAA;AAErD,EAAA,IACE,CAAC,OAAA,IACD,CAAC,cAAA,IACD,CAACF,qBAAA,CAAc,aAAA,IACf,CAACG,iCAAA,CAAuB,YAAA,EAAc,OAAA,EAASH,qBAAA,CAAc,aAAa,CAAA,EAC1E;AAEA,IAAA;AAAA,EACF;AAOA,EAAA,MAAM,QAAA,GAAWI,eAAA,CAAW,IAAI,CAAA,CAAE,IAAA;AAClC,EAAA,MAAM,kBAAA,GAAqB,QAAA,CAAS,eAAe,CAAA,IAAK,SAAS,gBAAgB,CAAA;AACjF,EAAA,MAAM,eAAA,GAAkB,QAAA,CAAS,eAAe,CAAA,IAAK,SAAS,aAAa,CAAA;AAC3E,EAAA,IAAI,mBAAmB,kBAAA,EAAoB;AACzC,IAAA,IAAA,CAAK,cAAc,EAAE,sBAAA,EAAwB,kBAAA,EAAoB,mBAAA,EAAqB,iBAAiB,CAAA;AAAA,EACzG;AAEA,EAAA,MAAM,aAAA,GAAgBC,kCAAuB,QAAQ,CAAA;AAErD,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,IAAA,CAAK,YAAA,CAAaC,yCAAoC,aAAa,CAAA;AAAA,EACrE;AAEA,EAAA,IAAIC,uBAAA,CAAaC,uBAAA,EAAc,YAAY,CAAA,IAAK,kBAAkB,MAAA,EAAW;AAC3E,IAAA,IAAA,CAAK,YA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