@sentry/cloudflare 11.0.0-alpha.1 → 11.0.0-alpha.2

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 (339) hide show
  1. package/build/cjs/dev/baseSdk.js +20 -8
  2. package/build/cjs/dev/baseSdk.js.map +1 -1
  3. package/build/cjs/dev/client.js +116 -24
  4. package/build/cjs/dev/client.js.map +1 -1
  5. package/build/cjs/dev/clientCache.js +15 -0
  6. package/build/cjs/dev/clientCache.js.map +1 -0
  7. package/build/cjs/dev/defineCloudflareOptions.js.map +1 -1
  8. package/build/cjs/dev/durableobject.js +24 -8
  9. package/build/cjs/dev/durableobject.js.map +1 -1
  10. package/build/cjs/dev/flush.js +6 -4
  11. package/build/cjs/dev/flush.js.map +1 -1
  12. package/build/cjs/dev/index.js +3 -3
  13. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  14. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  15. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  16. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  17. package/build/cjs/dev/instrumentations/worker/instrumentD1.js +5 -1
  18. package/build/cjs/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  19. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js +4 -2
  20. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  21. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js +5 -5
  22. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  23. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js +8 -8
  24. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  25. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js +4 -2
  26. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  27. package/build/cjs/dev/instrumentations/worker/instrumentR2.js +21 -18
  28. package/build/cjs/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  29. package/build/cjs/dev/instrumentations/worker/instrumentRateLimit.js +6 -1
  30. package/build/cjs/dev/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  31. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js +4 -2
  32. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  33. package/build/cjs/dev/instrumentations/worker/instrumentTail.js +2 -0
  34. package/build/cjs/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  35. package/build/cjs/dev/integrations/fetch.js +1 -11
  36. package/build/cjs/dev/integrations/fetch.js.map +1 -1
  37. package/build/cjs/dev/opentelemetry/tracer.js +2 -40
  38. package/build/cjs/dev/opentelemetry/tracer.js.map +1 -1
  39. package/build/cjs/dev/pages-plugin.js +2 -2
  40. package/build/cjs/dev/pages-plugin.js.map +1 -1
  41. package/build/cjs/dev/request.js +2 -123
  42. package/build/cjs/dev/request.js.map +1 -1
  43. package/build/cjs/dev/sdk.js +12 -6
  44. package/build/cjs/dev/sdk.js.map +1 -1
  45. package/build/cjs/dev/transport.js +1 -1
  46. package/build/cjs/dev/transport.js.map +1 -1
  47. package/build/cjs/dev/utils/invocationContext.js +41 -0
  48. package/build/cjs/dev/utils/invocationContext.js.map +1 -0
  49. package/build/cjs/dev/utils/invocationScope.js +7 -2
  50. package/build/cjs/dev/utils/invocationScope.js.map +1 -1
  51. package/build/cjs/dev/utils/rpcPropagation.js +15 -0
  52. package/build/cjs/dev/utils/rpcPropagation.js.map +1 -0
  53. package/build/cjs/dev/vite/autoInstrument.js +2 -1
  54. package/build/cjs/dev/vite/autoInstrument.js.map +1 -1
  55. package/build/cjs/dev/vite/index.js.map +1 -1
  56. package/build/cjs/dev/vite/transform.js +30 -5
  57. package/build/cjs/dev/vite/transform.js.map +1 -1
  58. package/build/cjs/dev/vite/wranglerConfig.js +21 -1
  59. package/build/cjs/dev/vite/wranglerConfig.js.map +1 -1
  60. package/build/cjs/dev/withSentry.js.map +1 -1
  61. package/build/cjs/dev/workflows.js +45 -33
  62. package/build/cjs/dev/workflows.js.map +1 -1
  63. package/build/cjs/dev/wrapMethodWithSentry.js +51 -15
  64. package/build/cjs/dev/wrapMethodWithSentry.js.map +1 -1
  65. package/build/cjs/dev/wrapRequestHandlerWithInit.js +133 -0
  66. package/build/cjs/dev/wrapRequestHandlerWithInit.js.map +1 -0
  67. package/build/cjs/prod/baseSdk.js +20 -8
  68. package/build/cjs/prod/baseSdk.js.map +1 -1
  69. package/build/cjs/prod/client.js +116 -24
  70. package/build/cjs/prod/client.js.map +1 -1
  71. package/build/cjs/prod/clientCache.js +15 -0
  72. package/build/cjs/prod/clientCache.js.map +1 -0
  73. package/build/cjs/prod/defineCloudflareOptions.js.map +1 -1
  74. package/build/cjs/prod/durableobject.js +24 -8
  75. package/build/cjs/prod/durableobject.js.map +1 -1
  76. package/build/cjs/prod/flush.js +6 -4
  77. package/build/cjs/prod/flush.js.map +1 -1
  78. package/build/cjs/prod/index.js +3 -3
  79. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  80. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  81. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  82. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  83. package/build/cjs/prod/instrumentations/worker/instrumentD1.js +5 -1
  84. package/build/cjs/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  85. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js +4 -2
  86. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  87. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js +5 -5
  88. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  89. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js +8 -8
  90. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  91. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js +4 -2
  92. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  93. package/build/cjs/prod/instrumentations/worker/instrumentR2.js +21 -18
  94. package/build/cjs/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  95. package/build/cjs/prod/instrumentations/worker/instrumentRateLimit.js +6 -1
  96. package/build/cjs/prod/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  97. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js +4 -2
  98. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  99. package/build/cjs/prod/instrumentations/worker/instrumentTail.js +2 -0
  100. package/build/cjs/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  101. package/build/cjs/prod/integrations/fetch.js +1 -11
  102. package/build/cjs/prod/integrations/fetch.js.map +1 -1
  103. package/build/cjs/prod/opentelemetry/tracer.js +2 -40
  104. package/build/cjs/prod/opentelemetry/tracer.js.map +1 -1
  105. package/build/cjs/prod/pages-plugin.js +2 -2
  106. package/build/cjs/prod/pages-plugin.js.map +1 -1
  107. package/build/cjs/prod/request.js +2 -123
  108. package/build/cjs/prod/request.js.map +1 -1
  109. package/build/cjs/prod/sdk.js +12 -6
  110. package/build/cjs/prod/sdk.js.map +1 -1
  111. package/build/cjs/prod/transport.js +1 -1
  112. package/build/cjs/prod/transport.js.map +1 -1
  113. package/build/cjs/prod/utils/invocationContext.js +41 -0
  114. package/build/cjs/prod/utils/invocationContext.js.map +1 -0
  115. package/build/cjs/prod/utils/invocationScope.js +7 -2
  116. package/build/cjs/prod/utils/invocationScope.js.map +1 -1
  117. package/build/cjs/prod/utils/rpcPropagation.js +15 -0
  118. package/build/cjs/prod/utils/rpcPropagation.js.map +1 -0
  119. package/build/cjs/prod/vite/autoInstrument.js +2 -1
  120. package/build/cjs/prod/vite/autoInstrument.js.map +1 -1
  121. package/build/cjs/prod/vite/index.js.map +1 -1
  122. package/build/cjs/prod/vite/transform.js +30 -5
  123. package/build/cjs/prod/vite/transform.js.map +1 -1
  124. package/build/cjs/prod/vite/wranglerConfig.js +21 -1
  125. package/build/cjs/prod/vite/wranglerConfig.js.map +1 -1
  126. package/build/cjs/prod/withSentry.js.map +1 -1
  127. package/build/cjs/prod/workflows.js +45 -33
  128. package/build/cjs/prod/workflows.js.map +1 -1
  129. package/build/cjs/prod/wrapMethodWithSentry.js +51 -15
  130. package/build/cjs/prod/wrapMethodWithSentry.js.map +1 -1
  131. package/build/cjs/prod/wrapRequestHandlerWithInit.js +133 -0
  132. package/build/cjs/prod/wrapRequestHandlerWithInit.js.map +1 -0
  133. package/build/esm/dev/baseSdk.js +21 -9
  134. package/build/esm/dev/baseSdk.js.map +1 -1
  135. package/build/esm/dev/client.js +117 -25
  136. package/build/esm/dev/client.js.map +1 -1
  137. package/build/esm/dev/clientCache.js +12 -0
  138. package/build/esm/dev/clientCache.js.map +1 -0
  139. package/build/esm/dev/defineCloudflareOptions.js.map +1 -1
  140. package/build/esm/dev/durableobject.js +23 -7
  141. package/build/esm/dev/durableobject.js.map +1 -1
  142. package/build/esm/dev/flush.js +6 -4
  143. package/build/esm/dev/flush.js.map +1 -1
  144. package/build/esm/dev/index.js +3 -4
  145. package/build/esm/dev/index.js.map +1 -1
  146. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  147. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  148. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  149. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  150. package/build/esm/dev/instrumentations/worker/instrumentD1.js +6 -2
  151. package/build/esm/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  152. package/build/esm/dev/instrumentations/worker/instrumentEmail.js +7 -5
  153. package/build/esm/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  154. package/build/esm/dev/instrumentations/worker/instrumentEnv.js +5 -5
  155. package/build/esm/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  156. package/build/esm/dev/instrumentations/worker/instrumentFetch.js +1 -1
  157. package/build/esm/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  158. package/build/esm/dev/instrumentations/worker/instrumentQueue.js +7 -5
  159. package/build/esm/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  160. package/build/esm/dev/instrumentations/worker/instrumentR2.js +22 -19
  161. package/build/esm/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  162. package/build/esm/dev/instrumentations/worker/instrumentRateLimit.js +6 -1
  163. package/build/esm/dev/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  164. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js +7 -5
  165. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  166. package/build/esm/dev/instrumentations/worker/instrumentTail.js +2 -0
  167. package/build/esm/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  168. package/build/esm/dev/integrations/fetch.js +2 -12
  169. package/build/esm/dev/integrations/fetch.js.map +1 -1
  170. package/build/esm/dev/opentelemetry/tracer.js +2 -40
  171. package/build/esm/dev/opentelemetry/tracer.js.map +1 -1
  172. package/build/esm/dev/package.json +1 -1
  173. package/build/esm/dev/pages-plugin.js +1 -1
  174. package/build/esm/dev/pages-plugin.js.map +1 -1
  175. package/build/esm/dev/request.js +2 -122
  176. package/build/esm/dev/request.js.map +1 -1
  177. package/build/esm/dev/sdk.js +12 -7
  178. package/build/esm/dev/sdk.js.map +1 -1
  179. package/build/esm/dev/transport.js +1 -1
  180. package/build/esm/dev/transport.js.map +1 -1
  181. package/build/esm/dev/utils/invocationContext.js +37 -0
  182. package/build/esm/dev/utils/invocationContext.js.map +1 -0
  183. package/build/esm/dev/utils/invocationScope.js +7 -2
  184. package/build/esm/dev/utils/invocationScope.js.map +1 -1
  185. package/build/esm/dev/utils/rpcPropagation.js +13 -0
  186. package/build/esm/dev/utils/rpcPropagation.js.map +1 -0
  187. package/build/esm/dev/utils/traceLinks.js +1 -1
  188. package/build/esm/dev/vite/autoInstrument.js +2 -1
  189. package/build/esm/dev/vite/autoInstrument.js.map +1 -1
  190. package/build/esm/dev/vite/index.js.map +1 -1
  191. package/build/esm/dev/vite/transform.js +30 -5
  192. package/build/esm/dev/vite/transform.js.map +1 -1
  193. package/build/esm/dev/vite/wranglerConfig.js +21 -2
  194. package/build/esm/dev/vite/wranglerConfig.js.map +1 -1
  195. package/build/esm/dev/withSentry.js.map +1 -1
  196. package/build/esm/dev/workflows.js +48 -36
  197. package/build/esm/dev/workflows.js.map +1 -1
  198. package/build/esm/dev/wrapMethodWithSentry.js +53 -17
  199. package/build/esm/dev/wrapMethodWithSentry.js.map +1 -1
  200. package/build/esm/dev/wrapRequestHandlerWithInit.js +131 -0
  201. package/build/esm/dev/wrapRequestHandlerWithInit.js.map +1 -0
  202. package/build/esm/prod/baseSdk.js +21 -9
  203. package/build/esm/prod/baseSdk.js.map +1 -1
  204. package/build/esm/prod/client.js +117 -25
  205. package/build/esm/prod/client.js.map +1 -1
  206. package/build/esm/prod/clientCache.js +12 -0
  207. package/build/esm/prod/clientCache.js.map +1 -0
  208. package/build/esm/prod/defineCloudflareOptions.js.map +1 -1
  209. package/build/esm/prod/durableobject.js +23 -7
  210. package/build/esm/prod/durableobject.js.map +1 -1
  211. package/build/esm/prod/flush.js +6 -4
  212. package/build/esm/prod/flush.js.map +1 -1
  213. package/build/esm/prod/index.js +3 -4
  214. package/build/esm/prod/index.js.map +1 -1
  215. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  216. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  217. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  218. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  219. package/build/esm/prod/instrumentations/worker/instrumentD1.js +6 -2
  220. package/build/esm/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  221. package/build/esm/prod/instrumentations/worker/instrumentEmail.js +7 -5
  222. package/build/esm/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  223. package/build/esm/prod/instrumentations/worker/instrumentEnv.js +5 -5
  224. package/build/esm/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  225. package/build/esm/prod/instrumentations/worker/instrumentFetch.js +1 -1
  226. package/build/esm/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  227. package/build/esm/prod/instrumentations/worker/instrumentQueue.js +7 -5
  228. package/build/esm/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  229. package/build/esm/prod/instrumentations/worker/instrumentR2.js +22 -19
  230. package/build/esm/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  231. package/build/esm/prod/instrumentations/worker/instrumentRateLimit.js +6 -1
  232. package/build/esm/prod/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  233. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js +7 -5
  234. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  235. package/build/esm/prod/instrumentations/worker/instrumentTail.js +2 -0
  236. package/build/esm/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  237. package/build/esm/prod/integrations/fetch.js +2 -12
  238. package/build/esm/prod/integrations/fetch.js.map +1 -1
  239. package/build/esm/prod/opentelemetry/tracer.js +2 -40
  240. package/build/esm/prod/opentelemetry/tracer.js.map +1 -1
  241. package/build/esm/prod/package.json +1 -1
  242. package/build/esm/prod/pages-plugin.js +1 -1
  243. package/build/esm/prod/pages-plugin.js.map +1 -1
  244. package/build/esm/prod/request.js +2 -122
  245. package/build/esm/prod/request.js.map +1 -1
  246. package/build/esm/prod/sdk.js +12 -7
  247. package/build/esm/prod/sdk.js.map +1 -1
  248. package/build/esm/prod/transport.js +1 -1
  249. package/build/esm/prod/transport.js.map +1 -1
  250. package/build/esm/prod/utils/invocationContext.js +37 -0
  251. package/build/esm/prod/utils/invocationContext.js.map +1 -0
  252. package/build/esm/prod/utils/invocationScope.js +7 -2
  253. package/build/esm/prod/utils/invocationScope.js.map +1 -1
  254. package/build/esm/prod/utils/rpcPropagation.js +13 -0
  255. package/build/esm/prod/utils/rpcPropagation.js.map +1 -0
  256. package/build/esm/prod/utils/traceLinks.js +1 -1
  257. package/build/esm/prod/vite/autoInstrument.js +2 -1
  258. package/build/esm/prod/vite/autoInstrument.js.map +1 -1
  259. package/build/esm/prod/vite/index.js.map +1 -1
  260. package/build/esm/prod/vite/transform.js +30 -5
  261. package/build/esm/prod/vite/transform.js.map +1 -1
  262. package/build/esm/prod/vite/wranglerConfig.js +21 -2
  263. package/build/esm/prod/vite/wranglerConfig.js.map +1 -1
  264. package/build/esm/prod/withSentry.js.map +1 -1
  265. package/build/esm/prod/workflows.js +48 -36
  266. package/build/esm/prod/workflows.js.map +1 -1
  267. package/build/esm/prod/wrapMethodWithSentry.js +53 -17
  268. package/build/esm/prod/wrapMethodWithSentry.js.map +1 -1
  269. package/build/esm/prod/wrapRequestHandlerWithInit.js +131 -0
  270. package/build/esm/prod/wrapRequestHandlerWithInit.js.map +1 -0
  271. package/build/types/baseSdk.d.ts +8 -0
  272. package/build/types/baseSdk.d.ts.map +1 -1
  273. package/build/types/client.d.ts +90 -17
  274. package/build/types/client.d.ts.map +1 -1
  275. package/build/types/clientCache.d.ts +8 -0
  276. package/build/types/clientCache.d.ts.map +1 -0
  277. package/build/types/defineCloudflareOptions.d.ts +3 -2
  278. package/build/types/defineCloudflareOptions.d.ts.map +1 -1
  279. package/build/types/durableobject.d.ts +5 -7
  280. package/build/types/durableobject.d.ts.map +1 -1
  281. package/build/types/flush.d.ts +2 -0
  282. package/build/types/flush.d.ts.map +1 -1
  283. package/build/types/index.d.ts +3 -4
  284. package/build/types/index.d.ts.map +1 -1
  285. package/build/types/instrumentations/instrumentDurableObjectNamespace.d.ts +2 -1
  286. package/build/types/instrumentations/instrumentDurableObjectNamespace.d.ts.map +1 -1
  287. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts +2 -3
  288. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts.map +1 -1
  289. package/build/types/instrumentations/worker/instrumentD1.d.ts.map +1 -1
  290. package/build/types/instrumentations/worker/instrumentEmail.d.ts.map +1 -1
  291. package/build/types/instrumentations/worker/instrumentEnv.d.ts.map +1 -1
  292. package/build/types/instrumentations/worker/instrumentQueue.d.ts.map +1 -1
  293. package/build/types/instrumentations/worker/instrumentR2.d.ts.map +1 -1
  294. package/build/types/instrumentations/worker/instrumentRateLimit.d.ts.map +1 -1
  295. package/build/types/instrumentations/worker/instrumentScheduled.d.ts.map +1 -1
  296. package/build/types/instrumentations/worker/instrumentTail.d.ts.map +1 -1
  297. package/build/types/integrations/fetch.d.ts.map +1 -1
  298. package/build/types/opentelemetry/tracer.d.ts.map +1 -1
  299. package/build/types/pages-plugin.d.ts +3 -1
  300. package/build/types/pages-plugin.d.ts.map +1 -1
  301. package/build/types/request.d.ts +5 -31
  302. package/build/types/request.d.ts.map +1 -1
  303. package/build/types/sdk.d.ts +13 -4
  304. package/build/types/sdk.d.ts.map +1 -1
  305. package/build/types/transport.d.ts.map +1 -1
  306. package/build/types/types.d.ts +28 -0
  307. package/build/types/types.d.ts.map +1 -1
  308. package/build/types/utils/invocationContext.d.ts +58 -0
  309. package/build/types/utils/invocationContext.d.ts.map +1 -0
  310. package/build/types/utils/invocationScope.d.ts +2 -1
  311. package/build/types/utils/invocationScope.d.ts.map +1 -1
  312. package/build/types/utils/rpcPropagation.d.ts +10 -0
  313. package/build/types/utils/rpcPropagation.d.ts.map +1 -0
  314. package/build/types/vite/autoInstrument.d.ts.map +1 -1
  315. package/build/types/vite/index.d.ts +4 -0
  316. package/build/types/vite/index.d.ts.map +1 -1
  317. package/build/types/vite/transform.d.ts +3 -0
  318. package/build/types/vite/transform.d.ts.map +1 -1
  319. package/build/types/vite/wranglerConfig.d.ts +13 -0
  320. package/build/types/vite/wranglerConfig.d.ts.map +1 -1
  321. package/build/types/withSentry.d.ts +2 -3
  322. package/build/types/withSentry.d.ts.map +1 -1
  323. package/build/types/workflows.d.ts +3 -3
  324. package/build/types/workflows.d.ts.map +1 -1
  325. package/build/types/wrapMethodWithSentry.d.ts +6 -1
  326. package/build/types/wrapMethodWithSentry.d.ts.map +1 -1
  327. package/build/types/wrapRequestHandlerWithInit.d.ts +31 -0
  328. package/build/types/wrapRequestHandlerWithInit.d.ts.map +1 -0
  329. package/package.json +6 -4
  330. package/build/cjs/dev/integrations/tracing/vercelai.js +0 -18
  331. package/build/cjs/dev/integrations/tracing/vercelai.js.map +0 -1
  332. package/build/cjs/prod/integrations/tracing/vercelai.js +0 -18
  333. package/build/cjs/prod/integrations/tracing/vercelai.js.map +0 -1
  334. package/build/esm/dev/integrations/tracing/vercelai.js +0 -16
  335. package/build/esm/dev/integrations/tracing/vercelai.js.map +0 -1
  336. package/build/esm/prod/integrations/tracing/vercelai.js +0 -16
  337. package/build/esm/prod/integrations/tracing/vercelai.js.map +0 -1
  338. package/build/types/integrations/tracing/vercelai.d.ts +0 -39
  339. package/build/types/integrations/tracing/vercelai.d.ts.map +0 -1
@@ -4,6 +4,7 @@ const core = require('@sentry/core');
4
4
  const flush = require('./flush.js');
5
5
  const instrument = require('./instrument.js');
6
6
  const sdk = require('./sdk.js');
7
+ const invocationContext = require('./utils/invocationContext.js');
7
8
  const invocationScope = require('./utils/invocationScope.js');
8
9
  const rpcMeta = require('./utils/rpcMeta.js');
9
10
  const traceLinks = require('./utils/traceLinks.js');
@@ -33,9 +34,11 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
33
34
  args = extracted.args;
34
35
  rpcMeta$1 = extracted.rpcMeta;
35
36
  }
37
+ const spanName = typeof wrapperOptions.spanName === "function" ? wrapperOptions.spanName(rpcMeta$1) : wrapperOptions.spanName;
36
38
  const wrappedFunction = (scope) => {
37
39
  const context = wrapperOptions.context;
38
- const waitUntil = context ? flush.getOriginalWaitUntil(context)?.bind(context) : void 0;
40
+ const invocationState = invocationContext.getInvocationState();
41
+ const waitUntil = invocationState ? invocationContext.getInvocationWaitUntil(invocationState) : context ? flush.getOriginalWaitUntil(context)?.bind(context) : void 0;
39
42
  const storage = resolveOriginalStorage(context, thisArg);
40
43
  let scopeClient = scope.getClient();
41
44
  if (startNewTrace || !scopeClient?.getTransport()) {
@@ -47,7 +50,7 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
47
50
  scopeClient = client;
48
51
  }
49
52
  const clientToDispose = scopeClient;
50
- const methodName = wrapperOptions.spanName || "unknown";
53
+ const methodName = spanName || "unknown";
51
54
  const teardown = async () => {
52
55
  if (startNewTrace && storage) {
53
56
  traceLinks.storeSpanContext(storage, methodName);
@@ -58,17 +61,23 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
58
61
  waitUntil?.(teardown());
59
62
  return res;
60
63
  };
61
- const onRejected = (e) => {
64
+ const captureAndRethrow = (e) => {
62
65
  core.captureException(e, {
63
66
  mechanism: {
64
67
  type: origin,
65
68
  handled: false
66
69
  }
67
70
  });
68
- waitUntil?.(teardown());
69
71
  throw e;
70
72
  };
71
- if (!wrapperOptions.spanName) {
73
+ const onRejected = (e) => {
74
+ try {
75
+ return captureAndRethrow(e);
76
+ } finally {
77
+ waitUntil?.(teardown());
78
+ }
79
+ };
80
+ if (!spanName) {
72
81
  try {
73
82
  if (callback) {
74
83
  callback(...args);
@@ -103,27 +112,54 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
103
112
  try {
104
113
  const result = Reflect.apply(target, thisArg, args);
105
114
  if (core.isThenable(result)) {
106
- return result.then(onFulfilled, onRejected);
107
- } else {
108
- return onFulfilled(result);
115
+ return result.then(void 0, captureAndRethrow);
109
116
  }
117
+ return result;
110
118
  } catch (e) {
111
- return onRejected(e);
119
+ return captureAndRethrow(e);
112
120
  }
113
121
  });
114
122
  };
123
+ const runWithTeardown = (run) => {
124
+ let out;
125
+ try {
126
+ out = run();
127
+ } catch (e) {
128
+ waitUntil?.(teardown());
129
+ throw e;
130
+ }
131
+ if (core.isThenable(out)) {
132
+ return out.then(
133
+ (res) => {
134
+ waitUntil?.(teardown());
135
+ return res;
136
+ },
137
+ (e) => {
138
+ waitUntil?.(teardown());
139
+ throw e;
140
+ }
141
+ );
142
+ }
143
+ waitUntil?.(teardown());
144
+ return out;
145
+ };
115
146
  if (rpcMeta$1) {
116
- return core.continueTrace(
117
- { sentryTrace: rpcMeta$1["sentry-trace"] || "", baggage: rpcMeta$1.baggage || "" },
118
- executeSpan
147
+ return runWithTeardown(
148
+ () => core.continueTrace(
149
+ { sentryTrace: rpcMeta$1["sentry-trace"] || "", baggage: rpcMeta$1.baggage || "" },
150
+ executeSpan
151
+ )
119
152
  );
120
153
  }
121
154
  if (startNewTrace) {
122
- return core.startNewTrace(() => executeSpan());
155
+ return runWithTeardown(() => core.startNewTrace(() => executeSpan()));
123
156
  }
124
- return executeSpan();
157
+ return runWithTeardown(executeSpan);
125
158
  };
126
- return invocationScope.withInvocationIsolationScope(wrappedFunction);
159
+ return invocationScope.withInvocationIsolationScope(
160
+ wrappedFunction,
161
+ wrapperOptions.context
162
+ );
127
163
  }
128
164
  }),
129
165
  noMark
@@ -1 +1 @@
1
- {"version":3,"file":"wrapMethodWithSentry.js","sources":["../../../src/wrapMethodWithSentry.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport type { SerializedTraceData } from '@sentry/core';\nimport {\n isObjectLike,\n captureException,\n continueTrace,\n isThenable,\n type Scope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startNewTrace as startNewTraceCore,\n startSpan,\n} from '@sentry/core';\nimport type { CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { ensureInstrumented } from './instrument';\nimport { init } from './sdk';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\nimport { extractRpcMeta } from './utils/rpcMeta';\nimport { buildSpanLinks, getStoredSpanContext, storeSpanContext } from './utils/traceLinks';\n\n/** Extended DurableObjectState with originalStorage exposed by instrumentContext */\nexport interface InstrumentedDurableObjectState extends DurableObjectState {\n originalStorage?: DurableObjectStorage;\n}\n\n/**\n * Resolves uninstrumented DO storage for the current invocation.\n * Prefer `thisArg.ctx` (the live Durable Object instance) over the context captured at\n * construction time to avoid cross-DO I/O errors in the same isolate.\n */\nfunction resolveOriginalStorage(\n context: ExecutionContext | InstrumentedDurableObjectState | undefined,\n thisArg: unknown,\n): DurableObjectStorage | undefined {\n if (isObjectLike(thisArg) && 'ctx' in thisArg) {\n const doCtx = (thisArg as { ctx: InstrumentedDurableObjectState }).ctx;\n if (doCtx?.originalStorage) {\n return doCtx.originalStorage;\n }\n }\n\n if (context && 'originalStorage' in context && context.originalStorage) {\n return context.originalStorage;\n }\n\n return undefined;\n}\n\ntype MethodWrapperOptions = {\n spanName?: string;\n spanOp?: string;\n options: CloudflareOptions;\n context: ExecutionContext | InstrumentedDurableObjectState;\n /**\n * If true, starts a fresh trace instead of inheriting from a parent trace.\n * Useful for scheduled/independent invocations like alarms.\n *\n * If true, it also stores the current span context and links to the previous invocation's span.\n * Uses Durable Object storage to persist the link. The link is set asynchronously via `span.addLinks()`\n * in a `waitUntil` to avoid blocking.\n *\n * @default false\n */\n startNewTrace?: boolean;\n /**\n * The trace origin identifying which instrumentation created the span, e.g. `auto.faas.cloudflare.durable_object`.\n * Used both as the span's `sentry.origin` attribute and as the `mechanism.type` for captured exceptions.\n */\n origin: string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type UncheckedMethod = (...args: any[]) => any;\ntype OriginalMethod = UncheckedMethod;\n\n/**\n * Wraps a method with Sentry error tracking and optional tracing.\n * Supports starting new traces and linking to previous invocations via Durable Object storage.\n *\n * @param wrapperOptions - The options for the wrapper.\n * @param handler - The method to wrap.\n * @param callback - The callback to call.\n * @param noMark - Whether to mark the method as instrumented.\n * @returns The wrapped method.\n */\nexport function wrapMethodWithSentry<T extends OriginalMethod>(\n wrapperOptions: MethodWrapperOptions,\n handler: T,\n callback?: (...args: Parameters<T>) => void,\n noMark?: true,\n): T {\n return ensureInstrumented(\n handler,\n original =>\n new Proxy(original, {\n apply(target, thisArg, rawArgs: Parameters<T>) {\n const { startNewTrace, origin } = wrapperOptions;\n\n // For RPC methods, extract Sentry trace context from the trailing argument.\n // The caller side (instrumentDurableObjectStub / JSRPC proxy) appends it;\n // we strip it here so the user's method never sees it.\n let args = rawArgs;\n let rpcMeta: SerializedTraceData | undefined;\n\n if (wrapperOptions.spanOp === 'rpc') {\n const extracted = extractRpcMeta(rawArgs);\n args = extracted.args;\n rpcMeta = extracted.rpcMeta;\n }\n\n const wrappedFunction = (scope: Scope): unknown | Promise<unknown> => {\n // In certain situations, the passed context can become undefined.\n // For example, for Astro while prerendering pages at build time.\n // see: https://github.com/getsentry/sentry-javascript/issues/13217\n const context: typeof wrapperOptions.context | undefined = wrapperOptions.context;\n\n // see: https://github.com/getsentry/sentry-javascript/issues/22328\n const waitUntil = context\n ? getOriginalWaitUntil(context as ExecutionContextCompat)?.bind(context)\n : undefined;\n const storage = resolveOriginalStorage(context, thisArg);\n\n let scopeClient = scope.getClient();\n // Check if client exists AND is still usable (transport not disposed)\n // This handles the case where a previous handler disposed the client\n // but the scope still holds a reference to it (e.g., alarm handlers in Durable Objects)\n // For startNewTrace, always create a fresh client\n if (startNewTrace || !scopeClient?.getTransport()) {\n const client = init({\n ...wrapperOptions.options,\n ctx: context as unknown as ExecutionContext | undefined,\n });\n scope.setClient(client);\n scopeClient = client;\n }\n\n const clientToDispose = scopeClient;\n const methodName = wrapperOptions.spanName || 'unknown';\n\n const teardown = async (): Promise<void> => {\n if (startNewTrace && storage) {\n storeSpanContext(storage, methodName);\n }\n await flushAndDispose(clientToDispose);\n };\n\n const onFulfilled = (res: unknown) => {\n waitUntil?.(teardown());\n return res;\n };\n\n const onRejected = (e: unknown) => {\n captureException(e, {\n mechanism: {\n type: origin,\n handled: false,\n },\n });\n waitUntil?.(teardown());\n throw e;\n };\n\n if (!wrapperOptions.spanName) {\n try {\n if (callback) {\n callback(...args);\n }\n\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(onFulfilled, onRejected);\n } else {\n return onFulfilled(result);\n }\n } catch (e) {\n return onRejected(e);\n }\n }\n\n const attributes = wrapperOptions.spanOp\n ? {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,\n }\n : {};\n\n const executeSpan = (): unknown => {\n return startSpan({ name: methodName, attributes }, span => {\n if (startNewTrace && storage) {\n const storedContext = getStoredSpanContext(storage, methodName);\n\n if (storedContext) {\n span.addLinks(buildSpanLinks(storedContext));\n // TODO: Remove this once EAP can store span links. We currently only set this attribute so that we\n // can obtain the previous trace information from the EAP store. Long-term, EAP will handle\n // span links and then we should remove this again. Also throwing in a TODO(v11), to remind us\n // to check this at v11 time :)\n const sampledFlag = storedContext.sampled ? '1' : '0';\n span.setAttribute(\n 'sentry.previous_trace',\n `${storedContext.traceId}-${storedContext.spanId}-${sampledFlag}`,\n );\n }\n }\n\n try {\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(onFulfilled, onRejected);\n } else {\n return onFulfilled(result);\n }\n } catch (e) {\n return onRejected(e);\n }\n });\n };\n\n if (rpcMeta) {\n return continueTrace(\n { sentryTrace: rpcMeta['sentry-trace'] || '', baggage: rpcMeta.baggage || '' },\n executeSpan,\n );\n }\n\n if (startNewTrace) {\n return startNewTraceCore(() => executeSpan());\n }\n\n return executeSpan();\n };\n\n return withInvocationIsolationScope(wrappedFunction);\n },\n }),\n noMark,\n );\n}\n"],"names":["isObjectLike","ensureInstrumented","rpcMeta","extractRpcMeta","getOriginalWaitUntil","init","storeSpanContext","flushAndDispose","captureException","isThenable","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMAN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A,CAAW,MAAM,CAAA,EAAG;AACtB,kBAAA,OAAO,MAAA,CAAO,IAAA,CAAK,WAAA,EAAa,UAAU,CAAA;AAAA,gBAC5C,CAAA,MAAO;AACL,kBAAA,OAAO,YAAY,MAAM,CAAA;AAAA,gBAC3B;AAAA,cACF,SAAS,CAAA,EAAG;AACV,gBAAA,OAAO,WAAW,CAAC,CAAA;AAAA,cACrB;AAAA,YACF,CAAC,CAAA;AAAA,UACH,CAAA;AAEA,UAAA,IAAIP,SAAA,EAAS;AACX,YAAA,OAAOa,kBAAA;AAAA,cACL,EAAE,aAAab,SAAA,CAAQ,cAAc,KAAK,EAAA,EAAI,OAAA,EAASA,SAAA,CAAQ,OAAA,IAAW,EAAA,EAAG;AAAA,cAC7E;AAAA,aACF;AAAA,UACF;AAEA,UAAA,IAAI,aAAA,EAAe;AACjB,YAAA,OAAOc,kBAAA,CAAkB,MAAM,WAAA,EAAa,CAAA;AAAA,UAC9C;AAEA,UAAA,OAAO,WAAA,EAAY;AAAA,QACrB,CAAA;AAEA,QAAA,OAAOC,6CAA6B,eAAe,CAAA;AAAA,MACrD;AAAA,KACD,CAAA;AAAA,IACH;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"wrapMethodWithSentry.js","sources":["../../../src/wrapMethodWithSentry.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport type { SerializedTraceData } from '@sentry/core';\nimport {\n isObjectLike,\n captureException,\n continueTrace,\n isThenable,\n type Scope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startNewTrace as startNewTraceCore,\n startSpan,\n} from '@sentry/core';\nimport type { CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { ensureInstrumented } from './instrument';\nimport { init } from './sdk';\nimport { getInvocationState, getInvocationWaitUntil } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\nimport { extractRpcMeta } from './utils/rpcMeta';\nimport { buildSpanLinks, getStoredSpanContext, storeSpanContext } from './utils/traceLinks';\n\n/** Extended DurableObjectState with originalStorage exposed by instrumentContext */\nexport interface InstrumentedDurableObjectState extends DurableObjectState {\n originalStorage?: DurableObjectStorage;\n}\n\n/**\n * Resolves uninstrumented DO storage for the current invocation.\n * Prefer `thisArg.ctx` (the live Durable Object instance) over the context captured at\n * construction time to avoid cross-DO I/O errors in the same isolate.\n */\nfunction resolveOriginalStorage(\n context: ExecutionContext | InstrumentedDurableObjectState | undefined,\n thisArg: unknown,\n): DurableObjectStorage | undefined {\n if (isObjectLike(thisArg) && 'ctx' in thisArg) {\n const doCtx = (thisArg as { ctx: InstrumentedDurableObjectState }).ctx;\n if (doCtx?.originalStorage) {\n return doCtx.originalStorage;\n }\n }\n\n if (context && 'originalStorage' in context && context.originalStorage) {\n return context.originalStorage;\n }\n\n return undefined;\n}\n\ntype MethodWrapperOptions = {\n /**\n * The span name, or a resolver called with the RPC metadata of the current call.\n * Returning `undefined` skips the span and only captures errors.\n */\n spanName?: string | ((rpcMeta: SerializedTraceData | undefined) => string | undefined);\n spanOp?: string;\n options: CloudflareOptions;\n context: ExecutionContext | InstrumentedDurableObjectState;\n /**\n * If true, starts a fresh trace instead of inheriting from a parent trace.\n * Useful for scheduled/independent invocations like alarms.\n *\n * If true, it also stores the current span context and links to the previous invocation's span.\n * Uses Durable Object storage to persist the link. The link is set asynchronously via `span.addLinks()`\n * in a `waitUntil` to avoid blocking.\n *\n * @default false\n */\n startNewTrace?: boolean;\n /**\n * The trace origin identifying which instrumentation created the span, e.g. `auto.faas.cloudflare.durable_object`.\n * Used both as the span's `sentry.origin` attribute and as the `mechanism.type` for captured exceptions.\n */\n origin: string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type UncheckedMethod = (...args: any[]) => any;\ntype OriginalMethod = UncheckedMethod;\n\n/**\n * Wraps a method with Sentry error tracking and optional tracing.\n * Supports starting new traces and linking to previous invocations via Durable Object storage.\n *\n * @param wrapperOptions - The options for the wrapper.\n * @param handler - The method to wrap.\n * @param callback - The callback to call.\n * @param noMark - Whether to mark the method as instrumented.\n * @returns The wrapped method.\n */\nexport function wrapMethodWithSentry<T extends OriginalMethod>(\n wrapperOptions: MethodWrapperOptions,\n handler: T,\n callback?: (...args: Parameters<T>) => void,\n noMark?: true,\n): T {\n return ensureInstrumented(\n handler,\n original =>\n new Proxy(original, {\n apply(target, thisArg, rawArgs: Parameters<T>) {\n const { startNewTrace, origin } = wrapperOptions;\n\n // For RPC methods, extract Sentry trace context from the trailing argument.\n // The caller side (instrumentDurableObjectStub / JSRPC proxy) appends it;\n // we strip it here so the user's method never sees it.\n let args = rawArgs;\n let rpcMeta: SerializedTraceData | undefined;\n\n if (wrapperOptions.spanOp === 'rpc') {\n const extracted = extractRpcMeta(rawArgs);\n args = extracted.args;\n rpcMeta = extracted.rpcMeta;\n }\n\n const spanName =\n typeof wrapperOptions.spanName === 'function' ? wrapperOptions.spanName(rpcMeta) : wrapperOptions.spanName;\n\n const wrappedFunction = (scope: Scope): unknown | Promise<unknown> => {\n // In certain situations, the passed context can become undefined.\n // For example, for Astro while prerendering pages at build time.\n // see: https://github.com/getsentry/sentry-javascript/issues/13217\n const context: typeof wrapperOptions.context | undefined = wrapperOptions.context;\n\n // see: https://github.com/getsentry/sentry-javascript/issues/22328\n // Resolved once per invocation and cached on its state: reading `ctx.waitUntil`\n // on a native context is a runtime getter call.\n const invocationState = getInvocationState();\n const waitUntil = invocationState\n ? getInvocationWaitUntil(invocationState)\n : context\n ? getOriginalWaitUntil(context as ExecutionContextCompat)?.bind(context)\n : undefined;\n const storage = resolveOriginalStorage(context, thisArg);\n\n let scopeClient = scope.getClient();\n // Re-init when the scope has no usable client (a previous handler disposed it, e.g.\n // DO alarm handlers) or for `startNewTrace`, so the client points at this\n // invocation's context. With `cacheClient: true` `init()` returns the isolate's\n // cached client and only creates (and caches) a fresh one when nothing is cached yet;\n // `cacheClient: false` creates one per invocation.\n if (startNewTrace || !scopeClient?.getTransport()) {\n const client = init({\n ...wrapperOptions.options,\n ctx: context as unknown as ExecutionContext | undefined,\n });\n scope.setClient(client);\n scopeClient = client;\n }\n\n const clientToDispose = scopeClient;\n const methodName = spanName || 'unknown';\n\n const teardown = async (): Promise<void> => {\n if (startNewTrace && storage) {\n storeSpanContext(storage, methodName);\n }\n await flushAndDispose(clientToDispose);\n };\n\n const onFulfilled = (res: unknown) => {\n waitUntil?.(teardown());\n return res;\n };\n\n const captureAndRethrow = (e: unknown): never => {\n captureException(e, {\n mechanism: {\n type: origin,\n handled: false,\n },\n });\n throw e;\n };\n\n const onRejected = (e: unknown) => {\n try {\n return captureAndRethrow(e);\n } finally {\n waitUntil?.(teardown());\n }\n };\n\n if (!spanName) {\n try {\n if (callback) {\n callback(...args);\n }\n\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(onFulfilled, onRejected);\n } else {\n return onFulfilled(result);\n }\n } catch (e) {\n return onRejected(e);\n }\n }\n\n const attributes = wrapperOptions.spanOp\n ? {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,\n }\n : {};\n\n const executeSpan = (): unknown => {\n return startSpan({ name: methodName, attributes }, span => {\n if (startNewTrace && storage) {\n const storedContext = getStoredSpanContext(storage, methodName);\n\n if (storedContext) {\n span.addLinks(buildSpanLinks(storedContext));\n // TODO: Remove this once EAP can store span links. We currently only set this attribute so that we\n // can obtain the previous trace information from the EAP store. Long-term, EAP will handle\n // span links and then we should remove this again. Also throwing in a TODO(v11), to remind us\n // to check this at v11 time :)\n const sampledFlag = storedContext.sampled ? '1' : '0';\n span.setAttribute(\n 'sentry.previous_trace',\n `${storedContext.traceId}-${storedContext.spanId}-${sampledFlag}`,\n );\n }\n }\n\n try {\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(undefined, captureAndRethrow);\n }\n return result;\n } catch (e) {\n return captureAndRethrow(e);\n }\n });\n };\n\n // The boundary flush (teardown) must run after the method span has ended, so the\n // span is in the buffer when that flush drains it. Running it inside the span\n // callback (before `startSpan` ends the span) would leave the span for the eager\n // path and cost a second flush per invocation.\n const runWithTeardown = (run: () => unknown): unknown => {\n let out: unknown;\n try {\n out = run();\n } catch (e) {\n // Synchronous throw: `startSpan` already ended the span and rethrew.\n waitUntil?.(teardown());\n throw e;\n }\n if (isThenable(out)) {\n return out.then(\n res => {\n waitUntil?.(teardown());\n return res;\n },\n e => {\n waitUntil?.(teardown());\n throw e;\n },\n );\n }\n waitUntil?.(teardown());\n return out;\n };\n\n if (rpcMeta) {\n return runWithTeardown(() =>\n continueTrace(\n { sentryTrace: rpcMeta['sentry-trace'] || '', baggage: rpcMeta.baggage || '' },\n executeSpan,\n ),\n );\n }\n\n if (startNewTrace) {\n return runWithTeardown(() => startNewTraceCore(() => executeSpan()));\n }\n\n return runWithTeardown(executeSpan);\n };\n\n return withInvocationIsolationScope(\n wrappedFunction,\n wrapperOptions.context as ExecutionContextCompat | undefined,\n );\n },\n }),\n noMark,\n );\n}\n"],"names":["isObjectLike","ensureInstrumented","rpcMeta","extractRpcMeta","getInvocationState","getInvocationWaitUntil","getOriginalWaitUntil","init","storeSpanContext","flushAndDispose","captureException","isThenable","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","getStoredSpanContext","buildSpanLinks","continueTrace","startNewTraceCore","withInvocationIsolationScope"],"mappings":";;;;;;;;;;;AAiCA,SAAS,sBAAA,CACP,SACA,OAAA,EACkC;AAClC,EAAA,IAAIA,iBAAA,CAAa,OAAO,CAAA,IAAK,KAAA,IAAS,OAAA,EAAS;AAC7C,IAAA,MAAM,QAAS,OAAA,CAAoD,GAAA;AACnE,IAAA,IAAI,OAAO,eAAA,EAAiB;AAC1B,MAAA,OAAO,K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WAAA,EAAa,CAAC,CAAA;AAAA,UACrE;AAEA,UAAA,OAAO,gBAAgB,WAAW,CAAA;AAAA,QACpC,CAAA;AAEA,QAAA,OAAOC,4CAAA;AAAA,UACL,eAAA;AAAA,UACA,cAAA,CAAe;AAAA,SACjB;AAAA,MACF;AAAA,KACD,CAAA;AAAA,IACH;AAAA,GACF;AACF;;;;"}
@@ -0,0 +1,133 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const attributes = require('@sentry/conventions/attributes');
4
+ const core = require('@sentry/core');
5
+ const httpServer = require('./integrations/httpServer.js');
6
+ const flush = require('./flush.js');
7
+ const scopeUtils = require('./scope-utils.js');
8
+ const invocationContext = require('./utils/invocationContext.js');
9
+ const invocationScope = require('./utils/invocationScope.js');
10
+ const streaming = require('./utils/streaming.js');
11
+
12
+ function getRequestErrorMechanismType(context) {
13
+ return context && "storage" in context ? "auto.faas.cloudflare.durable_object" : "auto.http.cloudflare";
14
+ }
15
+ function wrapRequestHandlerWithInit(wrapperOptions, handler, initSdk) {
16
+ return invocationScope.withInvocationIsolationScope(async (isolationScope) => {
17
+ const { options, request, captureErrors = true } = wrapperOptions;
18
+ const context = wrapperOptions.context;
19
+ const invocationState = invocationContext.getInvocationState();
20
+ const waitUntil = invocationState ? invocationContext.getInvocationWaitUntil(invocationState) : context ? flush.getOriginalWaitUntil(context).bind(context) : void 0;
21
+ const errorMechanismType = getRequestErrorMechanismType(context);
22
+ const client = initSdk({ ...options, ctx: context });
23
+ isolationScope.setClient(client);
24
+ const urlObject = core.parseStringToURLObject(request.url);
25
+ const [rawName, attributes$1] = core.getHttpSpanDetailsFromUrlObject(
26
+ urlObject,
27
+ "server",
28
+ "auto.http.cloudflare",
29
+ request,
30
+ void 0,
31
+ client
32
+ );
33
+ const name = attributes$1[attributes.SENTRY_SEGMENT_NAME_SOURCE] === "route" || !client || !core.hasSpanStreamingEnabled(client) ? rawName : request.method?.toUpperCase() || core.HTTP_SPAN_NAME_FALLBACK;
34
+ const contentLength = request.headers.get("content-length");
35
+ if (contentLength) {
36
+ attributes$1["http.request.body.size"] = parseInt(contentLength, 10);
37
+ }
38
+ const userAgentHeader = request.headers.get("user-agent");
39
+ if (userAgentHeader) {
40
+ attributes$1["user_agent.original"] = userAgentHeader;
41
+ }
42
+ if (client) {
43
+ Object.assign(
44
+ attributes$1,
45
+ core.httpHeadersToSpanAttributes(core.winterCGHeadersToDict(request.headers), client.getDataCollectionOptions())
46
+ );
47
+ }
48
+ attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] = "http.server";
49
+ scopeUtils.addCloudResourceContext(isolationScope);
50
+ scopeUtils.addRequest(isolationScope, request);
51
+ if (request.cf) {
52
+ scopeUtils.addCultureContext(isolationScope, request.cf);
53
+ if (typeof request.cf.httpProtocol === "string") {
54
+ const [protocolName, protocolVersion] = request.cf.httpProtocol.toLowerCase().split("/");
55
+ attributes$1[attributes.NETWORK_PROTOCOL_NAME] = protocolName;
56
+ attributes$1[attributes.NETWORK_PROTOCOL_VERSION] = protocolVersion;
57
+ }
58
+ }
59
+ if (request.method === "OPTIONS" || request.method === "HEAD") {
60
+ try {
61
+ return await handler();
62
+ } catch (e) {
63
+ if (captureErrors) {
64
+ core.captureException(e, { mechanism: { handled: false, type: errorMechanismType } });
65
+ }
66
+ throw e;
67
+ } finally {
68
+ waitUntil?.(flush.flushAndDispose(client));
69
+ }
70
+ }
71
+ if (client) {
72
+ await httpServer.captureIncomingRequestBody(client, request);
73
+ }
74
+ return core.continueTrace(
75
+ { sentryTrace: request.headers.get("sentry-trace") || "", baggage: request.headers.get("baggage") },
76
+ () => {
77
+ return core.startSpanManual({ name, attributes: attributes$1 }, async (span) => {
78
+ let res;
79
+ try {
80
+ res = await handler();
81
+ core.setHttpStatus(span, res.status);
82
+ } catch (e) {
83
+ span.end();
84
+ if (captureErrors) {
85
+ core.captureException(e, { mechanism: { handled: false, type: errorMechanismType } });
86
+ }
87
+ waitUntil?.(flush.flushAndDispose(client));
88
+ throw e;
89
+ }
90
+ const classification = streaming.classifyResponseStreaming(res);
91
+ if (classification.isStreaming && res.body) {
92
+ try {
93
+ let ended = false;
94
+ const endSpanOnce = () => {
95
+ if (ended) return;
96
+ ended = true;
97
+ span.end();
98
+ waitUntil?.(flush.flushAndDispose(client));
99
+ };
100
+ const transform = new TransformStream({
101
+ flush() {
102
+ endSpanOnce();
103
+ },
104
+ cancel() {
105
+ endSpanOnce();
106
+ }
107
+ });
108
+ return new Response(res.body.pipeThrough(transform), {
109
+ status: res.status,
110
+ statusText: res.statusText,
111
+ headers: res.headers
112
+ });
113
+ } catch {
114
+ span.end();
115
+ waitUntil?.(flush.flushAndDispose(client));
116
+ return res;
117
+ }
118
+ }
119
+ span.end();
120
+ if (res.status === 101) {
121
+ waitUntil?.(client?.flush(2e3));
122
+ } else {
123
+ waitUntil?.(flush.flushAndDispose(client));
124
+ }
125
+ return res;
126
+ });
127
+ }
128
+ );
129
+ }, wrapperOptions.context);
130
+ }
131
+
132
+ exports.wrapRequestHandlerWithInit = wrapRequestHandlerWithInit;
133
+ //# sourceMappingURL=wrapRequestHandlerWithInit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapRequestHandlerWithInit.js","sources":["../../../src/wrapRequestHandlerWithInit.ts"],"sourcesContent":["import type { CfProperties, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport {\n NETWORK_PROTOCOL_NAME,\n NETWORK_PROTOCOL_VERSION,\n SENTRY_SEGMENT_NAME_SOURCE,\n} from '@sentry/conventions/attributes';\nimport {\n captureException,\n continueTrace,\n getHttpSpanDetailsFromUrlObject,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n setHttpStatus,\n startSpanManual,\n winterCGHeadersToDict,\n} from '@sentry/core';\nimport { captureIncomingRequestBody } from './integrations/httpServer';\nimport type { CloudflareClient, CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { addCloudResourceContext, addCultureContext, addRequest } from './scope-utils';\nimport { getInvocationState, getInvocationWaitUntil } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\nimport { classifyResponseStreaming } from './utils/streaming';\n\nfunction getRequestErrorMechanismType(context: ExecutionContextCompat | undefined): string {\n // Durable Object fetch handlers use DO state as context (see instrumentDurableObjectWithSentry)\n return context && 'storage' in context ? 'auto.faas.cloudflare.durable_object' : 'auto.http.cloudflare';\n}\n\nexport interface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown> | CfProperties<unknown>>;\n context: ExecutionContextCompat | undefined;\n /**\n * If true, errors will be captured, rethrown and sent to Sentry.\n * Otherwise, errors are rethrown but not captured.\n *\n * You most likely don't want to set this to `false`, if you use `wrapRequestHandler` directly.\n * This is primarily meant as an escape hatch for higher-level SDKs relying on additional error\n * capturing mechanisms where this wrapper captures errors too early or too generally.\n *\n * @default true\n */\n captureErrors?: boolean;\n}\n\ntype InitSdk = (options: CloudflareOptions) => CloudflareClient | undefined;\n\n/**\n * Same as {@link wrapRequestHandler}, but with the SDK initialization injected.\n *\n * Wrappers that are only reachable from the main entry point — where `nodejs_compat` is a\n * requirement anyway — pass `init` from `sdk.ts` to get the full default integrations.\n *\n * @internal\n */\nexport function wrapRequestHandlerWithInit(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n initSdk: InitSdk,\n): Promise<Response> {\n return withInvocationIsolationScope(async isolationScope => {\n const { options, request, captureErrors = true } = wrapperOptions;\n const context = wrapperOptions.context;\n\n // The un-instrumented waitUntil, so flushAndDispose cannot deadlock on the flush\n // lock's own wrapper. Resolved once per invocation and cached on its state; reading\n // `ctx.waitUntil` on a native context is a runtime getter call.\n const invocationState = getInvocationState();\n const waitUntil = invocationState\n ? getInvocationWaitUntil(invocationState)\n : context\n ? getOriginalWaitUntil(context).bind(context)\n : undefined;\n const errorMechanismType = getRequestErrorMechanismType(context);\n\n const client = initSdk({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n const urlObject = parseStringToURLObject(request.url);\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n 'auto.http.cloudflare',\n request,\n undefined,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !client || !hasSpanStreamingEnabled(client)\n ? rawName\n : request.method?.toUpperCase() || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes['http.request.body.size'] = parseInt(contentLength, 10);\n }\n\n const userAgentHeader = request.headers.get('user-agent');\n if (userAgentHeader) {\n attributes['user_agent.original'] = userAgentHeader;\n }\n\n if (client) {\n Object.assign(\n attributes,\n httpHeadersToSpanAttributes(winterCGHeadersToDict(request.headers), client.getDataCollectionOptions()),\n );\n }\n\n attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server';\n\n addCloudResourceContext(isolationScope);\n addRequest(isolationScope, request);\n if (request.cf) {\n addCultureContext(isolationScope, request.cf);\n\n if (typeof request.cf.httpProtocol === 'string') {\n const [protocolName, protocolVersion] = request.cf.httpProtocol.toLowerCase().split('/');\n attributes[NETWORK_PROTOCOL_NAME] = protocolName;\n attributes[NETWORK_PROTOCOL_VERSION] = protocolVersion;\n }\n }\n\n // Do not capture spans for OPTIONS and HEAD requests\n if (request.method === 'OPTIONS' || request.method === 'HEAD') {\n try {\n return await handler();\n } catch (e) {\n if (captureErrors) {\n captureException(e, { mechanism: { handled: false, type: errorMechanismType } });\n }\n throw e;\n } finally {\n waitUntil?.(flushAndDispose(client));\n }\n }\n\n if (client) {\n await captureIncomingRequestBody(client, request);\n }\n\n return continueTrace(\n { sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },\n () => {\n // Note: This span will not have a duration unless I/O happens in the handler. This is\n // because of how the cloudflare workers runtime works.\n // See: https://developers.cloudflare.com/workers/runtime-apis/performance/\n\n // Use startSpanManual to control when span ends (needed for streaming responses)\n return startSpanManual({ name, attributes }, async span => {\n let res: Response;\n\n try {\n res = await handler();\n setHttpStatus(span, res.status);\n\n // After the handler runs, the span name might have been updated by nested instrumentation\n // (e.g., Remix parameterizing routes). The span should already have the correct name\n // from that instrumentation, so we don't need to do anything here.\n } catch (e) {\n span.end();\n if (captureErrors) {\n captureException(e, { mechanism: { handled: false, type: errorMechanismType } });\n }\n waitUntil?.(flushAndDispose(client));\n throw e;\n }\n\n // Classify response to detect actual streaming\n const classification = classifyResponseStreaming(res);\n\n if (classification.isStreaming && res.body) {\n try {\n let ended = false;\n\n const endSpanOnce = (): void => {\n if (ended) return;\n\n ended = true;\n span.end();\n waitUntil?.(flushAndDispose(client));\n };\n\n const transform = new TransformStream({\n flush() {\n // Source stream completed normally.\n endSpanOnce();\n },\n cancel() {\n // Client disconnected (or downstream cancelled). The `cancel`\n // is being called while the response is still considered\n // active, so this is a safe place to end the span.\n endSpanOnce();\n },\n });\n\n return new Response(res.body.pipeThrough(transform), {\n status: res.status,\n statusText: res.statusText,\n headers: res.headers,\n });\n } catch {\n span.end();\n waitUntil?.(flushAndDispose(client));\n return res;\n }\n }\n\n // Non-streaming response - end span immediately and return original\n span.end();\n\n // Don't dispose for protocol upgrades (101 Switching Protocols) - the connection stays alive.\n // This includes WebSocket upgrades where webSocketMessage/webSocketClose handlers\n // will still be called and may need the client to capture errors.\n if (res.status === 101) {\n waitUntil?.(client?.flush(2000));\n } else {\n waitUntil?.(flushAndDispose(client));\n }\n return res;\n });\n },\n );\n }, wrapperOptions.context);\n}\n"],"names":["withInvocationIsolationScope","getInvocationState","getInvocationWaitUntil","getOriginalWaitUntil","parseStringToURLObject","attributes","getHttpSpanDetailsFromUrlObject","SENTRY_SEGMENT_NAME_SOURCE","hasSpanStreamingEnabled","HTTP_SPAN_NAME_FALLBACK","httpHeadersToSpanAttributes","winterCGHeadersToDict","SEMANTIC_ATTRIBUTE_SENTRY_OP","addCloudResourceContext","addRequest","addCultureContext","NETWORK_PROTOCOL_NAME","NETWORK_PROTOCOL_VERSION","captureException","flushAndDispose","captureIncomingRequestBody","continueTrace","startSpanManual","setHttpStatus","classifyResponseStreaming"],"mappings":";;;;;;;;;;;AA4BA,SAAS,6BAA6B,OAAA,EAAqD;AAEzF,EAAA,OAAO,OAAA,IAAW,SAAA,IAAa,OAAA,GAAU,qCAAA,GAAwC,sBAAA;AACnF;AA6BO,SAAS,0BAAA,CACd,cAAA,EACA,OAAA,EACA,OAAA,EACmB;AACnB,EAAA,OAAOA,4CAAA,CAA6B,OAAM,cAAA,KAAkB;AAC1D,IAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,aAAA,GAAgB,MAAK,GAAI,cAAA;AACnD,IAAA,MAAM,UAAU,cAAA,CAAe,OAAA;AAK/B,IAAA,MAAM,kBAAkBC,oCAAA,EAAmB;AAC3C,IAAA,MAAM,SAAA,GAAY,eAAA,GACdC,wCAAA,CAAuB,eAAe,CAAA,GACtC,OAAA,GACEC,0BAAA,CAAqB,OAAO,CAAA,CAAE,IAAA,CAAK,OAAO,CAAA,GAC1C,MAAA;AACN,IAAA,MAAM,kBAAA,GAAqB,6BAA6B,OAAO,CAAA;AAE/D,IAAA,MAAM,SAAS,OAAA,CAAQ,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AACnD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,IAAA,MAAM,SAAA,GAAYC,2BAAA,CAAuB,OAAA,CAAQ,GAAG,CAAA;AACpD,IAAA,MAAM,CAAC,OAAA,EAASC,YAAU,CAAA,GAAIC,oCAAA;AAAA,MAC5B,SAAA;AAAA,MACA,QAAA;AAAA,MACA,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AAA,EAAI;AAKT,UAAA,IAAI,GAAA,CAAI,WAAW,GAAA,EAAK;AACtB,YAAA,SAAA,GAAY,MAAA,EAAQ,KAAA,CAAM,GAAI,CAAC,CAAA;AAAA,UACjC,CAAA,MAAO;AACL,YAAA,SAAA,GAAYA,qBAAA,CAAgB,MAAM,CAAC,CAAA;AAAA,UACrC;AACA,UAAA,OAAO,GAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH;AAAA,KACF;AAAA,EACF,CAAA,EAAG,eAAe,OAAO,CAAA;AAC3B;;;;"}
@@ -1,10 +1,11 @@
1
- import { dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, conversationIdIntegration, linkedErrorsIntegration, requestDataIntegration, consoleIntegration, GLOBAL_OBJ, getIntegrationsToSetup, stackParserFromStackParserOptions, initAndBind } from '@sentry/core';
1
+ import { dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, conversationIdIntegration, linkedErrorsIntegration, requestDataIntegration, consoleIntegration, GLOBAL_OBJ, debug, getCurrentScope, setCurrentClient, getIntegrationsToSetup, stackParserFromStackParserOptions, initAndBind } from '@sentry/core';
2
2
  import { CloudflareClient } from './client.js';
3
3
  import { makeFlushLock } from './flush.js';
4
+ import { getCachedClient, cacheClient } from './clientCache.js';
5
+ import { DEBUG_BUILD } from './debug-build.js';
4
6
  import { fetchIntegration } from './integrations/fetch.js';
5
7
  import { httpServerIntegration } from './integrations/httpServer.js';
6
8
  import { INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight.js';
7
- import { setupOpenTelemetryTracer } from './opentelemetry/tracer.js';
8
9
  import { makeCloudflareTransport } from './transport.js';
9
10
  import { defaultStackParser } from './vendor/stacktrace.js';
10
11
 
@@ -35,19 +36,30 @@ function getBaseDefaultIntegrations(options) {
35
36
  ];
36
37
  }
37
38
  function initWithDefaultIntegrations(options, getDefaultIntegrationsImpl) {
39
+ const cached = getCachedClient();
40
+ const cacheEnabled = options.cacheClient !== false;
41
+ if (cacheEnabled && cached) {
42
+ if (DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {
43
+ debug.warn(
44
+ "[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options."
45
+ );
46
+ }
47
+ getCurrentScope().update(options.initialScope);
48
+ setCurrentClient(cached);
49
+ return cached;
50
+ }
38
51
  if (options.defaultIntegrations === void 0) {
39
52
  options.defaultIntegrations = getDefaultIntegrationsImpl(options);
40
53
  }
41
- const flushLock = options.ctx ? makeFlushLock(options.ctx) : void 0;
54
+ const invocationContext = options.ctx;
55
+ const flushLock = !cacheEnabled && invocationContext ? makeFlushLock(invocationContext) : void 0;
42
56
  delete options.ctx;
43
57
  const clientOptions = {
44
58
  ...options,
59
+ cacheClient: cacheEnabled,
45
60
  stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
46
61
  integrations: getIntegrationsToSetup(options),
47
62
  transport: options.transport || makeCloudflareTransport,
48
- // Like most Node-based SDKs, Cloudflare defaults to running without a Sentry OpenTelemetry tracer
49
- // provider. Scope isolation is handled by the entrypoint wrappers' AsyncLocalStorage strategy.
50
- enableOpenTelemetrySetup: options.enableOpenTelemetrySetup ?? false,
51
63
  flushLock
52
64
  };
53
65
  /*! rollup-include-development-only */
@@ -59,10 +71,10 @@ function initWithDefaultIntegrations(options, getDefaultIntegrationsImpl) {
59
71
  );
60
72
  }
61
73
  /*! rollup-include-development-only-end */
62
- if (clientOptions.enableOpenTelemetrySetup) {
63
- setupOpenTelemetryTracer();
64
- }
65
74
  const client = initAndBind(CloudflareClient, clientOptions);
75
+ if (cacheEnabled && client) {
76
+ cacheClient(client);
77
+ }
66
78
  client.on("orchestrion.module-injected", (moduleName) => {
67
79
  const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);
68
80
  if (factory) {
@@ -1 +1 @@
1
- {"version":3,"file":"baseSdk.js","sources":["../../../src/baseSdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n eventFiltersIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n GLOBAL_OBJ,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { fetchIntegration } from './integrations/fetch';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { INTEGRATION_NAME as SPOTLIGHT_INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight';\nimport { setupOpenTelemetryTracer } from './opentelemetry/tracer';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/**\n * Instantiate the channel-subscriber factories the `@sentry/cloudflare/vite`\n * plugin registered on the global marker. The plugin splices a small snippet\n * into each instrumented module that `.set`s its factory here (keyed by module\n * name), so the marker holds one factory per package actually bundled.\n *\n * The marker is read directly instead of importing the factories, so a worker\n * built without the plugin — where the channels never fire — ships none of this\n * code.\n * TODO(v11): Use `@sentry/server-utils/orchestrion` once we move to `nodejs_compat` by default.\n */\nfunction getRegisteredChannelIntegrations(): Integration[] {\n const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;\n\n return registered ? [...registered.values()].map(factory => factory()) : [];\n}\n\n/**\n * Get the default integrations that run on any Workers-compatible runtime, i.e. without the\n * `nodejs_compat` compatibility flag.\n *\n * `getDefaultIntegrations` in `sdk.ts` extends this set with the integrations that do depend on\n * Node.js APIs. Keeping the two apart is what allows `wrapRequestHandler` to stay usable on runtimes\n * that cannot enable `nodejs_compat`, such as Shopify Oxygen.\n */\nexport function getBaseDefaultIntegrations(options: CloudflareOptions): Integration[] {\n return [\n // The Dedupe integration should not be used in workflows because we want to\n // capture all step failures, even if they are the same error.\n ...(options.enableDedupe === false ? [] : [dedupeIntegration()]),\n eventFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n httpServerIntegration(),\n requestDataIntegration(),\n consoleIntegration(),\n // The orchestrion diagnostics-channel subscribers (mysql, pg, …). The\n // `@sentry/cloudflare/vite` plugin injects the channels at build time and,\n // next to each, a snippet that registers the matching subscriber factory on\n // the global marker. Read from there instead of importing them so bundles\n // built without the plugin — where the channels would never fire — don't\n // ship the code.\n ...getRegisteredChannelIntegrations(),\n ];\n}\n\n/**\n * Initializes the Cloudflare SDK with the passed default integrations.\n *\n * The default integrations are injected rather than imported so that this module stays free of\n * Node.js-only code. `request.ts` — which backs both `wrapRequestHandler` and the\n * `@sentry/cloudflare/request` entry point, and therefore has to work on runtimes without the\n * `nodejs_compat` compatibility flag — creates its client from here instead of from `sdk.ts`.\n */\nexport function initWithDefaultIntegrations(\n options: CloudflareOptions,\n getDefaultIntegrationsImpl: (options: CloudflareOptions) => Integration[],\n): CloudflareClient | undefined {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(options);\n }\n\n const flushLock = options.ctx ? makeFlushLock(options.ctx) : undefined;\n delete options.ctx;\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n // Like most Node-based SDKs, Cloudflare defaults to running without a Sentry OpenTelemetry tracer\n // provider. Scope isolation is handled by the entrypoint wrappers' AsyncLocalStorage strategy.\n enableOpenTelemetrySetup: options.enableOpenTelemetrySetup ?? false,\n flushLock,\n };\n\n /*! rollup-include-development-only */\n if (options.spotlight && !clientOptions.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) {\n clientOptions.integrations.push(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n /*! rollup-include-development-only-end */\n\n // Opt-in only: when `enableOpenTelemetrySetup` is `true`, set up a custom trace provider so spans\n // emitted via `@opentelemetry/api` are captured by Sentry. See the option's docs for the caveats.\n if (clientOptions.enableOpenTelemetrySetup) {\n setupOpenTelemetryTracer();\n }\n\n const client = initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n\n // An instrumented module that first evaluates AFTER this init (e.g. a driver\n // lazily required on first use) stores its subscriber factory on the global\n // marker too late for the default-integrations snapshot above. Its injected\n // snippet emits this event right after storing the factory, so install the\n // integration on the live client here. `addIntegration` dedupes by\n // integration name, so already-installed integrations are no-ops.\n client.on('orchestrion.module-injected', moduleName => {\n const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);\n if (factory) {\n client.addIntegration(factory());\n }\n });\n\n return client;\n}\n\n/**\n * Initializes the Cloudflare SDK with only the default integrations from\n * {@link getBaseDefaultIntegrations}, i.e. those that work without the `nodejs_compat`\n * compatibility flag.\n */\nexport function initBaseSdk(options: CloudflareOptions): CloudflareClient | undefined {\n return initWithDefaultIntegrations(options, getBaseDefaultIntegrations);\n}\n"],"names":["SPOTLIGHT_INTEGRATION_NAME"],"mappings":";;;;;;;;;;AAmCA,SAAS,gCAAA,GAAkD;AACzD,EAAA,MAAM,UAAA,GAAa,WAAW,sBAAA,EAAwB,YAAA;AAEtD,EAAA,OAAO,UAAA,GAAa,CAAC,GAAG,UAAA,CAAW,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,CAAA,OAAA,KAAW,OAAA,EAAS,CAAA,GAAI,EAAC;AAC5E;AAUO,SAAS,2BAA2B,OAAA,EAA2C;AACpF,EAAA,OAAO;AAAA;AAAA;AAAA,IAGL,GAAI,QAAQ,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAAI,CAAC,mBAAmB,CAAA;AAAA,IAC9D,uBAAA,EAAwB;AAAA,IACxB,2BAAA,EAA4B;AAAA,IAC5B,yBAAA,EAA0B;AAAA,IAC1B,uBAAA,EAAwB;AAAA,IACxB,gBAAA,EAAiB;AAAA,IACjB,qBAA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AAY,gBAAA,EAAkB,aAAa,CAAA;AAQ1D,EAAA,MAAA,CAAO,EAAA,CAAG,+BAA+B,CAAA,UAAA,KAAc;AACrD,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,sBAAA,EAAwB,YAAA,EAAc,IAAI,UAAU,CAAA;AAC/E,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,MAAA,CAAO,cAAA,CAAe,SAAS,CAAA;AAAA,IACjC;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;AAOO,SAAS,YAAY,OAAA,EAA0D;AACpF,EAAA,OAAO,2BAAA,CAA4B,SAAS,0BAA0B,CAAA;AACxE;;;;"}
1
+ {"version":3,"file":"baseSdk.js","sources":["../../../src/baseSdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { debug, getCurrentScope, setCurrentClient } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n eventFiltersIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n GLOBAL_OBJ,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { cacheClient, getCachedClient } from './clientCache';\nimport { DEBUG_BUILD } from './debug-build';\nimport { fetchIntegration } from './integrations/fetch';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { INTEGRATION_NAME as SPOTLIGHT_INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/**\n * Instantiate the channel-subscriber factories the `@sentry/cloudflare/vite`\n * plugin registered on the global marker. The plugin splices a small snippet\n * into each instrumented module that `.set`s its factory here (keyed by module\n * name), so the marker holds one factory per package actually bundled.\n *\n * The marker is read directly instead of importing the factories, so a worker\n * built without the plugin — where the channels never fire — ships none of this\n * code.\n */\nfunction getRegisteredChannelIntegrations(): Integration[] {\n const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;\n\n return registered ? [...registered.values()].map(factory => factory()) : [];\n}\n\n/**\n * Get the default integrations that run on any Workers-compatible runtime, i.e. without the\n * `nodejs_compat` compatibility flag.\n *\n * `getDefaultIntegrations` in `sdk.ts` extends this set with the integrations that do depend on\n * Node.js APIs. Keeping the two apart is what allows `wrapRequestHandler` to stay usable on runtimes\n * that cannot enable `nodejs_compat`, such as Shopify Oxygen.\n */\nexport function getBaseDefaultIntegrations(options: CloudflareOptions): Integration[] {\n return [\n // The Dedupe integration should not be used in workflows because we want to\n // capture all step failures, even if they are the same error.\n ...(options.enableDedupe === false ? [] : [dedupeIntegration()]),\n eventFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n httpServerIntegration(),\n requestDataIntegration(),\n consoleIntegration(),\n // The orchestrion diagnostics-channel subscribers (mysql, pg, …). The\n // `@sentry/cloudflare/vite` plugin injects the channels at build time and,\n // next to each, a snippet that registers the matching subscriber factory on\n // the global marker. Read from there instead of importing them so bundles\n // built without the plugin — where the channels would never fire — don't\n // ship the code.\n ...getRegisteredChannelIntegrations(),\n ];\n}\n\n/**\n * Initializes the Cloudflare SDK with the passed default integrations.\n *\n * The default integrations are injected rather than imported so that this module stays free of\n * Node.js-only code. `request.ts` — which backs both `wrapRequestHandler` and the\n * `@sentry/cloudflare/request` entry point, and therefore has to work on runtimes without the\n * `nodejs_compat` compatibility flag — creates its client from here instead of from `sdk.ts`.\n *\n * The client is cached and reused across invocations within the same isolate,\n * unless `cacheClient: false` is passed. This avoids the\n * per-invocation cost of constructing a new client, and it is what makes\n * Durable Object telemetry reliable: a per-invocation client is disposed at\n * the end of the handler, and in a Durable Object there is no `waitUntil`\n * boundary that reliably extends execution, so spans/events that end after\n * disposal would otherwise be lost.\n */\nexport function initWithDefaultIntegrations(\n options: CloudflareOptions,\n getDefaultIntegrationsImpl: (options: CloudflareOptions) => Integration[],\n): CloudflareClient | undefined {\n const cached = getCachedClient();\n const cacheEnabled = options.cacheClient !== false;\n\n if (cacheEnabled && cached) {\n if (DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {\n debug.warn(\n '[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options.',\n );\n }\n getCurrentScope().update(options.initialScope);\n setCurrentClient(cached);\n return cached;\n }\n\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(options);\n }\n\n // A cached client outlives any single invocation, so binding it to one\n // invocation's flush lock would make later flushes wait on that invocation's\n // waitUntil work forever. Eager delivery replaces the flush lock's purpose.\n const invocationContext = options.ctx;\n const flushLock = !cacheEnabled && invocationContext ? makeFlushLock(invocationContext) : undefined;\n delete options.ctx;\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n cacheClient: cacheEnabled,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n flushLock,\n };\n\n /*! rollup-include-development-only */\n if (options.spotlight && !clientOptions.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) {\n clientOptions.integrations.push(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n /*! rollup-include-development-only-end */\n\n const client = initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n\n if (cacheEnabled && client) {\n cacheClient(client);\n }\n\n // An instrumented module that first evaluates AFTER this init (e.g. a driver\n // lazily required on first use) stores its subscriber factory on the global\n // marker too late for the default-integrations snapshot above. Its injected\n // snippet emits this event right after storing the factory, so install the\n // integration on the live client here. `addIntegration` dedupes by\n // integration name, so already-installed integrations are no-ops.\n client.on('orchestrion.module-injected', moduleName => {\n const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);\n if (factory) {\n client.addIntegration(factory());\n }\n });\n\n return client;\n}\n\n/**\n * Initializes the Cloudflare SDK with only the default integrations from\n * {@link getBaseDefaultIntegrations}, i.e. those that work without the `nodejs_compat`\n * compatibility flag.\n */\nexport function initBaseSdk(options: CloudflareOptions): CloudflareClient | undefined {\n return initWithDefaultIntegrations(options, getBaseDefaultIntegrations);\n}\n"],"names":["SPOTLIGHT_INTEGRATION_NAME"],"mappings":";;;;;;;;;;;AAoCA,SAAS,gCAAA,GAAkD;AACzD,EAAA,MAAM,UAAA,GAAa,WAAW,sBAAA,EAAwB,YAAA;AAEtD,EAAA,OAAO,UAAA,GAAa,CAAC,GAAG,UAAA,CAAW,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,CAAA,OAAA,KAAW,OAAA,EAAS,CAAA,GAAI,EAAC;AAC5E;AAUO,SAAS,2BAA2B,OAAA,EAA2C;AACpF,EAAA,OAAO;AAAA;AAAA;AAAA,IAGL,GAAI,QAAQ,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAAI,CAAC,mBAAmB,CAAA;AAAA,IAC9D,uBAAA,EAAwB;AAAA,IACxB,2BAAA,EAA4B;AAAA,IAC5B,yBAAA,EAA0B;AAAA,IAC1B,uBAAA,EAAwB;AAAA,IACxB,gBAAA,EAAiB;AAAA,IACjB,qBAAA,EAAsB;AAAA,IACtB,sBAAA,EAAuB;AAAA,IACvB,kBAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOnB,GAAG,gCAAA;AAAiC,GACtC;AACF;AAkBO,SAAS,2BAAA,CACd,SACA,0BAAA,EAC8B;AAC9B,EAAA,MAAM,SAAS,eAAA,EAAgB;AAC/B,EAAA,MAAM,YAAA,GAAe,QAAQ,WAAA,KAAgB,KAAA;AAE7C,EAAA,IAAI,gBAAgB,MAAA,EAAQ;AAC1B,IAAA,IAAI,eAAe,MAAA,CAAO,UAAA,EAAW,CAAE,GAAA,KAAQ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