@sentry/cloudflare 11.0.0-alpha.1 → 11.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (415) 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 +118 -25
  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 +4 -62
  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 +8 -7
  13. package/build/cjs/dev/index.js.map +1 -1
  14. package/build/cjs/dev/instrumentations/agents/instrumentAgentCallableRpc.js +3 -1
  15. package/build/cjs/dev/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  16. package/build/cjs/dev/instrumentations/instrumentDurableObjectHandlers.js +123 -0
  17. package/build/cjs/dev/instrumentations/instrumentDurableObjectHandlers.js.map +1 -0
  18. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  19. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  20. package/build/cjs/dev/instrumentations/instrumentDurableObjectStorage.js +3 -1
  21. package/build/cjs/dev/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  22. package/build/cjs/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js +3 -1
  23. package/build/cjs/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  24. package/build/cjs/dev/instrumentations/instrumentSqlStorage.js +6 -3
  25. package/build/cjs/dev/instrumentations/instrumentSqlStorage.js.map +1 -1
  26. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js +9 -16
  27. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  28. package/build/cjs/dev/instrumentations/worker/instrumentD1.js +10 -3
  29. package/build/cjs/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  30. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js +4 -2
  31. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  32. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js +5 -12
  33. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  34. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js +8 -8
  35. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  36. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js +4 -2
  37. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  38. package/build/cjs/dev/instrumentations/worker/instrumentQueueProducer.js +3 -2
  39. package/build/cjs/dev/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  40. package/build/cjs/dev/instrumentations/worker/instrumentR2.js +21 -18
  41. package/build/cjs/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  42. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js +4 -2
  43. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  44. package/build/cjs/dev/instrumentations/worker/instrumentTail.js +2 -0
  45. package/build/cjs/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  46. package/build/cjs/dev/integrations/fetch.js +1 -11
  47. package/build/cjs/dev/integrations/fetch.js.map +1 -1
  48. package/build/cjs/dev/opentelemetry/tracer.js +2 -40
  49. package/build/cjs/dev/opentelemetry/tracer.js.map +1 -1
  50. package/build/cjs/dev/pages-plugin.js +2 -2
  51. package/build/cjs/dev/pages-plugin.js.map +1 -1
  52. package/build/cjs/dev/request.js +2 -123
  53. package/build/cjs/dev/request.js.map +1 -1
  54. package/build/cjs/dev/sdk.js +11 -6
  55. package/build/cjs/dev/sdk.js.map +1 -1
  56. package/build/cjs/dev/transport.js +1 -1
  57. package/build/cjs/dev/transport.js.map +1 -1
  58. package/build/cjs/dev/utils/invocationContext.js +41 -0
  59. package/build/cjs/dev/utils/invocationContext.js.map +1 -0
  60. package/build/cjs/dev/utils/invocationScope.js +7 -2
  61. package/build/cjs/dev/utils/invocationScope.js.map +1 -1
  62. package/build/cjs/dev/utils/isBinding.js +0 -4
  63. package/build/cjs/dev/utils/isBinding.js.map +1 -1
  64. package/build/cjs/dev/utils/rpcPropagation.js +15 -0
  65. package/build/cjs/dev/utils/rpcPropagation.js.map +1 -0
  66. package/build/cjs/dev/vendor/stacktrace.js +2 -1
  67. package/build/cjs/dev/vendor/stacktrace.js.map +1 -1
  68. package/build/cjs/dev/vite/autoInstrument.js +2 -1
  69. package/build/cjs/dev/vite/autoInstrument.js.map +1 -1
  70. package/build/cjs/dev/vite/index.js.map +1 -1
  71. package/build/cjs/dev/vite/transform.js +30 -5
  72. package/build/cjs/dev/vite/transform.js.map +1 -1
  73. package/build/cjs/dev/vite/wranglerConfig.js +21 -1
  74. package/build/cjs/dev/vite/wranglerConfig.js.map +1 -1
  75. package/build/cjs/dev/withSentry.js.map +1 -1
  76. package/build/cjs/dev/workflows.js +45 -33
  77. package/build/cjs/dev/workflows.js.map +1 -1
  78. package/build/cjs/dev/wrapMethodWithSentry.js +51 -15
  79. package/build/cjs/dev/wrapMethodWithSentry.js.map +1 -1
  80. package/build/cjs/dev/wrapRequestHandlerWithInit.js +134 -0
  81. package/build/cjs/dev/wrapRequestHandlerWithInit.js.map +1 -0
  82. package/build/cjs/prod/baseSdk.js +20 -8
  83. package/build/cjs/prod/baseSdk.js.map +1 -1
  84. package/build/cjs/prod/client.js +118 -25
  85. package/build/cjs/prod/client.js.map +1 -1
  86. package/build/cjs/prod/clientCache.js +15 -0
  87. package/build/cjs/prod/clientCache.js.map +1 -0
  88. package/build/cjs/prod/defineCloudflareOptions.js.map +1 -1
  89. package/build/cjs/prod/durableobject.js +4 -62
  90. package/build/cjs/prod/durableobject.js.map +1 -1
  91. package/build/cjs/prod/flush.js +6 -4
  92. package/build/cjs/prod/flush.js.map +1 -1
  93. package/build/cjs/prod/index.js +8 -7
  94. package/build/cjs/prod/index.js.map +1 -1
  95. package/build/cjs/prod/instrumentations/agents/instrumentAgentCallableRpc.js +3 -1
  96. package/build/cjs/prod/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  97. package/build/cjs/prod/instrumentations/instrumentDurableObjectHandlers.js +123 -0
  98. package/build/cjs/prod/instrumentations/instrumentDurableObjectHandlers.js.map +1 -0
  99. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  100. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  101. package/build/cjs/prod/instrumentations/instrumentDurableObjectStorage.js +3 -1
  102. package/build/cjs/prod/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  103. package/build/cjs/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js +3 -1
  104. package/build/cjs/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  105. package/build/cjs/prod/instrumentations/instrumentSqlStorage.js +6 -3
  106. package/build/cjs/prod/instrumentations/instrumentSqlStorage.js.map +1 -1
  107. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js +9 -16
  108. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  109. package/build/cjs/prod/instrumentations/worker/instrumentD1.js +10 -3
  110. package/build/cjs/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  111. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js +4 -2
  112. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  113. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js +5 -12
  114. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  115. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js +8 -8
  116. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  117. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js +4 -2
  118. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  119. package/build/cjs/prod/instrumentations/worker/instrumentQueueProducer.js +3 -2
  120. package/build/cjs/prod/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  121. package/build/cjs/prod/instrumentations/worker/instrumentR2.js +21 -18
  122. package/build/cjs/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  123. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js +4 -2
  124. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  125. package/build/cjs/prod/instrumentations/worker/instrumentTail.js +2 -0
  126. package/build/cjs/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  127. package/build/cjs/prod/integrations/fetch.js +1 -11
  128. package/build/cjs/prod/integrations/fetch.js.map +1 -1
  129. package/build/cjs/prod/opentelemetry/tracer.js +2 -40
  130. package/build/cjs/prod/opentelemetry/tracer.js.map +1 -1
  131. package/build/cjs/prod/pages-plugin.js +2 -2
  132. package/build/cjs/prod/pages-plugin.js.map +1 -1
  133. package/build/cjs/prod/request.js +2 -123
  134. package/build/cjs/prod/request.js.map +1 -1
  135. package/build/cjs/prod/sdk.js +11 -6
  136. package/build/cjs/prod/sdk.js.map +1 -1
  137. package/build/cjs/prod/transport.js +1 -1
  138. package/build/cjs/prod/transport.js.map +1 -1
  139. package/build/cjs/prod/utils/invocationContext.js +41 -0
  140. package/build/cjs/prod/utils/invocationContext.js.map +1 -0
  141. package/build/cjs/prod/utils/invocationScope.js +7 -2
  142. package/build/cjs/prod/utils/invocationScope.js.map +1 -1
  143. package/build/cjs/prod/utils/isBinding.js +0 -4
  144. package/build/cjs/prod/utils/isBinding.js.map +1 -1
  145. package/build/cjs/prod/utils/rpcPropagation.js +15 -0
  146. package/build/cjs/prod/utils/rpcPropagation.js.map +1 -0
  147. package/build/cjs/prod/vendor/stacktrace.js +2 -1
  148. package/build/cjs/prod/vendor/stacktrace.js.map +1 -1
  149. package/build/cjs/prod/vite/autoInstrument.js +2 -1
  150. package/build/cjs/prod/vite/autoInstrument.js.map +1 -1
  151. package/build/cjs/prod/vite/index.js.map +1 -1
  152. package/build/cjs/prod/vite/transform.js +30 -5
  153. package/build/cjs/prod/vite/transform.js.map +1 -1
  154. package/build/cjs/prod/vite/wranglerConfig.js +21 -1
  155. package/build/cjs/prod/vite/wranglerConfig.js.map +1 -1
  156. package/build/cjs/prod/withSentry.js.map +1 -1
  157. package/build/cjs/prod/workflows.js +45 -33
  158. package/build/cjs/prod/workflows.js.map +1 -1
  159. package/build/cjs/prod/wrapMethodWithSentry.js +51 -15
  160. package/build/cjs/prod/wrapMethodWithSentry.js.map +1 -1
  161. package/build/cjs/prod/wrapRequestHandlerWithInit.js +134 -0
  162. package/build/cjs/prod/wrapRequestHandlerWithInit.js.map +1 -0
  163. package/build/esm/dev/baseSdk.js +21 -9
  164. package/build/esm/dev/baseSdk.js.map +1 -1
  165. package/build/esm/dev/client.js +118 -25
  166. package/build/esm/dev/client.js.map +1 -1
  167. package/build/esm/dev/clientCache.js +12 -0
  168. package/build/esm/dev/clientCache.js.map +1 -0
  169. package/build/esm/dev/defineCloudflareOptions.js.map +1 -1
  170. package/build/esm/dev/durableobject.js +5 -63
  171. package/build/esm/dev/durableobject.js.map +1 -1
  172. package/build/esm/dev/flush.js +6 -4
  173. package/build/esm/dev/flush.js.map +1 -1
  174. package/build/esm/dev/index.js +4 -4
  175. package/build/esm/dev/instrumentations/agents/instrumentAgentCallableRpc.js +4 -2
  176. package/build/esm/dev/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  177. package/build/esm/dev/instrumentations/instrumentDurableObjectHandlers.js +121 -0
  178. package/build/esm/dev/instrumentations/instrumentDurableObjectHandlers.js.map +1 -0
  179. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  180. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  181. package/build/esm/dev/instrumentations/instrumentDurableObjectStorage.js +3 -1
  182. package/build/esm/dev/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  183. package/build/esm/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js +3 -1
  184. package/build/esm/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  185. package/build/esm/dev/instrumentations/instrumentSqlStorage.js +5 -2
  186. package/build/esm/dev/instrumentations/instrumentSqlStorage.js.map +1 -1
  187. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js +9 -16
  188. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  189. package/build/esm/dev/instrumentations/worker/instrumentD1.js +11 -4
  190. package/build/esm/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  191. package/build/esm/dev/instrumentations/worker/instrumentEmail.js +7 -5
  192. package/build/esm/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  193. package/build/esm/dev/instrumentations/worker/instrumentEnv.js +6 -13
  194. package/build/esm/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  195. package/build/esm/dev/instrumentations/worker/instrumentFetch.js +1 -1
  196. package/build/esm/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  197. package/build/esm/dev/instrumentations/worker/instrumentQueue.js +7 -5
  198. package/build/esm/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  199. package/build/esm/dev/instrumentations/worker/instrumentQueueProducer.js +4 -3
  200. package/build/esm/dev/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  201. package/build/esm/dev/instrumentations/worker/instrumentR2.js +22 -19
  202. package/build/esm/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  203. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js +7 -5
  204. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  205. package/build/esm/dev/instrumentations/worker/instrumentTail.js +2 -0
  206. package/build/esm/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  207. package/build/esm/dev/integrations/fetch.js +2 -12
  208. package/build/esm/dev/integrations/fetch.js.map +1 -1
  209. package/build/esm/dev/opentelemetry/tracer.js +2 -40
  210. package/build/esm/dev/opentelemetry/tracer.js.map +1 -1
  211. package/build/esm/dev/package.json +1 -1
  212. package/build/esm/dev/pages-plugin.js +1 -1
  213. package/build/esm/dev/pages-plugin.js.map +1 -1
  214. package/build/esm/dev/request.js +2 -122
  215. package/build/esm/dev/request.js.map +1 -1
  216. package/build/esm/dev/sdk.js +11 -7
  217. package/build/esm/dev/sdk.js.map +1 -1
  218. package/build/esm/dev/transport.js +1 -1
  219. package/build/esm/dev/transport.js.map +1 -1
  220. package/build/esm/dev/utils/invocationContext.js +37 -0
  221. package/build/esm/dev/utils/invocationContext.js.map +1 -0
  222. package/build/esm/dev/utils/invocationScope.js +7 -2
  223. package/build/esm/dev/utils/invocationScope.js.map +1 -1
  224. package/build/esm/dev/utils/isBinding.js +1 -4
  225. package/build/esm/dev/utils/isBinding.js.map +1 -1
  226. package/build/esm/dev/utils/rpcPropagation.js +13 -0
  227. package/build/esm/dev/utils/rpcPropagation.js.map +1 -0
  228. package/build/esm/dev/utils/traceLinks.js +1 -1
  229. package/build/esm/dev/vendor/stacktrace.js +2 -1
  230. package/build/esm/dev/vendor/stacktrace.js.map +1 -1
  231. package/build/esm/dev/vite/autoInstrument.js +2 -1
  232. package/build/esm/dev/vite/autoInstrument.js.map +1 -1
  233. package/build/esm/dev/vite/index.js.map +1 -1
  234. package/build/esm/dev/vite/transform.js +30 -5
  235. package/build/esm/dev/vite/transform.js.map +1 -1
  236. package/build/esm/dev/vite/wranglerConfig.js +21 -2
  237. package/build/esm/dev/vite/wranglerConfig.js.map +1 -1
  238. package/build/esm/dev/withSentry.js.map +1 -1
  239. package/build/esm/dev/workflows.js +48 -36
  240. package/build/esm/dev/workflows.js.map +1 -1
  241. package/build/esm/dev/wrapMethodWithSentry.js +53 -17
  242. package/build/esm/dev/wrapMethodWithSentry.js.map +1 -1
  243. package/build/esm/dev/wrapRequestHandlerWithInit.js +132 -0
  244. package/build/esm/dev/wrapRequestHandlerWithInit.js.map +1 -0
  245. package/build/esm/prod/baseSdk.js +21 -9
  246. package/build/esm/prod/baseSdk.js.map +1 -1
  247. package/build/esm/prod/client.js +118 -25
  248. package/build/esm/prod/client.js.map +1 -1
  249. package/build/esm/prod/clientCache.js +12 -0
  250. package/build/esm/prod/clientCache.js.map +1 -0
  251. package/build/esm/prod/defineCloudflareOptions.js.map +1 -1
  252. package/build/esm/prod/durableobject.js +5 -63
  253. package/build/esm/prod/durableobject.js.map +1 -1
  254. package/build/esm/prod/flush.js +6 -4
  255. package/build/esm/prod/flush.js.map +1 -1
  256. package/build/esm/prod/index.js +4 -4
  257. package/build/esm/prod/instrumentations/agents/instrumentAgentCallableRpc.js +4 -2
  258. package/build/esm/prod/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  259. package/build/esm/prod/instrumentations/instrumentDurableObjectHandlers.js +121 -0
  260. package/build/esm/prod/instrumentations/instrumentDurableObjectHandlers.js.map +1 -0
  261. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js +4 -4
  262. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  263. package/build/esm/prod/instrumentations/instrumentDurableObjectStorage.js +3 -1
  264. package/build/esm/prod/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  265. package/build/esm/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js +3 -1
  266. package/build/esm/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  267. package/build/esm/prod/instrumentations/instrumentSqlStorage.js +5 -2
  268. package/build/esm/prod/instrumentations/instrumentSqlStorage.js.map +1 -1
  269. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js +9 -16
  270. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  271. package/build/esm/prod/instrumentations/worker/instrumentD1.js +11 -4
  272. package/build/esm/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  273. package/build/esm/prod/instrumentations/worker/instrumentEmail.js +7 -5
  274. package/build/esm/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  275. package/build/esm/prod/instrumentations/worker/instrumentEnv.js +6 -13
  276. package/build/esm/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  277. package/build/esm/prod/instrumentations/worker/instrumentFetch.js +1 -1
  278. package/build/esm/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  279. package/build/esm/prod/instrumentations/worker/instrumentQueue.js +7 -5
  280. package/build/esm/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  281. package/build/esm/prod/instrumentations/worker/instrumentQueueProducer.js +4 -3
  282. package/build/esm/prod/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  283. package/build/esm/prod/instrumentations/worker/instrumentR2.js +22 -19
  284. package/build/esm/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  285. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js +7 -5
  286. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  287. package/build/esm/prod/instrumentations/worker/instrumentTail.js +2 -0
  288. package/build/esm/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  289. package/build/esm/prod/integrations/fetch.js +2 -12
  290. package/build/esm/prod/integrations/fetch.js.map +1 -1
  291. package/build/esm/prod/opentelemetry/tracer.js +2 -40
  292. package/build/esm/prod/opentelemetry/tracer.js.map +1 -1
  293. package/build/esm/prod/package.json +1 -1
  294. package/build/esm/prod/pages-plugin.js +1 -1
  295. package/build/esm/prod/pages-plugin.js.map +1 -1
  296. package/build/esm/prod/request.js +2 -122
  297. package/build/esm/prod/request.js.map +1 -1
  298. package/build/esm/prod/sdk.js +11 -7
  299. package/build/esm/prod/sdk.js.map +1 -1
  300. package/build/esm/prod/transport.js +1 -1
  301. package/build/esm/prod/transport.js.map +1 -1
  302. package/build/esm/prod/utils/invocationContext.js +37 -0
  303. package/build/esm/prod/utils/invocationContext.js.map +1 -0
  304. package/build/esm/prod/utils/invocationScope.js +7 -2
  305. package/build/esm/prod/utils/invocationScope.js.map +1 -1
  306. package/build/esm/prod/utils/isBinding.js +1 -4
  307. package/build/esm/prod/utils/isBinding.js.map +1 -1
  308. package/build/esm/prod/utils/rpcPropagation.js +13 -0
  309. package/build/esm/prod/utils/rpcPropagation.js.map +1 -0
  310. package/build/esm/prod/utils/traceLinks.js +1 -1
  311. package/build/esm/prod/vendor/stacktrace.js +2 -1
  312. package/build/esm/prod/vendor/stacktrace.js.map +1 -1
  313. package/build/esm/prod/vite/autoInstrument.js +2 -1
  314. package/build/esm/prod/vite/autoInstrument.js.map +1 -1
  315. package/build/esm/prod/vite/index.js.map +1 -1
  316. package/build/esm/prod/vite/transform.js +30 -5
  317. package/build/esm/prod/vite/transform.js.map +1 -1
  318. package/build/esm/prod/vite/wranglerConfig.js +21 -2
  319. package/build/esm/prod/vite/wranglerConfig.js.map +1 -1
  320. package/build/esm/prod/withSentry.js.map +1 -1
  321. package/build/esm/prod/workflows.js +48 -36
  322. package/build/esm/prod/workflows.js.map +1 -1
  323. package/build/esm/prod/wrapMethodWithSentry.js +53 -17
  324. package/build/esm/prod/wrapMethodWithSentry.js.map +1 -1
  325. package/build/esm/prod/wrapRequestHandlerWithInit.js +132 -0
  326. package/build/esm/prod/wrapRequestHandlerWithInit.js.map +1 -0
  327. package/build/types/baseSdk.d.ts +8 -0
  328. package/build/types/baseSdk.d.ts.map +1 -1
  329. package/build/types/client.d.ts +91 -18
  330. package/build/types/client.d.ts.map +1 -1
  331. package/build/types/clientCache.d.ts +8 -0
  332. package/build/types/clientCache.d.ts.map +1 -0
  333. package/build/types/defineCloudflareOptions.d.ts +3 -2
  334. package/build/types/defineCloudflareOptions.d.ts.map +1 -1
  335. package/build/types/durableobject.d.ts +5 -7
  336. package/build/types/durableobject.d.ts.map +1 -1
  337. package/build/types/flush.d.ts +2 -0
  338. package/build/types/flush.d.ts.map +1 -1
  339. package/build/types/index.d.ts +4 -4
  340. package/build/types/index.d.ts.map +1 -1
  341. package/build/types/instrumentations/agents/instrumentAgentCallableRpc.d.ts.map +1 -1
  342. package/build/types/instrumentations/instrumentDurableObjectHandlers.d.ts +28 -0
  343. package/build/types/instrumentations/instrumentDurableObjectHandlers.d.ts.map +1 -0
  344. package/build/types/instrumentations/instrumentDurableObjectNamespace.d.ts +2 -1
  345. package/build/types/instrumentations/instrumentDurableObjectNamespace.d.ts.map +1 -1
  346. package/build/types/instrumentations/instrumentDurableObjectStorage.d.ts.map +1 -1
  347. package/build/types/instrumentations/instrumentDurableObjectSyncKvStorage.d.ts.map +1 -1
  348. package/build/types/instrumentations/instrumentSqlStorage.d.ts.map +1 -1
  349. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts +2 -3
  350. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts.map +1 -1
  351. package/build/types/instrumentations/worker/instrumentD1.d.ts.map +1 -1
  352. package/build/types/instrumentations/worker/instrumentEmail.d.ts.map +1 -1
  353. package/build/types/instrumentations/worker/instrumentEnv.d.ts +0 -1
  354. package/build/types/instrumentations/worker/instrumentEnv.d.ts.map +1 -1
  355. package/build/types/instrumentations/worker/instrumentQueue.d.ts.map +1 -1
  356. package/build/types/instrumentations/worker/instrumentQueueProducer.d.ts.map +1 -1
  357. package/build/types/instrumentations/worker/instrumentR2.d.ts.map +1 -1
  358. package/build/types/instrumentations/worker/instrumentScheduled.d.ts.map +1 -1
  359. package/build/types/instrumentations/worker/instrumentTail.d.ts.map +1 -1
  360. package/build/types/integrations/fetch.d.ts.map +1 -1
  361. package/build/types/opentelemetry/tracer.d.ts.map +1 -1
  362. package/build/types/pages-plugin.d.ts +3 -1
  363. package/build/types/pages-plugin.d.ts.map +1 -1
  364. package/build/types/request.d.ts +5 -31
  365. package/build/types/request.d.ts.map +1 -1
  366. package/build/types/sdk.d.ts +13 -4
  367. package/build/types/sdk.d.ts.map +1 -1
  368. package/build/types/transport.d.ts.map +1 -1
  369. package/build/types/types.d.ts +28 -0
  370. package/build/types/types.d.ts.map +1 -1
  371. package/build/types/utils/invocationContext.d.ts +58 -0
  372. package/build/types/utils/invocationContext.d.ts.map +1 -0
  373. package/build/types/utils/invocationScope.d.ts +2 -1
  374. package/build/types/utils/invocationScope.d.ts.map +1 -1
  375. package/build/types/utils/isBinding.d.ts +1 -9
  376. package/build/types/utils/isBinding.d.ts.map +1 -1
  377. package/build/types/utils/rpcPropagation.d.ts +10 -0
  378. package/build/types/utils/rpcPropagation.d.ts.map +1 -0
  379. package/build/types/vendor/stacktrace.d.ts.map +1 -1
  380. package/build/types/vite/autoInstrument.d.ts.map +1 -1
  381. package/build/types/vite/index.d.ts +4 -0
  382. package/build/types/vite/index.d.ts.map +1 -1
  383. package/build/types/vite/transform.d.ts +3 -0
  384. package/build/types/vite/transform.d.ts.map +1 -1
  385. package/build/types/vite/wranglerConfig.d.ts +13 -0
  386. package/build/types/vite/wranglerConfig.d.ts.map +1 -1
  387. package/build/types/withSentry.d.ts +2 -3
  388. package/build/types/withSentry.d.ts.map +1 -1
  389. package/build/types/workflows.d.ts +3 -3
  390. package/build/types/workflows.d.ts.map +1 -1
  391. package/build/types/wrapMethodWithSentry.d.ts +6 -1
  392. package/build/types/wrapMethodWithSentry.d.ts.map +1 -1
  393. package/build/types/wrapRequestHandlerWithInit.d.ts +31 -0
  394. package/build/types/wrapRequestHandlerWithInit.d.ts.map +1 -0
  395. package/package.json +6 -4
  396. package/build/cjs/dev/instrumentations/worker/instrumentRateLimit.js +0 -29
  397. package/build/cjs/dev/instrumentations/worker/instrumentRateLimit.js.map +0 -1
  398. package/build/cjs/dev/integrations/tracing/vercelai.js +0 -18
  399. package/build/cjs/dev/integrations/tracing/vercelai.js.map +0 -1
  400. package/build/cjs/prod/instrumentations/worker/instrumentRateLimit.js +0 -29
  401. package/build/cjs/prod/instrumentations/worker/instrumentRateLimit.js.map +0 -1
  402. package/build/cjs/prod/integrations/tracing/vercelai.js +0 -18
  403. package/build/cjs/prod/integrations/tracing/vercelai.js.map +0 -1
  404. package/build/esm/dev/instrumentations/worker/instrumentRateLimit.js +0 -27
  405. package/build/esm/dev/instrumentations/worker/instrumentRateLimit.js.map +0 -1
  406. package/build/esm/dev/integrations/tracing/vercelai.js +0 -16
  407. package/build/esm/dev/integrations/tracing/vercelai.js.map +0 -1
  408. package/build/esm/prod/instrumentations/worker/instrumentRateLimit.js +0 -27
  409. package/build/esm/prod/instrumentations/worker/instrumentRateLimit.js.map +0 -1
  410. package/build/esm/prod/integrations/tracing/vercelai.js +0 -16
  411. package/build/esm/prod/integrations/tracing/vercelai.js.map +0 -1
  412. package/build/types/instrumentations/worker/instrumentRateLimit.d.ts +0 -6
  413. package/build/types/instrumentations/worker/instrumentRateLimit.d.ts.map +0 -1
  414. package/build/types/integrations/tracing/vercelai.d.ts +0 -39
  415. package/build/types/integrations/tracing/vercelai.d.ts.map +0 -1
@@ -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,GA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AAA,QACrB,WAAW,OAAO,OAAA,CAAQ,UAAA,KAAe,QAAA,GAAW,QAAQ,UAAA,GAAa;AAAA,OAC1E,CAAA;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,U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,IACH;AAAA,GACD,CAAA;AACH;;;;;"}
1
+ {"version":3,"file":"workflows.js","sources":["../../../src/workflows.ts"],"sourcesContent":["import { SENTRY_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,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AAYC,0BAAA,CAAqB,OAAO,CAAA,CAAE,KAAK,OAAO,CAAA;AAC5D,gBAAA,MAAM,MAAA,GAASC,SAAK,EAAE,GAAG,SAAS,GAAA,EAAK,OAAA,EAAS,YAAA,EAAc,KAAA,EAAO,CAAA;AACrE,gBAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,gBAAAC,kCAAA,CAAwB,cAAc,CAAA;AAEtC,gBAAA,OAAOC,cAAA,CAAU,OAAM,KAAA,KAAS;AAC9B,kBAAA,MAAM,kBAAA,GAAqB,MAAM,gCAAA,CAAiC,KAAA,CAAM,UAAU,CAAA;AAClF,kBAAA,KAAA,CAAM,sBAAsB,kBAAkB,CAAA;AAE9C,kBAAA,IAAI;AACF,oBAAA,OAAO,MAAM,IAAI,GAAA,CAAI,IAAA;AAAA,sBACnB,GAAA;AAAA,sBACA,KAAA;AAAA,sBACA,IAAI,mBAAA,CAAoB,KAAA,CAAM,YAAY,OAAA,EAAS,IAAA,EAAM,WAAW,cAAc;AAAA,qBACpF;AAAA,kBACF,CAAA,SAAE;AACA,oBAAA,SAAA,CAAUC,qBAAA,CAAgB,MAAM,CAAC,CAAA;AAAA,kBACnC;AAAA,gBACF,CAAC,CAAA;AAAA,cACH,GAAG,OAAO,CAAA;AAAA,YACZ,CAAA;AAAA,UACF;AACA,UAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,IAAA,EAAM,QAAQ,CAAA;AAAA,QACxC;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AACH;;;;;"}
@@ -4,6 +4,7 @@ const core = require('@sentry/core');
4
4
  const flush = require('./flush.js');
5
5
  const instrument = require('./instrument.js');
6
6
  const sdk = require('./sdk.js');
7
+ const invocationContext = require('./utils/invocationContext.js');
7
8
  const invocationScope = require('./utils/invocationScope.js');
8
9
  const rpcMeta = require('./utils/rpcMeta.js');
9
10
  const traceLinks = require('./utils/traceLinks.js');
@@ -33,9 +34,11 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
33
34
  args = extracted.args;
34
35
  rpcMeta$1 = extracted.rpcMeta;
35
36
  }
37
+ const spanName = typeof wrapperOptions.spanName === "function" ? wrapperOptions.spanName(rpcMeta$1) : wrapperOptions.spanName;
36
38
  const wrappedFunction = (scope) => {
37
39
  const context = wrapperOptions.context;
38
- const waitUntil = context ? flush.getOriginalWaitUntil(context)?.bind(context) : void 0;
40
+ const invocationState = invocationContext.getInvocationState();
41
+ const waitUntil = invocationState ? invocationContext.getInvocationWaitUntil(invocationState) : context ? flush.getOriginalWaitUntil(context)?.bind(context) : void 0;
39
42
  const storage = resolveOriginalStorage(context, thisArg);
40
43
  let scopeClient = scope.getClient();
41
44
  if (startNewTrace || !scopeClient?.getTransport()) {
@@ -47,7 +50,7 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
47
50
  scopeClient = client;
48
51
  }
49
52
  const clientToDispose = scopeClient;
50
- const methodName = wrapperOptions.spanName || "unknown";
53
+ const methodName = spanName || "unknown";
51
54
  const teardown = async () => {
52
55
  if (startNewTrace && storage) {
53
56
  traceLinks.storeSpanContext(storage, methodName);
@@ -58,17 +61,23 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
58
61
  waitUntil?.(teardown());
59
62
  return res;
60
63
  };
61
- const onRejected = (e) => {
64
+ const captureAndRethrow = (e) => {
62
65
  core.captureException(e, {
63
66
  mechanism: {
64
67
  type: origin,
65
68
  handled: false
66
69
  }
67
70
  });
68
- waitUntil?.(teardown());
69
71
  throw e;
70
72
  };
71
- if (!wrapperOptions.spanName) {
73
+ const onRejected = (e) => {
74
+ try {
75
+ return captureAndRethrow(e);
76
+ } finally {
77
+ waitUntil?.(teardown());
78
+ }
79
+ };
80
+ if (!spanName) {
72
81
  try {
73
82
  if (callback) {
74
83
  callback(...args);
@@ -103,27 +112,54 @@ function wrapMethodWithSentry(wrapperOptions, handler, callback, noMark) {
103
112
  try {
104
113
  const result = Reflect.apply(target, thisArg, args);
105
114
  if (core.isThenable(result)) {
106
- return result.then(onFulfilled, onRejected);
107
- } else {
108
- return onFulfilled(result);
115
+ return result.then(void 0, captureAndRethrow);
109
116
  }
117
+ return result;
110
118
  } catch (e) {
111
- return onRejected(e);
119
+ return captureAndRethrow(e);
112
120
  }
113
121
  });
114
122
  };
123
+ const runWithTeardown = (run) => {
124
+ let out;
125
+ try {
126
+ out = run();
127
+ } catch (e) {
128
+ waitUntil?.(teardown());
129
+ throw e;
130
+ }
131
+ if (core.isThenable(out)) {
132
+ return out.then(
133
+ (res) => {
134
+ waitUntil?.(teardown());
135
+ return res;
136
+ },
137
+ (e) => {
138
+ waitUntil?.(teardown());
139
+ throw e;
140
+ }
141
+ );
142
+ }
143
+ waitUntil?.(teardown());
144
+ return out;
145
+ };
115
146
  if (rpcMeta$1) {
116
- return core.continueTrace(
117
- { sentryTrace: rpcMeta$1["sentry-trace"] || "", baggage: rpcMeta$1.baggage || "" },
118
- executeSpan
147
+ return runWithTeardown(
148
+ () => core.continueTrace(
149
+ { sentryTrace: rpcMeta$1["sentry-trace"] || "", baggage: rpcMeta$1.baggage || "" },
150
+ executeSpan
151
+ )
119
152
  );
120
153
  }
121
154
  if (startNewTrace) {
122
- return core.startNewTrace(() => executeSpan());
155
+ return runWithTeardown(() => core.startNewTrace(() => executeSpan()));
123
156
  }
124
- return executeSpan();
157
+ return runWithTeardown(executeSpan);
125
158
  };
126
- return invocationScope.withInvocationIsolationScope(wrappedFunction);
159
+ return invocationScope.withInvocationIsolationScope(
160
+ wrappedFunction,
161
+ wrapperOptions.context
162
+ );
127
163
  }
128
164
  }),
129
165
  noMark
@@ -1 +1 @@
1
- {"version":3,"file":"wrapMethodWithSentry.js","sources":["../../../src/wrapMethodWithSentry.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport type { SerializedTraceData } from '@sentry/core';\nimport {\n isObjectLike,\n captureException,\n continueTrace,\n isThenable,\n type Scope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startNewTrace as startNewTraceCore,\n startSpan,\n} from '@sentry/core';\nimport type { CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { ensureInstrumented } from './instrument';\nimport { init } from './sdk';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\nimport { extractRpcMeta } from './utils/rpcMeta';\nimport { buildSpanLinks, getStoredSpanContext, storeSpanContext } from './utils/traceLinks';\n\n/** Extended DurableObjectState with originalStorage exposed by instrumentContext */\nexport interface InstrumentedDurableObjectState extends DurableObjectState {\n originalStorage?: DurableObjectStorage;\n}\n\n/**\n * Resolves uninstrumented DO storage for the current invocation.\n * Prefer `thisArg.ctx` (the live Durable Object instance) over the context captured at\n * construction time to avoid cross-DO I/O errors in the same isolate.\n */\nfunction resolveOriginalStorage(\n context: ExecutionContext | InstrumentedDurableObjectState | undefined,\n thisArg: unknown,\n): DurableObjectStorage | undefined {\n if (isObjectLike(thisArg) && 'ctx' in thisArg) {\n const doCtx = (thisArg as { ctx: InstrumentedDurableObjectState }).ctx;\n if (doCtx?.originalStorage) {\n return doCtx.originalStorage;\n }\n }\n\n if (context && 'originalStorage' in context && context.originalStorage) {\n return context.originalStorage;\n }\n\n return undefined;\n}\n\ntype MethodWrapperOptions = {\n spanName?: string;\n spanOp?: string;\n options: CloudflareOptions;\n context: ExecutionContext | InstrumentedDurableObjectState;\n /**\n * If true, starts a fresh trace instead of inheriting from a parent trace.\n * Useful for scheduled/independent invocations like alarms.\n *\n * If true, it also stores the current span context and links to the previous invocation's span.\n * Uses Durable Object storage to persist the link. The link is set asynchronously via `span.addLinks()`\n * in a `waitUntil` to avoid blocking.\n *\n * @default false\n */\n startNewTrace?: boolean;\n /**\n * The trace origin identifying which instrumentation created the span, e.g. `auto.faas.cloudflare.durable_object`.\n * Used both as the span's `sentry.origin` attribute and as the `mechanism.type` for captured exceptions.\n */\n origin: string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type UncheckedMethod = (...args: any[]) => any;\ntype OriginalMethod = UncheckedMethod;\n\n/**\n * Wraps a method with Sentry error tracking and optional tracing.\n * Supports starting new traces and linking to previous invocations via Durable Object storage.\n *\n * @param wrapperOptions - The options for the wrapper.\n * @param handler - The method to wrap.\n * @param callback - The callback to call.\n * @param noMark - Whether to mark the method as instrumented.\n * @returns The wrapped method.\n */\nexport function wrapMethodWithSentry<T extends OriginalMethod>(\n wrapperOptions: MethodWrapperOptions,\n handler: T,\n callback?: (...args: Parameters<T>) => void,\n noMark?: true,\n): T {\n return ensureInstrumented(\n handler,\n original =>\n new Proxy(original, {\n apply(target, thisArg, rawArgs: Parameters<T>) {\n const { startNewTrace, origin } = wrapperOptions;\n\n // For RPC methods, extract Sentry trace context from the trailing argument.\n // The caller side (instrumentDurableObjectStub / JSRPC proxy) appends it;\n // we strip it here so the user's method never sees it.\n let args = rawArgs;\n let rpcMeta: SerializedTraceData | undefined;\n\n if (wrapperOptions.spanOp === 'rpc') {\n const extracted = extractRpcMeta(rawArgs);\n args = extracted.args;\n rpcMeta = extracted.rpcMeta;\n }\n\n const wrappedFunction = (scope: Scope): unknown | Promise<unknown> => {\n // In certain situations, the passed context can become undefined.\n // For example, for Astro while prerendering pages at build time.\n // see: https://github.com/getsentry/sentry-javascript/issues/13217\n const context: typeof wrapperOptions.context | undefined = wrapperOptions.context;\n\n // see: https://github.com/getsentry/sentry-javascript/issues/22328\n const waitUntil = context\n ? getOriginalWaitUntil(context as ExecutionContextCompat)?.bind(context)\n : undefined;\n const storage = resolveOriginalStorage(context, thisArg);\n\n let scopeClient = scope.getClient();\n // Check if client exists AND is still usable (transport not disposed)\n // This handles the case where a previous handler disposed the client\n // but the scope still holds a reference to it (e.g., alarm handlers in Durable Objects)\n // For startNewTrace, always create a fresh client\n if (startNewTrace || !scopeClient?.getTransport()) {\n const client = init({\n ...wrapperOptions.options,\n ctx: context as unknown as ExecutionContext | undefined,\n });\n scope.setClient(client);\n scopeClient = client;\n }\n\n const clientToDispose = scopeClient;\n const methodName = wrapperOptions.spanName || 'unknown';\n\n const teardown = async (): Promise<void> => {\n if (startNewTrace && storage) {\n storeSpanContext(storage, methodName);\n }\n await flushAndDispose(clientToDispose);\n };\n\n const onFulfilled = (res: unknown) => {\n waitUntil?.(teardown());\n return res;\n };\n\n const onRejected = (e: unknown) => {\n captureException(e, {\n mechanism: {\n type: origin,\n handled: false,\n },\n });\n waitUntil?.(teardown());\n throw e;\n };\n\n if (!wrapperOptions.spanName) {\n try {\n if (callback) {\n callback(...args);\n }\n\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(onFulfilled, onRejected);\n } else {\n return onFulfilled(result);\n }\n } catch (e) {\n return onRejected(e);\n }\n }\n\n const attributes = wrapperOptions.spanOp\n ? {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,\n }\n : {};\n\n const executeSpan = (): unknown => {\n return startSpan({ name: methodName, attributes }, span => {\n if (startNewTrace && storage) {\n const storedContext = getStoredSpanContext(storage, methodName);\n\n if (storedContext) {\n span.addLinks(buildSpanLinks(storedContext));\n // TODO: Remove this once EAP can store span links. We currently only set this attribute so that we\n // can obtain the previous trace information from the EAP store. Long-term, EAP will handle\n // span links and then we should remove this again. Also throwing in a TODO(v11), to remind us\n // to check this at v11 time :)\n const sampledFlag = storedContext.sampled ? '1' : '0';\n span.setAttribute(\n 'sentry.previous_trace',\n `${storedContext.traceId}-${storedContext.spanId}-${sampledFlag}`,\n );\n }\n }\n\n try {\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(onFulfilled, onRejected);\n } else {\n return onFulfilled(result);\n }\n } catch (e) {\n return onRejected(e);\n }\n });\n };\n\n if (rpcMeta) {\n return continueTrace(\n { sentryTrace: rpcMeta['sentry-trace'] || '', baggage: rpcMeta.baggage || '' },\n executeSpan,\n );\n }\n\n if (startNewTrace) {\n return startNewTraceCore(() => executeSpan());\n }\n\n return executeSpan();\n };\n\n return withInvocationIsolationScope(wrappedFunction);\n },\n }),\n noMark,\n );\n}\n"],"names":["isObjectLike","ensureInstrumented","rpcMeta","extractRpcMeta","getOriginalWaitUntil","init","storeSpanContext","flushAndDispose","captureException","isThenable","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","getStoredSpanContext","buildSpanLinks","continueTrace","startNewTraceCore","withInvocationIsolationScope"],"mappings":";;;;;;;;;;AAgCA,SAAS,sBAAA,CACP,SACA,OAAA,EACkC;AAClC,EAAA,IAAIA,iBAAA,CAAa,OAAO,CAAA,IAAK,KAAA,IAAS,OAAA,EAAS;AAC7C,IAAA,MAAM,QAAS,OAAA,CAAoD,GAAA;AACnE,IAAA,IAAI,OAAO,eAAA,EAAiB;AAC1B,MAAA,OAAO,KAAA,CAAM,eAAA;AAAA,IACf;AAAA,EACF;AAEA,EAAA,IAAI,OAAA,IAAW,iBAAA,IAAqB,OAAA,IAAW,OAAA,CAAQ,eAAA,EAAiB;AACtE,IAAA,OAAO,OAAA,CAAQ,eAAA;AAAA,EACjB;AAEA,EAAA,OAAO,MAAA;AACT;AAuCO,SAAS,oBAAA,CACd,cAAA,EACA,OAAA,EACA,QAAA,EACA,MAAA,EACG;AACH,EAAA,OAAOC,6BAAA;AAAA,IACL,OAAA;AAAA,IACA,CAAA,QAAA,KACE,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,MAClB,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,OAAA,EAAwB;AAC7C,QAAA,MAAM,EAAE,aAAA,EAAe,MAAA,EAAO,GAAI,cAAA;AAKlC,QAAA,IAAI,IAAA,GAAO,OAAA;AACX,QAAA,IAAIC,SAAA;AAEJ,QAAA,IAAI,cAAA,CAAe,WAAW,KAAA,EAAO;AACnC,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ClD,kBAAA,IAAA,CAAK,YAAA;AAAA,oBACH,uBAAA;AAAA,oBACA,GAAG,aAAA,CAAc,OAAO,IAAI,aAAA,CAAc,MAAM,IAAI,WAAW,CAAA;AAAA,mBACjE;AAAA,gBACF;AAAA,cACF;AAEA,cAAA,IAAI;AACF,gBAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,KAAA,CAAM,MAAA,EAAQ,SAAS,IAAI,CAAA;AAElD,gBAAA,IAAIL,eAAA,CAAW,MAAM,CAAA,EAAG;AACtB,kBAAA,OAAO,MAAA,CAAO,IAAA,CAAK,WAAA,EAAa,UAAU,CAAA;AAAA,gBAC5C,CAAA,MAAO;AACL,kBAAA,OAAO,YAAY,MAAM,CAAA;AAAA,gBAC3B;AAAA,cACF,SAAS,CAAA,EAAG;AACV,gBAAA,OAAO,WAAW,CAAC,CAAA;AAAA,cACrB;AAAA,YACF,CAAC,CAAA;AAAA,UACH,CAAA;AAEA,UAAA,IAAIP,SAAA,EAAS;AACX,YAAA,OAAOa,kBAAA;AAAA,cACL,EAAE,aAAab,SAAA,CAAQ,cAAc,KAAK,EAAA,EAAI,OAAA,EAASA,SAAA,CAAQ,OAAA,IAAW,EAAA,EAAG;AAAA,cAC7E;AAAA,aACF;AAAA,UACF;AAEA,UAAA,IAAI,aAAA,EAAe;AACjB,YAAA,OAAOc,kBAAA,CAAkB,MAAM,WAAA,EAAa,CAAA;AAAA,UAC9C;AAEA,UAAA,OAAO,WAAA,EAAY;AAAA,QACrB,CAAA;AAEA,QAAA,OAAOC,6CAA6B,eAAe,CAAA;AAAA,MACrD;AAAA,KACD,CAAA;AAAA,IACH;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"wrapMethodWithSentry.js","sources":["../../../src/wrapMethodWithSentry.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport type { SerializedTraceData } from '@sentry/core';\nimport {\n isObjectLike,\n captureException,\n continueTrace,\n isThenable,\n type Scope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startNewTrace as startNewTraceCore,\n startSpan,\n} from '@sentry/core';\nimport type { CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { ensureInstrumented } from './instrument';\nimport { init } from './sdk';\nimport { getInvocationState, getInvocationWaitUntil } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\nimport { extractRpcMeta } from './utils/rpcMeta';\nimport { buildSpanLinks, getStoredSpanContext, storeSpanContext } from './utils/traceLinks';\n\n/** Extended DurableObjectState with originalStorage exposed by instrumentContext */\nexport interface InstrumentedDurableObjectState extends DurableObjectState {\n originalStorage?: DurableObjectStorage;\n}\n\n/**\n * Resolves uninstrumented DO storage for the current invocation.\n * Prefer `thisArg.ctx` (the live Durable Object instance) over the context captured at\n * construction time to avoid cross-DO I/O errors in the same isolate.\n */\nfunction resolveOriginalStorage(\n context: ExecutionContext | InstrumentedDurableObjectState | undefined,\n thisArg: unknown,\n): DurableObjectStorage | undefined {\n if (isObjectLike(thisArg) && 'ctx' in thisArg) {\n const doCtx = (thisArg as { ctx: InstrumentedDurableObjectState }).ctx;\n if (doCtx?.originalStorage) {\n return doCtx.originalStorage;\n }\n }\n\n if (context && 'originalStorage' in context && context.originalStorage) {\n return context.originalStorage;\n }\n\n return undefined;\n}\n\ntype MethodWrapperOptions = {\n /**\n * The span name, or a resolver called with the RPC metadata of the current call.\n * Returning `undefined` skips the span and only captures errors.\n */\n spanName?: string | ((rpcMeta: SerializedTraceData | undefined) => string | undefined);\n spanOp?: string;\n options: CloudflareOptions;\n context: ExecutionContext | InstrumentedDurableObjectState;\n /**\n * If true, starts a fresh trace instead of inheriting from a parent trace.\n * Useful for scheduled/independent invocations like alarms.\n *\n * If true, it also stores the current span context and links to the previous invocation's span.\n * Uses Durable Object storage to persist the link. The link is set asynchronously via `span.addLinks()`\n * in a `waitUntil` to avoid blocking.\n *\n * @default false\n */\n startNewTrace?: boolean;\n /**\n * The trace origin identifying which instrumentation created the span, e.g. `auto.faas.cloudflare.durable_object`.\n * Used both as the span's `sentry.origin` attribute and as the `mechanism.type` for captured exceptions.\n */\n origin: string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type UncheckedMethod = (...args: any[]) => any;\ntype OriginalMethod = UncheckedMethod;\n\n/**\n * Wraps a method with Sentry error tracking and optional tracing.\n * Supports starting new traces and linking to previous invocations via Durable Object storage.\n *\n * @param wrapperOptions - The options for the wrapper.\n * @param handler - The method to wrap.\n * @param callback - The callback to call.\n * @param noMark - Whether to mark the method as instrumented.\n * @returns The wrapped method.\n */\nexport function wrapMethodWithSentry<T extends OriginalMethod>(\n wrapperOptions: MethodWrapperOptions,\n handler: T,\n callback?: (...args: Parameters<T>) => void,\n noMark?: true,\n): T {\n return ensureInstrumented(\n handler,\n original =>\n new Proxy(original, {\n apply(target, thisArg, rawArgs: Parameters<T>) {\n const { startNewTrace, origin } = wrapperOptions;\n\n // For RPC methods, extract Sentry trace context from the trailing argument.\n // The caller side (instrumentDurableObjectStub / JSRPC proxy) appends it;\n // we strip it here so the user's method never sees it.\n let args = rawArgs;\n let rpcMeta: SerializedTraceData | undefined;\n\n if (wrapperOptions.spanOp === 'rpc') {\n const extracted = extractRpcMeta(rawArgs);\n args = extracted.args;\n rpcMeta = extracted.rpcMeta;\n }\n\n const spanName =\n typeof wrapperOptions.spanName === 'function' ? wrapperOptions.spanName(rpcMeta) : wrapperOptions.spanName;\n\n const wrappedFunction = (scope: Scope): unknown | Promise<unknown> => {\n // In certain situations, the passed context can become undefined.\n // For example, for Astro while prerendering pages at build time.\n // see: https://github.com/getsentry/sentry-javascript/issues/13217\n const context: typeof wrapperOptions.context | undefined = wrapperOptions.context;\n\n // see: https://github.com/getsentry/sentry-javascript/issues/22328\n // Resolved once per invocation and cached on its state: reading `ctx.waitUntil`\n // on a native context is a runtime getter call.\n const invocationState = getInvocationState();\n const waitUntil = invocationState\n ? getInvocationWaitUntil(invocationState)\n : context\n ? getOriginalWaitUntil(context as ExecutionContextCompat)?.bind(context)\n : undefined;\n const storage = resolveOriginalStorage(context, thisArg);\n\n let scopeClient = scope.getClient();\n // Re-init when the scope has no usable client (a previous handler disposed it, e.g.\n // DO alarm handlers) or for `startNewTrace`, so the client points at this\n // invocation's context. With `cacheClient: true` `init()` returns the isolate's\n // cached client and only creates (and caches) a fresh one when nothing is cached yet;\n // `cacheClient: false` creates one per invocation.\n if (startNewTrace || !scopeClient?.getTransport()) {\n const client = init({\n ...wrapperOptions.options,\n ctx: context as unknown as ExecutionContext | undefined,\n });\n scope.setClient(client);\n scopeClient = client;\n }\n\n const clientToDispose = scopeClient;\n const methodName = spanName || 'unknown';\n\n const teardown = async (): Promise<void> => {\n if (startNewTrace && storage) {\n storeSpanContext(storage, methodName);\n }\n await flushAndDispose(clientToDispose);\n };\n\n const onFulfilled = (res: unknown) => {\n waitUntil?.(teardown());\n return res;\n };\n\n const captureAndRethrow = (e: unknown): never => {\n captureException(e, {\n mechanism: {\n type: origin,\n handled: false,\n },\n });\n throw e;\n };\n\n const onRejected = (e: unknown) => {\n try {\n return captureAndRethrow(e);\n } finally {\n waitUntil?.(teardown());\n }\n };\n\n if (!spanName) {\n try {\n if (callback) {\n callback(...args);\n }\n\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(onFulfilled, onRejected);\n } else {\n return onFulfilled(result);\n }\n } catch (e) {\n return onRejected(e);\n }\n }\n\n const attributes = wrapperOptions.spanOp\n ? {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,\n }\n : {};\n\n const executeSpan = (): unknown => {\n return startSpan({ name: methodName, attributes }, span => {\n if (startNewTrace && storage) {\n const storedContext = getStoredSpanContext(storage, methodName);\n\n if (storedContext) {\n span.addLinks(buildSpanLinks(storedContext));\n // TODO: Remove this once EAP can store span links. We currently only set this attribute so that we\n // can obtain the previous trace information from the EAP store. Long-term, EAP will handle\n // span links and then we should remove this again. Also throwing in a TODO(v11), to remind us\n // to check this at v11 time :)\n const sampledFlag = storedContext.sampled ? '1' : '0';\n span.setAttribute(\n 'sentry.previous_trace',\n `${storedContext.traceId}-${storedContext.spanId}-${sampledFlag}`,\n );\n }\n }\n\n try {\n const result = Reflect.apply(target, thisArg, args);\n\n if (isThenable(result)) {\n return result.then(undefined, captureAndRethrow);\n }\n return result;\n } catch (e) {\n return captureAndRethrow(e);\n }\n });\n };\n\n // The boundary flush (teardown) must run after the method span has ended, so the\n // span is in the buffer when that flush drains it. Running it inside the span\n // callback (before `startSpan` ends the span) would leave the span for the eager\n // path and cost a second flush per invocation.\n const runWithTeardown = (run: () => unknown): unknown => {\n let out: unknown;\n try {\n out = run();\n } catch (e) {\n // Synchronous throw: `startSpan` already ended the span and rethrew.\n waitUntil?.(teardown());\n throw e;\n }\n if (isThenable(out)) {\n return out.then(\n res => {\n waitUntil?.(teardown());\n return res;\n },\n e => {\n waitUntil?.(teardown());\n throw e;\n },\n );\n }\n waitUntil?.(teardown());\n return out;\n };\n\n if (rpcMeta) {\n return runWithTeardown(() =>\n continueTrace(\n { sentryTrace: rpcMeta['sentry-trace'] || '', baggage: rpcMeta.baggage || '' },\n executeSpan,\n ),\n );\n }\n\n if (startNewTrace) {\n return runWithTeardown(() => startNewTraceCore(() => executeSpan()));\n }\n\n return runWithTeardown(executeSpan);\n };\n\n return withInvocationIsolationScope(\n wrappedFunction,\n wrapperOptions.context as ExecutionContextCompat | undefined,\n );\n },\n }),\n noMark,\n );\n}\n"],"names":["isObjectLike","ensureInstrumented","rpcMeta","extractRpcMeta","getInvocationState","getInvocationWaitUntil","getOriginalWaitUntil","init","storeSpanContext","flushAndDispose","captureException","isThenable","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","getSto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