@depup/sentry__node 10.44.0-depup.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 (473) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/build/cjs/debug-build.js +11 -0
  4. package/build/cjs/debug-build.js.map +1 -0
  5. package/build/cjs/index.js +216 -0
  6. package/build/cjs/index.js.map +1 -0
  7. package/build/cjs/init.js +10 -0
  8. package/build/cjs/init.js.map +1 -0
  9. package/build/cjs/integrations/featureFlagShims/growthbook.js +12 -0
  10. package/build/cjs/integrations/featureFlagShims/growthbook.js.map +1 -0
  11. package/build/cjs/integrations/featureFlagShims/launchDarkly.js +43 -0
  12. package/build/cjs/integrations/featureFlagShims/launchDarkly.js.map +1 -0
  13. package/build/cjs/integrations/featureFlagShims/openFeature.js +55 -0
  14. package/build/cjs/integrations/featureFlagShims/openFeature.js.map +1 -0
  15. package/build/cjs/integrations/featureFlagShims/statsig.js +23 -0
  16. package/build/cjs/integrations/featureFlagShims/statsig.js.map +1 -0
  17. package/build/cjs/integrations/featureFlagShims/unleash.js +23 -0
  18. package/build/cjs/integrations/featureFlagShims/unleash.js.map +1 -0
  19. package/build/cjs/integrations/fs.js +142 -0
  20. package/build/cjs/integrations/fs.js.map +1 -0
  21. package/build/cjs/integrations/http.js +224 -0
  22. package/build/cjs/integrations/http.js.map +1 -0
  23. package/build/cjs/integrations/node-fetch.js +108 -0
  24. package/build/cjs/integrations/node-fetch.js.map +1 -0
  25. package/build/cjs/integrations/tracing/amqplib.js +47 -0
  26. package/build/cjs/integrations/tracing/amqplib.js.map +1 -0
  27. package/build/cjs/integrations/tracing/anthropic-ai/index.js +79 -0
  28. package/build/cjs/integrations/tracing/anthropic-ai/index.js.map +1 -0
  29. package/build/cjs/integrations/tracing/anthropic-ai/instrumentation.js +95 -0
  30. package/build/cjs/integrations/tracing/anthropic-ai/instrumentation.js.map +1 -0
  31. package/build/cjs/integrations/tracing/connect.js +110 -0
  32. package/build/cjs/integrations/tracing/connect.js.map +1 -0
  33. package/build/cjs/integrations/tracing/dataloader.js +72 -0
  34. package/build/cjs/integrations/tracing/dataloader.js.map +1 -0
  35. package/build/cjs/integrations/tracing/express.js +166 -0
  36. package/build/cjs/integrations/tracing/express.js.map +1 -0
  37. package/build/cjs/integrations/tracing/fastify/index.js +270 -0
  38. package/build/cjs/integrations/tracing/fastify/index.js.map +1 -0
  39. package/build/cjs/integrations/tracing/fastify/v3/constants.js +23 -0
  40. package/build/cjs/integrations/tracing/fastify/v3/constants.js.map +1 -0
  41. package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
  42. package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
  43. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +304 -0
  44. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
  45. package/build/cjs/integrations/tracing/fastify/v3/utils.js +135 -0
  46. package/build/cjs/integrations/tracing/fastify/v3/utils.js.map +1 -0
  47. package/build/cjs/integrations/tracing/firebase/firebase.js +50 -0
  48. package/build/cjs/integrations/tracing/firebase/firebase.js.map +1 -0
  49. package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js +44 -0
  50. package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -0
  51. package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js +297 -0
  52. package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -0
  53. package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js +265 -0
  54. package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js.map +1 -0
  55. package/build/cjs/integrations/tracing/genericPool.js +59 -0
  56. package/build/cjs/integrations/tracing/genericPool.js.map +1 -0
  57. package/build/cjs/integrations/tracing/google-genai/index.js +78 -0
  58. package/build/cjs/integrations/tracing/google-genai/index.js.map +1 -0
  59. package/build/cjs/integrations/tracing/google-genai/instrumentation.js +88 -0
  60. package/build/cjs/integrations/tracing/google-genai/instrumentation.js.map +1 -0
  61. package/build/cjs/integrations/tracing/graphql.js +127 -0
  62. package/build/cjs/integrations/tracing/graphql.js.map +1 -0
  63. package/build/cjs/integrations/tracing/hapi/index.js +135 -0
  64. package/build/cjs/integrations/tracing/hapi/index.js.map +1 -0
  65. package/build/cjs/integrations/tracing/hono/constants.js +15 -0
  66. package/build/cjs/integrations/tracing/hono/constants.js.map +1 -0
  67. package/build/cjs/integrations/tracing/hono/index.js +137 -0
  68. package/build/cjs/integrations/tracing/hono/index.js.map +1 -0
  69. package/build/cjs/integrations/tracing/hono/instrumentation.js +236 -0
  70. package/build/cjs/integrations/tracing/hono/instrumentation.js.map +1 -0
  71. package/build/cjs/integrations/tracing/index.js +110 -0
  72. package/build/cjs/integrations/tracing/index.js.map +1 -0
  73. package/build/cjs/integrations/tracing/kafka.js +48 -0
  74. package/build/cjs/integrations/tracing/kafka.js.map +1 -0
  75. package/build/cjs/integrations/tracing/knex.js +57 -0
  76. package/build/cjs/integrations/tracing/knex.js.map +1 -0
  77. package/build/cjs/integrations/tracing/koa.js +138 -0
  78. package/build/cjs/integrations/tracing/koa.js.map +1 -0
  79. package/build/cjs/integrations/tracing/langchain/index.js +116 -0
  80. package/build/cjs/integrations/tracing/langchain/index.js.map +1 -0
  81. package/build/cjs/integrations/tracing/langchain/instrumentation.js +220 -0
  82. package/build/cjs/integrations/tracing/langchain/instrumentation.js.map +1 -0
  83. package/build/cjs/integrations/tracing/langgraph/index.js +93 -0
  84. package/build/cjs/integrations/tracing/langgraph/index.js.map +1 -0
  85. package/build/cjs/integrations/tracing/langgraph/instrumentation.js +60 -0
  86. package/build/cjs/integrations/tracing/langgraph/instrumentation.js.map +1 -0
  87. package/build/cjs/integrations/tracing/lrumemoizer.js +37 -0
  88. package/build/cjs/integrations/tracing/lrumemoizer.js.map +1 -0
  89. package/build/cjs/integrations/tracing/mongo.js +93 -0
  90. package/build/cjs/integrations/tracing/mongo.js.map +1 -0
  91. package/build/cjs/integrations/tracing/mongoose.js +46 -0
  92. package/build/cjs/integrations/tracing/mongoose.js.map +1 -0
  93. package/build/cjs/integrations/tracing/mysql.js +38 -0
  94. package/build/cjs/integrations/tracing/mysql.js.map +1 -0
  95. package/build/cjs/integrations/tracing/mysql2.js +46 -0
  96. package/build/cjs/integrations/tracing/mysql2.js.map +1 -0
  97. package/build/cjs/integrations/tracing/openai/index.js +78 -0
  98. package/build/cjs/integrations/tracing/openai/index.js.map +1 -0
  99. package/build/cjs/integrations/tracing/openai/instrumentation.js +104 -0
  100. package/build/cjs/integrations/tracing/openai/instrumentation.js.map +1 -0
  101. package/build/cjs/integrations/tracing/postgres.js +48 -0
  102. package/build/cjs/integrations/tracing/postgres.js.map +1 -0
  103. package/build/cjs/integrations/tracing/postgresjs.js +378 -0
  104. package/build/cjs/integrations/tracing/postgresjs.js.map +1 -0
  105. package/build/cjs/integrations/tracing/prisma.js +203 -0
  106. package/build/cjs/integrations/tracing/prisma.js.map +1 -0
  107. package/build/cjs/integrations/tracing/redis.js +121 -0
  108. package/build/cjs/integrations/tracing/redis.js.map +1 -0
  109. package/build/cjs/integrations/tracing/tedious.js +67 -0
  110. package/build/cjs/integrations/tracing/tedious.js.map +1 -0
  111. package/build/cjs/integrations/tracing/vercelai/constants.js +6 -0
  112. package/build/cjs/integrations/tracing/vercelai/constants.js.map +1 -0
  113. package/build/cjs/integrations/tracing/vercelai/index.js +82 -0
  114. package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -0
  115. package/build/cjs/integrations/tracing/vercelai/instrumentation.js +274 -0
  116. package/build/cjs/integrations/tracing/vercelai/instrumentation.js.map +1 -0
  117. package/build/cjs/preload.js +21 -0
  118. package/build/cjs/preload.js.map +1 -0
  119. package/build/cjs/sdk/index.js +78 -0
  120. package/build/cjs/sdk/index.js.map +1 -0
  121. package/build/cjs/sdk/initOtel.js +126 -0
  122. package/build/cjs/sdk/initOtel.js.map +1 -0
  123. package/build/cjs/utils/redisCache.js +122 -0
  124. package/build/cjs/utils/redisCache.js.map +1 -0
  125. package/build/esm/debug-build.js +9 -0
  126. package/build/esm/debug-build.js.map +1 -0
  127. package/build/esm/index.js +44 -0
  128. package/build/esm/index.js.map +1 -0
  129. package/build/esm/init.js +10 -0
  130. package/build/esm/init.js.map +1 -0
  131. package/build/esm/integrations/featureFlagShims/growthbook.js +10 -0
  132. package/build/esm/integrations/featureFlagShims/growthbook.js.map +1 -0
  133. package/build/esm/integrations/featureFlagShims/launchDarkly.js +40 -0
  134. package/build/esm/integrations/featureFlagShims/launchDarkly.js.map +1 -0
  135. package/build/esm/integrations/featureFlagShims/openFeature.js +52 -0
  136. package/build/esm/integrations/featureFlagShims/openFeature.js.map +1 -0
  137. package/build/esm/integrations/featureFlagShims/statsig.js +21 -0
  138. package/build/esm/integrations/featureFlagShims/statsig.js.map +1 -0
  139. package/build/esm/integrations/featureFlagShims/unleash.js +21 -0
  140. package/build/esm/integrations/featureFlagShims/unleash.js.map +1 -0
  141. package/build/esm/integrations/fs.js +140 -0
  142. package/build/esm/integrations/fs.js.map +1 -0
  143. package/build/esm/integrations/http.js +219 -0
  144. package/build/esm/integrations/http.js.map +1 -0
  145. package/build/esm/integrations/node-fetch.js +105 -0
  146. package/build/esm/integrations/node-fetch.js.map +1 -0
  147. package/build/esm/integrations/tracing/amqplib.js +44 -0
  148. package/build/esm/integrations/tracing/amqplib.js.map +1 -0
  149. package/build/esm/integrations/tracing/anthropic-ai/index.js +76 -0
  150. package/build/esm/integrations/tracing/anthropic-ai/index.js.map +1 -0
  151. package/build/esm/integrations/tracing/anthropic-ai/instrumentation.js +93 -0
  152. package/build/esm/integrations/tracing/anthropic-ai/instrumentation.js.map +1 -0
  153. package/build/esm/integrations/tracing/connect.js +106 -0
  154. package/build/esm/integrations/tracing/connect.js.map +1 -0
  155. package/build/esm/integrations/tracing/dataloader.js +69 -0
  156. package/build/esm/integrations/tracing/dataloader.js.map +1 -0
  157. package/build/esm/integrations/tracing/express.js +161 -0
  158. package/build/esm/integrations/tracing/express.js.map +1 -0
  159. package/build/esm/integrations/tracing/fastify/index.js +265 -0
  160. package/build/esm/integrations/tracing/fastify/index.js.map +1 -0
  161. package/build/esm/integrations/tracing/fastify/v3/constants.js +21 -0
  162. package/build/esm/integrations/tracing/fastify/v3/constants.js.map +1 -0
  163. package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
  164. package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
  165. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +302 -0
  166. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
  167. package/build/esm/integrations/tracing/fastify/v3/utils.js +131 -0
  168. package/build/esm/integrations/tracing/fastify/v3/utils.js.map +1 -0
  169. package/build/esm/integrations/tracing/firebase/firebase.js +47 -0
  170. package/build/esm/integrations/tracing/firebase/firebase.js.map +1 -0
  171. package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js +42 -0
  172. package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -0
  173. package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js +294 -0
  174. package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -0
  175. package/build/esm/integrations/tracing/firebase/otel/patches/functions.js +262 -0
  176. package/build/esm/integrations/tracing/firebase/otel/patches/functions.js.map +1 -0
  177. package/build/esm/integrations/tracing/genericPool.js +56 -0
  178. package/build/esm/integrations/tracing/genericPool.js.map +1 -0
  179. package/build/esm/integrations/tracing/google-genai/index.js +75 -0
  180. package/build/esm/integrations/tracing/google-genai/index.js.map +1 -0
  181. package/build/esm/integrations/tracing/google-genai/instrumentation.js +86 -0
  182. package/build/esm/integrations/tracing/google-genai/instrumentation.js.map +1 -0
  183. package/build/esm/integrations/tracing/graphql.js +124 -0
  184. package/build/esm/integrations/tracing/graphql.js.map +1 -0
  185. package/build/esm/integrations/tracing/hapi/index.js +130 -0
  186. package/build/esm/integrations/tracing/hapi/index.js.map +1 -0
  187. package/build/esm/integrations/tracing/hono/constants.js +12 -0
  188. package/build/esm/integrations/tracing/hono/constants.js.map +1 -0
  189. package/build/esm/integrations/tracing/hono/index.js +133 -0
  190. package/build/esm/integrations/tracing/hono/index.js.map +1 -0
  191. package/build/esm/integrations/tracing/hono/instrumentation.js +234 -0
  192. package/build/esm/integrations/tracing/hono/instrumentation.js.map +1 -0
  193. package/build/esm/integrations/tracing/index.js +107 -0
  194. package/build/esm/integrations/tracing/index.js.map +1 -0
  195. package/build/esm/integrations/tracing/kafka.js +45 -0
  196. package/build/esm/integrations/tracing/kafka.js.map +1 -0
  197. package/build/esm/integrations/tracing/knex.js +54 -0
  198. package/build/esm/integrations/tracing/knex.js.map +1 -0
  199. package/build/esm/integrations/tracing/koa.js +134 -0
  200. package/build/esm/integrations/tracing/koa.js.map +1 -0
  201. package/build/esm/integrations/tracing/langchain/index.js +113 -0
  202. package/build/esm/integrations/tracing/langchain/index.js.map +1 -0
  203. package/build/esm/integrations/tracing/langchain/instrumentation.js +218 -0
  204. package/build/esm/integrations/tracing/langchain/instrumentation.js.map +1 -0
  205. package/build/esm/integrations/tracing/langgraph/index.js +90 -0
  206. package/build/esm/integrations/tracing/langgraph/index.js.map +1 -0
  207. package/build/esm/integrations/tracing/langgraph/instrumentation.js +58 -0
  208. package/build/esm/integrations/tracing/langgraph/instrumentation.js.map +1 -0
  209. package/build/esm/integrations/tracing/lrumemoizer.js +34 -0
  210. package/build/esm/integrations/tracing/lrumemoizer.js.map +1 -0
  211. package/build/esm/integrations/tracing/mongo.js +89 -0
  212. package/build/esm/integrations/tracing/mongo.js.map +1 -0
  213. package/build/esm/integrations/tracing/mongoose.js +43 -0
  214. package/build/esm/integrations/tracing/mongoose.js.map +1 -0
  215. package/build/esm/integrations/tracing/mysql.js +35 -0
  216. package/build/esm/integrations/tracing/mysql.js.map +1 -0
  217. package/build/esm/integrations/tracing/mysql2.js +43 -0
  218. package/build/esm/integrations/tracing/mysql2.js.map +1 -0
  219. package/build/esm/integrations/tracing/openai/index.js +75 -0
  220. package/build/esm/integrations/tracing/openai/index.js.map +1 -0
  221. package/build/esm/integrations/tracing/openai/instrumentation.js +102 -0
  222. package/build/esm/integrations/tracing/openai/instrumentation.js.map +1 -0
  223. package/build/esm/integrations/tracing/postgres.js +45 -0
  224. package/build/esm/integrations/tracing/postgres.js.map +1 -0
  225. package/build/esm/integrations/tracing/postgresjs.js +374 -0
  226. package/build/esm/integrations/tracing/postgresjs.js.map +1 -0
  227. package/build/esm/integrations/tracing/prisma.js +200 -0
  228. package/build/esm/integrations/tracing/prisma.js.map +1 -0
  229. package/build/esm/integrations/tracing/redis.js +117 -0
  230. package/build/esm/integrations/tracing/redis.js.map +1 -0
  231. package/build/esm/integrations/tracing/tedious.js +64 -0
  232. package/build/esm/integrations/tracing/tedious.js.map +1 -0
  233. package/build/esm/integrations/tracing/vercelai/constants.js +4 -0
  234. package/build/esm/integrations/tracing/vercelai/constants.js.map +1 -0
  235. package/build/esm/integrations/tracing/vercelai/index.js +79 -0
  236. package/build/esm/integrations/tracing/vercelai/index.js.map +1 -0
  237. package/build/esm/integrations/tracing/vercelai/instrumentation.js +269 -0
  238. package/build/esm/integrations/tracing/vercelai/instrumentation.js.map +1 -0
  239. package/build/esm/package.json +1 -0
  240. package/build/esm/preload.js +21 -0
  241. package/build/esm/preload.js.map +1 -0
  242. package/build/esm/sdk/index.js +73 -0
  243. package/build/esm/sdk/index.js.map +1 -0
  244. package/build/esm/sdk/initOtel.js +121 -0
  245. package/build/esm/sdk/initOtel.js.map +1 -0
  246. package/build/esm/utils/redisCache.js +114 -0
  247. package/build/esm/utils/redisCache.js.map +1 -0
  248. package/build/import-hook.mjs +5 -0
  249. package/build/loader-hook.mjs +1 -0
  250. package/build/types/debug-build.d.ts +7 -0
  251. package/build/types/debug-build.d.ts.map +1 -0
  252. package/build/types/index.d.ts +42 -0
  253. package/build/types/index.d.ts.map +1 -0
  254. package/build/types/init.d.ts +2 -0
  255. package/build/types/init.d.ts.map +1 -0
  256. package/build/types/integrations/featureFlagShims/growthbook.d.ts +6 -0
  257. package/build/types/integrations/featureFlagShims/growthbook.d.ts.map +1 -0
  258. package/build/types/integrations/featureFlagShims/index.d.ts +6 -0
  259. package/build/types/integrations/featureFlagShims/index.d.ts.map +1 -0
  260. package/build/types/integrations/featureFlagShims/launchDarkly.d.ts +10 -0
  261. package/build/types/integrations/featureFlagShims/launchDarkly.d.ts.map +1 -0
  262. package/build/types/integrations/featureFlagShims/openFeature.d.ts +23 -0
  263. package/build/types/integrations/featureFlagShims/openFeature.d.ts.map +1 -0
  264. package/build/types/integrations/featureFlagShims/statsig.d.ts +6 -0
  265. package/build/types/integrations/featureFlagShims/statsig.d.ts.map +1 -0
  266. package/build/types/integrations/featureFlagShims/unleash.d.ts +6 -0
  267. package/build/types/integrations/featureFlagShims/unleash.d.ts.map +1 -0
  268. package/build/types/integrations/fs.d.ts +24 -0
  269. package/build/types/integrations/fs.d.ts.map +1 -0
  270. package/build/types/integrations/http.d.ts +136 -0
  271. package/build/types/integrations/http.d.ts.map +1 -0
  272. package/build/types/integrations/node-fetch.d.ts +36 -0
  273. package/build/types/integrations/node-fetch.d.ts.map +1 -0
  274. package/build/types/integrations/tracing/amqplib.d.ts +20 -0
  275. package/build/types/integrations/tracing/amqplib.d.ts.map +1 -0
  276. package/build/types/integrations/tracing/anthropic-ai/index.d.ts +59 -0
  277. package/build/types/integrations/tracing/anthropic-ai/index.d.ts.map +1 -0
  278. package/build/types/integrations/tracing/anthropic-ai/instrumentation.d.ts +19 -0
  279. package/build/types/integrations/tracing/anthropic-ai/instrumentation.d.ts.map +1 -0
  280. package/build/types/integrations/tracing/connect.d.ts +46 -0
  281. package/build/types/integrations/tracing/connect.d.ts.map +1 -0
  282. package/build/types/integrations/tracing/dataloader.d.ts +20 -0
  283. package/build/types/integrations/tracing/dataloader.d.ts.map +1 -0
  284. package/build/types/integrations/tracing/express.d.ts +72 -0
  285. package/build/types/integrations/tracing/express.d.ts.map +1 -0
  286. package/build/types/integrations/tracing/fastify/index.d.ts +119 -0
  287. package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -0
  288. package/build/types/integrations/tracing/fastify/types.d.ts +33 -0
  289. package/build/types/integrations/tracing/fastify/types.d.ts.map +1 -0
  290. package/build/types/integrations/tracing/fastify/v3/constants.d.ts +3 -0
  291. package/build/types/integrations/tracing/fastify/v3/constants.d.ts.map +1 -0
  292. package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
  293. package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts.map +1 -0
  294. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
  295. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts.map +1 -0
  296. package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
  297. package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts.map +1 -0
  298. package/build/types/integrations/tracing/fastify/v3/types.d.ts +21 -0
  299. package/build/types/integrations/tracing/fastify/v3/types.d.ts.map +1 -0
  300. package/build/types/integrations/tracing/fastify/v3/utils.d.ts +28 -0
  301. package/build/types/integrations/tracing/fastify/v3/utils.d.ts.map +1 -0
  302. package/build/types/integrations/tracing/firebase/firebase.d.ts +6 -0
  303. package/build/types/integrations/tracing/firebase/firebase.d.ts.map +1 -0
  304. package/build/types/integrations/tracing/firebase/index.d.ts +2 -0
  305. package/build/types/integrations/tracing/firebase/index.d.ts.map +1 -0
  306. package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +19 -0
  307. package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts.map +1 -0
  308. package/build/types/integrations/tracing/firebase/otel/index.d.ts +3 -0
  309. package/build/types/integrations/tracing/firebase/otel/index.d.ts.map +1 -0
  310. package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts +25 -0
  311. package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts.map +1 -0
  312. package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts +23 -0
  313. package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts.map +1 -0
  314. package/build/types/integrations/tracing/firebase/otel/types.d.ts +120 -0
  315. package/build/types/integrations/tracing/firebase/otel/types.d.ts.map +1 -0
  316. package/build/types/integrations/tracing/genericPool.d.ts +20 -0
  317. package/build/types/integrations/tracing/genericPool.d.ts.map +1 -0
  318. package/build/types/integrations/tracing/google-genai/index.d.ts +59 -0
  319. package/build/types/integrations/tracing/google-genai/index.d.ts.map +1 -0
  320. package/build/types/integrations/tracing/google-genai/instrumentation.d.ts +20 -0
  321. package/build/types/integrations/tracing/google-genai/instrumentation.d.ts.map +1 -0
  322. package/build/types/integrations/tracing/graphql.d.ts +48 -0
  323. package/build/types/integrations/tracing/graphql.d.ts.map +1 -0
  324. package/build/types/integrations/tracing/hapi/index.d.ts +50 -0
  325. package/build/types/integrations/tracing/hapi/index.d.ts.map +1 -0
  326. package/build/types/integrations/tracing/hapi/types.d.ts +166 -0
  327. package/build/types/integrations/tracing/hapi/types.d.ts.map +1 -0
  328. package/build/types/integrations/tracing/hono/constants.d.ts +11 -0
  329. package/build/types/integrations/tracing/hono/constants.d.ts.map +1 -0
  330. package/build/types/integrations/tracing/hono/index.d.ts +52 -0
  331. package/build/types/integrations/tracing/hono/index.d.ts.map +1 -0
  332. package/build/types/integrations/tracing/hono/instrumentation.d.ts +55 -0
  333. package/build/types/integrations/tracing/hono/instrumentation.d.ts.map +1 -0
  334. package/build/types/integrations/tracing/hono/types.d.ts +36 -0
  335. package/build/types/integrations/tracing/hono/types.d.ts.map +1 -0
  336. package/build/types/integrations/tracing/index.d.ts +12 -0
  337. package/build/types/integrations/tracing/index.d.ts.map +1 -0
  338. package/build/types/integrations/tracing/kafka.d.ts +19 -0
  339. package/build/types/integrations/tracing/kafka.d.ts.map +1 -0
  340. package/build/types/integrations/tracing/knex.d.ts +20 -0
  341. package/build/types/integrations/tracing/knex.d.ts.map +1 -0
  342. package/build/types/integrations/tracing/koa.d.ts +70 -0
  343. package/build/types/integrations/tracing/koa.d.ts.map +1 -0
  344. package/build/types/integrations/tracing/langchain/index.d.ts +97 -0
  345. package/build/types/integrations/tracing/langchain/index.d.ts.map +1 -0
  346. package/build/types/integrations/tracing/langchain/instrumentation.d.ts +29 -0
  347. package/build/types/integrations/tracing/langchain/instrumentation.d.ts.map +1 -0
  348. package/build/types/integrations/tracing/langgraph/index.d.ts +74 -0
  349. package/build/types/integrations/tracing/langgraph/index.d.ts.map +1 -0
  350. package/build/types/integrations/tracing/langgraph/instrumentation.d.ts +19 -0
  351. package/build/types/integrations/tracing/langgraph/instrumentation.d.ts.map +1 -0
  352. package/build/types/integrations/tracing/lrumemoizer.d.ts +19 -0
  353. package/build/types/integrations/tracing/lrumemoizer.d.ts.map +1 -0
  354. package/build/types/integrations/tracing/mongo.d.ts +24 -0
  355. package/build/types/integrations/tracing/mongo.d.ts.map +1 -0
  356. package/build/types/integrations/tracing/mongoose.d.ts +20 -0
  357. package/build/types/integrations/tracing/mongoose.d.ts.map +1 -0
  358. package/build/types/integrations/tracing/mysql.d.ts +20 -0
  359. package/build/types/integrations/tracing/mysql.d.ts.map +1 -0
  360. package/build/types/integrations/tracing/mysql2.d.ts +20 -0
  361. package/build/types/integrations/tracing/mysql2.d.ts.map +1 -0
  362. package/build/types/integrations/tracing/openai/index.d.ts +59 -0
  363. package/build/types/integrations/tracing/openai/index.d.ts.map +1 -0
  364. package/build/types/integrations/tracing/openai/instrumentation.d.ts +26 -0
  365. package/build/types/integrations/tracing/openai/instrumentation.d.ts.map +1 -0
  366. package/build/types/integrations/tracing/postgres.d.ts +24 -0
  367. package/build/types/integrations/tracing/postgres.d.ts.map +1 -0
  368. package/build/types/integrations/tracing/postgresjs.d.ts +101 -0
  369. package/build/types/integrations/tracing/postgresjs.d.ts.map +1 -0
  370. package/build/types/integrations/tracing/prisma/vendor/v5-tracing-helper.d.ts +38 -0
  371. package/build/types/integrations/tracing/prisma/vendor/v5-tracing-helper.d.ts.map +1 -0
  372. package/build/types/integrations/tracing/prisma/vendor/v6-tracing-helper.d.ts +31 -0
  373. package/build/types/integrations/tracing/prisma/vendor/v6-tracing-helper.d.ts.map +1 -0
  374. package/build/types/integrations/tracing/prisma.d.ts +50 -0
  375. package/build/types/integrations/tracing/prisma.d.ts.map +1 -0
  376. package/build/types/integrations/tracing/redis.d.ts +41 -0
  377. package/build/types/integrations/tracing/redis.d.ts.map +1 -0
  378. package/build/types/integrations/tracing/tedious.d.ts +20 -0
  379. package/build/types/integrations/tracing/tedious.d.ts.map +1 -0
  380. package/build/types/integrations/tracing/vercelai/constants.d.ts +2 -0
  381. package/build/types/integrations/tracing/vercelai/constants.d.ts.map +1 -0
  382. package/build/types/integrations/tracing/vercelai/index.d.ts +43 -0
  383. package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -0
  384. package/build/types/integrations/tracing/vercelai/instrumentation.d.ts +56 -0
  385. package/build/types/integrations/tracing/vercelai/instrumentation.d.ts.map +1 -0
  386. package/build/types/integrations/tracing/vercelai/types.d.ts +59 -0
  387. package/build/types/integrations/tracing/vercelai/types.d.ts.map +1 -0
  388. package/build/types/preload.d.ts +2 -0
  389. package/build/types/preload.d.ts.map +1 -0
  390. package/build/types/sdk/index.d.ts +18 -0
  391. package/build/types/sdk/index.d.ts.map +1 -0
  392. package/build/types/sdk/initOtel.d.ts +28 -0
  393. package/build/types/sdk/initOtel.d.ts.map +1 -0
  394. package/build/types/types.d.ts +89 -0
  395. package/build/types/types.d.ts.map +1 -0
  396. package/build/types/utils/redisCache.d.ts +16 -0
  397. package/build/types/utils/redisCache.d.ts.map +1 -0
  398. package/build/types-ts3.8/debug-build.d.ts +7 -0
  399. package/build/types-ts3.8/index.d.ts +42 -0
  400. package/build/types-ts3.8/init.d.ts +2 -0
  401. package/build/types-ts3.8/integrations/featureFlagShims/growthbook.d.ts +6 -0
  402. package/build/types-ts3.8/integrations/featureFlagShims/index.d.ts +6 -0
  403. package/build/types-ts3.8/integrations/featureFlagShims/launchDarkly.d.ts +10 -0
  404. package/build/types-ts3.8/integrations/featureFlagShims/openFeature.d.ts +23 -0
  405. package/build/types-ts3.8/integrations/featureFlagShims/statsig.d.ts +6 -0
  406. package/build/types-ts3.8/integrations/featureFlagShims/unleash.d.ts +6 -0
  407. package/build/types-ts3.8/integrations/fs.d.ts +24 -0
  408. package/build/types-ts3.8/integrations/http.d.ts +139 -0
  409. package/build/types-ts3.8/integrations/node-fetch.d.ts +36 -0
  410. package/build/types-ts3.8/integrations/tracing/amqplib.d.ts +20 -0
  411. package/build/types-ts3.8/integrations/tracing/anthropic-ai/index.d.ts +59 -0
  412. package/build/types-ts3.8/integrations/tracing/anthropic-ai/instrumentation.d.ts +19 -0
  413. package/build/types-ts3.8/integrations/tracing/connect.d.ts +46 -0
  414. package/build/types-ts3.8/integrations/tracing/dataloader.d.ts +20 -0
  415. package/build/types-ts3.8/integrations/tracing/express.d.ts +72 -0
  416. package/build/types-ts3.8/integrations/tracing/fastify/index.d.ts +119 -0
  417. package/build/types-ts3.8/integrations/tracing/fastify/types.d.ts +33 -0
  418. package/build/types-ts3.8/integrations/tracing/fastify/v3/constants.d.ts +3 -0
  419. package/build/types-ts3.8/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
  420. package/build/types-ts3.8/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
  421. package/build/types-ts3.8/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
  422. package/build/types-ts3.8/integrations/tracing/fastify/v3/types.d.ts +21 -0
  423. package/build/types-ts3.8/integrations/tracing/fastify/v3/utils.d.ts +28 -0
  424. package/build/types-ts3.8/integrations/tracing/firebase/firebase.d.ts +6 -0
  425. package/build/types-ts3.8/integrations/tracing/firebase/index.d.ts +2 -0
  426. package/build/types-ts3.8/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +19 -0
  427. package/build/types-ts3.8/integrations/tracing/firebase/otel/index.d.ts +3 -0
  428. package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/firestore.d.ts +25 -0
  429. package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/functions.d.ts +23 -0
  430. package/build/types-ts3.8/integrations/tracing/firebase/otel/types.d.ts +120 -0
  431. package/build/types-ts3.8/integrations/tracing/genericPool.d.ts +20 -0
  432. package/build/types-ts3.8/integrations/tracing/google-genai/index.d.ts +59 -0
  433. package/build/types-ts3.8/integrations/tracing/google-genai/instrumentation.d.ts +20 -0
  434. package/build/types-ts3.8/integrations/tracing/graphql.d.ts +48 -0
  435. package/build/types-ts3.8/integrations/tracing/hapi/index.d.ts +50 -0
  436. package/build/types-ts3.8/integrations/tracing/hapi/types.d.ts +166 -0
  437. package/build/types-ts3.8/integrations/tracing/hono/constants.d.ts +11 -0
  438. package/build/types-ts3.8/integrations/tracing/hono/index.d.ts +52 -0
  439. package/build/types-ts3.8/integrations/tracing/hono/instrumentation.d.ts +55 -0
  440. package/build/types-ts3.8/integrations/tracing/hono/types.d.ts +36 -0
  441. package/build/types-ts3.8/integrations/tracing/index.d.ts +12 -0
  442. package/build/types-ts3.8/integrations/tracing/kafka.d.ts +19 -0
  443. package/build/types-ts3.8/integrations/tracing/knex.d.ts +20 -0
  444. package/build/types-ts3.8/integrations/tracing/koa.d.ts +70 -0
  445. package/build/types-ts3.8/integrations/tracing/langchain/index.d.ts +97 -0
  446. package/build/types-ts3.8/integrations/tracing/langchain/instrumentation.d.ts +29 -0
  447. package/build/types-ts3.8/integrations/tracing/langgraph/index.d.ts +74 -0
  448. package/build/types-ts3.8/integrations/tracing/langgraph/instrumentation.d.ts +19 -0
  449. package/build/types-ts3.8/integrations/tracing/lrumemoizer.d.ts +19 -0
  450. package/build/types-ts3.8/integrations/tracing/mongo.d.ts +24 -0
  451. package/build/types-ts3.8/integrations/tracing/mongoose.d.ts +20 -0
  452. package/build/types-ts3.8/integrations/tracing/mysql.d.ts +20 -0
  453. package/build/types-ts3.8/integrations/tracing/mysql2.d.ts +20 -0
  454. package/build/types-ts3.8/integrations/tracing/openai/index.d.ts +59 -0
  455. package/build/types-ts3.8/integrations/tracing/openai/instrumentation.d.ts +26 -0
  456. package/build/types-ts3.8/integrations/tracing/postgres.d.ts +24 -0
  457. package/build/types-ts3.8/integrations/tracing/postgresjs.d.ts +101 -0
  458. package/build/types-ts3.8/integrations/tracing/prisma/vendor/v5-tracing-helper.d.ts +44 -0
  459. package/build/types-ts3.8/integrations/tracing/prisma/vendor/v6-tracing-helper.d.ts +34 -0
  460. package/build/types-ts3.8/integrations/tracing/prisma.d.ts +50 -0
  461. package/build/types-ts3.8/integrations/tracing/redis.d.ts +41 -0
  462. package/build/types-ts3.8/integrations/tracing/tedious.d.ts +20 -0
  463. package/build/types-ts3.8/integrations/tracing/vercelai/constants.d.ts +2 -0
  464. package/build/types-ts3.8/integrations/tracing/vercelai/index.d.ts +43 -0
  465. package/build/types-ts3.8/integrations/tracing/vercelai/instrumentation.d.ts +56 -0
  466. package/build/types-ts3.8/integrations/tracing/vercelai/types.d.ts +59 -0
  467. package/build/types-ts3.8/preload.d.ts +2 -0
  468. package/build/types-ts3.8/sdk/index.d.ts +18 -0
  469. package/build/types-ts3.8/sdk/initOtel.d.ts +31 -0
  470. package/build/types-ts3.8/types.d.ts +89 -0
  471. package/build/types-ts3.8/utils/redisCache.d.ts +16 -0
  472. package/changes.json +10 -0
  473. package/package.json +150 -0
@@ -0,0 +1,378 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const api = require('@opentelemetry/api');
4
+ const instrumentation = require('@opentelemetry/instrumentation');
5
+ const semanticConventions = require('@opentelemetry/semantic-conventions');
6
+ const core = require('@sentry/core');
7
+ const nodeCore = require('@sentry/node-core');
8
+ const debugBuild = require('../../debug-build.js');
9
+
10
+ // Instrumentation for https://github.com/porsager/postgres
11
+
12
+
13
+ const INTEGRATION_NAME = 'PostgresJs';
14
+ const SUPPORTED_VERSIONS = ['>=3.0.0 <4'];
15
+ const SQL_OPERATION_REGEX = /^(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER)/i;
16
+
17
+ // Marker to track if a query was created from an instrumented sql instance
18
+ // This prevents double-spanning when both wrapper and prototype patches are active
19
+ const QUERY_FROM_INSTRUMENTED_SQL = Symbol.for('sentry.query.from.instrumented.sql');
20
+
21
+ const instrumentPostgresJs = nodeCore.generateInstrumentOnce(
22
+ INTEGRATION_NAME,
23
+ (options) =>
24
+ new PostgresJsInstrumentation({
25
+ requireParentSpan: options?.requireParentSpan ?? true,
26
+ requestHook: options?.requestHook,
27
+ }),
28
+ );
29
+
30
+ /**
31
+ * Instrumentation for the [postgres](https://www.npmjs.com/package/postgres) library.
32
+ * This instrumentation captures postgresjs queries and their attributes.
33
+ *
34
+ * Uses internal Sentry patching patterns to support both CommonJS and ESM environments.
35
+ */
36
+ class PostgresJsInstrumentation extends instrumentation.InstrumentationBase {
37
+ constructor(config) {
38
+ super('sentry-postgres-js', core.SDK_VERSION, config);
39
+ }
40
+
41
+ /**
42
+ * Initializes the instrumentation by patching the postgres module.
43
+ * Uses two complementary approaches:
44
+ * 1. Main function wrapper: instruments sql instances created AFTER instrumentation is set up (CJS + ESM)
45
+ * 2. Query.prototype patch: fallback for sql instances created BEFORE instrumentation (CJS only)
46
+ */
47
+ init() {
48
+ const module = new instrumentation.InstrumentationNodeModuleDefinition(
49
+ 'postgres',
50
+ SUPPORTED_VERSIONS,
51
+ exports$1 => {
52
+ try {
53
+ return this._patchPostgres(exports$1);
54
+ } catch (e) {
55
+ debugBuild.DEBUG_BUILD && core.debug.error('Failed to patch postgres module:', e);
56
+ return exports$1;
57
+ }
58
+ },
59
+ exports$1 => exports$1,
60
+ );
61
+
62
+ // Add fallback Query.prototype patching for pre-existing sql instances (CJS only)
63
+ // This catches queries from sql instances created before Sentry was initialized
64
+ ['src', 'cf/src', 'cjs/src'].forEach(path => {
65
+ module.files.push(
66
+ new instrumentation.InstrumentationNodeModuleFile(
67
+ `postgres/${path}/query.js`,
68
+ SUPPORTED_VERSIONS,
69
+ this._patchQueryPrototype.bind(this),
70
+ this._unpatchQueryPrototype.bind(this),
71
+ ),
72
+ );
73
+ });
74
+
75
+ return module;
76
+ }
77
+
78
+ /**
79
+ * Patches the postgres module by wrapping the main export function.
80
+ * This intercepts the creation of sql instances and instruments them.
81
+ */
82
+ _patchPostgres(exports$1) {
83
+ // In CJS: exports is the function itself
84
+ // In ESM: exports.default is the function
85
+ const isFunction = typeof exports$1 === 'function';
86
+ const Original = isFunction ? exports$1 : exports$1.default;
87
+
88
+ if (typeof Original !== 'function') {
89
+ debugBuild.DEBUG_BUILD && core.debug.warn('postgres module does not export a function. Skipping instrumentation.');
90
+ return exports$1;
91
+ }
92
+
93
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
94
+ const self = this;
95
+
96
+ const WrappedPostgres = function ( ...args) {
97
+ const sql = Reflect.construct(Original , args);
98
+
99
+ // Validate that construction succeeded and returned a valid function object
100
+ if (!sql || typeof sql !== 'function') {
101
+ debugBuild.DEBUG_BUILD && core.debug.warn('postgres() did not return a valid instance');
102
+ return sql;
103
+ }
104
+
105
+ // Delegate to the portable instrumentation from @sentry/core
106
+ const config = self.getConfig();
107
+ return core.instrumentPostgresJsSql(sql, {
108
+ requireParentSpan: config.requireParentSpan,
109
+ requestHook: config.requestHook,
110
+ });
111
+ };
112
+
113
+ Object.setPrototypeOf(WrappedPostgres, Original);
114
+ Object.setPrototypeOf(WrappedPostgres.prototype, (Original ).prototype);
115
+
116
+ for (const key of Object.getOwnPropertyNames(Original)) {
117
+ if (!['length', 'name', 'prototype'].includes(key)) {
118
+ const descriptor = Object.getOwnPropertyDescriptor(Original, key);
119
+ if (descriptor) {
120
+ Object.defineProperty(WrappedPostgres, key, descriptor);
121
+ }
122
+ }
123
+ }
124
+
125
+ // For CJS: the exports object IS the function, so return the wrapped function
126
+ // For ESM: replace the default export
127
+ if (isFunction) {
128
+ return WrappedPostgres ;
129
+ } else {
130
+ core.replaceExports(exports$1, 'default', WrappedPostgres);
131
+ return exports$1;
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Determines whether a span should be created based on the current context.
137
+ * If `requireParentSpan` is set to true in the configuration, a span will
138
+ * only be created if there is a parent span available.
139
+ */
140
+ _shouldCreateSpans() {
141
+ const config = this.getConfig();
142
+ const hasParentSpan = api.trace.getSpan(api.context.active()) !== undefined;
143
+ return hasParentSpan || !config.requireParentSpan;
144
+ }
145
+
146
+ /**
147
+ * Extracts DB operation name from SQL query and sets it on the span.
148
+ */
149
+ _setOperationName(span, sanitizedQuery, command) {
150
+ if (command) {
151
+ span.setAttribute(semanticConventions.ATTR_DB_OPERATION_NAME, command);
152
+ return;
153
+ }
154
+ // Fallback: extract operation from the SQL query
155
+ const operationMatch = sanitizedQuery?.match(SQL_OPERATION_REGEX);
156
+ if (operationMatch?.[1]) {
157
+ span.setAttribute(semanticConventions.ATTR_DB_OPERATION_NAME, operationMatch[1].toUpperCase());
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Reconstructs the full SQL query from template strings with PostgreSQL placeholders.
163
+ *
164
+ * For sql`SELECT * FROM users WHERE id = ${123} AND name = ${'foo'}`:
165
+ * strings = ["SELECT * FROM users WHERE id = ", " AND name = ", ""]
166
+ * returns: "SELECT * FROM users WHERE id = $1 AND name = $2"
167
+ */
168
+ _reconstructQuery(strings) {
169
+ if (!strings?.length) {
170
+ return undefined;
171
+ }
172
+ if (strings.length === 1) {
173
+ return strings[0] || undefined;
174
+ }
175
+ // Join template parts with PostgreSQL placeholders ($1, $2, etc.)
176
+ return strings.reduce((acc, str, i) => (i === 0 ? str : `${acc}$${i}${str}`), '');
177
+ }
178
+
179
+ /**
180
+ * Sanitize SQL query as per the OTEL semantic conventions
181
+ * https://opentelemetry.io/docs/specs/semconv/database/database-spans/#sanitization-of-dbquerytext
182
+ *
183
+ * PostgreSQL $n placeholders are preserved per OTEL spec - they're parameterized queries,
184
+ * not sensitive literals. Only actual values (strings, numbers, booleans) are sanitized.
185
+ */
186
+ _sanitizeSqlQuery(sqlQuery) {
187
+ if (!sqlQuery) {
188
+ return 'Unknown SQL Query';
189
+ }
190
+
191
+ return (
192
+ sqlQuery
193
+ // Remove comments first (they may contain newlines and extra spaces)
194
+ .replace(/--.*$/gm, '') // Single line comments (multiline mode)
195
+ .replace(/\/\*[\s\S]*?\*\//g, '') // Multi-line comments
196
+ .replace(/;\s*$/, '') // Remove trailing semicolons
197
+ // Collapse whitespace to a single space (after removing comments)
198
+ .replace(/\s+/g, ' ')
199
+ .trim() // Remove extra spaces and trim
200
+ // Sanitize hex/binary literals before string literals
201
+ .replace(/\bX'[0-9A-Fa-f]*'/gi, '?') // Hex string literals
202
+ .replace(/\bB'[01]*'/gi, '?') // Binary string literals
203
+ // Sanitize string literals (handles escaped quotes)
204
+ .replace(/'(?:[^']|'')*'/g, '?')
205
+ // Sanitize hex numbers
206
+ .replace(/\b0x[0-9A-Fa-f]+/gi, '?')
207
+ // Sanitize boolean literals
208
+ .replace(/\b(?:TRUE|FALSE)\b/gi, '?')
209
+ // Sanitize numeric literals (preserve $n placeholders via negative lookbehind)
210
+ .replace(/-?\b\d+\.?\d*[eE][+-]?\d+\b/g, '?') // Scientific notation
211
+ .replace(/-?\b\d+\.\d+\b/g, '?') // Decimals
212
+ .replace(/-?\.\d+\b/g, '?') // Decimals starting with dot
213
+ .replace(/(?<!\$)-?\b\d+\b/g, '?') // Integers (NOT $n placeholders)
214
+ // Collapse IN clauses for cardinality (both ? and $n variants)
215
+ .replace(/\bIN\b\s*\(\s*\?(?:\s*,\s*\?)*\s*\)/gi, 'IN (?)')
216
+ .replace(/\bIN\b\s*\(\s*\$\d+(?:\s*,\s*\$\d+)*\s*\)/gi, 'IN ($?)')
217
+ );
218
+ }
219
+
220
+ /**
221
+ * Fallback patch for Query.prototype.handle to instrument queries from pre-existing sql instances.
222
+ * This catches queries from sql instances created BEFORE Sentry was initialized (CJS only).
223
+ *
224
+ * Note: Queries from pre-existing instances won't have connection context (database, host, port)
225
+ * because the sql instance wasn't created through our instrumented wrapper.
226
+ */
227
+ _patchQueryPrototype(moduleExports
228
+
229
+ ) {
230
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
231
+ const self = this;
232
+ const originalHandle = moduleExports.Query.prototype.handle;
233
+
234
+ moduleExports.Query.prototype.handle = async function (
235
+
236
+ ...args
237
+ ) {
238
+ // Skip if this query came from an instrumented sql instance (already handled by wrapper)
239
+ if ((this )[QUERY_FROM_INSTRUMENTED_SQL]) {
240
+ return originalHandle.apply(this, args);
241
+ }
242
+
243
+ // Skip if we shouldn't create spans
244
+ if (!self._shouldCreateSpans()) {
245
+ return originalHandle.apply(this, args);
246
+ }
247
+
248
+ const fullQuery = self._reconstructQuery(this.strings);
249
+ const sanitizedSqlQuery = self._sanitizeSqlQuery(fullQuery);
250
+
251
+ return core.startSpanManual(
252
+ {
253
+ name: sanitizedSqlQuery || 'postgresjs.query',
254
+ op: 'db',
255
+ },
256
+ (span) => {
257
+ nodeCore.addOriginToSpan(span, 'auto.db.postgresjs');
258
+
259
+ span.setAttributes({
260
+ [semanticConventions.ATTR_DB_SYSTEM_NAME]: 'postgres',
261
+ [semanticConventions.ATTR_DB_QUERY_TEXT]: sanitizedSqlQuery,
262
+ });
263
+
264
+ // Note: No connection context available for pre-existing instances
265
+ // because the sql instance wasn't created through our instrumented wrapper
266
+
267
+ const config = self.getConfig();
268
+ const { requestHook } = config;
269
+ if (requestHook) {
270
+ instrumentation.safeExecuteInTheMiddle(
271
+ () => requestHook(span, sanitizedSqlQuery, undefined),
272
+ e => {
273
+ if (e) {
274
+ span.setAttribute('sentry.hook.error', 'requestHook failed');
275
+ debugBuild.DEBUG_BUILD && core.debug.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, e);
276
+ }
277
+ },
278
+ true,
279
+ );
280
+ }
281
+
282
+ // Wrap resolve to end span on success
283
+ const originalResolve = this.resolve;
284
+ this.resolve = new Proxy(originalResolve , {
285
+ apply: (resolveTarget, resolveThisArg, resolveArgs) => {
286
+ try {
287
+ self._setOperationName(span, sanitizedSqlQuery, resolveArgs?.[0]?.command);
288
+ span.end();
289
+ } catch (e) {
290
+ debugBuild.DEBUG_BUILD && core.debug.error('Error ending span in resolve callback:', e);
291
+ }
292
+ return Reflect.apply(resolveTarget, resolveThisArg, resolveArgs);
293
+ },
294
+ });
295
+
296
+ // Wrap reject to end span on error
297
+ const originalReject = this.reject;
298
+ this.reject = new Proxy(originalReject , {
299
+ apply: (rejectTarget, rejectThisArg, rejectArgs) => {
300
+ try {
301
+ span.setStatus({
302
+ code: core.SPAN_STATUS_ERROR,
303
+ message: rejectArgs?.[0]?.message || 'unknown_error',
304
+ });
305
+ span.setAttribute(semanticConventions.ATTR_DB_RESPONSE_STATUS_CODE, rejectArgs?.[0]?.code || 'unknown');
306
+ span.setAttribute(semanticConventions.ATTR_ERROR_TYPE, rejectArgs?.[0]?.name || 'unknown');
307
+ self._setOperationName(span, sanitizedSqlQuery);
308
+ span.end();
309
+ } catch (e) {
310
+ debugBuild.DEBUG_BUILD && core.debug.error('Error ending span in reject callback:', e);
311
+ }
312
+ return Reflect.apply(rejectTarget, rejectThisArg, rejectArgs);
313
+ },
314
+ });
315
+
316
+ try {
317
+ return originalHandle.apply(this, args);
318
+ } catch (e) {
319
+ span.setStatus({
320
+ code: core.SPAN_STATUS_ERROR,
321
+ message: e instanceof Error ? e.message : 'unknown_error',
322
+ });
323
+ span.end();
324
+ throw e;
325
+ }
326
+ },
327
+ );
328
+ };
329
+
330
+ // Store original for unpatch - must be set on the NEW patched function
331
+ moduleExports.Query.prototype.handle.__sentry_original__ = originalHandle;
332
+
333
+ return moduleExports;
334
+ }
335
+
336
+ /**
337
+ * Restores the original Query.prototype.handle method.
338
+ */
339
+ _unpatchQueryPrototype(moduleExports
340
+
341
+ ) {
342
+ if (moduleExports.Query.prototype.handle.__sentry_original__) {
343
+ moduleExports.Query.prototype.handle = moduleExports.Query.prototype.handle.__sentry_original__;
344
+ }
345
+ return moduleExports;
346
+ }
347
+ }
348
+
349
+ const _postgresJsIntegration = ((options) => {
350
+ return {
351
+ name: INTEGRATION_NAME,
352
+ setupOnce() {
353
+ instrumentPostgresJs(options);
354
+ },
355
+ };
356
+ }) ;
357
+
358
+ /**
359
+ * Adds Sentry tracing instrumentation for the [postgres](https://www.npmjs.com/package/postgres) library.
360
+ *
361
+ * For more information, see the [`postgresIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/postgres/).
362
+ *
363
+ * @example
364
+ * ```javascript
365
+ * const Sentry = require('@sentry/node');
366
+ *
367
+ * Sentry.init({
368
+ * integrations: [Sentry.postgresJsIntegration()],
369
+ * });
370
+ * ```
371
+ */
372
+
373
+ const postgresJsIntegration = core.defineIntegration(_postgresJsIntegration);
374
+
375
+ exports.PostgresJsInstrumentation = PostgresJsInstrumentation;
376
+ exports.instrumentPostgresJs = instrumentPostgresJs;
377
+ exports.postgresJsIntegration = postgresJsIntegration;
378
+ //# sourceMappingURL=postgresjs.js.map
@@ -0,0 +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 InstrumentationNodeModuleFile,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\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 },\n ...args: unknown[]\n ): Promise<unknown> {\n // Skip if this query came from an instrumented sql instance (already handled by wrapper)\n if ((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","exports","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":";;;;;;;;;AAAA;;;AA8BA,MAAM,gBAAA,GAAmB,YAAY;AACrC,MAAM,kBAAA,GAAqB,CAAC,YAAY,CAAC;AACzC,MAAM,mBAAA,GAAsB,mDAAmD;;AAQ/E;AACA;AACA,MAAM,8BAA8B,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC;;AAiB7E,MAAM,oBAAA,GAAuBA,+BAAsB;AAC1D,EAAE,gBAAgB;AAClB,EAAE,CAAC,OAAO;AACV,IAAI,IAAI,yBAAyB,CAAC;AAClC,MAAM,iBAAiB,EAAE,OAAO,EAAE,iBAAA,IAAqB,IAAI;AAC3D,MAAM,WAAW,EAAE,OAAO,EAAE,WAAW;AACvC,KAAK,CAAC;AACN;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,SAAkCC,mCAAmB,CAAkC;AACpG,GAAS,WAAW,CAAC,MAAM,EAAmC;AAC9D,IAAI,KAAK,CAAC,oBAAoB,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACpD,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,GA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,IAAA,IAAA,EAAA,gBAAA;AACA,IAAA,SAAA,GAAA;AACA,MAAA,oBAAA,CAAA,OAAA,CAAA;AACA,IAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAA,qBAAA,GAAAG,sBAAA,CAAA,sBAAA;;;;;;"}
@@ -0,0 +1,203 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const api = require('@opentelemetry/api');
4
+ const instrumentation = require('@prisma/instrumentation');
5
+ const core = require('@sentry/core');
6
+ const nodeCore = require('@sentry/node-core');
7
+
8
+ const INTEGRATION_NAME = 'Prisma';
9
+
10
+ function isPrismaV6TracingHelper(helper) {
11
+ return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;
12
+ }
13
+
14
+ function getPrismaTracingHelper() {
15
+ const prismaInstrumentationObject = (globalThis ).PRISMA_INSTRUMENTATION;
16
+ const prismaTracingHelper =
17
+ prismaInstrumentationObject &&
18
+ typeof prismaInstrumentationObject === 'object' &&
19
+ 'helper' in prismaInstrumentationObject
20
+ ? prismaInstrumentationObject.helper
21
+ : undefined;
22
+
23
+ return prismaTracingHelper;
24
+ }
25
+
26
+ class SentryPrismaInteropInstrumentation extends instrumentation.PrismaInstrumentation {
27
+ constructor(options) {
28
+ super(options?.instrumentationConfig);
29
+ }
30
+
31
+ enable() {
32
+ super.enable();
33
+
34
+ // 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.
35
+ // 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.
36
+ const prismaTracingHelper = getPrismaTracingHelper();
37
+
38
+ if (isPrismaV6TracingHelper(prismaTracingHelper)) {
39
+ // Inspired & adjusted from https://github.com/prisma/prisma/tree/5.22.0/packages/instrumentation
40
+ (prismaTracingHelper ).createEngineSpan = (
41
+ engineSpanEvent,
42
+ ) => {
43
+ const tracer = api.trace.getTracer('prismaV5Compatibility') ;
44
+
45
+ // Prisma v5 relies on being able to create spans with a specific span & trace ID
46
+ // this is no longer possible in OTEL v2, there is no public API to do this anymore
47
+ // So in order to kind of hack this possibility, we rely on the internal `_idGenerator` property
48
+ // This is used to generate the random IDs, and we overwrite this temporarily to generate static IDs
49
+ // This is flawed and may not work, e.g. if the code is bundled and the private property is renamed
50
+ // in such cases, these spans will not be captured and some Prisma spans will be missing
51
+ const initialIdGenerator = tracer._idGenerator;
52
+
53
+ if (!initialIdGenerator) {
54
+ core.consoleSandbox(() => {
55
+ // eslint-disable-next-line no-console
56
+ console.warn(
57
+ '[Sentry] Could not find _idGenerator on tracer, skipping Prisma v5 compatibility - some Prisma spans may be missing!',
58
+ );
59
+ });
60
+
61
+ return;
62
+ }
63
+
64
+ try {
65
+ engineSpanEvent.spans.forEach(engineSpan => {
66
+ const kind = engineSpanKindToOTELSpanKind(engineSpan.kind);
67
+
68
+ const parentSpanId = engineSpan.parent_span_id;
69
+ const spanId = engineSpan.span_id;
70
+ const traceId = engineSpan.trace_id;
71
+
72
+ const links = engineSpan.links?.map(link => {
73
+ return {
74
+ context: {
75
+ traceId: link.trace_id,
76
+ spanId: link.span_id,
77
+ traceFlags: api.TraceFlags.SAMPLED,
78
+ },
79
+ };
80
+ });
81
+
82
+ const ctx = api.trace.setSpanContext(api.context.active(), {
83
+ traceId,
84
+ spanId: parentSpanId,
85
+ traceFlags: api.TraceFlags.SAMPLED,
86
+ });
87
+
88
+ api.context.with(ctx, () => {
89
+ const temporaryIdGenerator = {
90
+ generateTraceId: () => {
91
+ return traceId;
92
+ },
93
+ generateSpanId: () => {
94
+ return spanId;
95
+ },
96
+ };
97
+
98
+ tracer._idGenerator = temporaryIdGenerator;
99
+
100
+ const span = tracer.startSpan(engineSpan.name, {
101
+ kind,
102
+ links,
103
+ startTime: engineSpan.start_time,
104
+ attributes: engineSpan.attributes,
105
+ });
106
+
107
+ span.end(engineSpan.end_time);
108
+
109
+ tracer._idGenerator = initialIdGenerator;
110
+ });
111
+ });
112
+ } finally {
113
+ // Ensure we always restore this at the end, even if something errors
114
+ tracer._idGenerator = initialIdGenerator;
115
+ }
116
+ };
117
+ }
118
+ }
119
+ }
120
+
121
+ function engineSpanKindToOTELSpanKind(engineSpanKind) {
122
+ switch (engineSpanKind) {
123
+ case 'client':
124
+ return api.SpanKind.CLIENT;
125
+ case 'internal':
126
+ default: // Other span kinds aren't currently supported
127
+ return api.SpanKind.INTERNAL;
128
+ }
129
+ }
130
+
131
+ const instrumentPrisma = nodeCore.generateInstrumentOnce(INTEGRATION_NAME, options => {
132
+ return new SentryPrismaInteropInstrumentation(options);
133
+ });
134
+
135
+ /**
136
+ * Adds Sentry tracing instrumentation for the [prisma](https://www.npmjs.com/package/prisma) library.
137
+ * For more information, see the [`prismaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/).
138
+ *
139
+ * NOTE: By default, this integration works with Prisma version 6.
140
+ * To get performance instrumentation for other Prisma versions,
141
+ * 1. Install the `@prisma/instrumentation` package with the desired version.
142
+ * 1. Pass a `new PrismaInstrumentation()` instance as exported from `@prisma/instrumentation` to the `prismaInstrumentation` option of this integration:
143
+ *
144
+ * ```js
145
+ * import { PrismaInstrumentation } from '@prisma/instrumentation'
146
+ *
147
+ * Sentry.init({
148
+ * integrations: [
149
+ * prismaIntegration({
150
+ * // Override the default instrumentation that Sentry uses
151
+ * prismaInstrumentation: new PrismaInstrumentation()
152
+ * })
153
+ * ]
154
+ * })
155
+ * ```
156
+ *
157
+ * 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.
158
+ * 1. Depending on your Prisma version (prior to version 6), add `previewFeatures = ["tracing"]` to the client generator block of your Prisma schema:
159
+ *
160
+ * ```
161
+ * generator client {
162
+ * provider = "prisma-client-js"
163
+ * previewFeatures = ["tracing"]
164
+ * }
165
+ * ```
166
+ */
167
+ const prismaIntegration = core.defineIntegration((options) => {
168
+ return {
169
+ name: INTEGRATION_NAME,
170
+ setupOnce() {
171
+ instrumentPrisma(options);
172
+ },
173
+ setup(client) {
174
+ // If no tracing helper exists, we skip any work here
175
+ // this means that prisma is not being used
176
+ if (!getPrismaTracingHelper()) {
177
+ return;
178
+ }
179
+
180
+ client.on('spanStart', span => {
181
+ const spanJSON = core.spanToJSON(span);
182
+ if (spanJSON.description?.startsWith('prisma:')) {
183
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.prisma');
184
+ }
185
+
186
+ // Make sure we use the query text as the span name, for ex. SELECT * FROM "User" WHERE "id" = $1
187
+ if (spanJSON.description === 'prisma:engine:db_query' && spanJSON.data['db.query.text']) {
188
+ span.updateName(spanJSON.data['db.query.text'] );
189
+ }
190
+
191
+ // In Prisma v5.22+, the `db.system` attribute is automatically set
192
+ // On older versions, this is missing, so we add it here
193
+ if (spanJSON.description === 'prisma:engine:db_query' && !spanJSON.data['db.system']) {
194
+ span.setAttribute('db.system', 'prisma');
195
+ }
196
+ });
197
+ },
198
+ };
199
+ });
200
+
201
+ exports.instrumentPrisma = instrumentPrisma;
202
+ exports.prismaIntegration = prismaIntegration;
203
+ //# sourceMappingURL=prisma.js.map