@sentry/cloudflare 11.12.0 → 11.14.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 (618) hide show
  1. package/build/cjs/dev/_virtual/_rolldown/runtime.js +22 -0
  2. package/build/cjs/dev/baseSdk.js +98 -103
  3. package/build/cjs/dev/baseSdk.js.map +1 -1
  4. package/build/cjs/dev/client.js +218 -237
  5. package/build/cjs/dev/client.js.map +1 -1
  6. package/build/cjs/dev/clientCache.js +8 -8
  7. package/build/cjs/dev/clientCache.js.map +1 -1
  8. package/build/cjs/dev/debug-build.js +9 -5
  9. package/build/cjs/dev/debug-build.js.map +1 -1
  10. package/build/cjs/dev/defineCloudflareOptions.js +5 -8
  11. package/build/cjs/dev/defineCloudflareOptions.js.map +1 -1
  12. package/build/cjs/dev/durableobject.js +287 -176
  13. package/build/cjs/dev/durableobject.js.map +1 -1
  14. package/build/cjs/dev/flush.js +104 -77
  15. package/build/cjs/dev/flush.js.map +1 -1
  16. package/build/cjs/dev/index.js +181 -182
  17. package/build/cjs/dev/instrument.js +53 -39
  18. package/build/cjs/dev/instrument.js.map +1 -1
  19. package/build/cjs/dev/instrumentations/agents/index.js +34 -13
  20. package/build/cjs/dev/instrumentations/agents/index.js.map +1 -1
  21. package/build/cjs/dev/instrumentations/agents/instrumentAgentCallableRpc.js +46 -49
  22. package/build/cjs/dev/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  23. package/build/cjs/dev/instrumentations/agents/instrumentAgentRequestConversation.js +23 -16
  24. package/build/cjs/dev/instrumentations/agents/instrumentAgentRequestConversation.js.map +1 -1
  25. package/build/cjs/dev/instrumentations/agents/instrumentChatAgentConversation.js +36 -28
  26. package/build/cjs/dev/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -1
  27. package/build/cjs/dev/instrumentations/agents/types.js +103 -58
  28. package/build/cjs/dev/instrumentations/agents/types.js.map +1 -1
  29. package/build/cjs/dev/instrumentations/instrumentDurableObjectHandlers.js +87 -118
  30. package/build/cjs/dev/instrumentations/instrumentDurableObjectHandlers.js.map +1 -1
  31. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js +46 -44
  32. package/build/cjs/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  33. package/build/cjs/dev/instrumentations/instrumentDurableObjectStorage.js +70 -71
  34. package/build/cjs/dev/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  35. package/build/cjs/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js +31 -39
  36. package/build/cjs/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  37. package/build/cjs/dev/instrumentations/instrumentSqlStorage.js +50 -52
  38. package/build/cjs/dev/instrumentations/instrumentSqlStorage.js.map +1 -1
  39. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js +136 -123
  40. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  41. package/build/cjs/dev/instrumentations/worker/instrumentD1.js +131 -146
  42. package/build/cjs/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  43. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js +63 -61
  44. package/build/cjs/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  45. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js +83 -88
  46. package/build/cjs/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  47. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js +41 -48
  48. package/build/cjs/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  49. package/build/cjs/dev/instrumentations/worker/instrumentFetcher.js +25 -21
  50. package/build/cjs/dev/instrumentations/worker/instrumentFetcher.js.map +1 -1
  51. package/build/cjs/dev/instrumentations/worker/instrumentKV.js +54 -67
  52. package/build/cjs/dev/instrumentations/worker/instrumentKV.js.map +1 -1
  53. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js +98 -105
  54. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  55. package/build/cjs/dev/instrumentations/worker/instrumentQueueProducer.js +88 -94
  56. package/build/cjs/dev/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  57. package/build/cjs/dev/instrumentations/worker/instrumentR2.js +128 -115
  58. package/build/cjs/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  59. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js +90 -94
  60. package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  61. package/build/cjs/dev/instrumentations/worker/instrumentTail.js +100 -55
  62. package/build/cjs/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  63. package/build/cjs/dev/integrations/cronTriggers.js +130 -85
  64. package/build/cjs/dev/integrations/cronTriggers.js.map +1 -1
  65. package/build/cjs/dev/integrations/fetch.js +9 -9
  66. package/build/cjs/dev/integrations/fetch.js.map +1 -1
  67. package/build/cjs/dev/integrations/httpServer.js +41 -22
  68. package/build/cjs/dev/integrations/httpServer.js.map +1 -1
  69. package/build/cjs/dev/integrations/spotlight.js +52 -55
  70. package/build/cjs/dev/integrations/spotlight.js.map +1 -1
  71. package/build/cjs/dev/opentelemetry/tracer.js +10 -8
  72. package/build/cjs/dev/opentelemetry/tracer.js.map +1 -1
  73. package/build/cjs/dev/options.js +56 -39
  74. package/build/cjs/dev/options.js.map +1 -1
  75. package/build/cjs/dev/orchestrion-deferred-channels.js +45 -29
  76. package/build/cjs/dev/orchestrion-deferred-channels.js.map +1 -1
  77. package/build/cjs/dev/orchestrion-diagnostics-channel.js +97 -72
  78. package/build/cjs/dev/orchestrion-diagnostics-channel.js.map +1 -1
  79. package/build/cjs/dev/pages-plugin.js +20 -21
  80. package/build/cjs/dev/pages-plugin.js.map +1 -1
  81. package/build/cjs/dev/request.js +16 -10
  82. package/build/cjs/dev/request.js.map +1 -1
  83. package/build/cjs/dev/scope-utils.js +12 -12
  84. package/build/cjs/dev/scope-utils.js.map +1 -1
  85. package/build/cjs/dev/sdk.js +24 -15
  86. package/build/cjs/dev/sdk.js.map +1 -1
  87. package/build/cjs/dev/transport.js +93 -86
  88. package/build/cjs/dev/transport.js.map +1 -1
  89. package/build/cjs/dev/utils/asyncContextStrategy.js +10 -10
  90. package/build/cjs/dev/utils/asyncContextStrategy.js.map +1 -1
  91. package/build/cjs/dev/utils/bindingPropagation.js +17 -11
  92. package/build/cjs/dev/utils/bindingPropagation.js.map +1 -1
  93. package/build/cjs/dev/utils/cloudflareTrace.js +34 -0
  94. package/build/cjs/dev/utils/cloudflareTrace.js.map +1 -0
  95. package/build/cjs/dev/utils/instrumentContext.js +74 -58
  96. package/build/cjs/dev/utils/instrumentContext.js.map +1 -1
  97. package/build/cjs/dev/utils/internalSqlQuery.js +38 -21
  98. package/build/cjs/dev/utils/internalSqlQuery.js.map +1 -1
  99. package/build/cjs/dev/utils/internalStorageKey.js +41 -38
  100. package/build/cjs/dev/utils/internalStorageKey.js.map +1 -1
  101. package/build/cjs/dev/utils/invocationContext.js +42 -32
  102. package/build/cjs/dev/utils/invocationContext.js.map +1 -1
  103. package/build/cjs/dev/utils/invocationScope.js +45 -21
  104. package/build/cjs/dev/utils/invocationScope.js.map +1 -1
  105. package/build/cjs/dev/utils/isBinding.js +47 -15
  106. package/build/cjs/dev/utils/isBinding.js.map +1 -1
  107. package/build/cjs/dev/utils/isCloudflareClass.js +11 -20
  108. package/build/cjs/dev/utils/isCloudflareClass.js.map +1 -1
  109. package/build/cjs/dev/utils/queueTraceMeta.js +24 -35
  110. package/build/cjs/dev/utils/queueTraceMeta.js.map +1 -1
  111. package/build/cjs/dev/utils/rpcMeta.js +37 -27
  112. package/build/cjs/dev/utils/rpcMeta.js.map +1 -1
  113. package/build/cjs/dev/utils/traceLinks.js +52 -42
  114. package/build/cjs/dev/utils/traceLinks.js.map +1 -1
  115. package/build/cjs/dev/vendor/stacktrace.js +32 -24
  116. package/build/cjs/dev/vendor/stacktrace.js.map +1 -1
  117. package/build/cjs/dev/vite/agentClass.js +105 -98
  118. package/build/cjs/dev/vite/agentClass.js.map +1 -1
  119. package/build/cjs/dev/vite/autoInstrument.js +125 -122
  120. package/build/cjs/dev/vite/autoInstrument.js.map +1 -1
  121. package/build/cjs/dev/vite/index.js +44 -21
  122. package/build/cjs/dev/vite/index.js.map +1 -1
  123. package/build/cjs/dev/vite/instrumentFile.js +37 -20
  124. package/build/cjs/dev/vite/instrumentFile.js.map +1 -1
  125. package/build/cjs/dev/vite/mastraObservability.js +19 -12
  126. package/build/cjs/dev/vite/mastraObservability.js.map +1 -1
  127. package/build/cjs/dev/vite/moduleShape.js +220 -201
  128. package/build/cjs/dev/vite/moduleShape.js.map +1 -1
  129. package/build/cjs/dev/vite/providedModulePlugin.js +62 -45
  130. package/build/cjs/dev/vite/providedModulePlugin.js.map +1 -1
  131. package/build/cjs/dev/vite/transform.js +332 -284
  132. package/build/cjs/dev/vite/transform.js.map +1 -1
  133. package/build/cjs/dev/vite/workerEntrypoint.js +66 -57
  134. package/build/cjs/dev/vite/workerEntrypoint.js.map +1 -1
  135. package/build/cjs/dev/vite/wranglerConfig.js +94 -67
  136. package/build/cjs/dev/vite/wranglerConfig.js.map +1 -1
  137. package/build/cjs/dev/withSentry.js +32 -26
  138. package/build/cjs/dev/withSentry.js.map +1 -1
  139. package/build/cjs/dev/workflows.js +164 -151
  140. package/build/cjs/dev/workflows.js.map +1 -1
  141. package/build/cjs/dev/wrapMethodWithSentry.js +148 -169
  142. package/build/cjs/dev/wrapMethodWithSentry.js.map +1 -1
  143. package/build/cjs/dev/wrapRequestHandlerWithInit.js +76 -78
  144. package/build/cjs/dev/wrapRequestHandlerWithInit.js.map +1 -1
  145. package/build/cjs/prod/_virtual/_rolldown/runtime.js +22 -0
  146. package/build/cjs/prod/baseSdk.js +94 -93
  147. package/build/cjs/prod/baseSdk.js.map +1 -1
  148. package/build/cjs/prod/client.js +218 -237
  149. package/build/cjs/prod/client.js.map +1 -1
  150. package/build/cjs/prod/clientCache.js +8 -8
  151. package/build/cjs/prod/clientCache.js.map +1 -1
  152. package/build/cjs/prod/debug-build.js +9 -5
  153. package/build/cjs/prod/debug-build.js.map +1 -1
  154. package/build/cjs/prod/defineCloudflareOptions.js +5 -8
  155. package/build/cjs/prod/defineCloudflareOptions.js.map +1 -1
  156. package/build/cjs/prod/durableobject.js +287 -176
  157. package/build/cjs/prod/durableobject.js.map +1 -1
  158. package/build/cjs/prod/flush.js +104 -77
  159. package/build/cjs/prod/flush.js.map +1 -1
  160. package/build/cjs/prod/index.js +181 -182
  161. package/build/cjs/prod/instrument.js +53 -39
  162. package/build/cjs/prod/instrument.js.map +1 -1
  163. package/build/cjs/prod/instrumentations/agents/index.js +34 -13
  164. package/build/cjs/prod/instrumentations/agents/index.js.map +1 -1
  165. package/build/cjs/prod/instrumentations/agents/instrumentAgentCallableRpc.js +46 -49
  166. package/build/cjs/prod/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  167. package/build/cjs/prod/instrumentations/agents/instrumentAgentRequestConversation.js +23 -16
  168. package/build/cjs/prod/instrumentations/agents/instrumentAgentRequestConversation.js.map +1 -1
  169. package/build/cjs/prod/instrumentations/agents/instrumentChatAgentConversation.js +36 -28
  170. package/build/cjs/prod/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -1
  171. package/build/cjs/prod/instrumentations/agents/types.js +103 -58
  172. package/build/cjs/prod/instrumentations/agents/types.js.map +1 -1
  173. package/build/cjs/prod/instrumentations/instrumentDurableObjectHandlers.js +87 -118
  174. package/build/cjs/prod/instrumentations/instrumentDurableObjectHandlers.js.map +1 -1
  175. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js +46 -44
  176. package/build/cjs/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  177. package/build/cjs/prod/instrumentations/instrumentDurableObjectStorage.js +70 -71
  178. package/build/cjs/prod/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  179. package/build/cjs/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js +31 -39
  180. package/build/cjs/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  181. package/build/cjs/prod/instrumentations/instrumentSqlStorage.js +50 -52
  182. package/build/cjs/prod/instrumentations/instrumentSqlStorage.js.map +1 -1
  183. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js +136 -123
  184. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  185. package/build/cjs/prod/instrumentations/worker/instrumentD1.js +131 -146
  186. package/build/cjs/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  187. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js +63 -61
  188. package/build/cjs/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  189. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js +83 -88
  190. package/build/cjs/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  191. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js +41 -48
  192. package/build/cjs/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  193. package/build/cjs/prod/instrumentations/worker/instrumentFetcher.js +25 -21
  194. package/build/cjs/prod/instrumentations/worker/instrumentFetcher.js.map +1 -1
  195. package/build/cjs/prod/instrumentations/worker/instrumentKV.js +54 -67
  196. package/build/cjs/prod/instrumentations/worker/instrumentKV.js.map +1 -1
  197. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js +98 -105
  198. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  199. package/build/cjs/prod/instrumentations/worker/instrumentQueueProducer.js +88 -94
  200. package/build/cjs/prod/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  201. package/build/cjs/prod/instrumentations/worker/instrumentR2.js +128 -115
  202. package/build/cjs/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  203. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js +90 -94
  204. package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  205. package/build/cjs/prod/instrumentations/worker/instrumentTail.js +100 -55
  206. package/build/cjs/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  207. package/build/cjs/prod/integrations/cronTriggers.js +130 -85
  208. package/build/cjs/prod/integrations/cronTriggers.js.map +1 -1
  209. package/build/cjs/prod/integrations/fetch.js +9 -9
  210. package/build/cjs/prod/integrations/fetch.js.map +1 -1
  211. package/build/cjs/prod/integrations/httpServer.js +41 -22
  212. package/build/cjs/prod/integrations/httpServer.js.map +1 -1
  213. package/build/cjs/prod/integrations/spotlight.js +52 -55
  214. package/build/cjs/prod/integrations/spotlight.js.map +1 -1
  215. package/build/cjs/prod/opentelemetry/tracer.js +10 -8
  216. package/build/cjs/prod/opentelemetry/tracer.js.map +1 -1
  217. package/build/cjs/prod/options.js +38 -24
  218. package/build/cjs/prod/options.js.map +1 -1
  219. package/build/cjs/prod/orchestrion-deferred-channels.js +45 -29
  220. package/build/cjs/prod/orchestrion-deferred-channels.js.map +1 -1
  221. package/build/cjs/prod/orchestrion-diagnostics-channel.js +97 -72
  222. package/build/cjs/prod/orchestrion-diagnostics-channel.js.map +1 -1
  223. package/build/cjs/prod/pages-plugin.js +20 -21
  224. package/build/cjs/prod/pages-plugin.js.map +1 -1
  225. package/build/cjs/prod/request.js +16 -10
  226. package/build/cjs/prod/request.js.map +1 -1
  227. package/build/cjs/prod/scope-utils.js +12 -12
  228. package/build/cjs/prod/scope-utils.js.map +1 -1
  229. package/build/cjs/prod/sdk.js +24 -15
  230. package/build/cjs/prod/sdk.js.map +1 -1
  231. package/build/cjs/prod/transport.js +93 -86
  232. package/build/cjs/prod/transport.js.map +1 -1
  233. package/build/cjs/prod/utils/asyncContextStrategy.js +10 -10
  234. package/build/cjs/prod/utils/asyncContextStrategy.js.map +1 -1
  235. package/build/cjs/prod/utils/bindingPropagation.js +17 -11
  236. package/build/cjs/prod/utils/bindingPropagation.js.map +1 -1
  237. package/build/cjs/prod/utils/cloudflareTrace.js +34 -0
  238. package/build/cjs/prod/utils/cloudflareTrace.js.map +1 -0
  239. package/build/cjs/prod/utils/instrumentContext.js +74 -58
  240. package/build/cjs/prod/utils/instrumentContext.js.map +1 -1
  241. package/build/cjs/prod/utils/internalSqlQuery.js +38 -21
  242. package/build/cjs/prod/utils/internalSqlQuery.js.map +1 -1
  243. package/build/cjs/prod/utils/internalStorageKey.js +41 -38
  244. package/build/cjs/prod/utils/internalStorageKey.js.map +1 -1
  245. package/build/cjs/prod/utils/invocationContext.js +42 -32
  246. package/build/cjs/prod/utils/invocationContext.js.map +1 -1
  247. package/build/cjs/prod/utils/invocationScope.js +45 -21
  248. package/build/cjs/prod/utils/invocationScope.js.map +1 -1
  249. package/build/cjs/prod/utils/isBinding.js +47 -15
  250. package/build/cjs/prod/utils/isBinding.js.map +1 -1
  251. package/build/cjs/prod/utils/isCloudflareClass.js +11 -20
  252. package/build/cjs/prod/utils/isCloudflareClass.js.map +1 -1
  253. package/build/cjs/prod/utils/queueTraceMeta.js +24 -35
  254. package/build/cjs/prod/utils/queueTraceMeta.js.map +1 -1
  255. package/build/cjs/prod/utils/rpcMeta.js +37 -27
  256. package/build/cjs/prod/utils/rpcMeta.js.map +1 -1
  257. package/build/cjs/prod/utils/traceLinks.js +52 -42
  258. package/build/cjs/prod/utils/traceLinks.js.map +1 -1
  259. package/build/cjs/prod/vendor/stacktrace.js +32 -24
  260. package/build/cjs/prod/vendor/stacktrace.js.map +1 -1
  261. package/build/cjs/prod/vite/agentClass.js +105 -98
  262. package/build/cjs/prod/vite/agentClass.js.map +1 -1
  263. package/build/cjs/prod/vite/autoInstrument.js +125 -122
  264. package/build/cjs/prod/vite/autoInstrument.js.map +1 -1
  265. package/build/cjs/prod/vite/index.js +44 -21
  266. package/build/cjs/prod/vite/index.js.map +1 -1
  267. package/build/cjs/prod/vite/instrumentFile.js +37 -20
  268. package/build/cjs/prod/vite/instrumentFile.js.map +1 -1
  269. package/build/cjs/prod/vite/mastraObservability.js +19 -12
  270. package/build/cjs/prod/vite/mastraObservability.js.map +1 -1
  271. package/build/cjs/prod/vite/moduleShape.js +220 -201
  272. package/build/cjs/prod/vite/moduleShape.js.map +1 -1
  273. package/build/cjs/prod/vite/providedModulePlugin.js +62 -45
  274. package/build/cjs/prod/vite/providedModulePlugin.js.map +1 -1
  275. package/build/cjs/prod/vite/transform.js +332 -284
  276. package/build/cjs/prod/vite/transform.js.map +1 -1
  277. package/build/cjs/prod/vite/workerEntrypoint.js +66 -57
  278. package/build/cjs/prod/vite/workerEntrypoint.js.map +1 -1
  279. package/build/cjs/prod/vite/wranglerConfig.js +94 -67
  280. package/build/cjs/prod/vite/wranglerConfig.js.map +1 -1
  281. package/build/cjs/prod/withSentry.js +32 -26
  282. package/build/cjs/prod/withSentry.js.map +1 -1
  283. package/build/cjs/prod/workflows.js +164 -151
  284. package/build/cjs/prod/workflows.js.map +1 -1
  285. package/build/cjs/prod/wrapMethodWithSentry.js +148 -169
  286. package/build/cjs/prod/wrapMethodWithSentry.js.map +1 -1
  287. package/build/cjs/prod/wrapRequestHandlerWithInit.js +76 -78
  288. package/build/cjs/prod/wrapRequestHandlerWithInit.js.map +1 -1
  289. package/build/esm/dev/baseSdk.js +98 -101
  290. package/build/esm/dev/baseSdk.js.map +1 -1
  291. package/build/esm/dev/client.js +218 -235
  292. package/build/esm/dev/client.js.map +1 -1
  293. package/build/esm/dev/clientCache.js +8 -6
  294. package/build/esm/dev/clientCache.js.map +1 -1
  295. package/build/esm/dev/debug-build.js +9 -3
  296. package/build/esm/dev/debug-build.js.map +1 -1
  297. package/build/esm/dev/defineCloudflareOptions.js +5 -6
  298. package/build/esm/dev/defineCloudflareOptions.js.map +1 -1
  299. package/build/esm/dev/durableobject.js +287 -174
  300. package/build/esm/dev/durableobject.js.map +1 -1
  301. package/build/esm/dev/flush.js +104 -75
  302. package/build/esm/dev/flush.js.map +1 -1
  303. package/build/esm/dev/index.js +19 -18
  304. package/build/esm/dev/instrument.js +53 -37
  305. package/build/esm/dev/instrument.js.map +1 -1
  306. package/build/esm/dev/instrumentations/agents/index.js +34 -11
  307. package/build/esm/dev/instrumentations/agents/index.js.map +1 -1
  308. package/build/esm/dev/instrumentations/agents/instrumentAgentCallableRpc.js +46 -47
  309. package/build/esm/dev/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  310. package/build/esm/dev/instrumentations/agents/instrumentAgentRequestConversation.js +23 -14
  311. package/build/esm/dev/instrumentations/agents/instrumentAgentRequestConversation.js.map +1 -1
  312. package/build/esm/dev/instrumentations/agents/instrumentChatAgentConversation.js +36 -26
  313. package/build/esm/dev/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -1
  314. package/build/esm/dev/instrumentations/agents/types.js +103 -56
  315. package/build/esm/dev/instrumentations/agents/types.js.map +1 -1
  316. package/build/esm/dev/instrumentations/instrumentDurableObjectHandlers.js +87 -116
  317. package/build/esm/dev/instrumentations/instrumentDurableObjectHandlers.js.map +1 -1
  318. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js +46 -42
  319. package/build/esm/dev/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  320. package/build/esm/dev/instrumentations/instrumentDurableObjectStorage.js +70 -69
  321. package/build/esm/dev/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  322. package/build/esm/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js +31 -37
  323. package/build/esm/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  324. package/build/esm/dev/instrumentations/instrumentSqlStorage.js +50 -50
  325. package/build/esm/dev/instrumentations/instrumentSqlStorage.js.map +1 -1
  326. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js +136 -121
  327. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  328. package/build/esm/dev/instrumentations/worker/instrumentD1.js +131 -144
  329. package/build/esm/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  330. package/build/esm/dev/instrumentations/worker/instrumentEmail.js +63 -59
  331. package/build/esm/dev/instrumentations/worker/instrumentEmail.js.map +1 -1
  332. package/build/esm/dev/instrumentations/worker/instrumentEnv.js +83 -86
  333. package/build/esm/dev/instrumentations/worker/instrumentEnv.js.map +1 -1
  334. package/build/esm/dev/instrumentations/worker/instrumentFetch.js +41 -46
  335. package/build/esm/dev/instrumentations/worker/instrumentFetch.js.map +1 -1
  336. package/build/esm/dev/instrumentations/worker/instrumentFetcher.js +25 -19
  337. package/build/esm/dev/instrumentations/worker/instrumentFetcher.js.map +1 -1
  338. package/build/esm/dev/instrumentations/worker/instrumentKV.js +54 -65
  339. package/build/esm/dev/instrumentations/worker/instrumentKV.js.map +1 -1
  340. package/build/esm/dev/instrumentations/worker/instrumentQueue.js +98 -103
  341. package/build/esm/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  342. package/build/esm/dev/instrumentations/worker/instrumentQueueProducer.js +88 -92
  343. package/build/esm/dev/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  344. package/build/esm/dev/instrumentations/worker/instrumentR2.js +128 -113
  345. package/build/esm/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  346. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js +90 -92
  347. package/build/esm/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
  348. package/build/esm/dev/instrumentations/worker/instrumentTail.js +100 -53
  349. package/build/esm/dev/instrumentations/worker/instrumentTail.js.map +1 -1
  350. package/build/esm/dev/integrations/cronTriggers.js +129 -82
  351. package/build/esm/dev/integrations/cronTriggers.js.map +1 -1
  352. package/build/esm/dev/integrations/fetch.js +9 -6
  353. package/build/esm/dev/integrations/fetch.js.map +1 -1
  354. package/build/esm/dev/integrations/httpServer.js +40 -19
  355. package/build/esm/dev/integrations/httpServer.js.map +1 -1
  356. package/build/esm/dev/integrations/spotlight.js +51 -52
  357. package/build/esm/dev/integrations/spotlight.js.map +1 -1
  358. package/build/esm/dev/opentelemetry/tracer.js +10 -6
  359. package/build/esm/dev/opentelemetry/tracer.js.map +1 -1
  360. package/build/esm/dev/options.js +56 -37
  361. package/build/esm/dev/options.js.map +1 -1
  362. package/build/esm/dev/orchestrion-deferred-channels.js +45 -27
  363. package/build/esm/dev/orchestrion-deferred-channels.js.map +1 -1
  364. package/build/esm/dev/orchestrion-diagnostics-channel.js +87 -66
  365. package/build/esm/dev/orchestrion-diagnostics-channel.js.map +1 -1
  366. package/build/esm/dev/package.json +1 -1
  367. package/build/esm/dev/pages-plugin.js +20 -19
  368. package/build/esm/dev/pages-plugin.js.map +1 -1
  369. package/build/esm/dev/request.js +14 -7
  370. package/build/esm/dev/request.js.map +1 -1
  371. package/build/esm/dev/scope-utils.js +12 -10
  372. package/build/esm/dev/scope-utils.js.map +1 -1
  373. package/build/esm/dev/sdk.js +23 -13
  374. package/build/esm/dev/sdk.js.map +1 -1
  375. package/build/esm/dev/transport.js +93 -84
  376. package/build/esm/dev/transport.js.map +1 -1
  377. package/build/esm/dev/utils/asyncContextStrategy.js +10 -8
  378. package/build/esm/dev/utils/asyncContextStrategy.js.map +1 -1
  379. package/build/esm/dev/utils/bindingPropagation.js +17 -9
  380. package/build/esm/dev/utils/bindingPropagation.js.map +1 -1
  381. package/build/esm/dev/utils/cloudflareTrace.js +34 -0
  382. package/build/esm/dev/utils/cloudflareTrace.js.map +1 -0
  383. package/build/esm/dev/utils/instrumentContext.js +74 -56
  384. package/build/esm/dev/utils/instrumentContext.js.map +1 -1
  385. package/build/esm/dev/utils/internalSqlQuery.js +38 -19
  386. package/build/esm/dev/utils/internalSqlQuery.js.map +1 -1
  387. package/build/esm/dev/utils/internalStorageKey.js +41 -36
  388. package/build/esm/dev/utils/internalStorageKey.js.map +1 -1
  389. package/build/esm/dev/utils/invocationContext.js +42 -30
  390. package/build/esm/dev/utils/invocationContext.js.map +1 -1
  391. package/build/esm/dev/utils/invocationScope.js +45 -19
  392. package/build/esm/dev/utils/invocationScope.js.map +1 -1
  393. package/build/esm/dev/utils/isBinding.js +47 -13
  394. package/build/esm/dev/utils/isBinding.js.map +1 -1
  395. package/build/esm/dev/utils/isCloudflareClass.js +11 -18
  396. package/build/esm/dev/utils/isCloudflareClass.js.map +1 -1
  397. package/build/esm/dev/utils/queueTraceMeta.js +24 -33
  398. package/build/esm/dev/utils/queueTraceMeta.js.map +1 -1
  399. package/build/esm/dev/utils/rpcMeta.js +37 -25
  400. package/build/esm/dev/utils/rpcMeta.js.map +1 -1
  401. package/build/esm/dev/utils/traceLinks.js +52 -40
  402. package/build/esm/dev/utils/traceLinks.js.map +1 -1
  403. package/build/esm/dev/vendor/stacktrace.js +31 -21
  404. package/build/esm/dev/vendor/stacktrace.js.map +1 -1
  405. package/build/esm/dev/vite/agentClass.js +105 -96
  406. package/build/esm/dev/vite/agentClass.js.map +1 -1
  407. package/build/esm/dev/vite/autoInstrument.js +125 -120
  408. package/build/esm/dev/vite/autoInstrument.js.map +1 -1
  409. package/build/esm/dev/vite/index.js +43 -19
  410. package/build/esm/dev/vite/index.js.map +1 -1
  411. package/build/esm/dev/vite/instrumentFile.js +37 -18
  412. package/build/esm/dev/vite/instrumentFile.js.map +1 -1
  413. package/build/esm/dev/vite/mastraObservability.js +19 -10
  414. package/build/esm/dev/vite/mastraObservability.js.map +1 -1
  415. package/build/esm/dev/vite/moduleShape.js +220 -199
  416. package/build/esm/dev/vite/moduleShape.js.map +1 -1
  417. package/build/esm/dev/vite/providedModulePlugin.js +60 -43
  418. package/build/esm/dev/vite/providedModulePlugin.js.map +1 -1
  419. package/build/esm/dev/vite/transform.js +330 -282
  420. package/build/esm/dev/vite/transform.js.map +1 -1
  421. package/build/esm/dev/vite/workerEntrypoint.js +66 -55
  422. package/build/esm/dev/vite/workerEntrypoint.js.map +1 -1
  423. package/build/esm/dev/vite/wranglerConfig.js +94 -65
  424. package/build/esm/dev/vite/wranglerConfig.js.map +1 -1
  425. package/build/esm/dev/withSentry.js +32 -24
  426. package/build/esm/dev/withSentry.js.map +1 -1
  427. package/build/esm/dev/workflows.js +164 -149
  428. package/build/esm/dev/workflows.js.map +1 -1
  429. package/build/esm/dev/wrapMethodWithSentry.js +148 -167
  430. package/build/esm/dev/wrapMethodWithSentry.js.map +1 -1
  431. package/build/esm/dev/wrapRequestHandlerWithInit.js +76 -76
  432. package/build/esm/dev/wrapRequestHandlerWithInit.js.map +1 -1
  433. package/build/esm/prod/baseSdk.js +94 -91
  434. package/build/esm/prod/baseSdk.js.map +1 -1
  435. package/build/esm/prod/client.js +218 -235
  436. package/build/esm/prod/client.js.map +1 -1
  437. package/build/esm/prod/clientCache.js +8 -6
  438. package/build/esm/prod/clientCache.js.map +1 -1
  439. package/build/esm/prod/debug-build.js +9 -3
  440. package/build/esm/prod/debug-build.js.map +1 -1
  441. package/build/esm/prod/defineCloudflareOptions.js +5 -6
  442. package/build/esm/prod/defineCloudflareOptions.js.map +1 -1
  443. package/build/esm/prod/durableobject.js +287 -174
  444. package/build/esm/prod/durableobject.js.map +1 -1
  445. package/build/esm/prod/flush.js +104 -75
  446. package/build/esm/prod/flush.js.map +1 -1
  447. package/build/esm/prod/index.js +19 -18
  448. package/build/esm/prod/instrument.js +53 -37
  449. package/build/esm/prod/instrument.js.map +1 -1
  450. package/build/esm/prod/instrumentations/agents/index.js +34 -11
  451. package/build/esm/prod/instrumentations/agents/index.js.map +1 -1
  452. package/build/esm/prod/instrumentations/agents/instrumentAgentCallableRpc.js +46 -47
  453. package/build/esm/prod/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  454. package/build/esm/prod/instrumentations/agents/instrumentAgentRequestConversation.js +23 -14
  455. package/build/esm/prod/instrumentations/agents/instrumentAgentRequestConversation.js.map +1 -1
  456. package/build/esm/prod/instrumentations/agents/instrumentChatAgentConversation.js +36 -26
  457. package/build/esm/prod/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -1
  458. package/build/esm/prod/instrumentations/agents/types.js +103 -56
  459. package/build/esm/prod/instrumentations/agents/types.js.map +1 -1
  460. package/build/esm/prod/instrumentations/instrumentDurableObjectHandlers.js +87 -116
  461. package/build/esm/prod/instrumentations/instrumentDurableObjectHandlers.js.map +1 -1
  462. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js +46 -42
  463. package/build/esm/prod/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  464. package/build/esm/prod/instrumentations/instrumentDurableObjectStorage.js +70 -69
  465. package/build/esm/prod/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  466. package/build/esm/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js +31 -37
  467. package/build/esm/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  468. package/build/esm/prod/instrumentations/instrumentSqlStorage.js +50 -50
  469. package/build/esm/prod/instrumentations/instrumentSqlStorage.js.map +1 -1
  470. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js +136 -121
  471. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  472. package/build/esm/prod/instrumentations/worker/instrumentD1.js +131 -144
  473. package/build/esm/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  474. package/build/esm/prod/instrumentations/worker/instrumentEmail.js +63 -59
  475. package/build/esm/prod/instrumentations/worker/instrumentEmail.js.map +1 -1
  476. package/build/esm/prod/instrumentations/worker/instrumentEnv.js +83 -86
  477. package/build/esm/prod/instrumentations/worker/instrumentEnv.js.map +1 -1
  478. package/build/esm/prod/instrumentations/worker/instrumentFetch.js +41 -46
  479. package/build/esm/prod/instrumentations/worker/instrumentFetch.js.map +1 -1
  480. package/build/esm/prod/instrumentations/worker/instrumentFetcher.js +25 -19
  481. package/build/esm/prod/instrumentations/worker/instrumentFetcher.js.map +1 -1
  482. package/build/esm/prod/instrumentations/worker/instrumentKV.js +54 -65
  483. package/build/esm/prod/instrumentations/worker/instrumentKV.js.map +1 -1
  484. package/build/esm/prod/instrumentations/worker/instrumentQueue.js +98 -103
  485. package/build/esm/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  486. package/build/esm/prod/instrumentations/worker/instrumentQueueProducer.js +88 -92
  487. package/build/esm/prod/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  488. package/build/esm/prod/instrumentations/worker/instrumentR2.js +128 -113
  489. package/build/esm/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  490. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js +90 -92
  491. package/build/esm/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
  492. package/build/esm/prod/instrumentations/worker/instrumentTail.js +100 -53
  493. package/build/esm/prod/instrumentations/worker/instrumentTail.js.map +1 -1
  494. package/build/esm/prod/integrations/cronTriggers.js +129 -82
  495. package/build/esm/prod/integrations/cronTriggers.js.map +1 -1
  496. package/build/esm/prod/integrations/fetch.js +9 -6
  497. package/build/esm/prod/integrations/fetch.js.map +1 -1
  498. package/build/esm/prod/integrations/httpServer.js +40 -19
  499. package/build/esm/prod/integrations/httpServer.js.map +1 -1
  500. package/build/esm/prod/integrations/spotlight.js +51 -52
  501. package/build/esm/prod/integrations/spotlight.js.map +1 -1
  502. package/build/esm/prod/opentelemetry/tracer.js +10 -6
  503. package/build/esm/prod/opentelemetry/tracer.js.map +1 -1
  504. package/build/esm/prod/options.js +38 -22
  505. package/build/esm/prod/options.js.map +1 -1
  506. package/build/esm/prod/orchestrion-deferred-channels.js +45 -27
  507. package/build/esm/prod/orchestrion-deferred-channels.js.map +1 -1
  508. package/build/esm/prod/orchestrion-diagnostics-channel.js +87 -66
  509. package/build/esm/prod/orchestrion-diagnostics-channel.js.map +1 -1
  510. package/build/esm/prod/package.json +1 -1
  511. package/build/esm/prod/pages-plugin.js +20 -19
  512. package/build/esm/prod/pages-plugin.js.map +1 -1
  513. package/build/esm/prod/request.js +14 -7
  514. package/build/esm/prod/request.js.map +1 -1
  515. package/build/esm/prod/scope-utils.js +12 -10
  516. package/build/esm/prod/scope-utils.js.map +1 -1
  517. package/build/esm/prod/sdk.js +23 -13
  518. package/build/esm/prod/sdk.js.map +1 -1
  519. package/build/esm/prod/transport.js +93 -84
  520. package/build/esm/prod/transport.js.map +1 -1
  521. package/build/esm/prod/utils/asyncContextStrategy.js +10 -8
  522. package/build/esm/prod/utils/asyncContextStrategy.js.map +1 -1
  523. package/build/esm/prod/utils/bindingPropagation.js +17 -9
  524. package/build/esm/prod/utils/bindingPropagation.js.map +1 -1
  525. package/build/esm/prod/utils/cloudflareTrace.js +34 -0
  526. package/build/esm/prod/utils/cloudflareTrace.js.map +1 -0
  527. package/build/esm/prod/utils/instrumentContext.js +74 -56
  528. package/build/esm/prod/utils/instrumentContext.js.map +1 -1
  529. package/build/esm/prod/utils/internalSqlQuery.js +38 -19
  530. package/build/esm/prod/utils/internalSqlQuery.js.map +1 -1
  531. package/build/esm/prod/utils/internalStorageKey.js +41 -36
  532. package/build/esm/prod/utils/internalStorageKey.js.map +1 -1
  533. package/build/esm/prod/utils/invocationContext.js +42 -30
  534. package/build/esm/prod/utils/invocationContext.js.map +1 -1
  535. package/build/esm/prod/utils/invocationScope.js +45 -19
  536. package/build/esm/prod/utils/invocationScope.js.map +1 -1
  537. package/build/esm/prod/utils/isBinding.js +47 -13
  538. package/build/esm/prod/utils/isBinding.js.map +1 -1
  539. package/build/esm/prod/utils/isCloudflareClass.js +11 -18
  540. package/build/esm/prod/utils/isCloudflareClass.js.map +1 -1
  541. package/build/esm/prod/utils/queueTraceMeta.js +24 -33
  542. package/build/esm/prod/utils/queueTraceMeta.js.map +1 -1
  543. package/build/esm/prod/utils/rpcMeta.js +37 -25
  544. package/build/esm/prod/utils/rpcMeta.js.map +1 -1
  545. package/build/esm/prod/utils/traceLinks.js +52 -40
  546. package/build/esm/prod/utils/traceLinks.js.map +1 -1
  547. package/build/esm/prod/vendor/stacktrace.js +31 -21
  548. package/build/esm/prod/vendor/stacktrace.js.map +1 -1
  549. package/build/esm/prod/vite/agentClass.js +105 -96
  550. package/build/esm/prod/vite/agentClass.js.map +1 -1
  551. package/build/esm/prod/vite/autoInstrument.js +125 -120
  552. package/build/esm/prod/vite/autoInstrument.js.map +1 -1
  553. package/build/esm/prod/vite/index.js +43 -19
  554. package/build/esm/prod/vite/index.js.map +1 -1
  555. package/build/esm/prod/vite/instrumentFile.js +37 -18
  556. package/build/esm/prod/vite/instrumentFile.js.map +1 -1
  557. package/build/esm/prod/vite/mastraObservability.js +19 -10
  558. package/build/esm/prod/vite/mastraObservability.js.map +1 -1
  559. package/build/esm/prod/vite/moduleShape.js +220 -199
  560. package/build/esm/prod/vite/moduleShape.js.map +1 -1
  561. package/build/esm/prod/vite/providedModulePlugin.js +60 -43
  562. package/build/esm/prod/vite/providedModulePlugin.js.map +1 -1
  563. package/build/esm/prod/vite/transform.js +330 -282
  564. package/build/esm/prod/vite/transform.js.map +1 -1
  565. package/build/esm/prod/vite/workerEntrypoint.js +66 -55
  566. package/build/esm/prod/vite/workerEntrypoint.js.map +1 -1
  567. package/build/esm/prod/vite/wranglerConfig.js +94 -65
  568. package/build/esm/prod/vite/wranglerConfig.js.map +1 -1
  569. package/build/esm/prod/withSentry.js +32 -24
  570. package/build/esm/prod/withSentry.js.map +1 -1
  571. package/build/esm/prod/workflows.js +164 -149
  572. package/build/esm/prod/workflows.js.map +1 -1
  573. package/build/esm/prod/wrapMethodWithSentry.js +148 -167
  574. package/build/esm/prod/wrapMethodWithSentry.js.map +1 -1
  575. package/build/esm/prod/wrapRequestHandlerWithInit.js +76 -76
  576. package/build/esm/prod/wrapRequestHandlerWithInit.js.map +1 -1
  577. package/build/types/baseSdk.d.ts.map +1 -1
  578. package/build/types/client.d.ts +9 -1
  579. package/build/types/client.d.ts.map +1 -1
  580. package/build/types/durableobject.d.ts.map +1 -1
  581. package/build/types/index.d.ts +3 -2
  582. package/build/types/index.d.ts.map +1 -1
  583. package/build/types/instrumentations/worker/instrumentEmail.d.ts.map +1 -1
  584. package/build/types/instrumentations/worker/instrumentFetcher.d.ts.map +1 -1
  585. package/build/types/instrumentations/worker/instrumentQueue.d.ts.map +1 -1
  586. package/build/types/instrumentations/worker/instrumentScheduled.d.ts.map +1 -1
  587. package/build/types/instrumentations/worker/instrumentTail.d.ts +4 -2
  588. package/build/types/instrumentations/worker/instrumentTail.d.ts.map +1 -1
  589. package/build/types/options.d.ts.map +1 -1
  590. package/build/types/utils/cloudflareTrace.d.ts +13 -0
  591. package/build/types/utils/cloudflareTrace.d.ts.map +1 -0
  592. package/build/types/vite/autoInstrument.d.ts.map +1 -1
  593. package/build/types/vite/index.d.ts +3 -0
  594. package/build/types/vite/index.d.ts.map +1 -1
  595. package/build/types/vite/providedModulePlugin.d.ts +15 -11
  596. package/build/types/vite/providedModulePlugin.d.ts.map +1 -1
  597. package/build/types/vite/transform.d.ts +12 -2
  598. package/build/types/vite/transform.d.ts.map +1 -1
  599. package/build/types/vite/wranglerConfig.d.ts +8 -0
  600. package/build/types/vite/wranglerConfig.d.ts.map +1 -1
  601. package/build/types/workflows.d.ts.map +1 -1
  602. package/build/types/wrapMethodWithSentry.d.ts.map +1 -1
  603. package/build/types/wrapRequestHandlerWithInit.d.ts.map +1 -1
  604. package/package.json +10 -14
  605. package/build/cjs/dev/index.js.map +0 -1
  606. package/build/cjs/dev/vite/flueRuntime.js +0 -15
  607. package/build/cjs/dev/vite/flueRuntime.js.map +0 -1
  608. package/build/cjs/prod/index.js.map +0 -1
  609. package/build/cjs/prod/vite/flueRuntime.js +0 -15
  610. package/build/cjs/prod/vite/flueRuntime.js.map +0 -1
  611. package/build/esm/dev/index.js.map +0 -1
  612. package/build/esm/dev/vite/flueRuntime.js +0 -13
  613. package/build/esm/dev/vite/flueRuntime.js.map +0 -1
  614. package/build/esm/prod/index.js.map +0 -1
  615. package/build/esm/prod/vite/flueRuntime.js +0 -13
  616. package/build/esm/prod/vite/flueRuntime.js.map +0 -1
  617. package/build/types/vite/flueRuntime.d.ts +0 -12
  618. package/build/types/vite/flueRuntime.d.ts.map +0 -1
@@ -1,327 +1,375 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const MagicString = require('magic-string');
4
- const wranglerConfig = require('./wranglerConfig.js');
5
- const workerEntrypoint = require('./workerEntrypoint.js');
6
-
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
2
+ const require_wranglerConfig = require("./wranglerConfig.js");
3
+ const require_workerEntrypoint = require("./workerEntrypoint.js");
4
+ let _sentry_core = require("@sentry/core");
5
+ let magic_string = require("magic-string");
6
+ magic_string = require_runtime.__toESM(magic_string);
7
+ // src/vite/transform.ts
7
8
  const MERGED_OPTIONS_IDENTIFIER = "__SENTRY_OPTIONS__";
9
+ const WORKER_INFO_GLOBAL = "__SENTRY_CLOUDFLARE_WORKER__";
8
10
  function isCallToMethod(node, methodName) {
9
- if (node.type !== "CallExpression") return false;
10
- const callee = node.callee;
11
- if (!callee) return false;
12
- if (callee.type === "Identifier" && callee.name === methodName) return true;
13
- return callee.type === "MemberExpression" && callee.property?.type === "Identifier" && callee.property.name === methodName;
11
+ if (node.type !== "CallExpression") return false;
12
+ const callee = node.callee;
13
+ if (!callee) return false;
14
+ if (callee.type === "Identifier" && callee.name === methodName) return true;
15
+ return callee.type === "MemberExpression" && callee.property?.type === "Identifier" && callee.property.name === methodName;
14
16
  }
17
+ /** Specifier name a `export { default as X } from '...'` re-export uses for the source's default. */
15
18
  const DEFAULT_IMPORT = "default";
19
+ /**
20
+ * The `@sentry/cloudflare` helper each wrapper kind emits. All share the same
21
+ * `(optionsCallback, Class)` signature. `WorkerEntrypoint` classes use
22
+ * `withSentry`, which runtime-detects the class type and routes accordingly.
23
+ */
16
24
  const WRAPPER_METHODS = {
17
- durableObject: "instrumentDurableObjectWithSentry",
18
- agent: "instrumentAgentWithSentry",
19
- workflow: "instrumentWorkflowWithSentry",
20
- workerEntrypoint: "withSentry"
25
+ durableObject: "instrumentDurableObjectWithSentry",
26
+ agent: "instrumentAgentWithSentry",
27
+ workflow: "instrumentWorkflowWithSentry",
28
+ workerEntrypoint: "withSentry"
21
29
  };
30
+ /**
31
+ * Rewrite the worker entry source to wrap its default export with `withSentry`
32
+ * and any configured class export with its matching Sentry wrapper (see
33
+ * {@link TransformContext.classWrappers}, e.g. Durable Object classes with
34
+ * `instrumentDurableObjectWithSentry`).
35
+ *
36
+ * Handles `export class MyDO {}`, the specifier form (`class MyDO {}` …
37
+ * `export { MyDO }` / `export { Foo as MyDO }`), and classes that live in
38
+ * another module (`import { MyDO } from './do'; export { MyDO }` or
39
+ * `export { MyDO } from './do'`). Only star re-exports (`export * from './do'`)
40
+ * are left alone — the plugin warns about those via
41
+ * {@link TransformResult.wrappedClasses}.
42
+ *
43
+ * Exported (rather than inlined into the plugin) so it can be unit-tested with a
44
+ * plain AST and no Vite context. Returns `undefined` when nothing was wrapped,
45
+ * there are no already-manually-wrapped classes to report, and there is no
46
+ * {@link TransformContext.workerInfo} to store.
47
+ */
22
48
  function applyAutoInstrumentTransforms(code, ast, ctx) {
23
- const ms = new MagicString.default(code);
24
- const topLevelClasses = collectTopLevelClasses(ast);
25
- const sameWorkerBindings = ctx.sameWorkerBindings ?? [];
26
- const state = {
27
- ms,
28
- needsImport: false,
29
- wrappedClasses: /* @__PURE__ */ new Set(),
30
- topLevelClasses,
31
- wrappedLocals: /* @__PURE__ */ new Map(),
32
- classWrappers: ctx.classWrappers,
33
- agentClasses: ctx.agentClasses ?? /* @__PURE__ */ new Set(),
34
- workerEntrypointClasses: workerEntrypoint.detectWorkerEntrypointClasses(ast),
35
- // The identifier must be chosen before wrapping, which bindings survive is only known after.
36
- optionsFn: sameWorkerBindings.length > 0 ? MERGED_OPTIONS_IDENTIFIER : ctx.optionsFn,
37
- autoWrapped: /* @__PURE__ */ new Set(),
38
- manuallyWrappedLocals: collectManuallyWrappedLocals(ast),
39
- declaringStatements: collectDeclaringStatements(ast)
40
- };
41
- const { wrappedClasses } = state;
42
- for (const node of ast.body) {
43
- if (node.type === "ExportNamedDeclaration") {
44
- handleNamedExport(node, ctx, state);
45
- }
46
- }
47
- for (const node of ast.body) {
48
- if (node.type === "ExportDefaultDeclaration") {
49
- wrapDefaultExport(node, ctx, state);
50
- }
51
- }
52
- if (!state.needsImport) {
53
- if (wrappedClasses.size === 0) return void 0;
54
- return { code, map: ms.generateMap({ hires: true }), wrappedClasses };
55
- }
56
- if (sameWorkerBindings.length > 0) {
57
- ms.prepend(buildMergedOptionsDeclaration(sameWorkerBindings, ctx.optionsFn, state));
58
- }
59
- if (ctx.optionsImport) ms.prepend(ctx.optionsImport);
60
- ms.prepend(`import * as __SENTRY__ from '${ctx.sentryModule ?? "@sentry/cloudflare"}';
61
- `);
62
- return {
63
- code: ms.toString(),
64
- map: ms.generateMap({ hires: true }),
65
- wrappedClasses
66
- };
49
+ const ms = new magic_string.default(code);
50
+ const topLevelClasses = collectTopLevelClasses(ast);
51
+ const sameWorkerBindings = ctx.sameWorkerBindings ?? [];
52
+ const state = {
53
+ ms,
54
+ needsImport: false,
55
+ wrappedClasses: /* @__PURE__ */ new Set(),
56
+ topLevelClasses,
57
+ wrappedLocals: /* @__PURE__ */ new Map(),
58
+ classWrappers: ctx.classWrappers,
59
+ agentClasses: ctx.agentClasses ?? /* @__PURE__ */ new Set(),
60
+ workerEntrypointClasses: require_workerEntrypoint.detectWorkerEntrypointClasses(ast),
61
+ optionsFn: sameWorkerBindings.length > 0 ? MERGED_OPTIONS_IDENTIFIER : ctx.optionsFn,
62
+ autoWrapped: /* @__PURE__ */ new Set(),
63
+ manuallyWrappedLocals: collectManuallyWrappedLocals(ast),
64
+ declaringStatements: collectDeclaringStatements(ast)
65
+ };
66
+ const { wrappedClasses } = state;
67
+ for (const node of ast.body) if (node.type === "ExportNamedDeclaration") handleNamedExport(node, ctx, state);
68
+ for (const node of ast.body) if (node.type === "ExportDefaultDeclaration") wrapDefaultExport(node, ctx, state);
69
+ if (state.needsImport) {
70
+ if (sameWorkerBindings.length > 0) ms.prepend(buildMergedOptionsDeclaration(sameWorkerBindings, ctx.optionsFn, state));
71
+ if (ctx.optionsImport) ms.prepend(ctx.optionsImport);
72
+ ms.prepend(`import * as __SENTRY__ from '${ctx.sentryModule ?? "@sentry/cloudflare"}';\n`);
73
+ }
74
+ if (ctx.workerInfo?.name || ctx.workerInfo?.compatibilityDate) ms.prepend(`globalThis.${WORKER_INFO_GLOBAL} = ${JSON.stringify(ctx.workerInfo)};\n`);
75
+ else if (!state.needsImport && wrappedClasses.size === 0) return;
76
+ return {
77
+ code: ms.toString(),
78
+ map: ms.generateMap({ hires: true }),
79
+ wrappedClasses
80
+ };
67
81
  }
82
+ /**
83
+ * Builds the callback that merges same-worker binding names into `rpcTracePropagationBindings` at
84
+ * runtime, the options object only exists once the callback runs with `env`. Only bindings whose
85
+ * class this transform wrapped survive, a hand-wrapped class runs on its own options.
86
+ */
68
87
  function buildMergedOptionsDeclaration(sameWorkerBindings, optionsFn, state) {
69
- const bindingNames = sameWorkerBindings.filter(({ className }) => state.autoWrapped.has(className)).map(({ bindingName }) => bindingName);
70
- if (!bindingNames.length) {
71
- return `const ${MERGED_OPTIONS_IDENTIFIER} = ${optionsFn};
72
- `;
73
- }
74
- const names = bindingNames.map((name) => JSON.stringify(name)).join(", ");
75
- return `const ${MERGED_OPTIONS_IDENTIFIER} = (env) => { const opts = (${optionsFn})(env); return { ...opts, rpcTracePropagationBindings: [${names}, ...(opts?.rpcTracePropagationBindings ?? [])] }; };
76
- `;
88
+ const bindingNames = sameWorkerBindings.filter(({ className }) => state.autoWrapped.has(className)).map(({ bindingName }) => bindingName);
89
+ if (!bindingNames.length) return `const ${MERGED_OPTIONS_IDENTIFIER} = ${optionsFn};\n`;
90
+ const names = bindingNames.map((name) => (0, _sentry_core.stringifyForCodeInjection)(name)).join(", ");
91
+ return `const ${MERGED_OPTIONS_IDENTIFIER} = (env) => { const opts = (${optionsFn})(env); return { ...opts, rpcTracePropagationBindings: [${names}, ...(opts?.rpcTracePropagationBindings ?? [])] }; };\n`;
77
92
  }
93
+ /**
94
+ * Resolve the wrapper kind for a class export.
95
+ *
96
+ * Config (`classWrappers`) wins — it's authoritative for Durable Objects and
97
+ * Workflows, and provides the self-binding fallback for WorkerEntrypoints whose
98
+ * base class this module can't see. Otherwise a structurally-detected
99
+ * `WorkerEntrypoint` subclass (matched by its *local* name) gets wrapped with
100
+ * `withSentry`.
101
+ *
102
+ * `localName` is the binding **in this module** the export refers to, and must be
103
+ * left undefined for `export { X } from '...'`: there the specifier's name belongs
104
+ * to the source module, so matching it against anything detected here would wrap a
105
+ * class that merely shares a name.
106
+ *
107
+ * The one case where config is refined rather than obeyed is an `agents` Agent:
108
+ * it *is* a Durable Object, so wrangler can only ever describe it as one, and
109
+ * only the detected base chain distinguishes the two.
110
+ */
78
111
  function resolveWrapperKind(exportedName, localName, state) {
79
- const configured = state.classWrappers.get(exportedName);
80
- if (configured === "durableObject" && (localName && state.agentClasses.has(localName) || state.agentClasses.has(exportedName))) {
81
- return "agent";
82
- }
83
- if (configured) return configured;
84
- if (localName && state.workerEntrypointClasses.has(localName)) return "workerEntrypoint";
85
- return void 0;
112
+ const configured = state.classWrappers.get(exportedName);
113
+ if (configured === "durableObject" && (localName && state.agentClasses.has(localName) || state.agentClasses.has(exportedName))) return "agent";
114
+ if (configured) return configured;
115
+ if (localName && state.workerEntrypointClasses.has(localName)) return "workerEntrypoint";
86
116
  }
117
+ /**
118
+ * Top-level `const X = instrument*WithSentry(...)` bindings — a hand-wrapped class that is exported
119
+ * separately (`export { X }`) rather than inline.
120
+ */
87
121
  function collectManuallyWrappedLocals(ast) {
88
- const wrapperMethods = Object.values(WRAPPER_METHODS);
89
- const locals = /* @__PURE__ */ new Set();
90
- for (const node of ast.body) {
91
- const declaration = declarationOf(node);
92
- if (declaration?.type !== "VariableDeclaration") continue;
93
- for (const declarator of declaration.declarations ?? []) {
94
- const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
95
- const init = declarator.init;
96
- if (name && init && wrapperMethods.some((method) => isCallToMethod(init, method))) {
97
- locals.add(name);
98
- }
99
- }
100
- }
101
- return locals;
122
+ const wrapperMethods = Object.values(WRAPPER_METHODS);
123
+ const locals = /* @__PURE__ */ new Set();
124
+ for (const node of ast.body) {
125
+ const declaration = declarationOf(node);
126
+ if (declaration?.type !== "VariableDeclaration") continue;
127
+ for (const declarator of declaration.declarations ?? []) {
128
+ const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
129
+ const init = declarator.init;
130
+ if (name && init && wrapperMethods.some((method) => isCallToMethod(init, method))) locals.add(name);
131
+ }
132
+ }
133
+ return locals;
102
134
  }
103
135
  function collectDeclaringStatements(ast) {
104
- const statements = /* @__PURE__ */ new Map();
105
- for (const node of ast.body) {
106
- const declaration = declarationOf(node);
107
- if (!declaration) continue;
108
- const ids = declaration.type === "VariableDeclaration" ? (declaration.declarations ?? []).map((declarator) => declarator.id) : declaration.type === "ImportDeclaration" ? (declaration.specifiers ?? []).map((specifier) => specifier.local) : [declaration.id];
109
- for (const id of ids) {
110
- if (id?.type === "Identifier" && id.name) statements.set(id.name, node);
111
- }
112
- }
113
- return statements;
136
+ const statements = /* @__PURE__ */ new Map();
137
+ for (const node of ast.body) {
138
+ const declaration = declarationOf(node);
139
+ if (!declaration) continue;
140
+ const ids = declaration.type === "VariableDeclaration" ? (declaration.declarations ?? []).map((declarator) => declarator.id) : declaration.type === "ImportDeclaration" ? (declaration.specifiers ?? []).map((specifier) => specifier.local) : [declaration.id];
141
+ for (const id of ids) if (id?.type === "Identifier" && id.name) statements.set(id.name, node);
142
+ }
143
+ return statements;
114
144
  }
115
145
  function collectTopLevelClasses(ast) {
116
- const classes = /* @__PURE__ */ new Map();
117
- for (const node of ast.body) {
118
- const declaration = declarationOf(node);
119
- if (declaration?.type !== "ClassDeclaration") continue;
120
- const classNode = declaration;
121
- if (classNode.id?.name) classes.set(classNode.id.name, classNode);
122
- }
123
- return classes;
146
+ const classes = /* @__PURE__ */ new Map();
147
+ for (const node of ast.body) {
148
+ const declaration = declarationOf(node);
149
+ if (declaration?.type !== "ClassDeclaration") continue;
150
+ const classNode = declaration;
151
+ if (classNode.id?.name) classes.set(classNode.id.name, classNode);
152
+ }
153
+ return classes;
124
154
  }
155
+ /** The declaration a top-level statement makes, looking through `export` (`export const x = ...`). */
125
156
  function declarationOf(node) {
126
- return node.type === "ExportNamedDeclaration" ? node.declaration : node;
157
+ return node.type === "ExportNamedDeclaration" ? node.declaration : node;
127
158
  }
128
159
  function wrapDefaultExport(node, ctx, state) {
129
- const decl = node.declaration;
130
- if (isCallToMethod(decl, "withSentry")) return;
131
- if (decl.type === "Identifier") {
132
- const wrappedName = state.wrappedLocals.get(decl.name);
133
- if (wrappedName) {
134
- state.ms.overwrite(decl.start, decl.end, wrappedName);
135
- state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
136
- return;
137
- }
138
- }
139
- const source = state.ms.original;
140
- const keywordsEnd = exportDefaultKeywordsEnd(source, node.start);
141
- const declaredName = decl.type === "ClassDeclaration" || decl.type === "FunctionDeclaration" ? decl.id?.name : void 0;
142
- let wrapped = "__SENTRY_DEFAULT_EXPORT__";
143
- if (declaredName) {
144
- state.ms.remove(node.start, decl.start);
145
- state.ms.appendLeft(node.end, `
146
- var __SENTRY_DEFAULT_EXPORT__ = ${declaredName};`);
147
- wrapped = declaredName;
148
- } else if (isAnonymousFunctionOrClass(decl)) {
149
- const hasSemicolon = source[node.end - 1] === ";";
150
- state.ms.overwrite(node.start, keywordsEnd, "var __SENTRY_DEFAULT_EXPORT__ = { default:");
151
- state.ms.appendLeft(hasSemicolon ? node.end - 1 : node.end, hasSemicolon ? " }.default" : " }.default;");
152
- } else {
153
- state.ms.overwrite(node.start, keywordsEnd, "var __SENTRY_DEFAULT_EXPORT__ =");
154
- }
155
- state.ms.appendLeft(node.end, "\nexport { __SENTRY_DEFAULT_EXPORT__ as default };");
156
- state.ms.append(`
157
- __SENTRY_DEFAULT_EXPORT__ = __SENTRY__.withSentry(${state.optionsFn}, ${wrapped});`);
158
- state.needsImport = true;
159
- state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
160
+ const decl = node.declaration;
161
+ if (isCallToMethod(decl, "withSentry")) return;
162
+ if (decl.type === "Identifier") {
163
+ const wrappedName = state.wrappedLocals.get(decl.name);
164
+ if (wrappedName) {
165
+ state.ms.overwrite(decl.start, decl.end, wrappedName);
166
+ state.autoWrapped.add(require_wranglerConfig.DEFAULT_EXPORT);
167
+ return;
168
+ }
169
+ }
170
+ const source = state.ms.original;
171
+ const keywordsEnd = exportDefaultKeywordsEnd(source, node.start);
172
+ const declaredName = decl.type === "ClassDeclaration" || decl.type === "FunctionDeclaration" ? decl.id?.name : void 0;
173
+ let wrapped = "__SENTRY_DEFAULT_EXPORT__";
174
+ if (declaredName) {
175
+ state.ms.remove(node.start, decl.start);
176
+ state.ms.appendLeft(node.end, `\nvar __SENTRY_DEFAULT_EXPORT__ = ${declaredName};`);
177
+ wrapped = declaredName;
178
+ } else if (isAnonymousFunctionOrClass(decl)) {
179
+ const hasSemicolon = source[node.end - 1] === ";";
180
+ state.ms.overwrite(node.start, keywordsEnd, "var __SENTRY_DEFAULT_EXPORT__ = { default:");
181
+ state.ms.appendLeft(hasSemicolon ? node.end - 1 : node.end, hasSemicolon ? " }.default" : " }.default;");
182
+ } else state.ms.overwrite(node.start, keywordsEnd, "var __SENTRY_DEFAULT_EXPORT__ =");
183
+ state.ms.appendLeft(node.end, "\nexport { __SENTRY_DEFAULT_EXPORT__ as default };");
184
+ state.ms.append(`\n__SENTRY_DEFAULT_EXPORT__ = __SENTRY__.withSentry(${state.optionsFn}, ${wrapped});`);
185
+ state.needsImport = true;
186
+ state.autoWrapped.add(require_wranglerConfig.DEFAULT_EXPORT);
160
187
  }
188
+ /**
189
+ * Offset just past the `default` keyword of the `export default` statement at `start`. Comments can
190
+ * sit between `export`, `default` and the expression, and may themselves contain the word `default`.
191
+ */
161
192
  function exportDefaultKeywordsEnd(source, start) {
162
- let index = start + "export".length;
163
- while (index < source.length && !source.startsWith("default", index)) {
164
- if (source.startsWith("//", index)) {
165
- const lineEnd = source.indexOf("\n", index);
166
- index = lineEnd === -1 ? source.length : lineEnd;
167
- } else if (source.startsWith("/*", index)) {
168
- const commentEnd = source.indexOf("*/", index + 2);
169
- index = commentEnd === -1 ? source.length : commentEnd + 2;
170
- } else {
171
- index++;
172
- }
173
- }
174
- return index + "default".length;
193
+ let index = start + 6;
194
+ while (index < source.length && !source.startsWith("default", index)) if (source.startsWith("//", index)) {
195
+ const lineEnd = source.indexOf("\n", index);
196
+ index = lineEnd === -1 ? source.length : lineEnd;
197
+ } else if (source.startsWith("/*", index)) {
198
+ const commentEnd = source.indexOf("*/", index + 2);
199
+ index = commentEnd === -1 ? source.length : commentEnd + 2;
200
+ } else index++;
201
+ return index + 7;
175
202
  }
176
203
  function isAnonymousFunctionOrClass(node) {
177
- if (node.type === "ArrowFunctionExpression") return true;
178
- const isFunctionOrClass = [
179
- "FunctionExpression",
180
- "FunctionDeclaration",
181
- "ClassExpression",
182
- "ClassDeclaration"
183
- ].includes(node.type);
184
- return isFunctionOrClass && !node.id;
204
+ if (node.type === "ArrowFunctionExpression") return true;
205
+ return [
206
+ "FunctionExpression",
207
+ "FunctionDeclaration",
208
+ "ClassExpression",
209
+ "ClassDeclaration"
210
+ ].includes(node.type) && !node.id;
185
211
  }
186
212
  function handleNamedExport(node, ctx, state) {
187
- const decl = node.declaration;
188
- if (decl?.type === "VariableDeclaration") {
189
- collectManuallyWrappedClassExports(decl, ctx, state);
190
- return;
191
- }
192
- if (decl?.type === "ClassDeclaration") {
193
- wrapInlineClassExport(node, decl, ctx, state);
194
- return;
195
- }
196
- wrapSpecifierExports(node, ctx, state);
213
+ const decl = node.declaration;
214
+ if (decl?.type === "VariableDeclaration") {
215
+ collectManuallyWrappedClassExports(decl, ctx, state);
216
+ return;
217
+ }
218
+ if (decl?.type === "ClassDeclaration") {
219
+ wrapInlineClassExport(node, decl, ctx, state);
220
+ return;
221
+ }
222
+ wrapSpecifierExports(node, ctx, state);
197
223
  }
198
224
  function collectManuallyWrappedClassExports(varDecl, ctx, state) {
199
- for (const declarator of varDecl.declarations ?? []) {
200
- const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
201
- const kind = name ? ctx.classWrappers.get(name) : void 0;
202
- if (!name || !kind || !declarator.init) continue;
203
- const accepted = kind === "durableObject" ? [WRAPPER_METHODS.durableObject, WRAPPER_METHODS.agent] : [WRAPPER_METHODS[kind]];
204
- if (accepted.some((method) => isCallToMethod(declarator.init, method))) {
205
- state.wrappedClasses.add(name);
206
- }
207
- }
225
+ for (const declarator of varDecl.declarations ?? []) {
226
+ const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
227
+ const kind = name ? ctx.classWrappers.get(name) : void 0;
228
+ if (!name || !kind || !declarator.init) continue;
229
+ if ((kind === "durableObject" ? [WRAPPER_METHODS.durableObject, WRAPPER_METHODS.agent] : [WRAPPER_METHODS[kind]]).some((method) => isCallToMethod(declarator.init, method))) state.wrappedClasses.add(name);
230
+ }
208
231
  }
209
232
  function wrapInlineClassExport(exportNode, classDecl, ctx, state) {
210
- const classId = classDecl.id;
211
- const kind = classId ? resolveWrapperKind(classId.name, classId.name, state) : void 0;
212
- if (!classId || !kind) return;
213
- const className = classId.name;
214
- state.ms.overwrite(exportNode.start, classDecl.start, "");
215
- const wrappedName = wrapLocalClass(className, classDecl, kind, state);
216
- state.ms.appendLeft(exportNode.end, `export { ${wrappedName} as ${className} };
217
- `);
218
- state.wrappedClasses.add(className);
219
- state.autoWrapped.add(className);
233
+ const classId = classDecl.id;
234
+ const kind = classId ? resolveWrapperKind(classId.name, classId.name, state) : void 0;
235
+ if (!classId || !kind) return;
236
+ const className = classId.name;
237
+ state.ms.overwrite(exportNode.start, classDecl.start, "");
238
+ const wrappedName = wrapLocalClass(className, classDecl, kind, state);
239
+ state.ms.appendLeft(exportNode.end, `export { ${wrappedName} as ${className} };\n`);
240
+ state.wrappedClasses.add(className);
241
+ state.autoWrapped.add(className);
220
242
  }
243
+ /**
244
+ * Wrap a class declared in this module and return the binding that holds the wrapper.
245
+ *
246
+ * The declaration is left exactly as written. Only the *export* has to become the wrapper, so the
247
+ * wrapper gets its own binding and the export is aliased to it, the same shape as the documented
248
+ * manual `instrument*WithSentry` pattern and the cross-module re-export path below. Renaming the
249
+ * declaration instead (`class __SENTRY_ORIGINAL_MyAgent__`) would also rename what the class reports
250
+ * as `Function.prototype.name`, which libraries read to identify the user's class: `@cloudflare/think`
251
+ * hands `this.constructor.name` to the AI SDK as the telemetry `functionId`, and that surfaced as a
252
+ * `gen_ai.invoke_agent __SENTRY_ORIGINAL_MyAgent__` span.
253
+ */
221
254
  function wrapLocalClass(localName, localClass, kind, state) {
222
- const existing = state.wrappedLocals.get(localName);
223
- if (existing) return existing;
224
- const wrappedName = `__SENTRY_WRAPPED_${localName}__`;
225
- state.wrappedLocals.set(localName, wrappedName);
226
- state.ms.appendLeft(
227
- localClass.end,
228
- `
229
- const ${wrappedName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${localName});
230
- `
231
- );
232
- state.needsImport = true;
233
- return wrappedName;
255
+ const existing = state.wrappedLocals.get(localName);
256
+ if (existing) return existing;
257
+ const wrappedName = `__SENTRY_WRAPPED_${localName}__`;
258
+ state.wrappedLocals.set(localName, wrappedName);
259
+ state.ms.appendLeft(localClass.end, `\nconst ${wrappedName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${localName});\n`);
260
+ state.needsImport = true;
261
+ return wrappedName;
234
262
  }
263
+ /**
264
+ * Wrap the configured classes an `export { ... }` statement names.
265
+ *
266
+ * Each such specifier is re-pointed at a binding holding the wrapper, which means rebuilding the
267
+ * statement; specifiers this plugin has no business touching are carried over verbatim. For a class
268
+ * declared in this module the wrapper binding follows the declaration (see {@link wrapLocalClass}).
269
+ * A class that lives in **another** module — imported and re-exported, or re-exported directly — is
270
+ * first bound under a private name, since an import binding cannot be reassigned and the `from` form
271
+ * has no local binding at all.
272
+ */
235
273
  function wrapSpecifierExports(node, ctx, state) {
236
- const specifiers = node.specifiers ?? [];
237
- if (specifiers.length === 0) return;
238
- const sourceLiteral = node.source ? state.ms.original.slice(node.source.start, node.source.end) : void 0;
239
- const prelude = [];
240
- const wrappedPairs = [];
241
- const kept = [];
242
- for (const specifier of specifiers) {
243
- const pair = wrapSpecifier(specifier, sourceLiteral, ctx, state, prelude);
244
- if (pair) {
245
- wrappedPairs.push(pair);
246
- } else {
247
- kept.push(state.ms.original.slice(specifier.start, specifier.end));
248
- }
249
- }
250
- if (wrappedPairs.length === 0) return;
251
- const statements = [...prelude, `export { ${wrappedPairs.join(", ")} };`];
252
- if (kept.length > 0) {
253
- const clause = `export { ${kept.join(", ")} }`;
254
- statements.push(sourceLiteral ? `${clause} from ${sourceLiteral};` : `${clause};`);
255
- }
256
- state.ms.overwrite(node.start, node.end, statements.join("\n"));
274
+ const specifiers = node.specifiers ?? [];
275
+ if (specifiers.length === 0) return;
276
+ const sourceLiteral = node.source ? state.ms.original.slice(node.source.start, node.source.end) : void 0;
277
+ const prelude = [];
278
+ const wrappedPairs = [];
279
+ const kept = [];
280
+ for (const specifier of specifiers) {
281
+ const pair = wrapSpecifier(specifier, sourceLiteral, ctx, state, prelude);
282
+ if (pair) wrappedPairs.push(pair);
283
+ else kept.push(state.ms.original.slice(specifier.start, specifier.end));
284
+ }
285
+ if (wrappedPairs.length === 0) return;
286
+ const statements = [...prelude, `export { ${wrappedPairs.join(", ")} };`];
287
+ if (kept.length > 0) {
288
+ const clause = `export { ${kept.join(", ")} }`;
289
+ statements.push(sourceLiteral ? `${clause} from ${sourceLiteral};` : `${clause};`);
290
+ }
291
+ state.ms.overwrite(node.start, node.end, statements.join("\n"));
257
292
  }
293
+ /**
294
+ * `export { handler as default }`, the form bundlers emit for a default export. The export is set
295
+ * in two steps. Right after `handler` is declared, it is bound to `handler` as-is, so a circular
296
+ * import that reads it during module evaluation gets the handler, as before the transform. At the
297
+ * end of the module, it is rebound to the wrapper, so a handler assigned or given methods later is
298
+ * wrapped as it ends up. The binding is a `var`: a read before `handler` is declared gets
299
+ * `undefined`, as it would from the bundler's own `var`, where a `const` would throw and stop the
300
+ * Worker from starting.
301
+ */
258
302
  function wrapDefaultSpecifier(localName, state) {
259
- if (state.manuallyWrappedLocals.has(localName)) return void 0;
260
- const wrappedName = state.wrappedLocals.get(localName);
261
- if (wrappedName) {
262
- state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
263
- return `${wrappedName} as default`;
264
- }
265
- const declaringStatement = state.declaringStatements.get(localName);
266
- if (declaringStatement) {
267
- state.ms.appendLeft(declaringStatement.end, `
268
- var __SENTRY_DEFAULT_EXPORT__ = ${localName};`);
269
- }
270
- state.ms.append(
271
- `
272
- ${declaringStatement ? "" : "var "}__SENTRY_DEFAULT_EXPORT__ = __SENTRY__.withSentry(${state.optionsFn}, ${localName});`
273
- );
274
- state.needsImport = true;
275
- state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
276
- return "__SENTRY_DEFAULT_EXPORT__ as default";
303
+ if (state.manuallyWrappedLocals.has(localName)) return void 0;
304
+ const wrappedName = state.wrappedLocals.get(localName);
305
+ if (wrappedName) {
306
+ state.autoWrapped.add(require_wranglerConfig.DEFAULT_EXPORT);
307
+ return `${wrappedName} as default`;
308
+ }
309
+ const declaringStatement = state.declaringStatements.get(localName);
310
+ if (declaringStatement) state.ms.appendLeft(declaringStatement.end, `\nvar __SENTRY_DEFAULT_EXPORT__ = ${localName};`);
311
+ state.ms.append(`\n${declaringStatement ? "" : "var "}__SENTRY_DEFAULT_EXPORT__ = __SENTRY__.withSentry(${state.optionsFn}, ${localName});`);
312
+ state.needsImport = true;
313
+ state.autoWrapped.add(require_wranglerConfig.DEFAULT_EXPORT);
314
+ return "__SENTRY_DEFAULT_EXPORT__ as default";
277
315
  }
316
+ /**
317
+ * `export { default } from './handler'`. The handler may already be wrapped in its own module,
318
+ * which this transform cannot see, so the emitted guard returns such a handler as-is.
319
+ *
320
+ * The original re-export is a live binding to the handler module's export, but the wrapper is not
321
+ * set until this module's body runs. A circular import that reads the default export before then
322
+ * gets `undefined` instead of the handler. The binding is a `var` so that the read does not throw,
323
+ * as a `const` would, and stop the Worker from starting. See `wrapDefaultSpecifier`.
324
+ */
278
325
  function wrapDefaultReexport(localName, sourceLiteral, state, prelude) {
279
- const target = "__SENTRY_REEXPORT_default__";
280
- prelude.push(
281
- localName === DEFAULT_IMPORT ? `import ${target} from ${sourceLiteral};` : `import { ${localName} as ${target} } from ${sourceLiteral};`,
282
- `var __SENTRY_DEFAULT_EXPORT__ = __SENTRY__._INTERNAL_wrapUnlessInstrumented(__SENTRY__.withSentry, ${state.optionsFn}, ${target});`
283
- );
284
- state.needsImport = true;
285
- state.autoWrapped.add(wranglerConfig.DEFAULT_EXPORT);
286
- return "__SENTRY_DEFAULT_EXPORT__ as default";
326
+ const target = "__SENTRY_REEXPORT_default__";
327
+ prelude.push(localName === DEFAULT_IMPORT ? `import ${target} from ${sourceLiteral};` : `import { ${localName} as ${target} } from ${sourceLiteral};`, `var __SENTRY_DEFAULT_EXPORT__ = __SENTRY__._INTERNAL_wrapUnlessInstrumented(__SENTRY__.withSentry, ${state.optionsFn}, ${target});`);
328
+ state.needsImport = true;
329
+ state.autoWrapped.add(require_wranglerConfig.DEFAULT_EXPORT);
330
+ return "__SENTRY_DEFAULT_EXPORT__ as default";
287
331
  }
332
+ /**
333
+ * Handle one export specifier, returning the `Wrapped as Exported` pair to emit for a class that
334
+ * gets wrapped. The import/wrapper statements a cross-module pair depends on are pushed onto
335
+ * `prelude`; a local class's wrapper binding is emitted after its declaration instead.
336
+ *
337
+ * Returns `undefined` when the specifier can stay exactly as written: it doesn't name a configured
338
+ * class, or the binding is already hand-wrapped.
339
+ */
288
340
  function wrapSpecifier(specifier, sourceLiteral, ctx, state, prelude) {
289
- const exportedName = specifier.type === "ExportSpecifier" && specifier.exported?.type === "Identifier" ? specifier.exported.name : void 0;
290
- const localName = specifier.local?.type === "Identifier" ? specifier.local.name : void 0;
291
- const kind = exportedName ? resolveWrapperKind(exportedName, sourceLiteral ? void 0 : localName, state) : void 0;
292
- if (!exportedName || !localName) return void 0;
293
- if (!kind) {
294
- if (exportedName !== DEFAULT_IMPORT) return void 0;
295
- return sourceLiteral ? wrapDefaultReexport(localName, sourceLiteral, state, prelude) : wrapDefaultSpecifier(localName, state);
296
- }
297
- if (!sourceLiteral) {
298
- const localClass = state.topLevelClasses.get(localName);
299
- if (localClass?.id) {
300
- const wrappedName2 = wrapLocalClass(localName, localClass, kind, state);
301
- state.wrappedClasses.add(exportedName);
302
- return `${wrappedName2} as ${exportedName}`;
303
- }
304
- if (state.manuallyWrappedLocals.has(localName)) {
305
- state.wrappedClasses.add(exportedName);
306
- return void 0;
307
- }
308
- }
309
- let target = localName;
310
- if (sourceLiteral) {
311
- target = `__SENTRY_REEXPORT_${exportedName}__`;
312
- prelude.push(
313
- localName === DEFAULT_IMPORT ? `import ${target} from ${sourceLiteral};` : `import { ${localName} as ${target} } from ${sourceLiteral};`
314
- );
315
- }
316
- const wrappedName = `__SENTRY_WRAPPED_${exportedName}__`;
317
- prelude.push(
318
- `const ${wrappedName} = __SENTRY__._INTERNAL_wrapUnlessInstrumented(__SENTRY__.${WRAPPER_METHODS[kind]}, ${state.optionsFn}, ${target});`
319
- );
320
- state.wrappedClasses.add(exportedName);
321
- state.autoWrapped.add(exportedName);
322
- state.needsImport = true;
323
- return `${wrappedName} as ${exportedName}`;
341
+ const exportedName = specifier.type === "ExportSpecifier" && specifier.exported?.type === "Identifier" ? specifier.exported.name : void 0;
342
+ const localName = specifier.local?.type === "Identifier" ? specifier.local.name : void 0;
343
+ const kind = exportedName ? resolveWrapperKind(exportedName, sourceLiteral ? void 0 : localName, state) : void 0;
344
+ if (!exportedName || !localName) return void 0;
345
+ if (!kind) {
346
+ if (exportedName !== DEFAULT_IMPORT) return void 0;
347
+ return sourceLiteral ? wrapDefaultReexport(localName, sourceLiteral, state, prelude) : wrapDefaultSpecifier(localName, state);
348
+ }
349
+ if (!sourceLiteral) {
350
+ const localClass = state.topLevelClasses.get(localName);
351
+ if (localClass?.id) {
352
+ const wrappedName = wrapLocalClass(localName, localClass, kind, state);
353
+ state.wrappedClasses.add(exportedName);
354
+ return `${wrappedName} as ${exportedName}`;
355
+ }
356
+ if (state.manuallyWrappedLocals.has(localName)) {
357
+ state.wrappedClasses.add(exportedName);
358
+ return;
359
+ }
360
+ }
361
+ let target = localName;
362
+ if (sourceLiteral) {
363
+ target = `__SENTRY_REEXPORT_${exportedName}__`;
364
+ prelude.push(localName === DEFAULT_IMPORT ? `import ${target} from ${sourceLiteral};` : `import { ${localName} as ${target} } from ${sourceLiteral};`);
365
+ }
366
+ const wrappedName = `__SENTRY_WRAPPED_${exportedName}__`;
367
+ prelude.push(`const ${wrappedName} = __SENTRY__._INTERNAL_wrapUnlessInstrumented(__SENTRY__.${WRAPPER_METHODS[kind]}, ${state.optionsFn}, ${target});`);
368
+ state.wrappedClasses.add(exportedName);
369
+ state.autoWrapped.add(exportedName);
370
+ state.needsImport = true;
371
+ return `${wrappedName} as ${exportedName}`;
324
372
  }
325
-
326
373
  exports.applyAutoInstrumentTransforms = applyAutoInstrumentTransforms;
327
- //# sourceMappingURL=transform.js.map
374
+
375
+ //# sourceMappingURL=transform.js.map