@sentry/cloudflare 11.0.0-alpha.0 → 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 (345) 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 +4 -3
  13. package/build/cjs/dev/index.js.map +1 -1
  14. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  15. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  16. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  17. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  18. package/build/cjs/dev/instrumentations/worker/instrumentD1.js +5 -1
  19. package/build/cjs/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  20. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js +4 -2
  21. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  22. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js +5 -5
  23. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  24. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js +8 -8
  25. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  26. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js +4 -2
  27. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  28. package/build/cjs/dev/instrumentations/worker/instrumentR2.js +21 -18
  29. package/build/cjs/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  30. package/build/cjs/dev/instrumentations/worker/instrumentRateLimit.js +6 -1
  31. package/build/cjs/dev/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  32. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js +4 -2
  33. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  34. package/build/cjs/dev/instrumentations/worker/instrumentTail.js +2 -0
  35. package/build/cjs/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  36. package/build/cjs/dev/integrations/fetch.js +1 -11
  37. package/build/cjs/dev/integrations/fetch.js.map +1 -1
  38. package/build/cjs/dev/opentelemetry/tracer.js +2 -40
  39. package/build/cjs/dev/opentelemetry/tracer.js.map +1 -1
  40. package/build/cjs/dev/pages-plugin.js +2 -2
  41. package/build/cjs/dev/pages-plugin.js.map +1 -1
  42. package/build/cjs/dev/request.js +2 -123
  43. package/build/cjs/dev/request.js.map +1 -1
  44. package/build/cjs/dev/sdk.js +12 -6
  45. package/build/cjs/dev/sdk.js.map +1 -1
  46. package/build/cjs/dev/transport.js +1 -1
  47. package/build/cjs/dev/transport.js.map +1 -1
  48. package/build/cjs/dev/utils/invocationContext.js +41 -0
  49. package/build/cjs/dev/utils/invocationContext.js.map +1 -0
  50. package/build/cjs/dev/utils/invocationScope.js +7 -2
  51. package/build/cjs/dev/utils/invocationScope.js.map +1 -1
  52. package/build/cjs/dev/utils/rpcPropagation.js +15 -0
  53. package/build/cjs/dev/utils/rpcPropagation.js.map +1 -0
  54. package/build/cjs/dev/vite/autoInstrument.js +2 -1
  55. package/build/cjs/dev/vite/autoInstrument.js.map +1 -1
  56. package/build/cjs/dev/vite/index.js +1 -1
  57. package/build/cjs/dev/vite/index.js.map +1 -1
  58. package/build/cjs/dev/vite/transform.js +30 -5
  59. package/build/cjs/dev/vite/transform.js.map +1 -1
  60. package/build/cjs/dev/vite/wranglerConfig.js +21 -1
  61. package/build/cjs/dev/vite/wranglerConfig.js.map +1 -1
  62. package/build/cjs/dev/withSentry.js.map +1 -1
  63. package/build/cjs/dev/workflows.js +45 -33
  64. package/build/cjs/dev/workflows.js.map +1 -1
  65. package/build/cjs/dev/wrapMethodWithSentry.js +51 -15
  66. package/build/cjs/dev/wrapMethodWithSentry.js.map +1 -1
  67. package/build/cjs/dev/wrapRequestHandlerWithInit.js +133 -0
  68. package/build/cjs/dev/wrapRequestHandlerWithInit.js.map +1 -0
  69. package/build/cjs/prod/baseSdk.js +20 -8
  70. package/build/cjs/prod/baseSdk.js.map +1 -1
  71. package/build/cjs/prod/client.js +116 -24
  72. package/build/cjs/prod/client.js.map +1 -1
  73. package/build/cjs/prod/clientCache.js +15 -0
  74. package/build/cjs/prod/clientCache.js.map +1 -0
  75. package/build/cjs/prod/defineCloudflareOptions.js.map +1 -1
  76. package/build/cjs/prod/durableobject.js +24 -8
  77. package/build/cjs/prod/durableobject.js.map +1 -1
  78. package/build/cjs/prod/flush.js +6 -4
  79. package/build/cjs/prod/flush.js.map +1 -1
  80. package/build/cjs/prod/index.js +4 -3
  81. package/build/cjs/prod/index.js.map +1 -1
  82. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  83. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  84. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  85. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  86. package/build/cjs/prod/instrumentations/worker/instrumentD1.js +5 -1
  87. package/build/cjs/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  88. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js +4 -2
  89. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  90. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js +5 -5
  91. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  92. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js +8 -8
  93. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  94. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js +4 -2
  95. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  96. package/build/cjs/prod/instrumentations/worker/instrumentR2.js +21 -18
  97. package/build/cjs/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  98. package/build/cjs/prod/instrumentations/worker/instrumentRateLimit.js +6 -1
  99. package/build/cjs/prod/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  100. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js +4 -2
  101. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  102. package/build/cjs/prod/instrumentations/worker/instrumentTail.js +2 -0
  103. package/build/cjs/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  104. package/build/cjs/prod/integrations/fetch.js +1 -11
  105. package/build/cjs/prod/integrations/fetch.js.map +1 -1
  106. package/build/cjs/prod/opentelemetry/tracer.js +2 -40
  107. package/build/cjs/prod/opentelemetry/tracer.js.map +1 -1
  108. package/build/cjs/prod/pages-plugin.js +2 -2
  109. package/build/cjs/prod/pages-plugin.js.map +1 -1
  110. package/build/cjs/prod/request.js +2 -123
  111. package/build/cjs/prod/request.js.map +1 -1
  112. package/build/cjs/prod/sdk.js +12 -6
  113. package/build/cjs/prod/sdk.js.map +1 -1
  114. package/build/cjs/prod/transport.js +1 -1
  115. package/build/cjs/prod/transport.js.map +1 -1
  116. package/build/cjs/prod/utils/invocationContext.js +41 -0
  117. package/build/cjs/prod/utils/invocationContext.js.map +1 -0
  118. package/build/cjs/prod/utils/invocationScope.js +7 -2
  119. package/build/cjs/prod/utils/invocationScope.js.map +1 -1
  120. package/build/cjs/prod/utils/rpcPropagation.js +15 -0
  121. package/build/cjs/prod/utils/rpcPropagation.js.map +1 -0
  122. package/build/cjs/prod/vite/autoInstrument.js +2 -1
  123. package/build/cjs/prod/vite/autoInstrument.js.map +1 -1
  124. package/build/cjs/prod/vite/index.js +1 -1
  125. package/build/cjs/prod/vite/index.js.map +1 -1
  126. package/build/cjs/prod/vite/transform.js +30 -5
  127. package/build/cjs/prod/vite/transform.js.map +1 -1
  128. package/build/cjs/prod/vite/wranglerConfig.js +21 -1
  129. package/build/cjs/prod/vite/wranglerConfig.js.map +1 -1
  130. package/build/cjs/prod/withSentry.js.map +1 -1
  131. package/build/cjs/prod/workflows.js +45 -33
  132. package/build/cjs/prod/workflows.js.map +1 -1
  133. package/build/cjs/prod/wrapMethodWithSentry.js +51 -15
  134. package/build/cjs/prod/wrapMethodWithSentry.js.map +1 -1
  135. package/build/cjs/prod/wrapRequestHandlerWithInit.js +133 -0
  136. package/build/cjs/prod/wrapRequestHandlerWithInit.js.map +1 -0
  137. package/build/esm/dev/baseSdk.js +21 -9
  138. package/build/esm/dev/baseSdk.js.map +1 -1
  139. package/build/esm/dev/client.js +117 -25
  140. package/build/esm/dev/client.js.map +1 -1
  141. package/build/esm/dev/clientCache.js +12 -0
  142. package/build/esm/dev/clientCache.js.map +1 -0
  143. package/build/esm/dev/defineCloudflareOptions.js.map +1 -1
  144. package/build/esm/dev/durableobject.js +23 -7
  145. package/build/esm/dev/durableobject.js.map +1 -1
  146. package/build/esm/dev/flush.js +6 -4
  147. package/build/esm/dev/flush.js.map +1 -1
  148. package/build/esm/dev/index.js +3 -4
  149. package/build/esm/dev/index.js.map +1 -1
  150. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  151. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  152. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  153. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  154. package/build/esm/dev/instrumentations/worker/instrumentD1.js +6 -2
  155. package/build/esm/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  156. package/build/esm/dev/instrumentations/worker/instrumentEmail.js +7 -5
  157. package/build/esm/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  158. package/build/esm/dev/instrumentations/worker/instrumentEnv.js +5 -5
  159. package/build/esm/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  160. package/build/esm/dev/instrumentations/worker/instrumentFetch.js +1 -1
  161. package/build/esm/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  162. package/build/esm/dev/instrumentations/worker/instrumentQueue.js +7 -5
  163. package/build/esm/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  164. package/build/esm/dev/instrumentations/worker/instrumentR2.js +22 -19
  165. package/build/esm/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  166. package/build/esm/dev/instrumentations/worker/instrumentRateLimit.js +6 -1
  167. package/build/esm/dev/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  168. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js +7 -5
  169. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  170. package/build/esm/dev/instrumentations/worker/instrumentTail.js +2 -0
  171. package/build/esm/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  172. package/build/esm/dev/integrations/fetch.js +2 -12
  173. package/build/esm/dev/integrations/fetch.js.map +1 -1
  174. package/build/esm/dev/opentelemetry/tracer.js +2 -40
  175. package/build/esm/dev/opentelemetry/tracer.js.map +1 -1
  176. package/build/esm/dev/package.json +1 -1
  177. package/build/esm/dev/pages-plugin.js +1 -1
  178. package/build/esm/dev/pages-plugin.js.map +1 -1
  179. package/build/esm/dev/request.js +2 -122
  180. package/build/esm/dev/request.js.map +1 -1
  181. package/build/esm/dev/sdk.js +12 -7
  182. package/build/esm/dev/sdk.js.map +1 -1
  183. package/build/esm/dev/transport.js +1 -1
  184. package/build/esm/dev/transport.js.map +1 -1
  185. package/build/esm/dev/utils/invocationContext.js +37 -0
  186. package/build/esm/dev/utils/invocationContext.js.map +1 -0
  187. package/build/esm/dev/utils/invocationScope.js +7 -2
  188. package/build/esm/dev/utils/invocationScope.js.map +1 -1
  189. package/build/esm/dev/utils/rpcPropagation.js +13 -0
  190. package/build/esm/dev/utils/rpcPropagation.js.map +1 -0
  191. package/build/esm/dev/utils/traceLinks.js +1 -1
  192. package/build/esm/dev/vite/autoInstrument.js +2 -1
  193. package/build/esm/dev/vite/autoInstrument.js.map +1 -1
  194. package/build/esm/dev/vite/index.js +1 -1
  195. package/build/esm/dev/vite/index.js.map +1 -1
  196. package/build/esm/dev/vite/transform.js +30 -5
  197. package/build/esm/dev/vite/transform.js.map +1 -1
  198. package/build/esm/dev/vite/wranglerConfig.js +21 -2
  199. package/build/esm/dev/vite/wranglerConfig.js.map +1 -1
  200. package/build/esm/dev/withSentry.js.map +1 -1
  201. package/build/esm/dev/workflows.js +48 -36
  202. package/build/esm/dev/workflows.js.map +1 -1
  203. package/build/esm/dev/wrapMethodWithSentry.js +53 -17
  204. package/build/esm/dev/wrapMethodWithSentry.js.map +1 -1
  205. package/build/esm/dev/wrapRequestHandlerWithInit.js +131 -0
  206. package/build/esm/dev/wrapRequestHandlerWithInit.js.map +1 -0
  207. package/build/esm/prod/baseSdk.js +21 -9
  208. package/build/esm/prod/baseSdk.js.map +1 -1
  209. package/build/esm/prod/client.js +117 -25
  210. package/build/esm/prod/client.js.map +1 -1
  211. package/build/esm/prod/clientCache.js +12 -0
  212. package/build/esm/prod/clientCache.js.map +1 -0
  213. package/build/esm/prod/defineCloudflareOptions.js.map +1 -1
  214. package/build/esm/prod/durableobject.js +23 -7
  215. package/build/esm/prod/durableobject.js.map +1 -1
  216. package/build/esm/prod/flush.js +6 -4
  217. package/build/esm/prod/flush.js.map +1 -1
  218. package/build/esm/prod/index.js +3 -4
  219. package/build/esm/prod/index.js.map +1 -1
  220. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  221. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  222. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js +8 -16
  223. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  224. package/build/esm/prod/instrumentations/worker/instrumentD1.js +6 -2
  225. package/build/esm/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  226. package/build/esm/prod/instrumentations/worker/instrumentEmail.js +7 -5
  227. package/build/esm/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  228. package/build/esm/prod/instrumentations/worker/instrumentEnv.js +5 -5
  229. package/build/esm/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  230. package/build/esm/prod/instrumentations/worker/instrumentFetch.js +1 -1
  231. package/build/esm/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  232. package/build/esm/prod/instrumentations/worker/instrumentQueue.js +7 -5
  233. package/build/esm/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  234. package/build/esm/prod/instrumentations/worker/instrumentR2.js +22 -19
  235. package/build/esm/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  236. package/build/esm/prod/instrumentations/worker/instrumentRateLimit.js +6 -1
  237. package/build/esm/prod/instrumentations/worker/instrumentRateLimit.js.map +1 -1
  238. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js +7 -5
  239. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  240. package/build/esm/prod/instrumentations/worker/instrumentTail.js +2 -0
  241. package/build/esm/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  242. package/build/esm/prod/integrations/fetch.js +2 -12
  243. package/build/esm/prod/integrations/fetch.js.map +1 -1
  244. package/build/esm/prod/opentelemetry/tracer.js +2 -40
  245. package/build/esm/prod/opentelemetry/tracer.js.map +1 -1
  246. package/build/esm/prod/package.json +1 -1
  247. package/build/esm/prod/pages-plugin.js +1 -1
  248. package/build/esm/prod/pages-plugin.js.map +1 -1
  249. package/build/esm/prod/request.js +2 -122
  250. package/build/esm/prod/request.js.map +1 -1
  251. package/build/esm/prod/sdk.js +12 -7
  252. package/build/esm/prod/sdk.js.map +1 -1
  253. package/build/esm/prod/transport.js +1 -1
  254. package/build/esm/prod/transport.js.map +1 -1
  255. package/build/esm/prod/utils/invocationContext.js +37 -0
  256. package/build/esm/prod/utils/invocationContext.js.map +1 -0
  257. package/build/esm/prod/utils/invocationScope.js +7 -2
  258. package/build/esm/prod/utils/invocationScope.js.map +1 -1
  259. package/build/esm/prod/utils/rpcPropagation.js +13 -0
  260. package/build/esm/prod/utils/rpcPropagation.js.map +1 -0
  261. package/build/esm/prod/utils/traceLinks.js +1 -1
  262. package/build/esm/prod/vite/autoInstrument.js +2 -1
  263. package/build/esm/prod/vite/autoInstrument.js.map +1 -1
  264. package/build/esm/prod/vite/index.js +1 -1
  265. package/build/esm/prod/vite/index.js.map +1 -1
  266. package/build/esm/prod/vite/transform.js +30 -5
  267. package/build/esm/prod/vite/transform.js.map +1 -1
  268. package/build/esm/prod/vite/wranglerConfig.js +21 -2
  269. package/build/esm/prod/vite/wranglerConfig.js.map +1 -1
  270. package/build/esm/prod/withSentry.js.map +1 -1
  271. package/build/esm/prod/workflows.js +48 -36
  272. package/build/esm/prod/workflows.js.map +1 -1
  273. package/build/esm/prod/wrapMethodWithSentry.js +53 -17
  274. package/build/esm/prod/wrapMethodWithSentry.js.map +1 -1
  275. package/build/esm/prod/wrapRequestHandlerWithInit.js +131 -0
  276. package/build/esm/prod/wrapRequestHandlerWithInit.js.map +1 -0
  277. package/build/types/baseSdk.d.ts +8 -0
  278. package/build/types/baseSdk.d.ts.map +1 -1
  279. package/build/types/client.d.ts +94 -21
  280. package/build/types/client.d.ts.map +1 -1
  281. package/build/types/clientCache.d.ts +8 -0
  282. package/build/types/clientCache.d.ts.map +1 -0
  283. package/build/types/defineCloudflareOptions.d.ts +3 -2
  284. package/build/types/defineCloudflareOptions.d.ts.map +1 -1
  285. package/build/types/durableobject.d.ts +5 -7
  286. package/build/types/durableobject.d.ts.map +1 -1
  287. package/build/types/flush.d.ts +2 -0
  288. package/build/types/flush.d.ts.map +1 -1
  289. package/build/types/index.d.ts +3 -4
  290. package/build/types/index.d.ts.map +1 -1
  291. package/build/types/instrumentations/instrumentDurableObjectNamespace.d.ts +2 -1
  292. package/build/types/instrumentations/instrumentDurableObjectNamespace.d.ts.map +1 -1
  293. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts +2 -3
  294. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts.map +1 -1
  295. package/build/types/instrumentations/worker/instrumentD1.d.ts.map +1 -1
  296. package/build/types/instrumentations/worker/instrumentEmail.d.ts.map +1 -1
  297. package/build/types/instrumentations/worker/instrumentEnv.d.ts.map +1 -1
  298. package/build/types/instrumentations/worker/instrumentQueue.d.ts.map +1 -1
  299. package/build/types/instrumentations/worker/instrumentR2.d.ts.map +1 -1
  300. package/build/types/instrumentations/worker/instrumentRateLimit.d.ts.map +1 -1
  301. package/build/types/instrumentations/worker/instrumentScheduled.d.ts.map +1 -1
  302. package/build/types/instrumentations/worker/instrumentTail.d.ts.map +1 -1
  303. package/build/types/integrations/fetch.d.ts.map +1 -1
  304. package/build/types/opentelemetry/tracer.d.ts.map +1 -1
  305. package/build/types/pages-plugin.d.ts +3 -1
  306. package/build/types/pages-plugin.d.ts.map +1 -1
  307. package/build/types/request.d.ts +5 -31
  308. package/build/types/request.d.ts.map +1 -1
  309. package/build/types/sdk.d.ts +13 -4
  310. package/build/types/sdk.d.ts.map +1 -1
  311. package/build/types/transport.d.ts.map +1 -1
  312. package/build/types/types.d.ts +28 -0
  313. package/build/types/types.d.ts.map +1 -1
  314. package/build/types/utils/invocationContext.d.ts +58 -0
  315. package/build/types/utils/invocationContext.d.ts.map +1 -0
  316. package/build/types/utils/invocationScope.d.ts +2 -1
  317. package/build/types/utils/invocationScope.d.ts.map +1 -1
  318. package/build/types/utils/rpcPropagation.d.ts +10 -0
  319. package/build/types/utils/rpcPropagation.d.ts.map +1 -0
  320. package/build/types/vite/autoInstrument.d.ts.map +1 -1
  321. package/build/types/vite/index.d.ts +24 -20
  322. package/build/types/vite/index.d.ts.map +1 -1
  323. package/build/types/vite/transform.d.ts +3 -0
  324. package/build/types/vite/transform.d.ts.map +1 -1
  325. package/build/types/vite/wranglerConfig.d.ts +13 -0
  326. package/build/types/vite/wranglerConfig.d.ts.map +1 -1
  327. package/build/types/withSentry.d.ts +2 -3
  328. package/build/types/withSentry.d.ts.map +1 -1
  329. package/build/types/workflows.d.ts +3 -3
  330. package/build/types/workflows.d.ts.map +1 -1
  331. package/build/types/wrapMethodWithSentry.d.ts +6 -1
  332. package/build/types/wrapMethodWithSentry.d.ts.map +1 -1
  333. package/build/types/wrapRequestHandlerWithInit.d.ts +31 -0
  334. package/build/types/wrapRequestHandlerWithInit.d.ts.map +1 -0
  335. package/package.json +6 -4
  336. package/build/cjs/dev/integrations/tracing/vercelai.js +0 -18
  337. package/build/cjs/dev/integrations/tracing/vercelai.js.map +0 -1
  338. package/build/cjs/prod/integrations/tracing/vercelai.js +0 -18
  339. package/build/cjs/prod/integrations/tracing/vercelai.js.map +0 -1
  340. package/build/esm/dev/integrations/tracing/vercelai.js +0 -16
  341. package/build/esm/dev/integrations/tracing/vercelai.js.map +0 -1
  342. package/build/esm/prod/integrations/tracing/vercelai.js +0 -16
  343. package/build/esm/prod/integrations/tracing/vercelai.js.map +0 -1
  344. package/build/types/integrations/tracing/vercelai.d.ts +0 -40
  345. package/build/types/integrations/tracing/vercelai.d.ts.map +0 -1
@@ -1,8 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const MagicString = require('magic-string');
4
+ const wranglerConfig = require('./wranglerConfig.js');
4
5
  const workerEntrypoint = require('./workerEntrypoint.js');
5
6
 
7
+ const MERGED_OPTIONS_IDENTIFIER = "__SENTRY_OPTIONS__";
6
8
  function isCallToMethod(node, methodName) {
7
9
  if (node.type !== "CallExpression") return false;
8
10
  const callee = node.callee;
@@ -19,6 +21,7 @@ const WRAPPER_METHODS = {
19
21
  function applyAutoInstrumentTransforms(code, ast, ctx) {
20
22
  const ms = new MagicString.default(code);
21
23
  const topLevelClasses = collectTopLevelClasses(ast);
24
+ const sameWorkerBindings = ctx.sameWorkerBindings ?? [];
22
25
  const state = {
23
26
  ms,
24
27
  needsImport: false,
@@ -27,7 +30,10 @@ function applyAutoInstrumentTransforms(code, ast, ctx) {
27
30
  renamedLocals: /* @__PURE__ */ new Set(),
28
31
  classWrappers: ctx.classWrappers,
29
32
  agentClasses: ctx.agentClasses ?? /* @__PURE__ */ new Set(),
30
- workerEntrypointClasses: workerEntrypoint.detectWorkerEntrypointClasses(ast)
33
+ workerEntrypointClasses: workerEntrypoint.detectWorkerEntrypointClasses(ast),
34
+ // The identifier must be chosen before wrapping, which bindings survive is only known after.
35
+ optionsFn: sameWorkerBindings.length > 0 ? MERGED_OPTIONS_IDENTIFIER : ctx.optionsFn,
36
+ autoWrapped: /* @__PURE__ */ new Set()
31
37
  };
32
38
  const { wrappedClasses } = state;
33
39
  for (const node of ast.body) {
@@ -44,6 +50,9 @@ function applyAutoInstrumentTransforms(code, ast, ctx) {
44
50
  if (wrappedClasses.size === 0) return void 0;
45
51
  return { code, map: ms.generateMap({ hires: true }), wrappedClasses };
46
52
  }
53
+ if (sameWorkerBindings.length > 0) {
54
+ ms.prepend(buildMergedOptionsDeclaration(sameWorkerBindings, ctx.optionsFn, state));
55
+ }
47
56
  if (ctx.optionsImport) ms.prepend(ctx.optionsImport);
48
57
  ms.prepend("import * as __SENTRY__ from '@sentry/cloudflare';\n");
49
58
  return {
@@ -52,6 +61,16 @@ function applyAutoInstrumentTransforms(code, ast, ctx) {
52
61
  wrappedClasses
53
62
  };
54
63
  }
64
+ function buildMergedOptionsDeclaration(sameWorkerBindings, optionsFn, state) {
65
+ const bindingNames = sameWorkerBindings.filter(({ className }) => state.autoWrapped.has(className)).map(({ bindingName }) => bindingName);
66
+ if (!bindingNames.length) {
67
+ return `const ${MERGED_OPTIONS_IDENTIFIER} = ${optionsFn};
68
+ `;
69
+ }
70
+ const names = bindingNames.map((name) => JSON.stringify(name)).join(", ");
71
+ return `const ${MERGED_OPTIONS_IDENTIFIER} = (env) => { const opts = (${optionsFn})(env); return { ...opts, rpcTracePropagationBindings: [${names}, ...(opts?.rpcTracePropagationBindings ?? [])] }; };
72
+ `;
73
+ }
55
74
  function resolveWrapperKind(exportedName, localName, state) {
56
75
  const configured = state.classWrappers.get(exportedName);
57
76
  if (configured === "durableObject" && localName && state.agentClasses.has(localName)) return "agent";
@@ -71,12 +90,16 @@ function collectTopLevelClasses(ast) {
71
90
  function wrapDefaultExport(node, ctx, state) {
72
91
  const decl = node.declaration;
73
92
  if (isCallToMethod(decl, "withSentry")) return;
74
- if (decl.type === "Identifier" && state.renamedLocals.has(decl.name)) return;
93
+ if (decl.type === "Identifier" && state.renamedLocals.has(decl.name)) {
94
+ state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
95
+ return;
96
+ }
75
97
  state.ms.overwrite(node.start, decl.start, "const __SENTRY_DEFAULT_EXPORT__ = ");
76
98
  state.ms.append(`
77
- export default __SENTRY__.withSentry(${ctx.optionsFn}, __SENTRY_DEFAULT_EXPORT__);
99
+ export default __SENTRY__.withSentry(${state.optionsFn}, __SENTRY_DEFAULT_EXPORT__);
78
100
  `);
79
101
  state.needsImport = true;
102
+ state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
80
103
  }
81
104
  function handleNamedExport(node, ctx, state) {
82
105
  const decl = node.declaration;
@@ -115,10 +138,11 @@ function wrapInlineClassExport(exportNode, classDecl, ctx, state) {
115
138
  state.ms.appendLeft(
116
139
  exportNode.end,
117
140
  `
118
- export const ${className} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});
141
+ export const ${className} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${renamedClass});
119
142
  `
120
143
  );
121
144
  state.wrappedClasses.add(className);
145
+ state.autoWrapped.add(className);
122
146
  state.renamedLocals.add(className);
123
147
  state.needsImport = true;
124
148
  }
@@ -132,6 +156,7 @@ function wrapSpecifierExport(specifier, ctx, state) {
132
156
  const localClass = localName ? state.topLevelClasses.get(localName) : void 0;
133
157
  if (!localName || !localClass?.id) return;
134
158
  state.wrappedClasses.add(exportedName);
159
+ state.autoWrapped.add(exportedName);
135
160
  state.needsImport = true;
136
161
  if (state.renamedLocals.has(localName)) return;
137
162
  state.renamedLocals.add(localName);
@@ -140,7 +165,7 @@ function wrapSpecifierExport(specifier, ctx, state) {
140
165
  state.ms.appendLeft(
141
166
  localClass.end,
142
167
  `
143
- const ${localName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});
168
+ const ${localName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${renamedClass});
144
169
  `
145
170
  );
146
171
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","sources":["../../../../src/vite/transform.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport { detectWorkerEntrypointClasses } from './workerEntrypoint';\n\n// ---------------------------------------------------------------------------\n// Minimal ESTree node types for the AST nodes we inspect.\n// ---------------------------------------------------------------------------\n\nexport interface BaseNode {\n type: string;\n start: number;\n end: number;\n}\n\nexport interface ProgramBody {\n body: BaseNode[];\n}\n\ninterface IdentifierNode extends BaseNode {\n name: string;\n}\n\ninterface CalleeNode {\n type: string;\n name?: string;\n property?: { type: string; name?: string };\n}\n\ninterface CallExpressionNode extends BaseNode {\n callee?: CalleeNode;\n}\n\ninterface ClassDeclarationNode extends BaseNode {\n id?: IdentifierNode | null;\n}\n\ninterface ExportDefaultNode extends BaseNode {\n declaration: BaseNode;\n}\n\ninterface ExportSpecifierNode {\n type: string;\n local?: { type: string; name?: string };\n exported?: { type: string; name?: string };\n}\n\ninterface ExportNamedNode extends BaseNode {\n declaration?: BaseNode | null;\n source?: unknown;\n specifiers?: ExportSpecifierNode[];\n}\n\ninterface VariableDeclaratorNode {\n id?: { type: string; name?: string };\n init?: BaseNode | null;\n}\n\ninterface VariableDeclarationNode extends BaseNode {\n declarations?: VariableDeclaratorNode[];\n}\n\nfunction isCallToMethod(node: BaseNode, methodName: string): boolean {\n if (node.type !== 'CallExpression') return false;\n const callee = (node as CallExpressionNode).callee;\n if (!callee) return false;\n if (callee.type === 'Identifier' && callee.name === methodName) return true;\n return (\n callee.type === 'MemberExpression' && callee.property?.type === 'Identifier' && callee.property.name === methodName\n );\n}\n\n/**\n * The kind of Sentry wrapper to apply to an exported class.\n *\n * `durableObject` and `workflow` are keyed by name from the wrangler config\n * (`durable_objects.bindings`, `workflows`), since those class names are\n * authoritative there. `workerEntrypoint` is different: a worker's own\n * entrypoints aren't enumerated in its config, so they're detected structurally\n * (a class extending `WorkerEntrypoint` from `cloudflare:workers`), with the\n * config providing only a fallback for self-bound entrypoints whose base class\n * lives in another module.\n */\nexport type ClassWrapperKind = 'durableObject' | 'agent' | 'workflow' | 'workerEntrypoint';\n\n/**\n * The `@sentry/cloudflare` helper each wrapper kind emits. All share the same\n * `(optionsCallback, Class)` signature. `WorkerEntrypoint` classes use\n * `withSentry`, which runtime-detects the class type and routes accordingly.\n */\nconst WRAPPER_METHODS: Record<ClassWrapperKind, string> = {\n durableObject: 'instrumentDurableObjectWithSentry',\n agent: 'instrumentAgentWithSentry',\n workflow: 'instrumentWorkflowWithSentry',\n workerEntrypoint: 'withSentry',\n};\n\nexport interface TransformContext {\n /**\n * Exported class name → the kind of Sentry wrapper to apply. Populated from\n * the wrangler config, so the transform can wrap by name without resolving\n * each class's base type.\n */\n classWrappers: Map<string, ClassWrapperKind>;\n /**\n * Local class names detected as `agents` Agents. An Agent is configured as a Durable Object in\n * wrangler, so this upgrades those entries from `durableObject` to `agent`.\n */\n agentClasses?: ReadonlySet<string>;\n optionsFn: string;\n /** Import statement prepended when `optionsFn` references a separate module. */\n optionsImport?: string;\n}\n\nexport interface TransformResult {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n /**\n * The configured class names that were actually wrapped. Lets the plugin warn\n * about configured classes it could not find, instead of silently leaving\n * them uninstrumented.\n */\n wrappedClasses: Set<string>;\n}\n\n/**\n * Rewrite the worker entry source to wrap its default export with `withSentry`\n * and any configured class export with its matching Sentry wrapper (see\n * {@link TransformContext.classWrappers}, e.g. Durable Object classes with\n * `instrumentDurableObjectWithSentry`).\n *\n * Handles both `export class MyDO {}` and the specifier form\n * (`class MyDO {}` … `export { MyDO }` / `export { Foo as MyDO }`).\n * Re-exports from other modules (`export { MyDO } from './do'`) cannot be\n * wrapped here and are left alone — the plugin warns about them via\n * {@link TransformResult.wrappedClasses}.\n *\n * Exported (rather than inlined into the plugin) so it can be unit-tested with a\n * plain AST and no Vite context. Returns `undefined` when nothing was wrapped and\n * there are no already-manually-wrapped classes to report.\n */\nexport function applyAutoInstrumentTransforms(\n code: string,\n ast: ProgramBody,\n ctx: TransformContext,\n): TransformResult | undefined {\n const ms = new MagicString(code);\n const topLevelClasses = collectTopLevelClasses(ast);\n const state: TransformState = {\n ms,\n needsImport: false,\n wrappedClasses: new Set<string>(),\n topLevelClasses,\n renamedLocals: new Set<string>(),\n classWrappers: ctx.classWrappers,\n agentClasses: ctx.agentClasses ?? new Set<string>(),\n workerEntrypointClasses: detectWorkerEntrypointClasses(ast),\n };\n const { wrappedClasses } = state;\n\n // Named exports first, regardless of source order: the default-export handler\n // needs to know which local bindings a named export already wrapped, so it can\n // skip a class that is both exported by name and re-exported as default (which\n // would otherwise wrap it twice).\n for (const node of ast.body) {\n if (node.type === 'ExportNamedDeclaration') {\n handleNamedExport(node, ctx, state);\n }\n }\n for (const node of ast.body) {\n if (node.type === 'ExportDefaultDeclaration') {\n wrapDefaultExport(node as ExportDefaultNode, ctx, state);\n }\n }\n\n if (!state.needsImport) {\n // Nothing was rewritten. Still surface any classes found already wrapped\n // manually (via `wrappedClasses`) so the caller doesn't warn about them;\n // return undefined only when there was nothing to report either.\n if (wrappedClasses.size === 0) return undefined;\n return { code, map: ms.generateMap({ hires: true }), wrappedClasses };\n }\n\n if (ctx.optionsImport) ms.prepend(ctx.optionsImport);\n ms.prepend(\"import * as __SENTRY__ from '@sentry/cloudflare';\\n\");\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: true }),\n wrappedClasses,\n };\n}\n\ninterface TransformState {\n ms: MagicString;\n needsImport: boolean;\n wrappedClasses: Set<string>;\n /**\n * Top-level (non-exported) class declarations, so specifier exports like\n * `export { MyDO }` can locate the class they refer to.\n */\n topLevelClasses: Map<string, ClassDeclarationNode>;\n /**\n * Local class names already renamed + wrapped, so two specifiers pointing at\n * the same class don't produce duplicate bindings.\n */\n renamedLocals: Set<string>;\n /** Class name → wrapper kind, keyed by the *exported* name (from config). */\n classWrappers: Map<string, ClassWrapperKind>;\n /** Local class names detected as `agents` Agents (see {@link TransformContext.agentClasses}). */\n agentClasses: ReadonlySet<string>;\n /**\n * Local class names detected as `WorkerEntrypoint` subclasses in this module,\n * so they can be wrapped without a config entry.\n */\n workerEntrypointClasses: Set<string>;\n}\n\n/**\n * Resolve the wrapper kind for a class export.\n *\n * Config (`classWrappers`) wins — it's authoritative for Durable Objects and\n * Workflows, and provides the self-binding fallback for WorkerEntrypoints whose\n * base class this module can't see. Otherwise a structurally-detected\n * `WorkerEntrypoint` subclass (matched by its *local* name) gets wrapped with\n * `withSentry`.\n *\n * The one case where config is refined rather than obeyed is an `agents` Agent:\n * it *is* a Durable Object, so wrangler can only ever describe it as one, and\n * only the detected base chain distinguishes the two.\n */\nfunction resolveWrapperKind(\n exportedName: string,\n localName: string | undefined,\n state: TransformState,\n): ClassWrapperKind | undefined {\n const configured = state.classWrappers.get(exportedName);\n if (configured === 'durableObject' && localName && state.agentClasses.has(localName)) return 'agent';\n if (configured) return configured;\n if (localName && state.workerEntrypointClasses.has(localName)) return 'workerEntrypoint';\n return undefined;\n}\n\nfunction collectTopLevelClasses(ast: ProgramBody): Map<string, ClassDeclarationNode> {\n const classes = new Map<string, ClassDeclarationNode>();\n for (const node of ast.body) {\n if (node.type !== 'ClassDeclaration') continue;\n const classNode = node as ClassDeclarationNode;\n if (classNode.id?.name) classes.set(classNode.id.name, classNode);\n }\n return classes;\n}\n\nfunction wrapDefaultExport(node: ExportDefaultNode, ctx: TransformContext, state: TransformState): void {\n const decl = node.declaration;\n\n // Already wrapped — leave it alone\n if (isCallToMethod(decl, 'withSentry')) return;\n\n // `export default Foo` where `Foo` is a local class already wrapped by a named\n // export (e.g. a self-bound WorkerEntrypoint also used as the default handler).\n // Wrapping again would produce `withSentry(withSentry(...))`.\n if (decl.type === 'Identifier' && state.renamedLocals.has((decl as IdentifierNode).name)) return;\n\n // `export default <expr>` → `const __SENTRY_DEFAULT_EXPORT__ = <expr>`\n // MagicString positions are always relative to the original source.\n state.ms.overwrite(node.start, decl.start, 'const __SENTRY_DEFAULT_EXPORT__ = ');\n state.ms.append(`\\nexport default __SENTRY__.withSentry(${ctx.optionsFn}, __SENTRY_DEFAULT_EXPORT__);\\n`);\n state.needsImport = true;\n}\n\nfunction handleNamedExport(node: ExportNamedNode, ctx: TransformContext, state: TransformState): void {\n const decl = node.declaration;\n\n // ---- Manually wrapped class export ----\n // `export const MyDO = instrumentDurableObjectWithSentry(...)` — count it\n // as wrapped so the plugin doesn't warn about it, but leave it alone.\n if (decl?.type === 'VariableDeclaration') {\n collectManuallyWrappedClassExports(decl, ctx, state);\n return;\n }\n\n // ---- Named class export matching a configured binding ----\n if (decl?.type === 'ClassDeclaration') {\n wrapInlineClassExport(node, decl, ctx, state);\n return;\n }\n\n // ---- Specifier export of a local class (`export { Foo as MyDO }`) ----\n // Re-exports from another module carry a `source` — nothing local to wrap.\n if (node.source) return;\n for (const specifier of node.specifiers ?? []) {\n wrapSpecifierExport(specifier, ctx, state);\n }\n}\n\nfunction collectManuallyWrappedClassExports(\n varDecl: VariableDeclarationNode,\n ctx: TransformContext,\n state: TransformState,\n): void {\n for (const declarator of varDecl.declarations ?? []) {\n const name = declarator.id?.type === 'Identifier' ? declarator.id.name : undefined;\n const kind = name ? ctx.classWrappers.get(name) : undefined;\n if (!name || !kind || !declarator.init) continue;\n\n // A hand-wrapped Agent is configured as a Durable Object, so accept either helper there —\n // otherwise an already-instrumented Agent would be reported as unwrapped.\n const accepted =\n kind === 'durableObject' ? [WRAPPER_METHODS.durableObject, WRAPPER_METHODS.agent] : [WRAPPER_METHODS[kind]];\n\n if (accepted.some(method => isCallToMethod(declarator.init as BaseNode, method))) {\n state.wrappedClasses.add(name);\n }\n }\n}\n\nfunction wrapInlineClassExport(\n exportNode: ExportNamedNode,\n classDecl: ClassDeclarationNode,\n ctx: TransformContext,\n state: TransformState,\n): void {\n const classId = classDecl.id;\n // Inline export: the exported name and the local class name are the same.\n const kind = classId ? resolveWrapperKind(classId.name, classId.name, state) : undefined;\n if (!classId || !kind) return;\n\n const className = classId.name;\n const renamedClass = `__SENTRY_ORIGINAL_${className}__`;\n\n // Strip the `export ` keyword\n state.ms.overwrite(exportNode.start, classDecl.start, '');\n\n // Rename the class to avoid a duplicate binding\n state.ms.overwrite(classId.start, classId.end, renamedClass);\n\n // Insert the wrapped re-export after the class body\n state.ms.appendLeft(\n exportNode.end,\n `\\nexport const ${className} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});\\n`,\n );\n\n state.wrappedClasses.add(className);\n state.renamedLocals.add(className);\n state.needsImport = true;\n}\n\nfunction wrapSpecifierExport(specifier: ExportSpecifierNode, ctx: TransformContext, state: TransformState): void {\n if (specifier.type !== 'ExportSpecifier' || specifier.exported?.type !== 'Identifier') return;\n const exportedName = specifier.exported.name;\n if (!exportedName) return;\n\n const localName = specifier.local?.type === 'Identifier' ? specifier.local.name : undefined;\n const kind = resolveWrapperKind(exportedName, localName, state);\n if (!kind) return;\n\n const localClass = localName ? state.topLevelClasses.get(localName) : undefined;\n if (!localName || !localClass?.id) return;\n\n state.wrappedClasses.add(exportedName);\n state.needsImport = true;\n if (state.renamedLocals.has(localName)) return;\n state.renamedLocals.add(localName);\n\n const renamedClass = `__SENTRY_ORIGINAL_${localName}__`;\n state.ms.overwrite(localClass.id.start, localClass.id.end, renamedClass);\n // The existing `export { ... }` statement keeps exporting the (now\n // wrapped) `localName` binding, so the wrapper is NOT exported here.\n state.ms.appendLeft(\n localClass.end,\n `\\nconst ${localName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});\\n`,\n );\n}\n"],"names":["MagicString","detectWorkerEntrypointClasses"],"mappings":";;;;;AA4DA,SAAS,cAAA,CAAe,MAAgB,UAAA,EAA6B;AACnE,EAAA,IAAI,IAAA,CAAK,IAAA,KAAS,gBAAA,EAAkB,OAAO,KAAA;AAC3C,EAAA,MAAM,SAAU,IAAA,CAA4B,MAAA;AAC5C,EAAA,IAAI,CAAC,QAAQ,OAAO,KAAA;AACpB,EAAA,IAAI,OAAO,IAAA,KAAS,YAAA,IAAgB,MAAA,CAAO,IAAA,KAAS,YAAY,OAAO,IAAA;AACvE,EAAA,OACE,MAAA,CAAO,SAAS,kBAAA,IAAsB,MAAA,CAAO,UAAU,IAAA,KAAS,YAAA,IAAgB,MAAA,CAAO,QAAA,CAAS,IAAA,KAAS,UAAA;AAE7G;AAoBA,MAAM,eAAA,GAAoD;AAAA,EACxD,aAAA,EAAe,mCAAA;AAAA,EACf,KAAA,EAAO,2BAAA;AAAA,EACP,QAAA,EAAU,8BAAA;AAAA,EACV,gBAAA,EAAkB;AACpB,CAAA;AA8CO,SAAS,6BAAA,CACd,IAAA,EACA,GAAA,EACA,GAAA,EAC6B;AAC7B,EAAA,MAAM,EAAA,GAAK,IAAIA,mBAAA,CAAY,IAAI,CAAA;AAC/B,EAAA,MAAM,eAAA,GAAkB,uBAAuB,GAAG,CAAA;AAClD,EAAA,MAAM,KAAA,GAAwB;AAAA,IAC5B,EAAA;AAAA,IACA,WAAA,EAAa,KAAA;AAAA,IACb,cAAA,sBAAoB,GAAA,EAAY;AAAA,IAChC,eAAA;AAAA,IACA,aAAA,sBAAmB,GAAA,EAAY;AAAA,IAC/B,eAAe,GAAA,CAAI,aAAA;AAAA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c;AAEnB,EAAA,MAAM,YAAY,SAAA,CAAU,KAAA,EAAO,SAAS,YAAA,GAAe,SAAA,CAAU,MAAM,IAAA,GAAO,MAAA;AAClF,EAAA,MAAM,IAAA,GAAO,kBAAA,CAAmB,YAAA,EAAc,SAAA,EAAW,KAAK,CAAA;AAC9D,EAAA,IAAI,CAAC,IAAA,EAAM;AAEX,EAAA,MAAM,aAAa,SAAA,GAAY,KAAA,CAAM,eAAA,CAAgB,GAAA,CAAI,SAAS,CAAA,GAAI,MAAA;AACtE,EAAA,IAAI,CAAC,SAAA,IAAa,CAAC,UAAA,EAAY,EAAA,EAAI;AAEnC,EAAA,KAAA,CAAM,cAAA,CAAe,IAAI,YAAY,CAAA;AACrC,EAAA,KAAA,CAAM,WAAA,GAAc,IAAA;AACpB,EAAA,IAAI,KAAA,CAAM,aAAA,CAAc,GAAA,CAAI,SAAS,CAAA,EAAG;AACxC,EAAA,KAAA,CAAM,aAAA,CAAc,IAAI,SAAS,CAAA;AAEjC,EAAA,MAAM,YAAA,GAAe,qBAAqB,SAAS,CAAA,EAAA,CAAA;AACnD,EAAA,KAAA,CAAM,EAAA,CAAG,UAAU,UAAA,CAAW,EAAA,CAAG,OAAO,UAAA,CAAW,EAAA,CAAG,KAAK,YAAY,CAAA;AAGvE,EAAA,KAAA,CAAM,EAAA,CAAG,UAAA;AAAA,IACP,UAAA,CAAW,GAAA;AAAA,IACX;AAAA,MAAA,EAAW,SAAS,iBAAiB,eAAA,CAAgB,IAAI,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,SAAS,CAAA,EAAA,EAAK,YAAY,CAAA;AAAA;AAAA,GAC9F;AACF;;;;"}
1
+ {"version":3,"file":"transform.js","sources":["../../../../src/vite/transform.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport { DEFAULT_EXPORT, type ExportName, type SameWorkerBinding } from './wranglerConfig';\nimport { detectWorkerEntrypointClasses } from './workerEntrypoint';\n\nconst MERGED_OPTIONS_IDENTIFIER = '__SENTRY_OPTIONS__';\n\n// ---------------------------------------------------------------------------\n// Minimal ESTree node types for the AST nodes we inspect.\n// ---------------------------------------------------------------------------\n\nexport interface BaseNode {\n type: string;\n start: number;\n end: number;\n}\n\nexport interface ProgramBody {\n body: BaseNode[];\n}\n\ninterface IdentifierNode extends BaseNode {\n name: string;\n}\n\ninterface CalleeNode {\n type: string;\n name?: string;\n property?: { type: string; name?: string };\n}\n\ninterface CallExpressionNode extends BaseNode {\n callee?: CalleeNode;\n}\n\ninterface ClassDeclarationNode extends BaseNode {\n id?: IdentifierNode | null;\n}\n\ninterface ExportDefaultNode extends BaseNode {\n declaration: BaseNode;\n}\n\ninterface ExportSpecifierNode {\n type: string;\n local?: { type: string; name?: string };\n exported?: { type: string; name?: string };\n}\n\ninterface ExportNamedNode extends BaseNode {\n declaration?: BaseNode | null;\n source?: unknown;\n specifiers?: ExportSpecifierNode[];\n}\n\ninterface VariableDeclaratorNode {\n id?: { type: string; name?: string };\n init?: BaseNode | null;\n}\n\ninterface VariableDeclarationNode extends BaseNode {\n declarations?: VariableDeclaratorNode[];\n}\n\nfunction isCallToMethod(node: BaseNode, methodName: string): boolean {\n if (node.type !== 'CallExpression') return false;\n const callee = (node as CallExpressionNode).callee;\n if (!callee) return false;\n if (callee.type === 'Identifier' && callee.name === methodName) return true;\n return (\n callee.type === 'MemberExpression' && callee.property?.type === 'Identifier' && callee.property.name === methodName\n );\n}\n\n/**\n * The kind of Sentry wrapper to apply to an exported class.\n *\n * `durableObject` and `workflow` are keyed by name from the wrangler config\n * (`durable_objects.bindings`, `workflows`), since those class names are\n * authoritative there. `workerEntrypoint` is different: a worker's own\n * entrypoints aren't enumerated in its config, so they're detected structurally\n * (a class extending `WorkerEntrypoint` from `cloudflare:workers`), with the\n * config providing only a fallback for self-bound entrypoints whose base class\n * lives in another module.\n */\nexport type ClassWrapperKind = 'durableObject' | 'agent' | 'workflow' | 'workerEntrypoint';\n\n/**\n * The `@sentry/cloudflare` helper each wrapper kind emits. All share the same\n * `(optionsCallback, Class)` signature. `WorkerEntrypoint` classes use\n * `withSentry`, which runtime-detects the class type and routes accordingly.\n */\nconst WRAPPER_METHODS: Record<ClassWrapperKind, string> = {\n durableObject: 'instrumentDurableObjectWithSentry',\n agent: 'instrumentAgentWithSentry',\n workflow: 'instrumentWorkflowWithSentry',\n workerEntrypoint: 'withSentry',\n};\n\nexport interface TransformContext {\n /**\n * Exported class name → the kind of Sentry wrapper to apply. Populated from\n * the wrangler config, so the transform can wrap by name without resolving\n * each class's base type.\n */\n classWrappers: Map<string, ClassWrapperKind>;\n /**\n * Local class names detected as `agents` Agents. An Agent is configured as a Durable Object in\n * wrangler, so this upgrades those entries from `durableObject` to `agent`.\n */\n agentClasses?: ReadonlySet<string>;\n optionsFn: string;\n /** Import statement prepended when `optionsFn` references a separate module. */\n optionsImport?: string;\n /** @see {@link import('./wranglerConfig').WranglerConfig.sameWorkerBindings} */\n sameWorkerBindings?: readonly SameWorkerBinding[];\n}\n\nexport interface TransformResult {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n /**\n * The configured class names that were actually wrapped. Lets the plugin warn\n * about configured classes it could not find, instead of silently leaving\n * them uninstrumented.\n */\n wrappedClasses: Set<string>;\n}\n\n/**\n * Rewrite the worker entry source to wrap its default export with `withSentry`\n * and any configured class export with its matching Sentry wrapper (see\n * {@link TransformContext.classWrappers}, e.g. Durable Object classes with\n * `instrumentDurableObjectWithSentry`).\n *\n * Handles both `export class MyDO {}` and the specifier form\n * (`class MyDO {}` … `export { MyDO }` / `export { Foo as MyDO }`).\n * Re-exports from other modules (`export { MyDO } from './do'`) cannot be\n * wrapped here and are left alone — the plugin warns about them via\n * {@link TransformResult.wrappedClasses}.\n *\n * Exported (rather than inlined into the plugin) so it can be unit-tested with a\n * plain AST and no Vite context. Returns `undefined` when nothing was wrapped and\n * there are no already-manually-wrapped classes to report.\n */\nexport function applyAutoInstrumentTransforms(\n code: string,\n ast: ProgramBody,\n ctx: TransformContext,\n): TransformResult | undefined {\n const ms = new MagicString(code);\n const topLevelClasses = collectTopLevelClasses(ast);\n const sameWorkerBindings = ctx.sameWorkerBindings ?? [];\n const state: TransformState = {\n ms,\n needsImport: false,\n wrappedClasses: new Set<string>(),\n topLevelClasses,\n renamedLocals: new Set<string>(),\n classWrappers: ctx.classWrappers,\n agentClasses: ctx.agentClasses ?? new Set<string>(),\n workerEntrypointClasses: detectWorkerEntrypointClasses(ast),\n // The identifier must be chosen before wrapping, which bindings survive is only known after.\n optionsFn: sameWorkerBindings.length > 0 ? MERGED_OPTIONS_IDENTIFIER : ctx.optionsFn,\n autoWrapped: new Set<ExportName>(),\n };\n const { wrappedClasses } = state;\n\n // Named exports first, regardless of source order: the default-export handler\n // needs to know which local bindings a named export already wrapped, so it can\n // skip a class that is both exported by name and re-exported as default (which\n // would otherwise wrap it twice).\n for (const node of ast.body) {\n if (node.type === 'ExportNamedDeclaration') {\n handleNamedExport(node, ctx, state);\n }\n }\n for (const node of ast.body) {\n if (node.type === 'ExportDefaultDeclaration') {\n wrapDefaultExport(node as ExportDefaultNode, ctx, state);\n }\n }\n\n if (!state.needsImport) {\n // Nothing was rewritten. Still surface any classes found already wrapped\n // manually (via `wrappedClasses`) so the caller doesn't warn about them;\n // return undefined only when there was nothing to report either.\n if (wrappedClasses.size === 0) return undefined;\n return { code, map: ms.generateMap({ hires: true }), wrappedClasses };\n }\n\n // `prepend` inserts before earlier prepends, yielding: Sentry import, options import, declaration.\n if (sameWorkerBindings.length > 0) {\n ms.prepend(buildMergedOptionsDeclaration(sameWorkerBindings, ctx.optionsFn, state));\n }\n if (ctx.optionsImport) ms.prepend(ctx.optionsImport);\n ms.prepend(\"import * as __SENTRY__ from '@sentry/cloudflare';\\n\");\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: true }),\n wrappedClasses,\n };\n}\n\ninterface TransformState {\n ms: MagicString;\n needsImport: boolean;\n wrappedClasses: Set<string>;\n /**\n * Top-level (non-exported) class declarations, so specifier exports like\n * `export { MyDO }` can locate the class they refer to.\n */\n topLevelClasses: Map<string, ClassDeclarationNode>;\n /**\n * Local class names already renamed + wrapped, so two specifiers pointing at\n * the same class don't produce duplicate bindings.\n */\n renamedLocals: Set<string>;\n /** Class name → wrapper kind, keyed by the *exported* name (from config). */\n classWrappers: Map<string, ClassWrapperKind>;\n /** Local class names detected as `agents` Agents (see {@link TransformContext.agentClasses}). */\n agentClasses: ReadonlySet<string>;\n /**\n * Local class names detected as `WorkerEntrypoint` subclasses in this module,\n * so they can be wrapped without a config entry.\n */\n workerEntrypointClasses: Set<string>;\n optionsFn: string;\n /**\n * Export names wrapped by this transform, so their options can be extended with\n * `rpcTracePropagationBindings`. Hand-wrapped exports stay out, they keep the options they were\n * wrapped with. `wrappedClasses` counts both.\n */\n autoWrapped: Set<ExportName>;\n}\n\n/**\n * Builds the callback that merges same-worker binding names into `rpcTracePropagationBindings` at\n * runtime, the options object only exists once the callback runs with `env`. Only bindings whose\n * class this transform wrapped survive, a hand-wrapped class runs on its own options.\n */\nfunction buildMergedOptionsDeclaration(\n sameWorkerBindings: readonly SameWorkerBinding[],\n optionsFn: string,\n state: TransformState,\n): string {\n const bindingNames = sameWorkerBindings\n .filter(({ className }) => state.autoWrapped.has(className))\n .map(({ bindingName }) => bindingName);\n\n if (!bindingNames.length) {\n return `const ${MERGED_OPTIONS_IDENTIFIER} = ${optionsFn};\\n`;\n }\n\n const names = bindingNames.map(name => JSON.stringify(name)).join(', ');\n return (\n `const ${MERGED_OPTIONS_IDENTIFIER} = (env) => { ` +\n `const opts = (${optionsFn})(env); ` +\n `return { ...opts, rpcTracePropagationBindings: [${names}, ...(opts?.rpcTracePropagationBindings ?? [])] }; };\\n`\n );\n}\n\n/**\n * Resolve the wrapper kind for a class export.\n *\n * Config (`classWrappers`) wins — it's authoritative for Durable Objects and\n * Workflows, and provides the self-binding fallback for WorkerEntrypoints whose\n * base class this module can't see. Otherwise a structurally-detected\n * `WorkerEntrypoint` subclass (matched by its *local* name) gets wrapped with\n * `withSentry`.\n *\n * The one case where config is refined rather than obeyed is an `agents` Agent:\n * it *is* a Durable Object, so wrangler can only ever describe it as one, and\n * only the detected base chain distinguishes the two.\n */\nfunction resolveWrapperKind(\n exportedName: string,\n localName: string | undefined,\n state: TransformState,\n): ClassWrapperKind | undefined {\n const configured = state.classWrappers.get(exportedName);\n if (configured === 'durableObject' && localName && state.agentClasses.has(localName)) return 'agent';\n if (configured) return configured;\n if (localName && state.workerEntrypointClasses.has(localName)) return 'workerEntrypoint';\n return undefined;\n}\n\nfunction collectTopLevelClasses(ast: ProgramBody): Map<string, ClassDeclarationNode> {\n const classes = new Map<string, ClassDeclarationNode>();\n for (const node of ast.body) {\n if (node.type !== 'ClassDeclaration') continue;\n const classNode = node as ClassDeclarationNode;\n if (classNode.id?.name) classes.set(classNode.id.name, classNode);\n }\n return classes;\n}\n\nfunction wrapDefaultExport(node: ExportDefaultNode, ctx: TransformContext, state: TransformState): void {\n const decl = node.declaration;\n\n // Already wrapped — leave it alone\n if (isCallToMethod(decl, 'withSentry')) return;\n\n // `export default Foo` where `Foo` is a local class already wrapped by a named\n // export (e.g. a self-bound WorkerEntrypoint also used as the default handler).\n // Wrapping again would produce `withSentry(withSentry(...))`. The binding still\n // points at the wrapped class, so the default export counts as auto-wrapped.\n if (decl.type === 'Identifier' && state.renamedLocals.has((decl as IdentifierNode).name)) {\n state.autoWrapped.add(DEFAULT_EXPORT);\n return;\n }\n\n // `export default <expr>` → `const __SENTRY_DEFAULT_EXPORT__ = <expr>`\n // MagicString positions are always relative to the original source.\n state.ms.overwrite(node.start, decl.start, 'const __SENTRY_DEFAULT_EXPORT__ = ');\n state.ms.append(`\\nexport default __SENTRY__.withSentry(${state.optionsFn}, __SENTRY_DEFAULT_EXPORT__);\\n`);\n state.needsImport = true;\n state.autoWrapped.add(DEFAULT_EXPORT);\n}\n\nfunction handleNamedExport(node: ExportNamedNode, ctx: TransformContext, state: TransformState): void {\n const decl = node.declaration;\n\n // ---- Manually wrapped class export ----\n // `export const MyDO = instrumentDurableObjectWithSentry(...)` — count it\n // as wrapped so the plugin doesn't warn about it, but leave it alone.\n if (decl?.type === 'VariableDeclaration') {\n collectManuallyWrappedClassExports(decl, ctx, state);\n return;\n }\n\n // ---- Named class export matching a configured binding ----\n if (decl?.type === 'ClassDeclaration') {\n wrapInlineClassExport(node, decl, ctx, state);\n return;\n }\n\n // ---- Specifier export of a local class (`export { Foo as MyDO }`) ----\n // Re-exports from another module carry a `source` — nothing local to wrap.\n if (node.source) return;\n for (const specifier of node.specifiers ?? []) {\n wrapSpecifierExport(specifier, ctx, state);\n }\n}\n\nfunction collectManuallyWrappedClassExports(\n varDecl: VariableDeclarationNode,\n ctx: TransformContext,\n state: TransformState,\n): void {\n for (const declarator of varDecl.declarations ?? []) {\n const name = declarator.id?.type === 'Identifier' ? declarator.id.name : undefined;\n const kind = name ? ctx.classWrappers.get(name) : undefined;\n if (!name || !kind || !declarator.init) continue;\n\n // A hand-wrapped Agent is configured as a Durable Object, so accept either helper there —\n // otherwise an already-instrumented Agent would be reported as unwrapped.\n const accepted =\n kind === 'durableObject' ? [WRAPPER_METHODS.durableObject, WRAPPER_METHODS.agent] : [WRAPPER_METHODS[kind]];\n\n if (accepted.some(method => isCallToMethod(declarator.init as BaseNode, method))) {\n state.wrappedClasses.add(name);\n }\n }\n}\n\nfunction wrapInlineClassExport(\n exportNode: ExportNamedNode,\n classDecl: ClassDeclarationNode,\n ctx: TransformContext,\n state: TransformState,\n): void {\n const classId = classDecl.id;\n // Inline export: the exported name and the local class name are the same.\n const kind = classId ? resolveWrapperKind(classId.name, classId.name, state) : undefined;\n if (!classId || !kind) return;\n\n const className = classId.name;\n const renamedClass = `__SENTRY_ORIGINAL_${className}__`;\n\n // Strip the `export ` keyword\n state.ms.overwrite(exportNode.start, classDecl.start, '');\n\n // Rename the class to avoid a duplicate binding\n state.ms.overwrite(classId.start, classId.end, renamedClass);\n\n // Insert the wrapped re-export after the class body\n state.ms.appendLeft(\n exportNode.end,\n `\\nexport const ${className} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${renamedClass});\\n`,\n );\n\n state.wrappedClasses.add(className);\n state.autoWrapped.add(className);\n state.renamedLocals.add(className);\n state.needsImport = true;\n}\n\nfunction wrapSpecifierExport(specifier: ExportSpecifierNode, ctx: TransformContext, state: TransformState): void {\n if (specifier.type !== 'ExportSpecifier' || specifier.exported?.type !== 'Identifier') return;\n const exportedName = specifier.exported.name;\n if (!exportedName) return;\n\n const localName = specifier.local?.type === 'Identifier' ? specifier.local.name : undefined;\n const kind = resolveWrapperKind(exportedName, localName, state);\n if (!kind) return;\n\n const localClass = localName ? state.topLevelClasses.get(localName) : undefined;\n if (!localName || !localClass?.id) return;\n\n state.wrappedClasses.add(exportedName);\n state.autoWrapped.add(exportedName);\n state.needsImport = true;\n if (state.renamedLocals.has(localName)) return;\n state.renamedLocals.add(localName);\n\n const renamedClass = `__SENTRY_ORIGINAL_${localName}__`;\n state.ms.overwrite(localClass.id.start, localClass.id.end, renamedClass);\n // The existing `export { ... }` statement keeps exporting the (now\n // wrapped) `localName` binding, so the wrapper is NOT exported here.\n state.ms.appendLeft(\n localClass.end,\n `\\nconst ${localName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${renamedClass});\\n`,\n );\n}\n"],"names":["MagicString","detectWorkerEntrypointClasses","DEFAULT_EXPORT"],"mappings":";;;;;;AAIA,MAAM,yBAAA,GAA4B,oBAAA;AA2DlC,SAAS,cAAA,CAAe,MAAgB,UAAA,EAA6B;AACnE,EAAA,IAAI,IAAA,CAAK,IAAA,KAAS,gBAAA,EAAkB,OAAO,KAAA;AAC3C,EAAA,MAAM,SAAU,IAAA,CAA4B,MAAA;AAC5C,EAAA,IAAI,CAAC,QAAQ,OAAO,KAAA;AACpB,EAAA,IAAI,OAAO,IAAA,KAAS,YAAA,IAAgB,MAAA,CAAO,IAAA,KAAS,YAAY,OAAO,IAAA;AACvE,EAAA,OACE,MAAA,CAAO,S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C,EAAA,KAAA,CAAM,aAAA,CAAc,IAAI,SAAS,CAAA;AAEjC,EAAA,MAAM,YAAA,GAAe,qBAAqB,SAAS,CAAA,EAAA,CAAA;AACnD,EAAA,KAAA,CAAM,EAAA,CAAG,UAAU,UAAA,CAAW,EAAA,CAAG,OAAO,UAAA,CAAW,EAAA,CAAG,KAAK,YAAY,CAAA;AAGvE,EAAA,KAAA,CAAM,EAAA,CAAG,UAAA;AAAA,IACP,UAAA,CAAW,GAAA;AAAA,IACX;AAAA,MAAA,EAAW,SAAS,iBAAiB,eAAA,CAAgB,IAAI,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,SAAS,CAAA,EAAA,EAAK,YAAY,CAAA;AAAA;AAAA,GAChG;AACF;;;;"}
@@ -4,6 +4,7 @@ const node_fs = require('node:fs');
4
4
  const node_path = require('node:path');
5
5
  const wrangler = require('wrangler');
6
6
 
7
+ const DEFAULT_EXPORT = /* @__PURE__ */ Symbol("defaultExport");
7
8
  function resolveWranglerConfig(root, explicitPath) {
8
9
  const configPath = explicitPath ? node_path.resolve(root, explicitPath) : ["wrangler.json", "wrangler.jsonc", "wrangler.toml"].map((name) => node_path.resolve(root, name)).find(node_fs.existsSync);
9
10
  if (!configPath || !node_fs.existsSync(configPath)) {
@@ -20,7 +21,8 @@ function resolveWranglerConfig(root, explicitPath) {
20
21
  main: raw.main,
21
22
  durableObjects: collectClassBindings(raw.durable_objects?.bindings),
22
23
  workflows: collectClassBindings(raw.workflows),
23
- workerEntrypoints: collectSelfBoundEntrypoints(raw)
24
+ workerEntrypoints: collectSelfBoundEntrypoints(raw),
25
+ sameWorkerBindings: collectSameWorkerBindings(raw)
24
26
  },
25
27
  configDir: node_path.dirname(raw.configPath ?? configPath)
26
28
  };
@@ -37,6 +39,23 @@ function collectSelfBoundEntrypoints(raw) {
37
39
  }
38
40
  return [...entrypoints];
39
41
  }
42
+ function collectSameWorkerBindings(raw) {
43
+ const bindings = [];
44
+ for (const binding of raw.durable_objects?.bindings ?? []) {
45
+ if (typeof binding?.name === "string" && typeof binding.class_name === "string" && !binding.script_name) {
46
+ bindings.push({ bindingName: binding.name, className: binding.class_name });
47
+ }
48
+ }
49
+ for (const binding of raw.services ?? []) {
50
+ if (raw.name && binding?.service === raw.name && typeof binding.binding === "string") {
51
+ bindings.push({
52
+ bindingName: binding.binding,
53
+ className: typeof binding.entrypoint === "string" ? binding.entrypoint : DEFAULT_EXPORT
54
+ });
55
+ }
56
+ }
57
+ return bindings;
58
+ }
40
59
  function collectClassBindings(bindings) {
41
60
  const result = [];
42
61
  const seenClassNames = /* @__PURE__ */ new Set();
@@ -50,5 +69,6 @@ function collectClassBindings(bindings) {
50
69
  return result;
51
70
  }
52
71
 
72
+ exports.DEFAULT_EXPORT = DEFAULT_EXPORT;
53
73
  exports.resolveWranglerConfig = resolveWranglerConfig;
54
74
  //# sourceMappingURL=wranglerConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wranglerConfig.js","sources":["../../../../src/vite/wranglerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { type Unstable_Config, unstable_readConfig } from 'wrangler';\n\n/**\n * The slice of the wrangler configuration the auto-instrument plugin cares\n * about. `main` is an absolute path (wrangler resolves it against the config\n * file's directory).\n */\nexport interface WranglerConfig {\n main?: string;\n durableObjects: Array<{ name: string; className: string }>;\n workflows: Array<{ name: string; className: string }>;\n /**\n * Named `WorkerEntrypoint` exports this worker binds to itself via a service\n * binding (`services[]` whose `service` is this worker's own `name`). Only\n * self-bindings appear here: a service binding's `entrypoint` otherwise names\n * an export on a *different* worker, which this build can't wrap.\n */\n workerEntrypoints: string[];\n}\n\n/**\n * Locate and resolve the wrangler configuration via wrangler's own\n * `unstable_readConfig` — the API `@cloudflare/vite-plugin` uses.\n *\n * We only locate the file (probing `wrangler.json`, `.jsonc`, `.toml` inside\n * `root` with wrangler's own precedence, since it discovers from `cwd` rather\n * than an arbitrary root); wrangler then parses it, flattens the active\n * environment (honoring `CLOUDFLARE_ENV`), and resolves `main` to an absolute\n * path. Durable Object and Workflow bindings are the active environment's,\n * matching what the deployed Worker actually binds.\n *\n * Returns `undefined` when no config file is found or it can't be read/parsed\n * (the caller warns and disables auto-instrumentation rather than failing the\n * whole build).\n */\nexport function resolveWranglerConfig(\n root: string,\n explicitPath?: string,\n): { config: WranglerConfig; configDir: string } | undefined {\n const configPath = explicitPath\n ? resolve(root, explicitPath)\n : ['wrangler.json', 'wrangler.jsonc', 'wrangler.toml'].map(name => resolve(root, name)).find(existsSync);\n\n if (!configPath || !existsSync(configPath)) {\n return undefined;\n }\n\n let raw: Unstable_Config;\n try {\n // `hideWarnings` keeps wrangler's config diagnostics (e.g. missing DO\n // migrations) out of the Vite build output.\n raw = unstable_readConfig({ config: configPath }, { hideWarnings: true });\n } catch {\n return undefined;\n }\n\n return {\n config: {\n main: raw.main,\n durableObjects: collectClassBindings(raw.durable_objects?.bindings),\n workflows: collectClassBindings(raw.workflows),\n workerEntrypoints: collectSelfBoundEntrypoints(raw),\n },\n configDir: dirname(raw.configPath ?? configPath),\n };\n}\n\n/**\n * Collect named `WorkerEntrypoint` exports the worker binds to itself. A service\n * binding's `entrypoint` normally names an export on the *target* worker, so it\n * is only ours when `service` equals this worker's own `name`. Without a `name`\n * there is nothing to match against, so no entrypoints are derivable.\n */\nfunction collectSelfBoundEntrypoints(raw: Unstable_Config): string[] {\n if (!raw.name) {\n return [];\n }\n const entrypoints = new Set<string>();\n for (const binding of raw.services ?? []) {\n if (binding?.service === raw.name && typeof binding.entrypoint === 'string') {\n entrypoints.add(binding.entrypoint);\n }\n }\n return [...entrypoints];\n}\n\n/**\n * Map wrangler class bindings (Durable Objects, Workflows — same shape) to the\n * `{ name, className }` the transform needs, skipping duplicates and bindings\n * with a `script_name` (those reference a class exported by a *different*\n * worker, so there is nothing to wrap in this worker's entry file).\n */\nfunction collectClassBindings(\n bindings: ReadonlyArray<{ name: string; class_name?: string; script_name?: string }> | undefined,\n): Array<{ name: string; className: string }> {\n const result: Array<{ name: string; className: string }> = [];\n const seenClassNames = new Set<string>();\n for (const binding of bindings ?? []) {\n if (typeof binding?.class_name !== 'string' || binding.script_name || seenClassNames.has(binding.class_name)) {\n continue;\n }\n seenClassNames.add(binding.class_name);\n result.push({ name: binding.name, className: binding.class_name });\n }\n return result;\n}\n"],"names":["resolve","existsSync","unstable_readConfig","dirname"],"mappings":";;;;;;AAqCO,SAAS,qBAAA,CACd,MACA,YAAA,EAC2D;AAC3D,EAAA,MAAM,aAAa,YAAA,GACfA,iBAAA,CAAQ,MAAM,YAAY,CAAA,GAC1B,CAAC,eAAA,EAAiB,gBAAA,EAAkB,eAAe,CAAA,CAAE,GAAA,CAAI,UAAQA,iBAAA,CAAQ,IAAA,EAAM,IAAI,CAAC,CAAA,CAAE,KAAKC,kBAAU,CAAA;AAEzG,EAAA,IAAI,CAAC,UAAA,IAAc,CAACA,kBAAA,CAAW,UAAU,CAAA,EAAG;AAC1C,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AAGF,IAAA,GAAA,GAAMC,4BAAA,CAAoB,EAAE,MAAA,EAAQ,UAAA,IAAc,EAAE,YAAA,EAAc,MAAM,CAAA;AAAA,EAC1E,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,MAAM,GAAA,CAAI,IAAA;AAAA,MACV,cAAA,EAAgB,oBAAA,CAAqB,GAAA,CAAI,eAAA,EAAiB,QAAQ,CAAA;AAAA,MAClE,SAAA,EAAW,oBAAA,CAAqB,GAAA,CAAI,SAAS,CAAA;AAAA,MAC7C,iBAAA,EAAmB,4BAA4B,GAAG;AAAA,KACpD;AAAA,IACA,SAAA,EAAWC,iBAAA,CAAQ,GAAA,CAAI,UAAA,IAAc,UAAU;AAAA,GACjD;AACF;AAQA,SAAS,4BAA4B,GAAA,EAAgC;AACnE,EAAA,IAAI,CAAC,IAAI,IAAA,EAAM;AACb,IAAA,OAAO,EAAC;AAAA,EACV;AACA,EAAA,MAAM,WAAA,uBAAkB,GAAA,EAAY;AACpC,EAAA,KAAA,MAAW,OAAA,IAAW,GAAA,CAAI,QAAA,IAAY,EAAC,EAAG;AACxC,IAAA,IAAI,SAAS,OAAA,KAAY,GAAA,CAAI,QAAQ,OAAO,OAAA,CAAQ,eAAe,QAAA,EAAU;AAC3E,MAAA,WAAA,CAAY,GAAA,CAAI,QAAQ,UAAU,CAAA;AAAA,IACpC;AAAA,EACF;AACA,EAAA,OAAO,CAAC,GAAG,WAAW,CAAA;AACxB;AAQA,SAAS,qBACP,QAAA,EAC4C;AAC5C,EAAA,MAAM,SAAqD,EAAC;AAC5D,EAAA,MAAM,cAAA,uBAAqB,GAAA,EAAY;AACvC,EAAA,KAAA,MAAW,OAAA,IAAW,QAAA,IAAY,EAAC,EAAG;AACpC,IAAA,IAAI,OAAO,OAAA,EAAS,UAAA,KAAe,QAAA,IAAY,OAAA,CAAQ,eAAe,cAAA,CAAe,GAAA,CAAI,OAAA,CAAQ,UAAU,CAAA,EAAG;AAC5G,MAAA;AAAA,IACF;AACA,IAAA,cAAA,CAAe,GAAA,CAAI,QAAQ,UAAU,CAAA;AACrC,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,CAAQ,MAAM,SAAA,EAAW,OAAA,CAAQ,YAAY,CAAA;AAAA,EACnE;AACA,EAAA,OAAO,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"wranglerConfig.js","sources":["../../../../src/vite/wranglerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { type Unstable_Config, unstable_readConfig } from 'wrangler';\n\n/**\n * The slice of the wrangler configuration the auto-instrument plugin cares\n * about. `main` is an absolute path (wrangler resolves it against the config\n * file's directory).\n */\nexport interface WranglerConfig {\n main?: string;\n durableObjects: Array<{ name: string; className: string }>;\n workflows: Array<{ name: string; className: string }>;\n /**\n * Named `WorkerEntrypoint` exports this worker binds to itself via a service\n * binding (`services[]` whose `service` is this worker's own `name`). Only\n * self-bindings appear here: a service binding's `entrypoint` otherwise names\n * an export on a *different* worker, which this build can't wrap.\n */\n workerEntrypoints: string[];\n /**\n * Bindings whose RPC receiver lives in this worker, so this build instruments it. Not deduped by\n * class, two bindings may point at the same class and both names have to be listed.\n */\n sameWorkerBindings: SameWorkerBinding[];\n}\n\n/** Stands in for a class name where a binding targets the module's default export. */\nexport const DEFAULT_EXPORT = Symbol('defaultExport');\n\n/** The name a binding or an export is known by, either an exported class name or the default export. */\nexport type ExportName = string | typeof DEFAULT_EXPORT;\n\nexport interface SameWorkerBinding {\n bindingName: string;\n className: ExportName;\n}\n\n/**\n * Locate and resolve the wrangler configuration via wrangler's own\n * `unstable_readConfig` — the API `@cloudflare/vite-plugin` uses.\n *\n * We only locate the file (probing `wrangler.json`, `.jsonc`, `.toml` inside\n * `root` with wrangler's own precedence, since it discovers from `cwd` rather\n * than an arbitrary root); wrangler then parses it, flattens the active\n * environment (honoring `CLOUDFLARE_ENV`), and resolves `main` to an absolute\n * path. Durable Object and Workflow bindings are the active environment's,\n * matching what the deployed Worker actually binds.\n *\n * Returns `undefined` when no config file is found or it can't be read/parsed\n * (the caller warns and disables auto-instrumentation rather than failing the\n * whole build).\n */\nexport function resolveWranglerConfig(\n root: string,\n explicitPath?: string,\n): { config: WranglerConfig; configDir: string } | undefined {\n const configPath = explicitPath\n ? resolve(root, explicitPath)\n : ['wrangler.json', 'wrangler.jsonc', 'wrangler.toml'].map(name => resolve(root, name)).find(existsSync);\n\n if (!configPath || !existsSync(configPath)) {\n return undefined;\n }\n\n let raw: Unstable_Config;\n try {\n // `hideWarnings` keeps wrangler's config diagnostics (e.g. missing DO\n // migrations) out of the Vite build output.\n raw = unstable_readConfig({ config: configPath }, { hideWarnings: true });\n } catch {\n return undefined;\n }\n\n return {\n config: {\n main: raw.main,\n durableObjects: collectClassBindings(raw.durable_objects?.bindings),\n workflows: collectClassBindings(raw.workflows),\n workerEntrypoints: collectSelfBoundEntrypoints(raw),\n sameWorkerBindings: collectSameWorkerBindings(raw),\n },\n configDir: dirname(raw.configPath ?? configPath),\n };\n}\n\n/**\n * Collect named `WorkerEntrypoint` exports the worker binds to itself. A service\n * binding's `entrypoint` normally names an export on the *target* worker, so it\n * is only ours when `service` equals this worker's own `name`. Without a `name`\n * there is nothing to match against, so no entrypoints are derivable.\n */\nfunction collectSelfBoundEntrypoints(raw: Unstable_Config): string[] {\n if (!raw.name) {\n return [];\n }\n const entrypoints = new Set<string>();\n for (const binding of raw.services ?? []) {\n if (binding?.service === raw.name && typeof binding.entrypoint === 'string') {\n entrypoints.add(binding.entrypoint);\n }\n }\n return [...entrypoints];\n}\n\n/**\n * Bindings with a `script_name` or naming another worker target a class this build does not wrap,\n * so they are excluded and stay opt-in.\n */\nfunction collectSameWorkerBindings(raw: Unstable_Config): SameWorkerBinding[] {\n const bindings: SameWorkerBinding[] = [];\n\n for (const binding of raw.durable_objects?.bindings ?? []) {\n if (typeof binding?.name === 'string' && typeof binding.class_name === 'string' && !binding.script_name) {\n bindings.push({ bindingName: binding.name, className: binding.class_name });\n }\n }\n\n for (const binding of raw.services ?? []) {\n // A service binding is only ours when `service` names this worker; without a `name` none can be.\n if (raw.name && binding?.service === raw.name && typeof binding.binding === 'string') {\n bindings.push({\n bindingName: binding.binding,\n className: typeof binding.entrypoint === 'string' ? binding.entrypoint : DEFAULT_EXPORT,\n });\n }\n }\n\n return bindings;\n}\n\n/**\n * Map wrangler class bindings (Durable Objects, Workflows — same shape) to the\n * `{ name, className }` the transform needs, skipping duplicates and bindings\n * with a `script_name` (those reference a class exported by a *different*\n * worker, so there is nothing to wrap in this worker's entry file).\n */\nfunction collectClassBindings(\n bindings: ReadonlyArray<{ name: string; class_name?: string; script_name?: string }> | undefined,\n): Array<{ name: string; className: string }> {\n const result: Array<{ name: string; className: string }> = [];\n const seenClassNames = new Set<string>();\n for (const binding of bindings ?? []) {\n if (typeof binding?.class_name !== 'string' || binding.script_name || seenClassNames.has(binding.class_name)) {\n continue;\n }\n seenClassNames.add(binding.class_name);\n result.push({ name: binding.name, className: binding.class_name });\n }\n return result;\n}\n"],"names":["resolve","existsSync","unstable_readConfig","dirname"],"mappings":";;;;;;AA4BO,MAAM,cAAA,0BAAwB,eAAe;AAyB7C,SAAS,qBAAA,CACd,MACA,YAAA,EAC2D;AAC3D,EAAA,MAAM,aAAa,YAAA,GACfA,iBAAA,CAAQ,MAAM,YAAY,CAAA,GAC1B,CAAC,eAAA,EAAiB,gBAAA,EAAkB,eAAe,CAAA,CAAE,GAAA,CAAI,UAAQA,iBAAA,CAAQ,IAAA,EAAM,IAAI,CAAC,CAAA,CAAE,KAAKC,kBAAU,CAAA;AAEzG,EAAA,IAAI,CAAC,UAAA,IAAc,CAACA,kBAAA,CAAW,UAAU,CAAA,EAAG;AAC1C,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AAGF,IAAA,GAAA,GAAMC,4BAAA,CAAoB,EAAE,MAAA,EAAQ,UAAA,IAAc,EAAE,YAAA,EAAc,MAAM,CAAA;AAAA,EAC1E,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,MAAM,GAAA,CAAI,IAAA;AAAA,MACV,cAAA,EAAgB,oBAAA,CAAqB,GAAA,CAAI,eAAA,EAAiB,QAAQ,CAAA;AAAA,MAClE,SAAA,EAAW,oBAAA,CAAqB,GAAA,CAAI,SAAS,CAAA;AAAA,MAC7C,iBAAA,EAAmB,4BAA4B,GAAG,CAAA;AAAA,MAClD,kBAAA,EAAoB,0BAA0B,GAAG;AAAA,KACnD;AAAA,IACA,SAAA,EAAWC,iBAAA,CAAQ,GAAA,CAAI,UAAA,IAAc,UAAU;AAAA,GACjD;AAC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AAAA,IACH;AAAA,EACF;AAEA,EAAA,OAAO,QAAA;AACT;AAQA,SAAS,qBACP,QAAA,EAC4C;AAC5C,EAAA,MAAM,SAAqD,EAAC;AAC5D,EAAA,MAAM,cAAA,uBAAqB,GAAA,EAAY;AACvC,EAAA,KAAA,MAAW,OAAA,IAAW,QAAA,IAAY,EAAC,EAAG;AACpC,IAAA,IAAI,OAAO,OAAA,EAAS,UAAA,KAAe,QAAA,IAAY,OAAA,CAAQ,eAAe,cAAA,CAAe,GAAA,CAAI,OAAA,CAAQ,UAAU,CAAA,EAAG;AAC5G,MAAA;AAAA,IACF;AACA,IAAA,cAAA,CAAe,GAAA,CAAI,QAAQ,UAAU,CAAA;AACrC,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,CAAQ,MAAM,SAAA,EAAW,OAAA,CAAQ,YAAY,CAAA;AAAA,EACnE;AACA,EAAA,OAAO,MAAA;AACT;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"withSentry.js","sources":["../../../src/withSentry.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\nimport type { CloudflareOptions } from './client';\nimport { instrumentExportedHandlerEmail } from './instrumentations/worker/instrumentEmail';\nimport { instrumentExportedHandlerFetch } from './instrumentations/worker/instrumentFetch';\nimport { instrumentExportedHandlerQueue } from './instrumentations/worker/instrumentQueue';\nimport { instrumentExportedHandlerScheduled } from './instrumentations/worker/instrumentScheduled';\nimport { instrumentExportedHandlerTail } from './instrumentations/worker/instrumentTail';\nimport { isCloudflareClass } from './utils/isCloudflareClass';\nimport type { AnyExportedHandler, DefaultEnv, ResolveEnv } from './types';\nimport {\n instrumentWorkerEntrypoint,\n type WorkerEntrypointConstructor,\n} from './instrumentations/instrumentWorkerEntrypoint';\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\nexport function withSentry<\n Env = DefaultEnv,\n QueueHandlerMessage = unknown,\n CfHostMetadata = unknown,\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends AnyExportedHandler | WorkerEntrypointConstructor<any, any> =\n | ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata>\n | WorkerEntrypointConstructor<Env>,\n>(optionsCallback: (env: ResolveEnv<T, Env>) => CloudflareOptions | undefined, handler: T): T {\n if (isCloudflareClass(handler, 'WorkerEntrypoint')) {\n // oxlint-disable-next-line typescript/no-explicit-any\n return instrumentWorkerEntrypoint(optionsCallback as any, handler);\n }\n\n setAsyncLocalStorageAsyncContextStrategy();\n\n try {\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerFetch(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerScheduled(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerEmail(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerQueue(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerTail(handler, optionsCallback as any);\n // This is here because Miniflare sometimes cannot get instrumented\n } catch {\n // Do not console anything here, we don't want to spam the console with errors\n }\n\n return handler;\n}\n"],"names":["isCloudflareClass","instrumentWorkerEntrypoint","setAsyncLocalStorageAsyncContextStrategy","instrumentExportedHandlerFetch","instrumentExportedHandlerScheduled","instrumentExportedHandlerEmail","instrumentExportedHandlerQueue","instrumentExportedHandlerTail"],"mappings":";;;;;;;;;;;AAyBO,SAAS,UAAA,CAQd,iBAA6E,OAAA,EAAe;AAC5F,EAAA,IAAIA,mCAAA,CAAkB,OAAA,EAAS,kBAAkB,CAAA,EAAG;AAElD,IAAA,OAAOC,qDAAA,CAA2B,iBAAwB,OAAO,CAAA;AAAA,EACnE;AAEA,EAAAC,6DAAA,EAAyC;AAEzC,EAAA,IAAI;AAEF,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,sDAAA,CAAmC,SAAS,eAAsB,CAAA;AAElE,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,4CAAA,CAA8B,SAAS,eAAsB,CAAA;AAAA,EAE/D,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
1
+ {"version":3,"file":"withSentry.js","sources":["../../../src/withSentry.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\nimport { instrumentExportedHandlerEmail } from './instrumentations/worker/instrumentEmail';\nimport { instrumentExportedHandlerFetch } from './instrumentations/worker/instrumentFetch';\nimport { instrumentExportedHandlerQueue } from './instrumentations/worker/instrumentQueue';\nimport { instrumentExportedHandlerScheduled } from './instrumentations/worker/instrumentScheduled';\nimport { instrumentExportedHandlerTail } from './instrumentations/worker/instrumentTail';\nimport { isCloudflareClass } from './utils/isCloudflareClass';\nimport type { AnyExportedHandler, DefaultEnv, ResolveEnv, StrictCloudflareOptions } from './types';\nimport {\n instrumentWorkerEntrypoint,\n type WorkerEntrypointConstructor,\n} from './instrumentations/instrumentWorkerEntrypoint';\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\nexport function withSentry<\n Env = DefaultEnv,\n QueueHandlerMessage = unknown,\n CfHostMetadata = unknown,\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends AnyExportedHandler | WorkerEntrypointConstructor<any, any> =\n | ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata>\n | WorkerEntrypointConstructor<Env>,\n O = unknown,\n>(optionsCallback: (env: ResolveEnv<T, Env>) => StrictCloudflareOptions<O> | undefined, handler: T): T {\n if (isCloudflareClass(handler, 'WorkerEntrypoint')) {\n // oxlint-disable-next-line typescript/no-explicit-any\n return instrumentWorkerEntrypoint(optionsCallback as any, handler);\n }\n\n setAsyncLocalStorageAsyncContextStrategy();\n\n try {\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerFetch(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerScheduled(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerEmail(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerQueue(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerTail(handler, optionsCallback as any);\n // This is here because Miniflare sometimes cannot get instrumented\n } catch {\n // Do not console anything here, we don't want to spam the console with errors\n }\n\n return handler;\n}\n"],"names":["isCloudflareClass","instrumentWorkerEntrypoint","setAsyncLocalStorageAsyncContextStrategy","instrumentExportedHandlerFetch","instrumentExportedHandlerScheduled","instrumentExportedHandlerEmail","instrumentExportedHandlerQueue","instrumentExportedHandlerTail"],"mappings":";;;;;;;;;;;AAwBO,SAAS,UAAA,CASd,iBAAsF,OAAA,EAAe;AACrG,EAAA,IAAIA,mCAAA,CAAkB,OAAA,EAAS,kBAAkB,CAAA,EAAG;AAElD,IAAA,OAAOC,qDAAA,CAA2B,iBAAwB,OAAO,CAAA;AAAA,EACnE;AAEA,EAAAC,6DAAA,EAAyC;AAEzC,EAAA,IAAI;AAEF,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,sDAAA,CAAmC,SAAS,eAAsB,CAAA;AAElE,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,4CAAA,CAA8B,SAAS,eAAsB,CAAA;AAAA,EAE/D,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
@@ -9,6 +9,7 @@ const instrumentEnv = require('./instrumentations/worker/instrumentEnv.js');
9
9
  const scopeUtils = require('./scope-utils.js');
10
10
  const sdk = require('./sdk.js');
11
11
  const instrumentContext = require('./utils/instrumentContext.js');
12
+ const invocationScope = require('./utils/invocationScope.js');
12
13
 
13
14
  const UUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;
14
15
  async function deterministicTraceIdFromInstanceId(instanceId) {
@@ -24,11 +25,12 @@ async function propagationContextFromInstanceId(instanceId) {
24
25
  };
25
26
  }
26
27
  class WrappedWorkflowStep {
27
- constructor(_instanceId, _options, _step, _waitUntil) {
28
+ constructor(_instanceId, _options, _step, _waitUntil, _isolationScope) {
28
29
  this._instanceId = _instanceId;
29
30
  this._options = _options;
30
31
  this._step = _step;
31
32
  this._waitUntil = _waitUntil;
33
+ this._isolationScope = _isolationScope;
32
34
  }
33
35
  async do(name, configOrCallback, callbackOrRollback, maybeRollback) {
34
36
  const scopeForStep = core.getCurrentScope();
@@ -42,39 +44,49 @@ class WrappedWorkflowStep {
42
44
  const retryLimit = stepContext?.config?.retries?.limit;
43
45
  const hasStepContext = typeof attempt === "number" && typeof retryLimit === "number";
44
46
  const isFinalAttempt = !hasStepContext || attempt > retryLimit;
45
- return core.startSpan(
46
- {
47
- name,
48
- scope: scopeForStep,
49
- attributes: {
50
- [attributes.SENTRY_OP]: op.GENERAL_FUNCTION_SPAN_OP,
51
- [attributes.CODE_FUNCTION_NAME]: name,
52
- "workflow.step.name": name,
53
- "cloudflare.workflow.timeout": config?.timeout,
54
- "cloudflare.workflow.retries.backoff": config?.retries?.backoff,
55
- // In workers-types v5, `delay` may be a `WorkflowDelayFunction`, which isn't a valid span attribute value.
56
- "cloudflare.workflow.retries.delay": typeof config?.retries?.delay === "function" ? void 0 : config?.retries?.delay,
57
- "cloudflare.workflow.retries.limit": config?.retries?.limit,
58
- "cloudflare.workflow.attempt": attempt,
59
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.faas.cloudflare.workflow",
60
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "task"
47
+ return core.withIsolationScope(this._isolationScope, () => {
48
+ const stepResult = core.startSpan(
49
+ {
50
+ name,
51
+ scope: scopeForStep,
52
+ attributes: {
53
+ [attributes.SENTRY_OP]: op.FUNCTION,
54
+ [attributes.CODE_FUNCTION_NAME]: name,
55
+ "workflow.step.name": name,
56
+ "cloudflare.workflow.timeout": config?.timeout,
57
+ "cloudflare.workflow.retries.backoff": config?.retries?.backoff,
58
+ // In workers-types v5, `delay` may be a `WorkflowDelayFunction`, which isn't a valid span attribute value.
59
+ "cloudflare.workflow.retries.delay": typeof config?.retries?.delay === "function" ? void 0 : config?.retries?.delay,
60
+ "cloudflare.workflow.retries.limit": config?.retries?.limit,
61
+ "cloudflare.workflow.attempt": attempt,
62
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.faas.cloudflare.workflow",
63
+ [attributes.SENTRY_SEGMENT_NAME_SOURCE]: "task"
64
+ }
65
+ },
66
+ async (span) => {
67
+ try {
68
+ const result = await userCallback(...args);
69
+ span.setStatus({ code: 1 });
70
+ return result;
71
+ } catch (error) {
72
+ if (isFinalAttempt) {
73
+ core.captureException(error, { mechanism: { handled: true, type: "auto.faas.cloudflare.workflow" } });
74
+ }
75
+ throw error;
76
+ }
61
77
  }
62
- },
63
- async (span) => {
64
- try {
65
- const result = await userCallback(...args);
66
- span.setStatus({ code: 1 });
78
+ );
79
+ return stepResult.then(
80
+ (result) => {
81
+ this._waitUntil(core.flush(2e3));
67
82
  return result;
68
- } catch (error) {
69
- if (isFinalAttempt) {
70
- core.captureException(error, { mechanism: { handled: true, type: "auto.faas.cloudflare.workflow" } });
71
- }
72
- throw error;
73
- } finally {
83
+ },
84
+ (error) => {
74
85
  this._waitUntil(core.flush(2e3));
86
+ throw error;
75
87
  }
76
- }
77
- );
88
+ );
89
+ });
78
90
  };
79
91
  if (config) {
80
92
  return rollbackOptions ? this._step.do(name, config, instrumentedCallback, rollbackOptions) : this._step.do(name, config, instrumentedCallback);
@@ -106,7 +118,7 @@ function instrumentWorkflowWithSentry(optionsCallback, WorkFlowClass) {
106
118
  if (prop === "run") {
107
119
  return async function(event, step) {
108
120
  noDiagnosticChannels.setAsyncLocalStorageAsyncContextStrategy();
109
- return core.withIsolationScope(async (isolationScope) => {
121
+ return invocationScope.withInvocationIsolationScope(async (isolationScope) => {
110
122
  const waitUntil = flush.getOriginalWaitUntil(context).bind(context);
111
123
  const client = sdk.init({ ...options, ctx: context, enableDedupe: false });
112
124
  isolationScope.setClient(client);
@@ -118,13 +130,13 @@ function instrumentWorkflowWithSentry(optionsCallback, WorkFlowClass) {
118
130
  return await obj.run.call(
119
131
  obj,
120
132
  event,
121
- new WrappedWorkflowStep(event.instanceId, options, step, waitUntil)
133
+ new WrappedWorkflowStep(event.instanceId, options, step, waitUntil, isolationScope)
122
134
  );
123
135
  } finally {
124
136
  waitUntil(flush.flushAndDispose(client));
125
137
  }
126
138
  });
127
- });
139
+ }, context);
128
140
  };
129
141
  }
130
142
  return Reflect.get(obj, prop, receiver);
@@ -1 +1 @@
1
- {"version":3,"file":"workflows.js","sources":["../../../src/workflows.ts"],"sourcesContent":["import { CODE_FUNCTION_NAME, SENTRY_OP } from '@sentry/conventions/attributes';\nimport { GENERAL_FUNCTION_SPAN_OP } from '@sentry/conventions/op';\nimport type { PropagationContext } from '@sentry/core';\nimport {\n captureException,\n flush,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type {\n WorkflowDelayDuration,\n WorkflowEntrypoint,\n WorkflowEvent,\n WorkflowSleepDuration,\n WorkflowStep,\n WorkflowStepConfig,\n WorkflowStepContext,\n WorkflowStepEvent,\n WorkflowStepRollbackOptions,\n WorkflowTimeoutDuration,\n} from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\nimport type { CloudflareOptions } from './client';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { instrumentEnv } from './instrumentations/worker/instrumentEnv';\nimport { addCloudResourceContext } from './scope-utils';\nimport { init } from './sdk';\nimport { instrumentContext } from './utils/instrumentContext';\nimport type { DefaultEnv, ResolveEnv } from './types';\n\nconst UUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;\n\n/**\n * Hashes a string to a UUID using SHA-1.\n */\nexport async function deterministicTraceIdFromInstanceId(instanceId: string): Promise<string> {\n const buf = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(instanceId));\n return (\n Array.from(new Uint8Array(buf))\n // We only need the first 16 bytes for the 32 characters\n .slice(0, 16)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n );\n}\n\nasync function propagationContextFromInstanceId(instanceId: string): Promise<PropagationContext> {\n const traceId = UUID_REGEX.test(instanceId)\n ? instanceId.replace(/-/g, '')\n : await deterministicTraceIdFromInstanceId(instanceId);\n\n // Derive sampleRand from last 4 characters of the random UUID\n //\n // We cannot store any state between workflow steps, so we derive the\n // sampleRand from the traceId itself. This ensures that the sampling is\n // consistent across all steps in the same workflow instance.\n const sampleRand = parseInt(traceId.slice(-4), 16) / 0xffff;\n\n return {\n traceId,\n sampleRand,\n };\n}\n\nclass WrappedWorkflowStep implements WorkflowStep {\n public constructor(\n private _instanceId: string,\n private _options: CloudflareOptions,\n private _step: WorkflowStep,\n private _waitUntil: ExecutionContext['waitUntil'],\n ) {}\n\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n callback: (ctx: WorkflowStepContext) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(\n name: string,\n config: C,\n callback: (\n ctx: WorkflowStepContext<C['retries'] extends { delay: infer D } ? D : WorkflowDelayDuration | number>,\n ) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n configOrCallback: WorkflowStepConfig | ((ctx: WorkflowStepContext) => Promise<T>),\n callbackOrRollback?: ((ctx: WorkflowStepContext) => Promise<T>) | WorkflowStepRollbackOptions<T>,\n maybeRollback?: WorkflowStepRollbackOptions<T>,\n ): Promise<T> {\n // Capture the current scope, so parent span (e.g., a startSpan surrounding step.do) is preserved\n const scopeForStep = getCurrentScope();\n\n const hasConfig = typeof configOrCallback !== 'function';\n const config = hasConfig ? configOrCallback : undefined;\n const userCallback = (hasConfig ? callbackOrRollback : configOrCallback) as (\n ctx: WorkflowStepContext,\n ) => Promise<T>;\n const rollbackOptions = (hasConfig ? maybeRollback : callbackOrRollback) as\n | WorkflowStepRollbackOptions<T>\n | undefined;\n\n const instrumentedCallback = async (...args: unknown[]): Promise<T> => {\n // Feature detection: Cloudflare Workflows (April 2026+) pass a step context\n // with `attempt` and `config.retries.limit`. When available, we only capture\n // errors on the final attempt to avoid duplicates during retries.\n const stepContext = args[0] as { attempt?: number; config?: { retries?: { limit?: number } } } | undefined;\n const attempt = stepContext?.attempt;\n const retryLimit = stepContext?.config?.retries?.limit;\n const hasStepContext = typeof attempt === 'number' && typeof retryLimit === 'number';\n\n // Only capture error on final attempt (attempt > retryLimit means no more retries left)\n // or when step context is unavailable (legacy behavior - capture all errors)\n const isFinalAttempt = !hasStepContext || attempt > retryLimit;\n\n return startSpan(\n {\n name,\n scope: scopeForStep,\n attributes: {\n [SENTRY_OP]: GENERAL_FUNCTION_SPAN_OP,\n [CODE_FUNCTION_NAME]: name,\n 'workflow.step.name': name,\n 'cloudflare.workflow.timeout': config?.timeout,\n 'cloudflare.workflow.retries.backoff': config?.retries?.backoff,\n // In workers-types v5, `delay` may be a `WorkflowDelayFunction`, which isn't a valid span attribute value.\n 'cloudflare.workflow.retries.delay':\n typeof config?.retries?.delay === 'function' ? undefined : config?.retries?.delay,\n 'cloudflare.workflow.retries.limit': config?.retries?.limit,\n 'cloudflare.workflow.attempt': attempt,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.workflow',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async span => {\n try {\n const result = await (userCallback as (...args: unknown[]) => Promise<T>)(...args);\n span.setStatus({ code: 1 });\n return result;\n } catch (error) {\n if (isFinalAttempt) {\n captureException(error, { mechanism: { handled: true, type: 'auto.faas.cloudflare.workflow' } });\n }\n throw error;\n } finally {\n this._waitUntil(flush(2000));\n }\n },\n );\n };\n\n if (config) {\n return rollbackOptions\n ? this._step.do(name, config, instrumentedCallback, rollbackOptions)\n : this._step.do(name, config, instrumentedCallback);\n }\n\n return rollbackOptions\n ? this._step.do(name, instrumentedCallback, rollbackOptions)\n : this._step.do(name, instrumentedCallback);\n }\n\n public async sleep(name: string, duration: WorkflowSleepDuration): Promise<void> {\n return this._step.sleep(name, duration);\n }\n\n public async sleepUntil(name: string, timestamp: Date | number): Promise<void> {\n return this._step.sleepUntil(name, timestamp);\n }\n\n public async waitForEvent<T extends Rpc.Serializable<T>>(\n name: string,\n options: { type: string; timeout?: WorkflowTimeoutDuration | number },\n ): Promise<WorkflowStepEvent<T>> {\n return this._step.waitForEvent<T>(name, options);\n }\n}\n\n/**\n * Instruments a Cloudflare Workflow class with Sentry.\n *\n * @example\n * ```typescript\n * const InstrumentedWorkflow = instrumentWorkflowWithSentry(\n * (env) => ({ dsn: env.SENTRY_DSN }),\n * MyWorkflowClass\n * );\n *\n * export default InstrumentedWorkflow;\n * ```\n *\n * @param optionsCallback - Function that returns Sentry options to initialize Sentry\n * @param WorkflowClass - The workflow class to instrument\n * @returns Instrumented workflow class with the same interface\n */\nexport function instrumentWorkflowWithSentry<\n E = DefaultEnv, // Environment type\n P = unknown, // Payload type\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends WorkflowEntrypoint<any, any> = WorkflowEntrypoint<E, P>, // WorkflowEntrypoint type\n // The constraint must not route through `T`: workers-types defaults `WorkflowEntrypoint`'s\n // `Env` to `unknown` (unlike `WorkerEntrypoint`/`DurableObject`, which default to\n // `Cloudflare.Env`), so a bare subclass would be rejected in a `wrangler types` project.\n // The callback env is resolved from the inferred constructor via `ResolveEnv` instead.\n // oxlint-disable-next-line typescript/no-explicit-any\n C extends new (ctx: ExecutionContext, env: any) => WorkflowEntrypoint<any, any> = new (\n ctx: ExecutionContext,\n // oxlint-disable-next-line typescript/no-explicit-any\n env: any,\n ) => T, // Constructor type of the WorkflowEntrypoint class\n>(optionsCallback: (env: ResolveEnv<C, E>) => CloudflareOptions, WorkFlowClass: C): C {\n return new Proxy(WorkFlowClass, {\n // oxlint-disable-next-line typescript/no-explicit-any\n construct(target: C, args: [ctx: ExecutionContext, env: any], newTarget) {\n const [ctx, env] = args;\n const context = instrumentContext(ctx);\n const options = optionsCallback(env);\n args[0] = context;\n args[1] = instrumentEnv(env as Record<string, unknown>, options) as E;\n const instance = Reflect.construct(target, args, newTarget) as T;\n return new Proxy(instance, {\n get(obj, prop, receiver) {\n if (prop === 'run') {\n return async function (event: WorkflowEvent<P>, step: WorkflowStep): Promise<unknown> {\n setAsyncLocalStorageAsyncContextStrategy();\n\n return withIsolationScope(async isolationScope => {\n const waitUntil = getOriginalWaitUntil(context).bind(context);\n const client = init({ ...options, ctx: context, enableDedupe: false });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return withScope(async scope => {\n const propagationContext = await propagationContextFromInstanceId(event.instanceId);\n scope.setPropagationContext(propagationContext);\n\n try {\n return await obj.run.call(\n obj,\n event,\n new WrappedWorkflowStep(event.instanceId, options, step, waitUntil),\n );\n } finally {\n waitUntil(flushAndDispose(client));\n }\n });\n });\n };\n }\n return Reflect.get(obj, prop, receiver);\n },\n });\n },\n });\n}\n"],"names":["getCurrentScope","startSpan","SENTRY_OP","GENERAL_FUNCTION_SPAN_OP","CODE_FUNCTION_NAME","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flush","instrumentContext","instrumentEnv","setAsyncLocalStorageAsyncContextStrategy","withIsolationScope","getOriginalWaitUntil","init","addCloudResourceContext","withScope","flushAndDispose"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,UAAA,GAAa,qEAAA;AAKnB,eAAsB,mCAAmC,UAAA,EAAqC;AAC5F,EAAA,MAAM,GAAA,GAAM,MAAM,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,OAAA,EAAS,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,UAAU,CAAC,CAAA;AACpF,EAAA,OACE,KAAA,CAAM,KAAK,IAAI,UAAA,CAAW,GAAG,CAAC,CAAA,CAE3B,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,CACX,IAAI,CAAA,CAAA,KAAK,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAC,CAAA,CACxC,IAAA,CAAK,EAAE,CAAA;AAEd;AAEA,eAAe,iCAAiC,UAAA,EAAiD;AAC/F,EAAA,MAAM,OAAA,GAAU,UAAA,CAAW,IAAA,CAAK,UAAU,CAAA,GACtC,UAAA,CAAW,OAAA,CAAQ,IAAA,EAAM,EAAE,CAAA,GAC3B,MAAM,kCAAA,CAAmC,UAAU,CAAA;AAOvD,EAAA,MAAM,aAAa,QAAA,CAAS,OAAA,CAAQ,MAAM,EAAE,CAAA,EAAG,EAAE,CAAA,G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Y_SEGMENT_NAME_SOURCE, CODE_FUNCTION_NAME, SENTRY_OP } from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport type { PropagationContext, Scope } from '@sentry/core';\nimport {\n captureException,\n flush,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type {\n WorkflowDelayDuration,\n WorkflowEntrypoint,\n WorkflowEvent,\n WorkflowSleepDuration,\n WorkflowStep,\n WorkflowStepConfig,\n WorkflowStepContext,\n WorkflowStepEvent,\n WorkflowStepRollbackOptions,\n WorkflowTimeoutDuration,\n} from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\nimport type { CloudflareOptions } from './client';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { instrumentEnv } from './instrumentations/worker/instrumentEnv';\nimport { addCloudResourceContext } from './scope-utils';\nimport { init } from './sdk';\nimport { instrumentContext } from './utils/instrumentContext';\nimport type { DefaultEnv, ResolveEnv, StrictCloudflareOptions } from './types';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\n\nconst UUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;\n\n/**\n * Hashes a string to a UUID using SHA-1.\n */\nexport async function deterministicTraceIdFromInstanceId(instanceId: string): Promise<string> {\n const buf = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(instanceId));\n return (\n Array.from(new Uint8Array(buf))\n // We only need the first 16 bytes for the 32 characters\n .slice(0, 16)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n );\n}\n\nasync function propagationContextFromInstanceId(instanceId: string): Promise<PropagationContext> {\n const traceId = UUID_REGEX.test(instanceId)\n ? instanceId.replace(/-/g, '')\n : await deterministicTraceIdFromInstanceId(instanceId);\n\n // Derive sampleRand from last 4 characters of the random UUID\n //\n // We cannot store any state between workflow steps, so we derive the\n // sampleRand from the traceId itself. This ensures that the sampling is\n // consistent across all steps in the same workflow instance.\n const sampleRand = parseInt(traceId.slice(-4), 16) / 0xffff;\n\n return {\n traceId,\n sampleRand,\n };\n}\n\nclass WrappedWorkflowStep implements WorkflowStep {\n public constructor(\n private _instanceId: string,\n private _options: CloudflareOptions,\n private _step: WorkflowStep,\n private _waitUntil: ExecutionContext['waitUntil'],\n private _isolationScope: Scope,\n ) {}\n\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n callback: (ctx: WorkflowStepContext) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(\n name: string,\n config: C,\n callback: (\n ctx: WorkflowStepContext<C['retries'] extends { delay: infer D } ? D : WorkflowDelayDuration | number>,\n ) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n configOrCallback: WorkflowStepConfig | ((ctx: WorkflowStepContext) => Promise<T>),\n callbackOrRollback?: ((ctx: WorkflowStepContext) => Promise<T>) | WorkflowStepRollbackOptions<T>,\n maybeRollback?: WorkflowStepRollbackOptions<T>,\n ): Promise<T> {\n // Capture the current scope, so parent span (e.g., a startSpan surrounding step.do) is preserved\n const scopeForStep = getCurrentScope();\n\n const hasConfig = typeof configOrCallback !== 'function';\n const config = hasConfig ? configOrCallback : undefined;\n const userCallback = (hasConfig ? callbackOrRollback : configOrCallback) as (\n ctx: WorkflowStepContext,\n ) => Promise<T>;\n const rollbackOptions = (hasConfig ? maybeRollback : callbackOrRollback) as\n | WorkflowStepRollbackOptions<T>\n | undefined;\n\n const instrumentedCallback = async (...args: unknown[]): Promise<T> => {\n // Feature detection: Cloudflare Workflows (April 2026+) pass a step context\n // with `attempt` and `config.retries.limit`. When available, we only capture\n // errors on the final attempt to avoid duplicates during retries.\n const stepContext = args[0] as { attempt?: number; config?: { retries?: { limit?: number } } } | undefined;\n const attempt = stepContext?.attempt;\n const retryLimit = stepContext?.config?.retries?.limit;\n const hasStepContext = typeof attempt === 'number' && typeof retryLimit === 'number';\n\n // Only capture error on final attempt (attempt > retryLimit means no more retries left)\n // or when step context is unavailable (legacy behavior - capture all errors)\n const isFinalAttempt = !hasStepContext || attempt > retryLimit;\n\n // The engine invokes step callbacks outside the async context of `run`, so the\n // run's isolation scope (and with it the invocation state that ties eager sends\n // to this invocation's `waitUntil`) has to be restored explicitly.\n return withIsolationScope(this._isolationScope, () => {\n const stepResult = startSpan(\n {\n name,\n scope: scopeForStep,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n [CODE_FUNCTION_NAME]: name,\n 'workflow.step.name': name,\n 'cloudflare.workflow.timeout': config?.timeout,\n 'cloudflare.workflow.retries.backoff': config?.retries?.backoff,\n // In workers-types v5, `delay` may be a `WorkflowDelayFunction`, which isn't a valid span attribute value.\n 'cloudflare.workflow.retries.delay':\n typeof config?.retries?.delay === 'function' ? undefined : config?.retries?.delay,\n 'cloudflare.workflow.retries.limit': config?.retries?.limit,\n 'cloudflare.workflow.attempt': attempt,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.workflow',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async span => {\n try {\n const result = await (userCallback as (...args: unknown[]) => Promise<T>)(...args);\n span.setStatus({ code: 1 });\n return result;\n } catch (error) {\n if (isFinalAttempt) {\n captureException(error, { mechanism: { handled: true, type: 'auto.faas.cloudflare.workflow' } });\n }\n throw error;\n }\n },\n );\n // Deliver after the step span has ended, so the span rides this flush instead of\n // starting an eager drain (same ordering as `wrapMethodWithSentry`'s teardown).\n return stepResult.then(\n result => {\n this._waitUntil(flush(2000));\n return result;\n },\n error => {\n this._waitUntil(flush(2000));\n throw error;\n },\n );\n });\n };\n\n if (config) {\n return rollbackOptions\n ? this._step.do(name, config, instrumentedCallback, rollbackOptions)\n : this._step.do(name, config, instrumentedCallback);\n }\n\n return rollbackOptions\n ? this._step.do(name, instrumentedCallback, rollbackOptions)\n : this._step.do(name, instrumentedCallback);\n }\n\n public async sleep(name: string, duration: WorkflowSleepDuration): Promise<void> {\n return this._step.sleep(name, duration);\n }\n\n public async sleepUntil(name: string, timestamp: Date | number): Promise<void> {\n return this._step.sleepUntil(name, timestamp);\n }\n\n public async waitForEvent<T extends Rpc.Serializable<T>>(\n name: string,\n options: { type: string; timeout?: WorkflowTimeoutDuration | number },\n ): Promise<WorkflowStepEvent<T>> {\n return this._step.waitForEvent<T>(name, options);\n }\n}\n\n/**\n * Instruments a Cloudflare Workflow class with Sentry.\n *\n * @example\n * ```typescript\n * const InstrumentedWorkflow = instrumentWorkflowWithSentry(\n * (env) => ({ dsn: env.SENTRY_DSN }),\n * MyWorkflowClass\n * );\n *\n * export default InstrumentedWorkflow;\n * ```\n *\n * @param optionsCallback - Function that returns Sentry options to initialize Sentry\n * @param WorkflowClass - The workflow class to instrument\n * @returns Instrumented workflow class with the same interface\n */\nexport function instrumentWorkflowWithSentry<\n E = DefaultEnv, // Environment type\n P = unknown, // Payload type\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends WorkflowEntrypoint<any, any> = WorkflowEntrypoint<E, P>, // WorkflowEntrypoint type\n // The constraint must not route through `T`: workers-types defaults `WorkflowEntrypoint`'s\n // `Env` to `unknown` (unlike `WorkerEntrypoint`/`DurableObject`, which default to\n // `Cloudflare.Env`), so a bare subclass would be rejected in a `wrangler types` project.\n // The callback env is resolved from the inferred constructor via `ResolveEnv` instead.\n // oxlint-disable-next-line typescript/no-explicit-any\n C extends new (ctx: ExecutionContext, env: any) => WorkflowEntrypoint<any, any> = new (\n ctx: ExecutionContext,\n // oxlint-disable-next-line typescript/no-explicit-any\n env: any,\n ) => T, // Constructor type of the WorkflowEntrypoint class\n O = unknown,\n>(optionsCallback: (env: ResolveEnv<C, E>) => StrictCloudflareOptions<O>, WorkFlowClass: C): C {\n return new Proxy(WorkFlowClass, {\n // oxlint-disable-next-line typescript/no-explicit-any\n construct(target: C, args: [ctx: ExecutionContext, env: any], newTarget) {\n const [ctx, env] = args;\n const context = instrumentContext(ctx);\n const options = optionsCallback(env);\n args[0] = context;\n args[1] = instrumentEnv(env as Record<string, unknown>, options) as E;\n const instance = Reflect.construct(target, args, newTarget) as T;\n return new Proxy(instance, {\n get(obj, prop, receiver) {\n if (prop === 'run') {\n return async function (event: WorkflowEvent<P>, step: WorkflowStep): Promise<unknown> {\n setAsyncLocalStorageAsyncContextStrategy();\n\n return withInvocationIsolationScope(async isolationScope => {\n const waitUntil = getOriginalWaitUntil(context).bind(context);\n const client = init({ ...options, ctx: context, enableDedupe: false });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return withScope(async scope => {\n const propagationContext = await propagationContextFromInstanceId(event.instanceId);\n scope.setPropagationContext(propagationContext);\n\n try {\n return await obj.run.call(\n obj,\n event,\n new WrappedWorkflowStep(event.instanceId, options, step, waitUntil, isolationScope),\n );\n } finally {\n waitUntil(flushAndDispose(client));\n }\n });\n }, context);\n };\n }\n return Reflect.get(obj, prop, receiver);\n },\n });\n },\n });\n}\n"],"names":["getCurrentScope","withIsolationScope","startSpan","SENTRY_OP","FUNCTION","CODE_FUNCTION_NAME","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SENTRY_SEGMENT_NAME_SOURCE","captureException","flush","instrumentContext","instrumentEnv","setAsyncLocalStorageAsyncContextStrategy","withInvocationIsolationScope","getOriginalWaitUntil","init","addCloudResourceContext","withScope","flushAndDispose"],"mappings":";;;;;;;;;;;;;AAkCA,MAAM,UAAA,GAAa,qEAAA;AAKnB,eAAsB,mCAAmC,UAAA,EAAqC;AAC5F,EAAA,MAAM,GAAA,GAAM,MAAM,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,OAAA,EAAS,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,UAAU,CAAC,CAAA;AAC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