@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
@@ -3,10 +3,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const core = require('@sentry/core');
4
4
  const client = require('./client.js');
5
5
  const flush = require('./flush.js');
6
+ const clientCache = require('./clientCache.js');
7
+ const debugBuild = require('./debug-build.js');
6
8
  const fetch = require('./integrations/fetch.js');
7
9
  const httpServer = require('./integrations/httpServer.js');
8
10
  const spotlight = require('./integrations/spotlight.js');
9
- const tracer = require('./opentelemetry/tracer.js');
10
11
  const transport = require('./transport.js');
11
12
  const stacktrace = require('./vendor/stacktrace.js');
12
13
 
@@ -37,19 +38,30 @@ function getBaseDefaultIntegrations(options) {
37
38
  ];
38
39
  }
39
40
  function initWithDefaultIntegrations(options, getDefaultIntegrationsImpl) {
41
+ const cached = clientCache.getCachedClient();
42
+ const cacheEnabled = options.cacheClient !== false;
43
+ if (cacheEnabled && cached) {
44
+ if (debugBuild.DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {
45
+ core.debug.warn(
46
+ "[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options."
47
+ );
48
+ }
49
+ core.getCurrentScope().update(options.initialScope);
50
+ core.setCurrentClient(cached);
51
+ return cached;
52
+ }
40
53
  if (options.defaultIntegrations === void 0) {
41
54
  options.defaultIntegrations = getDefaultIntegrationsImpl(options);
42
55
  }
43
- const flushLock = options.ctx ? flush.makeFlushLock(options.ctx) : void 0;
56
+ const invocationContext = options.ctx;
57
+ const flushLock = !cacheEnabled && invocationContext ? flush.makeFlushLock(invocationContext) : void 0;
44
58
  delete options.ctx;
45
59
  const clientOptions = {
46
60
  ...options,
61
+ cacheClient: cacheEnabled,
47
62
  stackParser: core.stackParserFromStackParserOptions(options.stackParser || stacktrace.defaultStackParser),
48
63
  integrations: core.getIntegrationsToSetup(options),
49
64
  transport: options.transport || transport.makeCloudflareTransport,
50
- // Like most Node-based SDKs, Cloudflare defaults to running without a Sentry OpenTelemetry tracer
51
- // provider. Scope isolation is handled by the entrypoint wrappers' AsyncLocalStorage strategy.
52
- enableOpenTelemetrySetup: options.enableOpenTelemetrySetup ?? false,
53
65
  flushLock
54
66
  };
55
67
  /*! rollup-include-development-only */
@@ -61,10 +73,10 @@ function initWithDefaultIntegrations(options, getDefaultIntegrationsImpl) {
61
73
  );
62
74
  }
63
75
  /*! rollup-include-development-only-end */
64
- if (clientOptions.enableOpenTelemetrySetup) {
65
- tracer.setupOpenTelemetryTracer();
66
- }
67
76
  const client$1 = core.initAndBind(client.CloudflareClient, clientOptions);
77
+ if (cacheEnabled && client$1) {
78
+ clientCache.cacheClient(client$1);
79
+ }
68
80
  client$1.on("orchestrion.module-injected", (moduleName) => {
69
81
  const factory = core.GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);
70
82
  if (factory) {
@@ -1 +1 @@
1
- {"version":3,"file":"baseSdk.js","sources":["../../../src/baseSdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n eventFiltersIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n GLOBAL_OBJ,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { fetchIntegration } from './integrations/fetch';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { INTEGRATION_NAME as SPOTLIGHT_INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight';\nimport { setupOpenTelemetryTracer } from './opentelemetry/tracer';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/**\n * Instantiate the channel-subscriber factories the `@sentry/cloudflare/vite`\n * plugin registered on the global marker. The plugin splices a small snippet\n * into each instrumented module that `.set`s its factory here (keyed by module\n * name), so the marker holds one factory per package actually bundled.\n *\n * The marker is read directly instead of importing the factories, so a worker\n * built without the plugin — where the channels never fire — ships none of this\n * code.\n * TODO(v11): Use `@sentry/server-utils/orchestrion` once we move to `nodejs_compat` by default.\n */\nfunction getRegisteredChannelIntegrations(): Integration[] {\n const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;\n\n return registered ? [...registered.values()].map(factory => factory()) : [];\n}\n\n/**\n * Get the default integrations that run on any Workers-compatible runtime, i.e. without the\n * `nodejs_compat` compatibility flag.\n *\n * `getDefaultIntegrations` in `sdk.ts` extends this set with the integrations that do depend on\n * Node.js APIs. Keeping the two apart is what allows `wrapRequestHandler` to stay usable on runtimes\n * that cannot enable `nodejs_compat`, such as Shopify Oxygen.\n */\nexport function getBaseDefaultIntegrations(options: CloudflareOptions): Integration[] {\n return [\n // The Dedupe integration should not be used in workflows because we want to\n // capture all step failures, even if they are the same error.\n ...(options.enableDedupe === false ? [] : [dedupeIntegration()]),\n eventFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n httpServerIntegration(),\n requestDataIntegration(),\n consoleIntegration(),\n // The orchestrion diagnostics-channel subscribers (mysql, pg, …). The\n // `@sentry/cloudflare/vite` plugin injects the channels at build time and,\n // next to each, a snippet that registers the matching subscriber factory on\n // the global marker. Read from there instead of importing them so bundles\n // built without the plugin — where the channels would never fire — don't\n // ship the code.\n ...getRegisteredChannelIntegrations(),\n ];\n}\n\n/**\n * Initializes the Cloudflare SDK with the passed default integrations.\n *\n * The default integrations are injected rather than imported so that this module stays free of\n * Node.js-only code. `request.ts` — which backs both `wrapRequestHandler` and the\n * `@sentry/cloudflare/request` entry point, and therefore has to work on runtimes without the\n * `nodejs_compat` compatibility flag — creates its client from here instead of from `sdk.ts`.\n */\nexport function initWithDefaultIntegrations(\n options: CloudflareOptions,\n getDefaultIntegrationsImpl: (options: CloudflareOptions) => Integration[],\n): CloudflareClient | undefined {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(options);\n }\n\n const flushLock = options.ctx ? makeFlushLock(options.ctx) : undefined;\n delete options.ctx;\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n // Like most Node-based SDKs, Cloudflare defaults to running without a Sentry OpenTelemetry tracer\n // provider. Scope isolation is handled by the entrypoint wrappers' AsyncLocalStorage strategy.\n enableOpenTelemetrySetup: options.enableOpenTelemetrySetup ?? false,\n flushLock,\n };\n\n /*! rollup-include-development-only */\n if (options.spotlight && !clientOptions.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) {\n clientOptions.integrations.push(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n /*! rollup-include-development-only-end */\n\n // Opt-in only: when `enableOpenTelemetrySetup` is `true`, set up a custom trace provider so spans\n // emitted via `@opentelemetry/api` are captured by Sentry. See the option's docs for the caveats.\n if (clientOptions.enableOpenTelemetrySetup) {\n setupOpenTelemetryTracer();\n }\n\n const client = initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n\n // An instrumented module that first evaluates AFTER this init (e.g. a driver\n // lazily required on first use) stores its subscriber factory on the global\n // marker too late for the default-integrations snapshot above. Its injected\n // snippet emits this event right after storing the factory, so install the\n // integration on the live client here. `addIntegration` dedupes by\n // integration name, so already-installed integrations are no-ops.\n client.on('orchestrion.module-injected', moduleName => {\n const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);\n if (factory) {\n client.addIntegration(factory());\n }\n });\n\n return client;\n}\n\n/**\n * Initializes the Cloudflare SDK with only the default integrations from\n * {@link getBaseDefaultIntegrations}, i.e. those that work without the `nodejs_compat`\n * compatibility flag.\n */\nexport function initBaseSdk(options: CloudflareOptions): CloudflareClient | undefined {\n return initWithDefaultIntegrations(options, getBaseDefaultIntegrations);\n}\n"],"names":["GLOBAL_OBJ","dedupeIntegration","eventFiltersIntegration","functionToStringIntegration","conversationIdIntegration","linkedErrorsIntegration","fetchIntegration","httpServerIntegration","requestDataIntegration","consoleIntegration","makeFlushLock","stackParserFromStackParserOptions","defaultStackParser","getIntegrationsToSetup","makeCloudflareTransport","SPOTLIGHT_INTEGRATION_NAME","spotlightIntegration","setupOpenTelemetryTracer","client","initAndBind","CloudflareClient"],"mappings":";;;;;;;;;;;;AAmCA,SAAS,gCAAA,GAAkD;AACzD,EAAA,MAAM,UAAA,GAAaA,gBAAW,sBAAA,EAAwB,YAAA;AAEtD,EAAA,OAAO,UAAA,GAAa,CAAC,GAAG,UAAA,CAAW,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,CAAA,OAAA,KAAW,OAAA,EAAS,CAAA,GAAI,EAAC;AAC5E;AAUO,SAAS,2BAA2B,OAAA,EAA2C;AACpF,EAAA,OAAO;AAAA;AAAA;AAAA,IAGL,GAAI,QAAQ,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAA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KAAc,QAAA,GAAW,QAAQ,SAAA,GAAY;AAAA,OACzE;AAAA,KACH;AAAA,EACF;AAAA;AAKA,EAAA,IAAI,cAAc,wBAAA,EAA0B;AAC1C,IAAAC,+BAAA,EAAyB;AAAA,EAC3B;AAEA,EAAA,MAAMC,QAAA,GAASC,gBAAA,CAAYC,uBAAA,EAAkB,aAAa,CAAA;AAQ1D,EAAAF,QAAA,CAAO,EAAA,CAAG,+BAA+B,CAAA,UAAA,KAAc;AACrD,IAAA,MAAM,OAAA,GAAUlB,eAAA,CAAW,sBAAA,EAAwB,YAAA,EAAc,IAAI,UAAU,CAAA;AAC/E,IAAA,IAAI,OAAA,EAAS;AACX,MAAAkB,QAAA,CAAO,cAAA,CAAe,SAAS,CAAA;AAAA,IACjC;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAOA,QAAA;AACT;AAOO,SAAS,YAAY,OAAA,EAA0D;AACpF,EAAA,OAAO,2BAAA,CAA4B,SAAS,0BAA0B,CAAA;AACxE;;;;;;"}
1
+ {"version":3,"file":"baseSdk.js","sources":["../../../src/baseSdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { debug, getCurrentScope, setCurrentClient } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n eventFiltersIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n GLOBAL_OBJ,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { cacheClient, getCachedClient } from './clientCache';\nimport { DEBUG_BUILD } from './debug-build';\nimport { fetchIntegration } from './integrations/fetch';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { INTEGRATION_NAME as SPOTLIGHT_INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/**\n * Instantiate the channel-subscriber factories the `@sentry/cloudflare/vite`\n * plugin registered on the global marker. The plugin splices a small snippet\n * into each instrumented module that `.set`s its factory here (keyed by module\n * name), so the marker holds one factory per package actually bundled.\n *\n * The marker is read directly instead of importing the factories, so a worker\n * built without the plugin — where the channels never fire — ships none of this\n * code.\n */\nfunction getRegisteredChannelIntegrations(): Integration[] {\n const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;\n\n return registered ? [...registered.values()].map(factory => factory()) : [];\n}\n\n/**\n * Get the default integrations that run on any Workers-compatible runtime, i.e. without the\n * `nodejs_compat` compatibility flag.\n *\n * `getDefaultIntegrations` in `sdk.ts` extends this set with the integrations that do depend on\n * Node.js APIs. Keeping the two apart is what allows `wrapRequestHandler` to stay usable on runtimes\n * that cannot enable `nodejs_compat`, such as Shopify Oxygen.\n */\nexport function getBaseDefaultIntegrations(options: CloudflareOptions): Integration[] {\n return [\n // The Dedupe integration should not be used in workflows because we want to\n // capture all step failures, even if they are the same error.\n ...(options.enableDedupe === false ? [] : [dedupeIntegration()]),\n eventFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n httpServerIntegration(),\n requestDataIntegration(),\n consoleIntegration(),\n // The orchestrion diagnostics-channel subscribers (mysql, pg, …). The\n // `@sentry/cloudflare/vite` plugin injects the channels at build time and,\n // next to each, a snippet that registers the matching subscriber factory on\n // the global marker. Read from there instead of importing them so bundles\n // built without the plugin — where the channels would never fire — don't\n // ship the code.\n ...getRegisteredChannelIntegrations(),\n ];\n}\n\n/**\n * Initializes the Cloudflare SDK with the passed default integrations.\n *\n * The default integrations are injected rather than imported so that this module stays free of\n * Node.js-only code. `request.ts` — which backs both `wrapRequestHandler` and the\n * `@sentry/cloudflare/request` entry point, and therefore has to work on runtimes without the\n * `nodejs_compat` compatibility flag — creates its client from here instead of from `sdk.ts`.\n *\n * The client is cached and reused across invocations within the same isolate,\n * unless `cacheClient: false` is passed. This avoids the\n * per-invocation cost of constructing a new client, and it is what makes\n * Durable Object telemetry reliable: a per-invocation client is disposed at\n * the end of the handler, and in a Durable Object there is no `waitUntil`\n * boundary that reliably extends execution, so spans/events that end after\n * disposal would otherwise be lost.\n */\nexport function initWithDefaultIntegrations(\n options: CloudflareOptions,\n getDefaultIntegrationsImpl: (options: CloudflareOptions) => Integration[],\n): CloudflareClient | undefined {\n const cached = getCachedClient();\n const cacheEnabled = options.cacheClient !== false;\n\n if (cacheEnabled && cached) {\n if (DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {\n debug.warn(\n '[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options.',\n );\n }\n getCurrentScope().update(options.initialScope);\n setCurrentClient(cached);\n return cached;\n }\n\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(options);\n }\n\n // A cached client outlives any single invocation, so binding it to one\n // invocation's flush lock would make later flushes wait on that invocation's\n // waitUntil work forever. Eager delivery replaces the flush lock's purpose.\n const invocationContext = options.ctx;\n const flushLock = !cacheEnabled && invocationContext ? makeFlushLock(invocationContext) : undefined;\n delete options.ctx;\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n cacheClient: cacheEnabled,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n flushLock,\n };\n\n /*! rollup-include-development-only */\n if (options.spotlight && !clientOptions.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) {\n clientOptions.integrations.push(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n /*! rollup-include-development-only-end */\n\n const client = initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n\n if (cacheEnabled && client) {\n cacheClient(client);\n }\n\n // An instrumented module that first evaluates AFTER this init (e.g. a driver\n // lazily required on first use) stores its subscriber factory on the global\n // marker too late for the default-integrations snapshot above. Its injected\n // snippet emits this event right after storing the factory, so install the\n // integration on the live client here. `addIntegration` dedupes by\n // integration name, so already-installed integrations are no-ops.\n client.on('orchestrion.module-injected', moduleName => {\n const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);\n if (factory) {\n client.addIntegration(factory());\n }\n });\n\n return client;\n}\n\n/**\n * Initializes the Cloudflare SDK with only the default integrations from\n * {@link getBaseDefaultIntegrations}, i.e. those that work without the `nodejs_compat`\n * compatibility flag.\n */\nexport function initBaseSdk(options: CloudflareOptions): CloudflareClient | undefined {\n return initWithDefaultIntegrations(options, getBaseDefaultIntegrations);\n}\n"],"names":["GLOBAL_OBJ","dedupeIntegration","eventFiltersIntegration","functionToStringIntegration","conversationIdIntegration","linkedErrorsIntegration","fetchIntegration","httpServerIntegration","requestDataIntegration","consoleIntegration","getCachedClient","DEBUG_BUILD","debug","getCurrentScope","setCurrentClient","makeFlushLock","stackParserFromStackParserOptions","defaultStackParser","getIntegrationsToSetup","makeCloudflareTransport","SPOTLIGHT_INTEGRATION_NAME","spotlightIntegration","client","initAndBind","CloudflareClient","cacheClient"],"mappings":";;;;;;;;;;;;;AAoCA,SAAS,gCAAA,GAAkD;AACzD,EAAA,MAAM,UAAA,GAAaA,gBAAW,sBAAA,EAAwB,YAAA;AAEtD,EAAA,OAAO,UAAA,GAAa,CAAC,GAAG,UAAA,CAAW,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,CAAA,OAAA,KAAW,OAAA,EAAS,CAAA,GAAI,EAAC;AAC5E;AAUO,SAAS,2BAA2B,OAAA,EAA2C;AACpF,EAAA,OAAO;AAAA;AAAA;AAAA,IAGL,GAAI,QAAQ,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAAI,CAACC,wBAAmB,CAAA;AAAA,IAC9DC,4BAAA,EAAwB;AAAA,IACxBC,gCAAA,EAA4B;AAAA,IAC5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AO,CAAA;AAAA,IAC5C,SAAA,EAAW,QAAQ,SAAA,IAAaC,iCAAA;AAAA,IAChC;AAAA,GACF;AAAA;AAGA,EAAA,IAAI,OAAA,CAAQ,SAAA,IAAa,CAAC,aAAA,CAAc,YAAA,CAAa,IAAA,CAAK,CAAC,EAAE,IAAA,EAAK,KAAM,IAAA,KAASC,0BAA0B,CAAA,EAAG;AAC5G,IAAA,aAAA,CAAc,YAAA,CAAa,IAAA;AAAA,MACzBC,8BAAA,CAAqB;AAAA,QACnB,YAAY,OAAO,OAAA,CAAQ,SAAA,KAAc,QAAA,GAAW,QAAQ,SAAA,GAAY;AAAA,OACzE;AAAA,KACH;AAAA,EACF;AAAA;AAGA,EAAA,MAAMC,QAAA,GAASC,gBAAA,CAAYC,uBAAA,EAAkB,aAAa,CAAA;AAE1D,EAAA,IAAI,gBAAgBF,QAAA,EAAQ;AAC1B,IAAAG,uBAAA,CAAYH,QAAM,CAAA;AAAA,EACpB;AAQA,EAAAA,QAAA,CAAO,EAAA,CAAG,+BAA+B,CAAA,UAAA,KAAc;AACrD,IAAA,MAAM,OAAA,GAAUtB,eAAA,CAAW,sBAAA,EAAwB,YAAA,EAAc,IAAI,UAAU,CAAA;AAC/E,IAAA,IAAI,OAAA,EAAS;AACX,MAAAsB,QAAA,CAAO,cAAA,CAAe,SAAS,CAAA;AAAA,IACjC;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAOA,QAAA;AACT;AAOO,SAAS,YAAY,OAAA,EAA0D;AACpF,EAAA,OAAO,2BAAA,CAA4B,SAAS,0BAA0B,CAAA;AACxE;;;;;;"}
@@ -1,9 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const core = require('@sentry/core');
4
+ const server = require('@sentry/core/server');
4
5
  const debugBuild = require('./debug-build.js');
6
+ const invocationContext = require('./utils/invocationContext.js');
5
7
 
6
- class CloudflareClient extends core.ServerRuntimeClient {
8
+ class CloudflareClient extends server.ServerRuntimeClient {
7
9
  /**
8
10
  * Creates a new Cloudflare SDK instance.
9
11
  * @param options Configuration options for this SDK.
@@ -26,30 +28,36 @@ class CloudflareClient extends core.ServerRuntimeClient {
26
28
  this._resolveSpanCompletion = null;
27
29
  this._unsubscribeSpanStart = null;
28
30
  this._unsubscribeSpanEnd = null;
31
+ // True while a boundary `flush()` is draining; envelopes created by that drain ride it
32
+ // and must not each start their own eager transport flush.
33
+ this._inBoundaryFlush = false;
29
34
  this._flushLock = flushLock;
30
- this._unsubscribeSpanStart = this.on("spanStart", (span) => {
31
- const spanId = span.spanContext().spanId;
32
- debugBuild.DEBUG_BUILD && core.debug.log("[CloudflareClient] Span started:", spanId);
33
- if (!core.spanIsSampled(span)) {
34
- return;
35
- }
36
- this._pendingSpans.add(spanId);
37
- if (!this._spanCompletionPromise) {
38
- this._spanCompletionPromise = new Promise((resolve) => {
39
- this._resolveSpanCompletion = resolve;
40
- });
41
- }
42
- });
43
- this._unsubscribeSpanEnd = this.on("spanEnd", (span) => {
44
- const spanId = span.spanContext().spanId;
45
- debugBuild.DEBUG_BUILD && core.debug.log("[CloudflareClient] Span ended:", spanId);
46
- this._pendingSpans.delete(spanId);
47
- if (this._pendingSpans.size === 0 && this._resolveSpanCompletion) {
48
- debugBuild.DEBUG_BUILD && core.debug.log("[CloudflareClient] All spans completed, resolving promise");
49
- this._resolveSpanCompletion();
50
- this._resetSpanCompletionPromise();
51
- }
52
- });
35
+ this.isCachedClient = options.cacheClient === true;
36
+ if (!this.isCachedClient) {
37
+ this._unsubscribeSpanStart = this.on("spanStart", (span) => {
38
+ const spanId = span.spanContext().spanId;
39
+ debugBuild.DEBUG_BUILD && core.debug.log("[CloudflareClient] Span started:", spanId);
40
+ if (!core.spanIsSampled(span)) {
41
+ return;
42
+ }
43
+ this._pendingSpans.add(spanId);
44
+ if (!this._spanCompletionPromise) {
45
+ this._spanCompletionPromise = new Promise((resolve) => {
46
+ this._resolveSpanCompletion = resolve;
47
+ });
48
+ }
49
+ });
50
+ this._unsubscribeSpanEnd = this.on("spanEnd", (span) => {
51
+ const spanId = span.spanContext().spanId;
52
+ debugBuild.DEBUG_BUILD && core.debug.log("[CloudflareClient] Span ended:", spanId);
53
+ this._pendingSpans.delete(spanId);
54
+ if (this._pendingSpans.size === 0 && this._resolveSpanCompletion) {
55
+ debugBuild.DEBUG_BUILD && core.debug.log("[CloudflareClient] All spans completed, preparing to flush");
56
+ this._resolveSpanCompletion();
57
+ this._resetSpanCompletionPromise();
58
+ }
59
+ });
60
+ }
53
61
  }
54
62
  /**
55
63
  * Flushes pending operations and ensures all data is processed.
@@ -78,7 +86,12 @@ class CloudflareClient extends core.ServerRuntimeClient {
78
86
  ]);
79
87
  await spanCompletionRace;
80
88
  }
81
- return super.flush(timeout);
89
+ this._inBoundaryFlush = true;
90
+ try {
91
+ return await super.flush(timeout);
92
+ } finally {
93
+ this._inBoundaryFlush = false;
94
+ }
82
95
  }
83
96
  /**
84
97
  * Disposes of the client and releases all resources.
@@ -107,6 +120,16 @@ class CloudflareClient extends core.ServerRuntimeClient {
107
120
  _setupIntegrations() {
108
121
  core._INTERNAL_clearAiProviderSkips();
109
122
  super._setupIntegrations();
123
+ if (this.isCachedClient) {
124
+ this.on("flush", () => {
125
+ const invocationState = invocationContext.getInvocationState();
126
+ if (invocationState) {
127
+ invocationState.flushPointReached = true;
128
+ }
129
+ });
130
+ this._setupEagerEnvelopeDelivery();
131
+ this._setupEagerBufferDelivery();
132
+ }
110
133
  }
111
134
  /**
112
135
  * Resets the span completion promise and resolve function.
@@ -116,6 +139,76 @@ class CloudflareClient extends core.ServerRuntimeClient {
116
139
  this._spanCompletionPromise = null;
117
140
  this._resolveSpanCompletion = null;
118
141
  }
142
+ /**
143
+ * Drains the transport after an envelope has been accepted past the invocation's
144
+ * flush point. The transport queues request producers until `flush()`; before the
145
+ * flush point the boundary `flush()` drains everything, but envelopes created after
146
+ * it (post-response `waitUntil` work, detached continuations) have no later flush to
147
+ * ride. The drain is registered with the invocation's `waitUntil` to keep the fetch
148
+ * alive; outside any instrumented invocation it always runs.
149
+ */
150
+ _setupEagerEnvelopeDelivery() {
151
+ this.on("afterEnvelope", () => {
152
+ const transport = this.getTransport();
153
+ const invocationState = invocationContext.getInvocationState();
154
+ if (!transport || this._inBoundaryFlush || invocationState && !invocationState.flushPointReached) {
155
+ return;
156
+ }
157
+ this._registerWithInvocationWaitUntil(transport.flush(2e3));
158
+ });
159
+ }
160
+ /**
161
+ * Turns spans, logs and metrics captured past the invocation's flush point into
162
+ * envelopes. Before the flush point the boundary `flush()` drains their buffers; after
163
+ * it (or outside any instrumented invocation) nothing else would: the log/metric idle
164
+ * timer is disabled for this runtime (`_flushInterval: 0`) and the span buffer's own 5s
165
+ * timer fires outside any invocation, where the runtime suspends the send. Each capture
166
+ * drains only its own bucket (the ended span's trace, the log buffer, the metric
167
+ * buffer), so a fan-out of concurrent traces stays one envelope per trace. RPC method
168
+ * spans never reach this path: `wrapMethodWithSentry` runs the boundary flush after the
169
+ * method span has ended, so only work past that (e.g. detached continuations) lands here.
170
+ */
171
+ _setupEagerBufferDelivery() {
172
+ this.on("afterSpanEnd", (span) => {
173
+ const traceId = span.spanContext().traceId;
174
+ this._eagerDrain(() => this.emit("flushTraceSpans", traceId));
175
+ });
176
+ this.on("afterCaptureLog", () => this._eagerDrain(() => core._INTERNAL_flushLogsBuffer(this)));
177
+ this.on("afterCaptureMetric", () => this._eagerDrain(() => core._INTERNAL_flushMetricsBuffer(this)));
178
+ }
179
+ /**
180
+ * Runs `drain` unless the owning invocation has not reached its flush point yet
181
+ * (before it the boundary `flush()` delivers the buffers).
182
+ */
183
+ _eagerDrain(drain) {
184
+ const invocationState = invocationContext.getInvocationState();
185
+ if (invocationState && !invocationState.flushPointReached) {
186
+ return;
187
+ }
188
+ drain();
189
+ }
190
+ /**
191
+ * Attaches a promise to the `waitUntil` of the invocation that owns the current
192
+ * async context, so the runtime keeps the send alive after the response is returned.
193
+ * Outside any instrumented invocation (or where the context has no `waitUntil`,
194
+ * e.g. Astro prerendering) the send is fire-and-forget.
195
+ */
196
+ _registerWithInvocationWaitUntil(promise) {
197
+ const invocationState = invocationContext.getInvocationState();
198
+ const waitUntil = invocationState && invocationContext.getInvocationWaitUntil(invocationState);
199
+ if (!waitUntil) {
200
+ return;
201
+ }
202
+ try {
203
+ waitUntil(
204
+ Promise.resolve(promise).then(
205
+ () => void 0,
206
+ () => void 0
207
+ )
208
+ );
209
+ } catch {
210
+ }
211
+ }
119
212
  }
120
213
 
121
214
  exports.CloudflareClient = CloudflareClient;
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sources":["../../../src/client.ts"],"sourcesContent":["import type { ClientOptions, Options, ServerRuntimeClientOptions } from '@sentry/core';\nimport {\n _INTERNAL_clearAiProviderSkips,\n applySdkMetadata,\n debug,\n ServerRuntimeClient,\n spanIsSampled,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { ExecutionContextCompat } from './executionContext';\nimport type { makeFlushLock } from './flush';\nimport type { CloudflareTransportOptions } from './transport';\n\n/**\n * The Sentry Cloudflare SDK Client.\n *\n * @see CloudflareClientOptions for documentation on configuration options.\n * @see ServerRuntimeClient for usage documentation.\n */\nexport class CloudflareClient extends ServerRuntimeClient {\n private readonly _flushLock: ReturnType<typeof makeFlushLock> | void;\n private _pendingSpans: Set<string> = new Set();\n private _spanCompletionPromise: Promise<void> | null = null;\n private _resolveSpanCompletion: (() => void) | null = null;\n\n private _unsubscribeSpanStart: (() => void) | null = null;\n private _unsubscribeSpanEnd: (() => void) | null = null;\n\n /**\n * Creates a new Cloudflare SDK instance.\n * @param options Configuration options for this SDK.\n */\n public constructor(options: CloudflareClientOptions) {\n applySdkMetadata(options, 'cloudflare');\n options._metadata = options._metadata || {};\n const { flushLock, ...serverOptions } = options;\n\n const clientOptions: ServerRuntimeClientOptions = {\n ...serverOptions,\n platform: 'javascript',\n // TODO: Grab version information\n runtime: { name: 'cloudflare' },\n // TODO: Add server name\n _flushInterval: 0,\n };\n\n super(clientOptions);\n this._flushLock = flushLock;\n\n // Track span lifecycle to know when to flush\n this._unsubscribeSpanStart = this.on('spanStart', span => {\n const spanId = span.spanContext().spanId;\n DEBUG_BUILD && debug.log('[CloudflareClient] Span started:', spanId);\n\n // Negatively sampled spans never emit spanEnd,\n // so tracking them would cause _pendingSpans to grow unboundedly.\n // We should fix the inconsistent behavior for NonRecordingSpans in the future but\n // for now, we just ignore them.\n if (!spanIsSampled(span)) {\n return;\n }\n\n this._pendingSpans.add(spanId);\n\n if (!this._spanCompletionPromise) {\n this._spanCompletionPromise = new Promise(resolve => {\n this._resolveSpanCompletion = resolve;\n });\n }\n });\n\n this._unsubscribeSpanEnd = this.on('spanEnd', span => {\n const spanId = span.spanContext().spanId;\n DEBUG_BUILD && debug.log('[CloudflareClient] Span ended:', spanId);\n this._pendingSpans.delete(spanId);\n\n // If no more pending spans, resolve the completion promise\n if (this._pendingSpans.size === 0 && this._resolveSpanCompletion) {\n DEBUG_BUILD && debug.log('[CloudflareClient] All spans completed, resolving promise');\n this._resolveSpanCompletion();\n this._resetSpanCompletionPromise();\n }\n });\n }\n\n /**\n * Flushes pending operations and ensures all data is processed.\n * If a timeout is provided, the operation will be completed within the specified time limit.\n *\n * It will wait for all pending spans to complete before flushing.\n *\n * @param {number} [timeout] - Optional timeout in milliseconds to force the completion of the flush operation.\n * @return {Promise<boolean>} A promise that resolves to a boolean indicating whether the flush operation was successful.\n */\n public async flush(timeout?: number): Promise<boolean> {\n if (this._flushLock) {\n await this._flushLock.finalize();\n }\n\n if (this._pendingSpans.size > 0 && this._spanCompletionPromise) {\n DEBUG_BUILD &&\n debug.log('[CloudflareClient] Waiting for', this._pendingSpans.size, 'pending spans to complete...');\n\n const timeoutMs = timeout ?? 5000;\n const spanCompletionRace = Promise.race([\n this._spanCompletionPromise,\n new Promise(resolve =>\n setTimeout(() => {\n DEBUG_BUILD &&\n debug.log('[CloudflareClient] Span completion timeout after', timeoutMs, 'ms, flushing anyway');\n resolve(undefined);\n }, timeoutMs),\n ),\n ]);\n\n await spanCompletionRace;\n }\n\n return super.flush(timeout);\n }\n\n /**\n * Disposes of the client and releases all resources.\n *\n * This method clears all Cloudflare-specific state in addition to the base client cleanup.\n * It unsubscribes from span lifecycle events and clears pending span tracking.\n *\n * Call this method after flushing to allow the client to be garbage collected.\n * After calling dispose(), the client should not be used anymore.\n */\n public override dispose(): void {\n DEBUG_BUILD && debug.log('[CloudflareClient] Disposing client...');\n\n super.dispose();\n\n if (this._unsubscribeSpanStart) {\n this._unsubscribeSpanStart();\n this._unsubscribeSpanStart = null;\n }\n if (this._unsubscribeSpanEnd) {\n this._unsubscribeSpanEnd();\n this._unsubscribeSpanEnd = null;\n }\n\n this._resetSpanCompletionPromise();\n (this as unknown as { _flushLock: ReturnType<typeof makeFlushLock> | void })._flushLock = undefined;\n }\n\n /** @inheritDoc */\n protected override _setupIntegrations(): void {\n // Clear AI provider skip registrations before setting up integrations.\n // The registry is module-global and Cloudflare calls `init()` per request, so without this a\n // single `ai` SDK call would suppress direct `env.AI.run` spans for the rest of the isolate's\n // life. Mirrors the same reset in the Node client.\n _INTERNAL_clearAiProviderSkips();\n super._setupIntegrations();\n }\n\n /**\n * Resets the span completion promise and resolve function.\n */\n private _resetSpanCompletionPromise(): void {\n this._pendingSpans.clear();\n this._spanCompletionPromise = null;\n this._resolveSpanCompletion = null;\n }\n}\n\ninterface BaseCloudflareOptions {\n /**\n * @ignore Used internally to disable the deDupeIntegration for workflows.\n * @hidden Used internally to disable the deDupeIntegration for workflows.\n * @default true\n */\n enableDedupe?: boolean;\n\n /**\n * The Cloudflare SDK is not OpenTelemetry native. By default (`false`) it does not set up a tracer\n * provider; spans are emitted via the SDK's own instrumentation and scopes are isolated with\n * AsyncLocalStorage.\n *\n * Set this to `true` to opt into the OpenTelemetry compatibility tracer, which captures spans\n * emitted via `@opentelemetry/api`. Big caveat: it does not handle custom context, always working\n * off the current scope. This is good enough for many, but not all, integrations.\n *\n * @default false\n */\n enableOpenTelemetrySetup?: boolean;\n\n /**\n * Enable trace propagation for RPC calls between Workers, Durable Objects, and Service Bindings.\n *\n * When enabled, trace context (sentry-trace + baggage) is propagated across:\n * - `stub.fetch()` calls to Durable Objects (via HTTP headers)\n * - Service binding `fetch()` calls (via HTTP headers)\n * - RPC method calls to Durable Objects and WorkerEntrypoints (via trailing argument)\n *\n * When enabled on the **receiver side** (DurableObject or WorkerEntrypoint), the SDK will also:\n * - Extract and continue traces from incoming RPC calls\n * - Create spans for each RPC method invocation\n * - Capture errors thrown by RPC methods\n *\n * **Important:** This option is enabled by default. Set it to `false` to opt out, e.g. if you\n * do not want trace context to leave your Worker via RPC calls.\n *\n * @default true\n * @example\n * ```ts\n * // Opt out of RPC trace propagation\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * enableRpcTracePropagation: false,\n * }),\n * handler,\n * );\n * ```\n */\n enableRpcTracePropagation?: boolean;\n\n /**\n * Table names that should stay instrumented even though they match the reserved `cf_` prefix used\n * by Durable Object frameworks (`agents`, `partyserver`, ...) for their internal SQLite tables.\n *\n * By default, `exec` queries against `cf_`-prefixed tables are treated as framework noise and no\n * `db.query` span is created for them. If one of your own tables happens to use this prefix, add it\n * here to opt it back into instrumentation. Entries are matched against each table name in the\n * query summary — strings must match exactly, while regular expressions give you prefix/pattern\n * matching.\n *\n * @default []\n * @example\n * ```ts\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * durableObjectSqlSpanAllowlist: ['cf_my_table', /^cf_reports_/],\n * }),\n * handler,\n * );\n * ```\n */\n durableObjectSqlSpanAllowlist?: Array<string | RegExp>;\n\n /**\n * KV keys that should stay instrumented even though they match a reserved prefix used by Durable\n * Object frameworks (`agents`, `partyserver`, ...) for their internal storage entries.\n *\n * By default, KV reads/writes (`get`, `put`, `delete`, `list`) of `cf_`- or `__ps_`-prefixed keys\n * are treated as framework noise and no `durable_object_storage_*` span is created for them,\n * mirroring how `cf_`-prefixed SQL tables are handled (see {@link durableObjectSqlSpanAllowlist}).\n * If one of your own keys happens to use such a prefix, add it here to opt it back into\n * instrumentation. Strings must match exactly, while regular expressions give you prefix/pattern\n * matching.\n *\n * @default []\n * @example\n * ```ts\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * durableObjectStorageSpanAllowlist: ['cf_my_key', /^cf_reports_/],\n * }),\n * handler,\n * );\n * ```\n */\n durableObjectStorageSpanAllowlist?: Array<string | RegExp>;\n\n /**\n * If you use Spotlight by Sentry during development, use\n * this option to forward captured Sentry events to Spotlight.\n *\n * Either set it to true, or provide a specific Spotlight Sidecar URL.\n *\n * More details: https://spotlightjs.com/\n *\n * IMPORTANT: Only set this option to `true` while developing, not in production!\n */\n spotlight?: boolean | string;\n}\n\n/**\n * Configuration options for the Sentry Cloudflare SDK\n *\n * @see @sentry/core Options for more information.\n */\nexport interface CloudflareOptions extends Options<CloudflareTransportOptions>, BaseCloudflareOptions {\n ctx?: ExecutionContextCompat;\n}\n\n/**\n * Configuration options for the Sentry Cloudflare SDK Client class\n *\n * @see CloudflareClient for more information.\n */\nexport interface CloudflareClientOptions extends ClientOptions<CloudflareTransportOptions>, BaseCloudflareOptions {\n flushLock?: ReturnType<typeof makeFlushLock>;\n}\n"],"names":["ServerRuntimeClient","applySdkMetadata","DEBUG_BUILD","debug","spanIsSampled","_INTERNAL_clearAiProviderSkips"],"mappings":";;;;;AAmBO,MAAM,yBAAyBA,wBAAA,CAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAajD,YAAY,OAAA,EAAkC;AACnD,IAAAC,qBAAA,CAAiB,SAAS,YAAY,CAAA;AACtC,IAAA,OAAA,CAAQ,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,EAAC;AAC1C,IAAA,MAAM,EAAE,SAAA,EAAW,GAAG,aAAA,EAAc,GAAI,OAAA;AAExC,IAAA,MAAM,aAAA,GAA4C;AAAA,MAChD,GAAG,aAAA;AAAA,M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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWgB,OAAA,GAAgB;AAC9B,IAAAD,sBAAA,IAAeC,UAAA,CAAM,IAAI,wCAAwC,CAAA;AAEjE,IAAA,KAAA,CAAM,OAAA,EAAQ;AAEd,IAAA,IAAI,KAAK,qBAAA,EAAuB;AAC9B,MAAA,IAAA,CAAK,qBAAA,EAAsB;AAC3B,MAAA,IAAA,CAAK,qBAAA,GAAwB,IAAA;AAAA,IAC/B;AACA,IAAA,IAAI,KAAK,mBAAA,EAAqB;AAC5B,MAAA,IAAA,CAAK,mBAAA,EAAoB;AACzB,MAAA,IAAA,CAAK,mBAAA,GAAsB,IAAA;AAAA,IAC7B;AAEA,IAAA,IAAA,CAAK,2BAAA,EAA4B;AACjC,IAAC,KAA4E,UAAA,GAAa,MAAA;AAAA,EAC5F;AAAA;AAAA,EAGmB,kBAAA,GAA2B;AAK5C,IAAAE,mCAAA,EAA+B;AAC/B,IAAA,KAAA,CAAM,kBAAA,EAAmB;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKQ,2BAAA,GAAoC;AAC1C,IAAA,IAAA,CAAK,cAAc,KAAA,EAAM;AACzB,IAAA,IAAA,CAAK,sBAAA,GAAyB,IAAA;AAC9B,IAAA,IAAA,CAAK,sBAAA,GAAyB,IAAA;AAAA,EAChC;AACF;;;;"}
1
+ {"version":3,"file":"client.js","sources":["../../../src/client.ts"],"sourcesContent":["import type { ClientOptions, Options, TracePropagationTargets } from '@sentry/core';\nimport {\n _INTERNAL_clearAiProviderSkips,\n _INTERNAL_flushLogsBuffer,\n _INTERNAL_flushMetricsBuffer,\n applySdkMetadata,\n debug,\n spanIsSampled,\n} from '@sentry/core';\nimport type { ServerRuntimeClientOptions } from '@sentry/core/server';\nimport { ServerRuntimeClient } from '@sentry/core/server';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { ExecutionContextCompat } from './executionContext';\nimport type { makeFlushLock } from './flush';\nimport type { CloudflareTransportOptions } from './transport';\nimport { getInvocationState, getInvocationWaitUntil } from './utils/invocationContext';\n\n/**\n * The Sentry Cloudflare SDK Client.\n *\n * @see CloudflareClientOptions for documentation on configuration options.\n * @see ServerRuntimeClient for usage documentation.\n */\nexport class CloudflareClient extends ServerRuntimeClient {\n private readonly _flushLock: ReturnType<typeof makeFlushLock> | void;\n private _pendingSpans: Set<string> = new Set();\n private _spanCompletionPromise: Promise<void> | null = null;\n private _resolveSpanCompletion: (() => void) | null = null;\n\n private _unsubscribeSpanStart: (() => void) | null = null;\n private _unsubscribeSpanEnd: (() => void) | null = null;\n\n // True while a boundary `flush()` is draining; envelopes created by that drain ride it\n // and must not each start their own eager transport flush.\n private _inBoundaryFlush = false;\n\n /**\n * Whether this client is a cached, cross-invocation client (`cacheClient`).\n * Cached clients are never disposed at an invocation boundary, so their spans/events\n * are delivered eagerly instead of waiting for a per-invocation flush.\n */\n public readonly isCachedClient: boolean;\n\n /**\n * Creates a new Cloudflare SDK instance.\n * @param options Configuration options for this SDK.\n */\n public constructor(options: CloudflareClientOptions) {\n applySdkMetadata(options, 'cloudflare');\n options._metadata = options._metadata || {};\n const { flushLock, ...serverOptions } = options;\n\n const clientOptions: ServerRuntimeClientOptions = {\n ...serverOptions,\n platform: 'javascript',\n // TODO: Grab version information\n runtime: { name: 'cloudflare' },\n // TODO: Add server name\n _flushInterval: 0,\n };\n\n super(clientOptions);\n this._flushLock = flushLock;\n this.isCachedClient = options.cacheClient === true;\n\n // Track span lifecycle to know when to flush. Skipped for cached clients\n // (`cacheClient`): they are never disposed, so spans that end after\n // a flush are still delivered. Per-invocation clients are disposed right after\n // the boundary flush, so the flush must wait for open spans to end otherwise\n // their transaction never gets emitted.\n if (!this.isCachedClient) {\n this._unsubscribeSpanStart = this.on('spanStart', span => {\n const spanId = span.spanContext().spanId;\n DEBUG_BUILD && debug.log('[CloudflareClient] Span started:', spanId);\n\n // Negatively sampled spans never emit spanEnd,\n // so tracking them would cause _pendingSpans to grow unboundedly.\n // We should fix the inconsistent behavior for NonRecordingSpans in the future but\n // for now, we just ignore them.\n if (!spanIsSampled(span)) {\n return;\n }\n\n this._pendingSpans.add(spanId);\n\n if (!this._spanCompletionPromise) {\n this._spanCompletionPromise = new Promise(resolve => {\n this._resolveSpanCompletion = resolve;\n });\n }\n });\n\n this._unsubscribeSpanEnd = this.on('spanEnd', span => {\n const spanId = span.spanContext().spanId;\n DEBUG_BUILD && debug.log('[CloudflareClient] Span ended:', spanId);\n this._pendingSpans.delete(spanId);\n\n // If no more pending spans, resolve the completion promise\n if (this._pendingSpans.size === 0 && this._resolveSpanCompletion) {\n DEBUG_BUILD && debug.log('[CloudflareClient] All spans completed, preparing to flush');\n this._resolveSpanCompletion();\n this._resetSpanCompletionPromise();\n }\n });\n }\n }\n\n /**\n * Flushes pending operations and ensures all data is processed.\n * If a timeout is provided, the operation will be completed within the specified time limit.\n *\n * It will wait for all pending spans to complete before flushing.\n *\n * @param {number} [timeout] - Optional timeout in milliseconds to force the completion of the flush operation.\n * @return {Promise<boolean>} A promise that resolves to a boolean indicating whether the flush operation was successful.\n */\n public async flush(timeout?: number): Promise<boolean> {\n // Wait for user waitUntil-registered work to settle before draining, so events\n // captured in that work are still in the buffer. Without this the final flush\n // can drain (and the client be disposed) before background captures land.\n if (this._flushLock) {\n await this._flushLock.finalize();\n }\n\n if (this._pendingSpans.size > 0 && this._spanCompletionPromise) {\n DEBUG_BUILD &&\n debug.log('[CloudflareClient] Waiting for', this._pendingSpans.size, 'pending spans to complete...');\n\n const timeoutMs = timeout ?? 5000;\n const spanCompletionRace = Promise.race([\n this._spanCompletionPromise,\n new Promise(resolve =>\n setTimeout(() => {\n DEBUG_BUILD &&\n debug.log('[CloudflareClient] Span completion timeout after', timeoutMs, 'ms, flushing anyway');\n resolve(undefined);\n }, timeoutMs),\n ),\n ]);\n\n await spanCompletionRace;\n }\n\n // Envelopes created while this flush drains (log/metric/span buffers turning into\n // envelopes on the `flush` emit) ride its own transport drain; without the flag each\n // of them would also start an eager drain and a `waitUntil` registration.\n this._inBoundaryFlush = true;\n try {\n return await super.flush(timeout);\n } finally {\n this._inBoundaryFlush = false;\n }\n }\n\n /**\n * Disposes of the client and releases all resources.\n *\n * This method clears all Cloudflare-specific state in addition to the base client cleanup.\n * It unsubscribes from span lifecycle events and clears pending span tracking.\n *\n * Call this method after flushing to allow the client to be garbage collected.\n * After calling dispose(), the client should not be used anymore.\n */\n public override dispose(): void {\n DEBUG_BUILD && debug.log('[CloudflareClient] Disposing client...');\n\n super.dispose();\n\n if (this._unsubscribeSpanStart) {\n this._unsubscribeSpanStart();\n this._unsubscribeSpanStart = null;\n }\n if (this._unsubscribeSpanEnd) {\n this._unsubscribeSpanEnd();\n this._unsubscribeSpanEnd = null;\n }\n\n this._resetSpanCompletionPromise();\n (this as unknown as { _flushLock: ReturnType<typeof makeFlushLock> | void })._flushLock = undefined;\n }\n\n /** @inheritDoc */\n protected override _setupIntegrations(): void {\n // Clear AI provider skip registrations before setting up integrations.\n // The registry is module-global and Cloudflare calls `init()` per request, so without this a\n // single `ai` SDK call would suppress direct `env.AI.run` spans for the rest of the isolate's\n // life. Mirrors the same reset in the Node client.\n _INTERNAL_clearAiProviderSkips();\n super._setupIntegrations();\n\n // Registered after the integrations on purpose: the flush-point marker must run\n // after core and the span buffer have turned their buffers into envelopes on the\n // same `flush` emit (so those envelopes ride the boundary drain instead of starting\n // eager ones), and the eager span handler relies on `spanStreamingIntegration`\n // having already buffered the span that triggers it.\n if (this.isCachedClient) {\n // Marks the invocation's natural flush point: anything captured from now on\n // (post-response `waitUntil` work, detached continuations) has no later flush\n // to ride and is delivered eagerly by the hooks below.\n this.on('flush', () => {\n const invocationState = getInvocationState();\n if (invocationState) {\n invocationState.flushPointReached = true;\n }\n });\n this._setupEagerEnvelopeDelivery();\n this._setupEagerBufferDelivery();\n }\n }\n\n /**\n * Resets the span completion promise and resolve function.\n */\n private _resetSpanCompletionPromise(): void {\n this._pendingSpans.clear();\n this._spanCompletionPromise = null;\n this._resolveSpanCompletion = null;\n }\n\n /**\n * Drains the transport after an envelope has been accepted past the invocation's\n * flush point. The transport queues request producers until `flush()`; before the\n * flush point the boundary `flush()` drains everything, but envelopes created after\n * it (post-response `waitUntil` work, detached continuations) have no later flush to\n * ride. The drain is registered with the invocation's `waitUntil` to keep the fetch\n * alive; outside any instrumented invocation it always runs.\n */\n private _setupEagerEnvelopeDelivery(): void {\n this.on('afterEnvelope', () => {\n const transport = this.getTransport();\n const invocationState = getInvocationState();\n\n if (!transport || this._inBoundaryFlush || (invocationState && !invocationState.flushPointReached)) {\n return;\n }\n\n this._registerWithInvocationWaitUntil(transport.flush(2000));\n });\n }\n\n /**\n * Turns spans, logs and metrics captured past the invocation's flush point into\n * envelopes. Before the flush point the boundary `flush()` drains their buffers; after\n * it (or outside any instrumented invocation) nothing else would: the log/metric idle\n * timer is disabled for this runtime (`_flushInterval: 0`) and the span buffer's own 5s\n * timer fires outside any invocation, where the runtime suspends the send. Each capture\n * drains only its own bucket (the ended span's trace, the log buffer, the metric\n * buffer), so a fan-out of concurrent traces stays one envelope per trace. RPC method\n * spans never reach this path: `wrapMethodWithSentry` runs the boundary flush after the\n * method span has ended, so only work past that (e.g. detached continuations) lands here.\n */\n private _setupEagerBufferDelivery(): void {\n this.on('afterSpanEnd', span => {\n // The trace id must come from the span, not the current scope: `continueTrace`\n // writes the propagation context to the *current* scope, so the forked\n // isolation scope's propagation context carries a different trace id and\n // flushing by it silently no-ops.\n const traceId = span.spanContext().traceId;\n this._eagerDrain(() => this.emit('flushTraceSpans', traceId));\n });\n this.on('afterCaptureLog', () => this._eagerDrain(() => _INTERNAL_flushLogsBuffer(this)));\n this.on('afterCaptureMetric', () => this._eagerDrain(() => _INTERNAL_flushMetricsBuffer(this)));\n }\n\n /**\n * Runs `drain` unless the owning invocation has not reached its flush point yet\n * (before it the boundary `flush()` delivers the buffers).\n */\n private _eagerDrain(drain: () => void): void {\n const invocationState = getInvocationState();\n\n if (invocationState && !invocationState.flushPointReached) {\n return;\n }\n\n drain();\n }\n\n /**\n * Attaches a promise to the `waitUntil` of the invocation that owns the current\n * async context, so the runtime keeps the send alive after the response is returned.\n * Outside any instrumented invocation (or where the context has no `waitUntil`,\n * e.g. Astro prerendering) the send is fire-and-forget.\n */\n private _registerWithInvocationWaitUntil(promise: PromiseLike<unknown>): void {\n const invocationState = getInvocationState();\n const waitUntil = invocationState && getInvocationWaitUntil(invocationState);\n if (!waitUntil) {\n return;\n }\n\n try {\n waitUntil(\n Promise.resolve(promise).then(\n () => undefined,\n () => undefined,\n ),\n );\n } catch {\n // The owning invocation already ended; the send races isolate teardown either way.\n }\n }\n}\n\ninterface BaseCloudflareOptions {\n /**\n * @ignore Used internally to disable the deDupeIntegration for workflows.\n * @hidden Used internally to disable the deDupeIntegration for workflows.\n * @default true\n */\n enableDedupe?: boolean;\n\n /**\n * The Cloudflare SDK is not OpenTelemetry native. By default (`false`) it does not set up a tracer\n * provider; spans are emitted via the SDK's own instrumentation and scopes are isolated with\n * AsyncLocalStorage.\n *\n * Set this to `true` to opt into the OpenTelemetry compatibility tracer, which captures spans\n * emitted via `@opentelemetry/api`. Big caveat: it does not handle custom context, always working\n * off the current scope. This is good enough for many, but not all, integrations.\n *\n * @default false\n */\n enableOpenTelemetrySetup?: boolean;\n\n /**\n * The bindings on `env` that outgoing RPC calls propagate trace context to.\n *\n * Strings match a binding name exactly, regular expressions match by pattern. An empty array\n * (the default) propagates to nothing.\n *\n * RPC has no headers to carry trace context, so the SDK appends it as a trailing argument to\n * every RPC method call on a matching binding. Only a Sentry-instrumented receiver strips that\n * argument again. Anywhere else it arrives as a real argument and changes what the method was\n * called with, so list only the bindings whose receiver you know runs Sentry.\n *\n * Propagation over `stub.fetch()` and service binding `fetch()` uses HTTP headers and is not\n * affected by this option.\n *\n * Strings match a binding name exactly, regular expressions match by pattern. Both match\n * case-insensitively.\n *\n * When you build with the Sentry Cloudflare Vite plugin, bindings that resolve to *this* worker\n * (its own Durable Objects, its self service bindings) are added for you, because the plugin\n * instruments those receivers itself. Whatever you list here is added on top of them.\n *\n * @default []\n * @example\n * ```ts\n * // Propagate to `env.ORDERS` and every `env.SVC_*` binding\n * export default Sentry.withSentry(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * rpcTracePropagationBindings: ['ORDERS', /^SVC_/],\n * }),\n * handler,\n * );\n * ```\n */\n rpcTracePropagationBindings?: TracePropagationTargets;\n\n /**\n * Table names that should stay instrumented even though they match the reserved `cf_` prefix used\n * by Durable Object frameworks (`agents`, `partyserver`, ...) for their internal SQLite tables.\n *\n * By default, `exec` queries against `cf_`-prefixed tables are treated as framework noise and no\n * `db.query` span is created for them. If one of your own tables happens to use this prefix, add it\n * here to opt it back into instrumentation. Entries are matched against each table name in the\n * query summary — strings must match exactly, while regular expressions give you prefix/pattern\n * matching.\n *\n * @default []\n * @example\n * ```ts\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * durableObjectSqlSpanAllowlist: ['cf_my_table', /^cf_reports_/],\n * }),\n * handler,\n * );\n * ```\n */\n durableObjectSqlSpanAllowlist?: Array<string | RegExp>;\n\n /**\n * KV keys that should stay instrumented even though they match a reserved prefix used by Durable\n * Object frameworks (`agents`, `partyserver`, ...) for their internal storage entries.\n *\n * By default, KV reads/writes (`get`, `put`, `delete`, `list`) of `cf_`- or `__ps_`-prefixed keys\n * are treated as framework noise and no `durable_object_storage_*` span is created for them,\n * mirroring how `cf_`-prefixed SQL tables are handled (see {@link durableObjectSqlSpanAllowlist}).\n * If one of your own keys happens to use such a prefix, add it here to opt it back into\n * instrumentation. Strings must match exactly, while regular expressions give you prefix/pattern\n * matching.\n *\n * @default []\n * @example\n * ```ts\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * durableObjectStorageSpanAllowlist: ['cf_my_key', /^cf_reports_/],\n * }),\n * handler,\n * );\n * ```\n */\n durableObjectStorageSpanAllowlist?: Array<string | RegExp>;\n\n /**\n * Sets an optional server name (device name).\n *\n * This is useful for identifying which server or instance is sending events.\n */\n serverName?: string;\n\n /**\n * If you use Spotlight by Sentry during development, use\n * this option to forward captured Sentry events to Spotlight.\n *\n * Either set it to true, or provide a specific Spotlight Sidecar URL.\n *\n * More details: https://spotlightjs.com/\n *\n * IMPORTANT: Only set this option to `true` while developing, not in production!\n */\n spotlight?: boolean | string;\n\n /**\n * Cache the client and reuse it across invocations within the same isolate.\n *\n * The SDK creates one client per isolate and reuses it for all requests/DO\n * handlers in that isolate. This avoids the per-invocation cost of\n * constructing a new client.\n *\n * Since a cached client outlives any single invocation, data captured after an\n * invocation's flush point (post-response `waitUntil` work, detached background\n * work) is delivered eagerly instead of waiting for a flush that never comes.\n *\n * The first `init()` in an isolate decides the cached client's options; later\n * `init()` calls with different options (e.g. another DSN) reuse the cached client\n * unchanged (a debug warning is logged for a DSN change). Use `cacheClient: false`\n * when options must differ per invocation.\n *\n * When disabled, a new client is created per invocation and disposed after the\n * handler completes.\n *\n * @default true\n */\n cacheClient?: boolean;\n}\n\n/**\n * Configuration options for the Sentry Cloudflare SDK\n *\n * @see @sentry/core Options for more information.\n */\nexport interface CloudflareOptions extends Options<CloudflareTransportOptions>, BaseCloudflareOptions {\n ctx?: ExecutionContextCompat;\n}\n\n/**\n * Configuration options for the Sentry Cloudflare SDK Client class\n *\n * @see CloudflareClient for more information.\n */\nexport interface CloudflareClientOptions extends ClientOptions<CloudflareTransportOptions>, BaseCloudflareOptions {\n flushLock?: ReturnType<typeof makeFlushLock>;\n}\n"],"names":["ServerRuntimeClient","applySdkMetadata","DEBUG_BUILD","debug","spanIsSampled","_INTERNAL_clearAiProviderSkips","getInvocationState","_INTERNAL_flushLogsBuffer","_INTERNAL_flushMetricsBuffer","getInvocationWaitUntil"],"mappings":";;;;;;;AAuBO,MAAM,yBAAyBA,0BAAA,CAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBjD,YAAY,OAAA,EAAkC;AACnD,IAAAC,qBAAA,CAAiB,SAAS,YAAY,C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;AAAA,IAC9D,CAAC,CAAA;AACD,IAAA,IAAA,CAAK,EAAA,CAAG,mBAAmB,MAAM,IAAA,CAAK,YAAY,MAAMC,8BAAA,CAA0B,IAAI,CAAC,CAAC,CAAA;AACxF,IAAA,IAAA,CAAK,EAAA,CAAG,sBAAsB,MAAM,IAAA,CAAK,YAAY,MAAMC,iCAAA,CAA6B,IAAI,CAAC,CAAC,CAAA;AAAA,EAChG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,YAAY,KAAA,EAAyB;AAC3C,IAAA,MAAM,kBAAkBF,oCAAA,EAAmB;AAE3C,IAAA,IAAI,eAAA,IAAmB,CAAC,eAAA,CAAgB,iBAAA,EAAmB;AACzD,MAAA;AAAA,IACF;AAEA,IAAA,KAAA,EAAM;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,iCAAiC,OAAA,EAAqC;AAC5E,IAAA,MAAM,kBAAkBA,oCAAA,EAAmB;AAC3C,IAAA,MAAM,SAAA,GAAY,eAAA,IAAmBG,wCAAA,CAAuB,eAAe,CAAA;AAC3E,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA;AAAA,IACF;AAEA,IAAA,IAAI;AACF,MAAA,SAAA;AAAA,QACE,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,CAAE,IAAA;AAAA,UACvB,MAAM,KAAA,CAAA;AAAA,UACN,MAAM,KAAA;AAAA;AACR,OACF;AAAA,IACF,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACF;;;;"}
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+
5
+ const GLOBAL_CLIENT_KEY = "__SENTRY_CLOUDFLARE_CLIENT__";
6
+ function getCachedClient() {
7
+ return core.GLOBAL_OBJ[GLOBAL_CLIENT_KEY];
8
+ }
9
+ function cacheClient(client) {
10
+ core.GLOBAL_OBJ[GLOBAL_CLIENT_KEY] = client;
11
+ }
12
+
13
+ exports.cacheClient = cacheClient;
14
+ exports.getCachedClient = getCachedClient;
15
+ //# sourceMappingURL=clientCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientCache.js","sources":["../../../src/clientCache.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\nimport type { CloudflareClient } from './client';\n\nconst GLOBAL_CLIENT_KEY = '__SENTRY_CLOUDFLARE_CLIENT__' as const;\n\ntype GlobalWithCloudflareClient = typeof GLOBAL_OBJ & {\n [GLOBAL_CLIENT_KEY]?: CloudflareClient;\n};\n\n/** Returns the one cached Cloudflare client for this isolate. */\nexport function getCachedClient(): CloudflareClient | undefined {\n return (GLOBAL_OBJ as GlobalWithCloudflareClient)[GLOBAL_CLIENT_KEY];\n}\n\n/** Stores the one Cloudflare client reused by every invocation in this isolate. */\nexport function cacheClient(client: CloudflareClient): void {\n (GLOBAL_OBJ as GlobalWithCloudflareClient)[GLOBAL_CLIENT_KEY] = client;\n}\n\n/** @hidden Only for testing - clears the isolate's cached Cloudflare client. */\nexport function _clearGlobalClientCache(): void {\n (GLOBAL_OBJ as GlobalWithCloudflareClient)[GLOBAL_CLIENT_KEY] = undefined;\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAGA,MAAM,iBAAA,GAAoB,8BAAA;AAOnB,SAAS,eAAA,GAAgD;AAC9D,EAAA,OAAQA,gBAA0C,iBAAiB,CAAA;AACrE;AAGO,SAAS,YAAY,MAAA,EAAgC;AAC1D,EAACA,eAAA,CAA0C,iBAAiB,CAAA,GAAI,MAAA;AAClE;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"defineCloudflareOptions.js","sources":["../../../src/defineCloudflareOptions.ts"],"sourcesContent":["import type { CloudflareOptions } from './client';\nimport type { DefaultEnv } from './types';\n\n/**\n * Define the Sentry options for a Cloudflare Worker in a dedicated module.\n *\n * This is the recommended way to configure the SDK when using the Vite plugin's\n * auto-instrumentation: place an `instrument.server.{ts,js,mjs}` file next to\n * the worker entry whose **default export** is the result of this function. The\n * plugin picks it up automatically and hands it to `withSentry`.\n *\n * Unlike Node's `Sentry.init(...)`, the options cannot be applied at module\n * load time on Cloudflare: the DSN and other settings typically come from the\n * per-request `env`, which only exists inside the handler. Pass a callback to\n * read from `env`, or a static object when no `env` access is needed — either\n * way you get full type-checking and autocomplete on {@link CloudflareOptions}.\n *\n * At runtime this is a thin pass-through; it only normalizes a static object\n * into a callback so the plugin always imports a `(env) => options` function.\n *\n * @example\n * ```ts\n * // src/instrument.server.ts\n * import { defineCloudflareOptions } from '@sentry/cloudflare';\n *\n * export default defineCloudflareOptions((env) => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }));\n * ```\n *\n * @example\n * ```ts\n * // Static options — no `env` access needed\n * export default defineCloudflareOptions({ tracesSampleRate: 1.0 });\n * ```\n */\nexport function defineCloudflareOptions<Env = DefaultEnv>(\n optionsOrCallback: CloudflareOptions | ((env: Env) => CloudflareOptions | undefined),\n): (env: Env) => CloudflareOptions | undefined {\n if (typeof optionsOrCallback === 'function') {\n return optionsOrCallback;\n }\n\n return () => optionsOrCallback;\n}\n"],"names":[],"mappings":";;AAqCO,SAAS,wBACd,iBAAA,EAC6C;AAC7C,EAAA,IAAI,OAAO,sBAAsB,UAAA,EAAY;AAC3C,IAAA,OAAO,iBAAA;AAAA,EACT;AAEA,EAAA,OAAO,MAAM,iBAAA;AACf;;;;"}
1
+ {"version":3,"file":"defineCloudflareOptions.js","sources":["../../../src/defineCloudflareOptions.ts"],"sourcesContent":["import type { CloudflareOptions } from './client';\nimport type { DefaultEnv, StrictCloudflareOptions } from './types';\n\n/**\n * Define the Sentry options for a Cloudflare Worker in a dedicated module.\n *\n * This is the recommended way to configure the SDK when using the Vite plugin's\n * auto-instrumentation: place an `instrument.server.{ts,js,mjs}` file next to\n * the worker entry whose **default export** is the result of this function. The\n * plugin picks it up automatically and hands it to `withSentry`.\n *\n * Unlike Node's `Sentry.init(...)`, the options cannot be applied at module\n * load time on Cloudflare: the DSN and other settings typically come from the\n * per-request `env`, which only exists inside the handler. Pass a callback to\n * read from `env`, or a static object when no `env` access is needed — either\n * way you get full type-checking and autocomplete on {@link CloudflareOptions}.\n *\n * At runtime this is a thin pass-through; it only normalizes a static object\n * into a callback so the plugin always imports a `(env) => options` function.\n *\n * @example\n * ```ts\n * // src/instrument.server.ts\n * import { defineCloudflareOptions } from '@sentry/cloudflare';\n *\n * export default defineCloudflareOptions((env) => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }));\n * ```\n *\n * @example\n * ```ts\n * // Static options — no `env` access needed\n * export default defineCloudflareOptions({ tracesSampleRate: 1.0 });\n * ```\n */\n// Overloads rather than a union parameter: TypeScript does not infer `O` out of a union member,\n// so a union signature falls back to the default and the unknown-key check never runs. The object\n// overload stays on plain `CloudflareOptions` — a direct object literal is still excess property\n// checked, and a callback cannot match it.\nexport function defineCloudflareOptions<Env = DefaultEnv, O = unknown>(\n callback: (env: Env) => StrictCloudflareOptions<O> | undefined,\n): (env: Env) => CloudflareOptions | undefined;\nexport function defineCloudflareOptions<Env = DefaultEnv>(\n options: CloudflareOptions,\n): (env: Env) => CloudflareOptions | undefined;\nexport function defineCloudflareOptions<Env = DefaultEnv>(\n optionsOrCallback: CloudflareOptions | ((env: Env) => CloudflareOptions | undefined),\n): (env: Env) => CloudflareOptions | undefined {\n if (typeof optionsOrCallback === 'function') {\n return optionsOrCallback;\n }\n\n return () => optionsOrCallback;\n}\n"],"names":[],"mappings":";;AA+CO,SAAS,wBACd,iBAAA,EAC6C;AAC7C,EAAA,IAAI,OAAO,sBAAsB,UAAA,EAAY;AAC3C,IAAA,OAAO,iBAAA;AAAA,EACT;AAEA,EAAA,OAAO,MAAM,iBAAA;AACf;;;;"}
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
+ const op = require('@sentry/conventions/op');
3
4
  const core = require('@sentry/core');
4
5
  const noDiagnosticChannels = require('@sentry/server-utils/no-diagnostic-channels');
5
6
  const instrument = require('./instrument.js');
7
+ const instrumentDurableObjectHandlers = require('./instrumentations/instrumentDurableObjectHandlers.js');
6
8
  const instrumentEnv = require('./instrumentations/worker/instrumentEnv.js');
7
9
  const options = require('./options.js');
8
- const request = require('./request.js');
9
- const sdk = require('./sdk.js');
10
10
  const instrumentContext = require('./utils/instrumentContext.js');
11
11
  const rpcMeta = require('./utils/rpcMeta.js');
12
12
  const index = require('./instrumentations/agents/index.js');
@@ -27,7 +27,7 @@ function constructInstrumentedDurableObject(target, ctx, env, newTarget, options
27
27
  methodsBeforeConstruction,
28
28
  cachedFrameworkManagedMethods
29
29
  );
30
- instrumentDurableObjectHandlers(obj, options$1, context);
30
+ instrumentDurableObjectHandlers.instrumentDurableObjectHandlers(obj, options$1, context);
31
31
  return { obj, options: options$1, context, frameworkManagedMethods };
32
32
  }
33
33
  const frameworkManagedMethodsCache = /* @__PURE__ */ new WeakMap();
@@ -61,61 +61,6 @@ function resolveFrameworkManagedMethods(prototype, obj, methodsBeforeConstructio
61
61
  frameworkManagedMethodsCache.set(prototype, managed);
62
62
  return managed;
63
63
  }
64
- function instrumentDurableObjectHandlers(obj, options, context) {
65
- if (obj.fetch && typeof obj.fetch === "function") {
66
- obj.fetch = instrument.ensureInstrumented(
67
- obj.fetch.bind(obj),
68
- (original) => new Proxy(original, {
69
- apply(target, thisArg, args) {
70
- return request.wrapRequestHandlerWithInit(
71
- { options, request: args[0], context },
72
- () => {
73
- return Reflect.apply(target, thisArg, args);
74
- },
75
- sdk.init
76
- );
77
- }
78
- })
79
- );
80
- }
81
- if (obj.alarm && typeof obj.alarm === "function") {
82
- obj.alarm = wrapMethodWithSentry.wrapMethodWithSentry(
83
- {
84
- options,
85
- context,
86
- spanName: "alarm",
87
- spanOp: "function",
88
- startNewTrace: true,
89
- origin: "auto.faas.cloudflare.durable_object"
90
- },
91
- obj.alarm.bind(obj)
92
- );
93
- }
94
- if (obj.webSocketMessage && typeof obj.webSocketMessage === "function") {
95
- obj.webSocketMessage = wrapMethodWithSentry.wrapMethodWithSentry(
96
- { options, context, spanName: "webSocketMessage", origin: "auto.faas.cloudflare.durable_object" },
97
- obj.webSocketMessage.bind(obj)
98
- );
99
- }
100
- if (obj.webSocketClose && typeof obj.webSocketClose === "function") {
101
- obj.webSocketClose = wrapMethodWithSentry.wrapMethodWithSentry(
102
- { options, context, spanName: "webSocketClose", origin: "auto.faas.cloudflare.durable_object" },
103
- obj.webSocketClose.bind(obj)
104
- );
105
- }
106
- if (obj.webSocketError && typeof obj.webSocketError === "function") {
107
- obj.webSocketError = wrapMethodWithSentry.wrapMethodWithSentry(
108
- { options, context, spanName: "webSocketError", origin: "auto.faas.cloudflare.durable_object" },
109
- obj.webSocketError.bind(obj),
110
- (_, error) => core.captureException(error, {
111
- mechanism: {
112
- type: "auto.faas.cloudflare.durable_object_websocket",
113
- handled: false
114
- }
115
- })
116
- );
117
- }
118
- }
119
64
  const RESERVED_RPC_METHOD_NAMES = /* @__PURE__ */ new Set([
120
65
  "constructor",
121
66
  "fetch",
@@ -128,9 +73,6 @@ const RESERVED_RPC_METHOD_NAMES = /* @__PURE__ */ new Set([
128
73
  ]);
129
74
  const rpcInstanceStates = /* @__PURE__ */ new WeakMap();
130
75
  function finalizeWithRpcInstrumentation(obj, options, context, excludedMethods) {
131
- if (options.enableRpcTracePropagation === false) {
132
- return obj;
133
- }
134
76
  rpcInstanceStates.set(obj, { options, context });
135
77
  instrumentPrototypeRpcMethods(obj, excludedMethods);
136
78
  return obj;
@@ -180,7 +122,7 @@ function createRpcPrototypeWrapper(methodName, originalMethod) {
180
122
  options: state.options,
181
123
  context: state.context,
182
124
  spanName: methodName,
183
- spanOp: "rpc",
125
+ spanOp: op.RPC,
184
126
  origin: "auto.faas.cloudflare.durable_object"
185
127
  },
186
128
  originalMethod,