@sentry/cloudflare 10.67.0 → 10.69.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 (170) hide show
  1. package/build/cjs/client.js +5 -0
  2. package/build/cjs/client.js.map +1 -1
  3. package/build/cjs/defineCloudflareOptions.js +11 -0
  4. package/build/cjs/defineCloudflareOptions.js.map +1 -0
  5. package/build/cjs/durableobject.js +131 -96
  6. package/build/cjs/durableobject.js.map +1 -1
  7. package/build/cjs/index.js +6 -0
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/instrumentations/agents/index.js +14 -0
  10. package/build/cjs/instrumentations/agents/index.js.map +1 -0
  11. package/build/cjs/instrumentations/agents/instrumentAgentCallableRpc.js +52 -0
  12. package/build/cjs/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -0
  13. package/build/cjs/instrumentations/agents/instrumentChatAgentConversation.js +31 -0
  14. package/build/cjs/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -0
  15. package/build/cjs/instrumentations/agents/types.js +32 -0
  16. package/build/cjs/instrumentations/agents/types.js.map +1 -0
  17. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js +6 -0
  18. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  19. package/build/cjs/instrumentations/instrumentSqlStorage.js +1 -1
  20. package/build/cjs/instrumentations/instrumentSqlStorage.js.map +1 -1
  21. package/build/cjs/integrations/spotlight.js +64 -0
  22. package/build/cjs/integrations/spotlight.js.map +1 -0
  23. package/build/cjs/integrations/tracing/vercelai.js.map +1 -1
  24. package/build/cjs/nodejs_compat/index.js +10 -4
  25. package/build/cjs/nodejs_compat/index.js.map +1 -1
  26. package/build/cjs/nodejs_compat/integrations/tracing/vercelai.js.map +1 -1
  27. package/build/cjs/options.js +14 -1
  28. package/build/cjs/options.js.map +1 -1
  29. package/build/cjs/sdk.js +20 -1
  30. package/build/cjs/sdk.js.map +1 -1
  31. package/build/cjs/utils/internalSqlQuery.js +13 -7
  32. package/build/cjs/utils/internalSqlQuery.js.map +1 -1
  33. package/build/cjs/utils/internalStorageKey.js +44 -0
  34. package/build/cjs/utils/internalStorageKey.js.map +1 -0
  35. package/build/cjs/vite/agentClass.js +114 -0
  36. package/build/cjs/vite/agentClass.js.map +1 -0
  37. package/build/cjs/vite/autoInstrument.js +94 -0
  38. package/build/cjs/vite/autoInstrument.js.map +1 -0
  39. package/build/cjs/vite/index.js +14 -0
  40. package/build/cjs/vite/index.js.map +1 -0
  41. package/build/cjs/vite/instrumentFile.js +31 -0
  42. package/build/cjs/vite/instrumentFile.js.map +1 -0
  43. package/build/cjs/vite/moduleShape.js +231 -0
  44. package/build/cjs/vite/moduleShape.js.map +1 -0
  45. package/build/cjs/vite/transform.js +149 -0
  46. package/build/cjs/vite/transform.js.map +1 -0
  47. package/build/cjs/vite/workerEntrypoint.js +66 -0
  48. package/build/cjs/vite/workerEntrypoint.js.map +1 -0
  49. package/build/cjs/vite/wranglerConfig.js +54 -0
  50. package/build/cjs/vite/wranglerConfig.js.map +1 -0
  51. package/build/esm/client.js +6 -1
  52. package/build/esm/client.js.map +1 -1
  53. package/build/esm/defineCloudflareOptions.js +9 -0
  54. package/build/esm/defineCloudflareOptions.js.map +1 -0
  55. package/build/esm/durableobject.js +129 -97
  56. package/build/esm/durableobject.js.map +1 -1
  57. package/build/esm/index.js +4 -2
  58. package/build/esm/index.js.map +1 -1
  59. package/build/esm/instrumentations/agents/index.js +12 -0
  60. package/build/esm/instrumentations/agents/index.js.map +1 -0
  61. package/build/esm/instrumentations/agents/instrumentAgentCallableRpc.js +50 -0
  62. package/build/esm/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -0
  63. package/build/esm/instrumentations/agents/instrumentChatAgentConversation.js +29 -0
  64. package/build/esm/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -0
  65. package/build/esm/instrumentations/agents/types.js +26 -0
  66. package/build/esm/instrumentations/agents/types.js.map +1 -0
  67. package/build/esm/instrumentations/instrumentDurableObjectStorage.js +7 -1
  68. package/build/esm/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  69. package/build/esm/instrumentations/instrumentSqlStorage.js +1 -1
  70. package/build/esm/instrumentations/instrumentSqlStorage.js.map +1 -1
  71. package/build/esm/integrations/spotlight.js +61 -0
  72. package/build/esm/integrations/spotlight.js.map +1 -0
  73. package/build/esm/integrations/tracing/vercelai.js.map +1 -1
  74. package/build/esm/nodejs_compat/index.js +5 -3
  75. package/build/esm/nodejs_compat/index.js.map +1 -1
  76. package/build/esm/nodejs_compat/integrations/tracing/vercelai.js.map +1 -1
  77. package/build/esm/options.js +14 -1
  78. package/build/esm/options.js.map +1 -1
  79. package/build/esm/package.json +1 -1
  80. package/build/esm/sdk.js +21 -2
  81. package/build/esm/sdk.js.map +1 -1
  82. package/build/esm/utils/internalSqlQuery.js +13 -7
  83. package/build/esm/utils/internalSqlQuery.js.map +1 -1
  84. package/build/esm/utils/internalStorageKey.js +41 -0
  85. package/build/esm/utils/internalStorageKey.js.map +1 -0
  86. package/build/esm/utils/traceLinks.js +1 -1
  87. package/build/esm/vite/agentClass.js +111 -0
  88. package/build/esm/vite/agentClass.js.map +1 -0
  89. package/build/esm/vite/autoInstrument.js +92 -0
  90. package/build/esm/vite/autoInstrument.js.map +1 -0
  91. package/build/esm/vite/index.js +12 -0
  92. package/build/esm/vite/index.js.map +1 -0
  93. package/build/esm/vite/instrumentFile.js +27 -0
  94. package/build/esm/vite/instrumentFile.js.map +1 -0
  95. package/build/esm/vite/moduleShape.js +227 -0
  96. package/build/esm/vite/moduleShape.js.map +1 -0
  97. package/build/esm/vite/transform.js +147 -0
  98. package/build/esm/vite/transform.js.map +1 -0
  99. package/build/esm/vite/workerEntrypoint.js +64 -0
  100. package/build/esm/vite/workerEntrypoint.js.map +1 -0
  101. package/build/esm/vite/wranglerConfig.js +52 -0
  102. package/build/esm/vite/wranglerConfig.js.map +1 -0
  103. package/build/types/client.d.ts +37 -0
  104. package/build/types/client.d.ts.map +1 -1
  105. package/build/types/defineCloudflareOptions.d.ts +38 -0
  106. package/build/types/defineCloudflareOptions.d.ts.map +1 -0
  107. package/build/types/durableobject.d.ts +81 -0
  108. package/build/types/durableobject.d.ts.map +1 -1
  109. package/build/types/index.d.ts +4 -2
  110. package/build/types/index.d.ts.map +1 -1
  111. package/build/types/instrumentations/agents/index.d.ts +24 -0
  112. package/build/types/instrumentations/agents/index.d.ts.map +1 -0
  113. package/build/types/instrumentations/agents/instrumentAgentCallableRpc.d.ts +11 -0
  114. package/build/types/instrumentations/agents/instrumentAgentCallableRpc.d.ts.map +1 -0
  115. package/build/types/instrumentations/agents/instrumentChatAgentConversation.d.ts +22 -0
  116. package/build/types/instrumentations/agents/instrumentChatAgentConversation.d.ts.map +1 -0
  117. package/build/types/instrumentations/agents/types.d.ts +49 -0
  118. package/build/types/instrumentations/agents/types.d.ts.map +1 -0
  119. package/build/types/instrumentations/instrumentDurableObjectStorage.d.ts.map +1 -1
  120. package/build/types/integrations/spotlight.d.ts +22 -0
  121. package/build/types/integrations/spotlight.d.ts.map +1 -0
  122. package/build/types/integrations/tracing/vercelai.d.ts.map +1 -1
  123. package/build/types/nodejs_compat/index.d.ts +1 -1
  124. package/build/types/nodejs_compat/index.d.ts.map +1 -1
  125. package/build/types/nodejs_compat/integrations/tracing/vercelai.d.ts +1 -8
  126. package/build/types/nodejs_compat/integrations/tracing/vercelai.d.ts.map +1 -1
  127. package/build/types/options.d.ts.map +1 -1
  128. package/build/types/sdk.d.ts.map +1 -1
  129. package/build/types/utils/internalSqlQuery.d.ts +4 -2
  130. package/build/types/utils/internalSqlQuery.d.ts.map +1 -1
  131. package/build/types/utils/internalStorageKey.d.ts +22 -0
  132. package/build/types/utils/internalStorageKey.d.ts.map +1 -0
  133. package/build/types/vite/agentClass.d.ts +41 -0
  134. package/build/types/vite/agentClass.d.ts.map +1 -0
  135. package/build/types/vite/autoInstrument.d.ts +22 -0
  136. package/build/types/vite/autoInstrument.d.ts.map +1 -0
  137. package/build/types/vite/index.d.ts +98 -0
  138. package/build/types/vite/index.d.ts.map +1 -0
  139. package/build/types/vite/instrumentFile.d.ts +22 -0
  140. package/build/types/vite/instrumentFile.d.ts.map +1 -0
  141. package/build/types/vite/moduleShape.d.ts +52 -0
  142. package/build/types/vite/moduleShape.d.ts.map +1 -0
  143. package/build/types/vite/transform.d.ts +65 -0
  144. package/build/types/vite/transform.d.ts.map +1 -0
  145. package/build/types/vite/workerEntrypoint.d.ts +12 -0
  146. package/build/types/vite/workerEntrypoint.d.ts.map +1 -0
  147. package/build/types/vite/wranglerConfig.d.ts +43 -0
  148. package/build/types/vite/wranglerConfig.d.ts.map +1 -0
  149. package/build/types-ts3.8/client.d.ts +37 -0
  150. package/build/types-ts3.8/defineCloudflareOptions.d.ts +38 -0
  151. package/build/types-ts3.8/durableobject.d.ts +81 -0
  152. package/build/types-ts3.8/index.d.ts +4 -2
  153. package/build/types-ts3.8/instrumentations/agents/index.d.ts +24 -0
  154. package/build/types-ts3.8/instrumentations/agents/instrumentAgentCallableRpc.d.ts +11 -0
  155. package/build/types-ts3.8/instrumentations/agents/instrumentChatAgentConversation.d.ts +22 -0
  156. package/build/types-ts3.8/instrumentations/agents/types.d.ts +49 -0
  157. package/build/types-ts3.8/integrations/spotlight.d.ts +22 -0
  158. package/build/types-ts3.8/nodejs_compat/index.d.ts +1 -1
  159. package/build/types-ts3.8/nodejs_compat/integrations/tracing/vercelai.d.ts +7 -14
  160. package/build/types-ts3.8/utils/internalSqlQuery.d.ts +4 -2
  161. package/build/types-ts3.8/utils/internalStorageKey.d.ts +22 -0
  162. package/build/types-ts3.8/vite/agentClass.d.ts +41 -0
  163. package/build/types-ts3.8/vite/autoInstrument.d.ts +22 -0
  164. package/build/types-ts3.8/vite/index.d.ts +98 -0
  165. package/build/types-ts3.8/vite/instrumentFile.d.ts +22 -0
  166. package/build/types-ts3.8/vite/moduleShape.d.ts +52 -0
  167. package/build/types-ts3.8/vite/transform.d.ts +65 -0
  168. package/build/types-ts3.8/vite/workerEntrypoint.d.ts +12 -0
  169. package/build/types-ts3.8/vite/wranglerConfig.d.ts +43 -0
  170. package/package.json +19 -5
@@ -0,0 +1,149 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const MagicString = require('magic-string');
4
+ const workerEntrypoint = require('./workerEntrypoint.js');
5
+
6
+ function isCallToMethod(node, methodName) {
7
+ if (node.type !== "CallExpression") return false;
8
+ const callee = node.callee;
9
+ if (!callee) return false;
10
+ if (callee.type === "Identifier" && callee.name === methodName) return true;
11
+ return callee.type === "MemberExpression" && callee.property?.type === "Identifier" && callee.property.name === methodName;
12
+ }
13
+ const WRAPPER_METHODS = {
14
+ durableObject: "instrumentDurableObjectWithSentry",
15
+ agent: "instrumentAgentWithSentry",
16
+ workflow: "instrumentWorkflowWithSentry",
17
+ workerEntrypoint: "withSentry"
18
+ };
19
+ function applyAutoInstrumentTransforms(code, ast, ctx) {
20
+ const ms = new MagicString.default(code);
21
+ const topLevelClasses = collectTopLevelClasses(ast);
22
+ const state = {
23
+ ms,
24
+ needsImport: false,
25
+ wrappedClasses: /* @__PURE__ */ new Set(),
26
+ topLevelClasses,
27
+ renamedLocals: /* @__PURE__ */ new Set(),
28
+ classWrappers: ctx.classWrappers,
29
+ agentClasses: ctx.agentClasses ?? /* @__PURE__ */ new Set(),
30
+ workerEntrypointClasses: workerEntrypoint.detectWorkerEntrypointClasses(ast)
31
+ };
32
+ const { wrappedClasses } = state;
33
+ for (const node of ast.body) {
34
+ if (node.type === "ExportNamedDeclaration") {
35
+ handleNamedExport(node, ctx, state);
36
+ }
37
+ }
38
+ for (const node of ast.body) {
39
+ if (node.type === "ExportDefaultDeclaration") {
40
+ wrapDefaultExport(node, ctx, state);
41
+ }
42
+ }
43
+ if (!state.needsImport) {
44
+ if (wrappedClasses.size === 0) return void 0;
45
+ return { code, map: ms.generateMap({ hires: true }), wrappedClasses };
46
+ }
47
+ if (ctx.optionsImport) ms.prepend(ctx.optionsImport);
48
+ ms.prepend("import * as __SENTRY__ from '@sentry/cloudflare';\n");
49
+ return {
50
+ code: ms.toString(),
51
+ map: ms.generateMap({ hires: true }),
52
+ wrappedClasses
53
+ };
54
+ }
55
+ function resolveWrapperKind(exportedName, localName, state) {
56
+ const configured = state.classWrappers.get(exportedName);
57
+ if (configured === "durableObject" && localName && state.agentClasses.has(localName)) return "agent";
58
+ if (configured) return configured;
59
+ if (localName && state.workerEntrypointClasses.has(localName)) return "workerEntrypoint";
60
+ return void 0;
61
+ }
62
+ function collectTopLevelClasses(ast) {
63
+ const classes = /* @__PURE__ */ new Map();
64
+ for (const node of ast.body) {
65
+ if (node.type !== "ClassDeclaration") continue;
66
+ const classNode = node;
67
+ if (classNode.id?.name) classes.set(classNode.id.name, classNode);
68
+ }
69
+ return classes;
70
+ }
71
+ function wrapDefaultExport(node, ctx, state) {
72
+ const decl = node.declaration;
73
+ if (isCallToMethod(decl, "withSentry")) return;
74
+ if (decl.type === "Identifier" && state.renamedLocals.has(decl.name)) return;
75
+ state.ms.overwrite(node.start, decl.start, "const __SENTRY_DEFAULT_EXPORT__ = ");
76
+ state.ms.append(`
77
+ export default __SENTRY__.withSentry(${ctx.optionsFn}, __SENTRY_DEFAULT_EXPORT__);
78
+ `);
79
+ state.needsImport = true;
80
+ }
81
+ function handleNamedExport(node, ctx, state) {
82
+ const decl = node.declaration;
83
+ if (decl?.type === "VariableDeclaration") {
84
+ collectManuallyWrappedClassExports(decl, ctx, state);
85
+ return;
86
+ }
87
+ if (decl?.type === "ClassDeclaration") {
88
+ wrapInlineClassExport(node, decl, ctx, state);
89
+ return;
90
+ }
91
+ if (node.source) return;
92
+ for (const specifier of node.specifiers ?? []) {
93
+ wrapSpecifierExport(specifier, ctx, state);
94
+ }
95
+ }
96
+ function collectManuallyWrappedClassExports(varDecl, ctx, state) {
97
+ for (const declarator of varDecl.declarations ?? []) {
98
+ const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
99
+ const kind = name ? ctx.classWrappers.get(name) : void 0;
100
+ if (!name || !kind || !declarator.init) continue;
101
+ const accepted = kind === "durableObject" ? [WRAPPER_METHODS.durableObject, WRAPPER_METHODS.agent] : [WRAPPER_METHODS[kind]];
102
+ if (accepted.some((method) => isCallToMethod(declarator.init, method))) {
103
+ state.wrappedClasses.add(name);
104
+ }
105
+ }
106
+ }
107
+ function wrapInlineClassExport(exportNode, classDecl, ctx, state) {
108
+ const classId = classDecl.id;
109
+ const kind = classId ? resolveWrapperKind(classId.name, classId.name, state) : void 0;
110
+ if (!classId || !kind) return;
111
+ const className = classId.name;
112
+ const renamedClass = `__SENTRY_ORIGINAL_${className}__`;
113
+ state.ms.overwrite(exportNode.start, classDecl.start, "");
114
+ state.ms.overwrite(classId.start, classId.end, renamedClass);
115
+ state.ms.appendLeft(
116
+ exportNode.end,
117
+ `
118
+ export const ${className} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});
119
+ `
120
+ );
121
+ state.wrappedClasses.add(className);
122
+ state.renamedLocals.add(className);
123
+ state.needsImport = true;
124
+ }
125
+ function wrapSpecifierExport(specifier, ctx, state) {
126
+ if (specifier.type !== "ExportSpecifier" || specifier.exported?.type !== "Identifier") return;
127
+ const exportedName = specifier.exported.name;
128
+ if (!exportedName) return;
129
+ const localName = specifier.local?.type === "Identifier" ? specifier.local.name : void 0;
130
+ const kind = resolveWrapperKind(exportedName, localName, state);
131
+ if (!kind) return;
132
+ const localClass = localName ? state.topLevelClasses.get(localName) : void 0;
133
+ if (!localName || !localClass?.id) return;
134
+ state.wrappedClasses.add(exportedName);
135
+ state.needsImport = true;
136
+ if (state.renamedLocals.has(localName)) return;
137
+ state.renamedLocals.add(localName);
138
+ const renamedClass = `__SENTRY_ORIGINAL_${localName}__`;
139
+ state.ms.overwrite(localClass.id.start, localClass.id.end, renamedClass);
140
+ state.ms.appendLeft(
141
+ localClass.end,
142
+ `
143
+ const ${localName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});
144
+ `
145
+ );
146
+ }
147
+
148
+ exports.applyAutoInstrumentTransforms = applyAutoInstrumentTransforms;
149
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sources":["../../../src/vite/transform.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport { detectWorkerEntrypointClasses } from './workerEntrypoint';\n\n// ---------------------------------------------------------------------------\n// Minimal ESTree node types for the AST nodes we inspect.\n// ---------------------------------------------------------------------------\n\nexport interface BaseNode {\n type: string;\n start: number;\n end: number;\n}\n\nexport interface ProgramBody {\n body: BaseNode[];\n}\n\ninterface IdentifierNode extends BaseNode {\n name: string;\n}\n\ninterface CalleeNode {\n type: string;\n name?: string;\n property?: { type: string; name?: string };\n}\n\ninterface CallExpressionNode extends BaseNode {\n callee?: CalleeNode;\n}\n\ninterface ClassDeclarationNode extends BaseNode {\n id?: IdentifierNode | null;\n}\n\ninterface ExportDefaultNode extends BaseNode {\n declaration: BaseNode;\n}\n\ninterface ExportSpecifierNode {\n type: string;\n local?: { type: string; name?: string };\n exported?: { type: string; name?: string };\n}\n\ninterface ExportNamedNode extends BaseNode {\n declaration?: BaseNode | null;\n source?: unknown;\n specifiers?: ExportSpecifierNode[];\n}\n\ninterface VariableDeclaratorNode {\n id?: { type: string; name?: string };\n init?: BaseNode | null;\n}\n\ninterface VariableDeclarationNode extends BaseNode {\n declarations?: VariableDeclaratorNode[];\n}\n\nfunction isCallToMethod(node: BaseNode, methodName: string): boolean {\n if (node.type !== 'CallExpression') return false;\n const callee = (node as CallExpressionNode).callee;\n if (!callee) return false;\n if (callee.type === 'Identifier' && callee.name === methodName) return true;\n return (\n callee.type === 'MemberExpression' && callee.property?.type === 'Identifier' && callee.property.name === methodName\n );\n}\n\n/**\n * The kind of Sentry wrapper to apply to an exported class.\n *\n * `durableObject` and `workflow` are keyed by name from the wrangler config\n * (`durable_objects.bindings`, `workflows`), since those class names are\n * authoritative there. `workerEntrypoint` is different: a worker's own\n * entrypoints aren't enumerated in its config, so they're detected structurally\n * (a class extending `WorkerEntrypoint` from `cloudflare:workers`), with the\n * config providing only a fallback for self-bound entrypoints whose base class\n * lives in another module.\n */\nexport type ClassWrapperKind = 'durableObject' | 'agent' | 'workflow' | 'workerEntrypoint';\n\n/**\n * The `@sentry/cloudflare` helper each wrapper kind emits. All share the same\n * `(optionsCallback, Class)` signature. `WorkerEntrypoint` classes use\n * `withSentry`, which runtime-detects the class type and routes accordingly.\n */\nconst WRAPPER_METHODS: Record<ClassWrapperKind, string> = {\n durableObject: 'instrumentDurableObjectWithSentry',\n agent: 'instrumentAgentWithSentry',\n workflow: 'instrumentWorkflowWithSentry',\n workerEntrypoint: 'withSentry',\n};\n\nexport interface TransformContext {\n /**\n * Exported class name → the kind of Sentry wrapper to apply. Populated from\n * the wrangler config, so the transform can wrap by name without resolving\n * each class's base type.\n */\n classWrappers: Map<string, ClassWrapperKind>;\n /**\n * Local class names detected as `agents` Agents. An Agent is configured as a Durable Object in\n * wrangler, so this upgrades those entries from `durableObject` to `agent`.\n */\n agentClasses?: ReadonlySet<string>;\n optionsFn: string;\n /** Import statement prepended when `optionsFn` references a separate module. */\n optionsImport?: string;\n}\n\nexport interface TransformResult {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n /**\n * The configured class names that were actually wrapped. Lets the plugin warn\n * about configured classes it could not find, instead of silently leaving\n * them uninstrumented.\n */\n wrappedClasses: Set<string>;\n}\n\n/**\n * Rewrite the worker entry source to wrap its default export with `withSentry`\n * and any configured class export with its matching Sentry wrapper (see\n * {@link TransformContext.classWrappers}, e.g. Durable Object classes with\n * `instrumentDurableObjectWithSentry`).\n *\n * Handles both `export class MyDO {}` and the specifier form\n * (`class MyDO {}` … `export { MyDO }` / `export { Foo as MyDO }`).\n * Re-exports from other modules (`export { MyDO } from './do'`) cannot be\n * wrapped here and are left alone — the plugin warns about them via\n * {@link TransformResult.wrappedClasses}.\n *\n * Exported (rather than inlined into the plugin) so it can be unit-tested with a\n * plain AST and no Vite context. Returns `undefined` when nothing was wrapped and\n * there are no already-manually-wrapped classes to report.\n */\nexport function applyAutoInstrumentTransforms(\n code: string,\n ast: ProgramBody,\n ctx: TransformContext,\n): TransformResult | undefined {\n const ms = new MagicString(code);\n const topLevelClasses = collectTopLevelClasses(ast);\n const state: TransformState = {\n ms,\n needsImport: false,\n wrappedClasses: new Set<string>(),\n topLevelClasses,\n renamedLocals: new Set<string>(),\n classWrappers: ctx.classWrappers,\n agentClasses: ctx.agentClasses ?? new Set<string>(),\n workerEntrypointClasses: detectWorkerEntrypointClasses(ast),\n };\n const { wrappedClasses } = state;\n\n // Named exports first, regardless of source order: the default-export handler\n // needs to know which local bindings a named export already wrapped, so it can\n // skip a class that is both exported by name and re-exported as default (which\n // would otherwise wrap it twice).\n for (const node of ast.body) {\n if (node.type === 'ExportNamedDeclaration') {\n handleNamedExport(node as ExportNamedNode, ctx, state);\n }\n }\n for (const node of ast.body) {\n if (node.type === 'ExportDefaultDeclaration') {\n wrapDefaultExport(node as ExportDefaultNode, ctx, state);\n }\n }\n\n if (!state.needsImport) {\n // Nothing was rewritten. Still surface any classes found already wrapped\n // manually (via `wrappedClasses`) so the caller doesn't warn about them;\n // return undefined only when there was nothing to report either.\n if (wrappedClasses.size === 0) return undefined;\n return { code, map: ms.generateMap({ hires: true }), wrappedClasses };\n }\n\n if (ctx.optionsImport) ms.prepend(ctx.optionsImport);\n ms.prepend(\"import * as __SENTRY__ from '@sentry/cloudflare';\\n\");\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: true }),\n wrappedClasses,\n };\n}\n\ninterface TransformState {\n ms: MagicString;\n needsImport: boolean;\n wrappedClasses: Set<string>;\n /**\n * Top-level (non-exported) class declarations, so specifier exports like\n * `export { MyDO }` can locate the class they refer to.\n */\n topLevelClasses: Map<string, ClassDeclarationNode>;\n /**\n * Local class names already renamed + wrapped, so two specifiers pointing at\n * the same class don't produce duplicate bindings.\n */\n renamedLocals: Set<string>;\n /** Class name → wrapper kind, keyed by the *exported* name (from config). */\n classWrappers: Map<string, ClassWrapperKind>;\n /** Local class names detected as `agents` Agents (see {@link TransformContext.agentClasses}). */\n agentClasses: ReadonlySet<string>;\n /**\n * Local class names detected as `WorkerEntrypoint` subclasses in this module,\n * so they can be wrapped without a config entry.\n */\n workerEntrypointClasses: Set<string>;\n}\n\n/**\n * Resolve the wrapper kind for a class export.\n *\n * Config (`classWrappers`) wins — it's authoritative for Durable Objects and\n * Workflows, and provides the self-binding fallback for WorkerEntrypoints whose\n * base class this module can't see. Otherwise a structurally-detected\n * `WorkerEntrypoint` subclass (matched by its *local* name) gets wrapped with\n * `withSentry`.\n *\n * The one case where config is refined rather than obeyed is an `agents` Agent:\n * it *is* a Durable Object, so wrangler can only ever describe it as one, and\n * only the detected base chain distinguishes the two.\n */\nfunction resolveWrapperKind(\n exportedName: string,\n localName: string | undefined,\n state: TransformState,\n): ClassWrapperKind | undefined {\n const configured = state.classWrappers.get(exportedName);\n if (configured === 'durableObject' && localName && state.agentClasses.has(localName)) return 'agent';\n if (configured) return configured;\n if (localName && state.workerEntrypointClasses.has(localName)) return 'workerEntrypoint';\n return undefined;\n}\n\nfunction collectTopLevelClasses(ast: ProgramBody): Map<string, ClassDeclarationNode> {\n const classes = new Map<string, ClassDeclarationNode>();\n for (const node of ast.body) {\n if (node.type !== 'ClassDeclaration') continue;\n const classNode = node as ClassDeclarationNode;\n if (classNode.id?.name) classes.set(classNode.id.name, classNode);\n }\n return classes;\n}\n\nfunction wrapDefaultExport(node: ExportDefaultNode, ctx: TransformContext, state: TransformState): void {\n const decl = node.declaration;\n\n // Already wrapped — leave it alone\n if (isCallToMethod(decl, 'withSentry')) return;\n\n // `export default Foo` where `Foo` is a local class already wrapped by a named\n // export (e.g. a self-bound WorkerEntrypoint also used as the default handler).\n // Wrapping again would produce `withSentry(withSentry(...))`.\n if (decl.type === 'Identifier' && state.renamedLocals.has((decl as IdentifierNode).name)) return;\n\n // `export default <expr>` → `const __SENTRY_DEFAULT_EXPORT__ = <expr>`\n // MagicString positions are always relative to the original source.\n state.ms.overwrite(node.start, decl.start, 'const __SENTRY_DEFAULT_EXPORT__ = ');\n state.ms.append(`\\nexport default __SENTRY__.withSentry(${ctx.optionsFn}, __SENTRY_DEFAULT_EXPORT__);\\n`);\n state.needsImport = true;\n}\n\nfunction handleNamedExport(node: ExportNamedNode, ctx: TransformContext, state: TransformState): void {\n const decl = node.declaration;\n\n // ---- Manually wrapped class export ----\n // `export const MyDO = instrumentDurableObjectWithSentry(...)` — count it\n // as wrapped so the plugin doesn't warn about it, but leave it alone.\n if (decl?.type === 'VariableDeclaration') {\n collectManuallyWrappedClassExports(decl as VariableDeclarationNode, ctx, state);\n return;\n }\n\n // ---- Named class export matching a configured binding ----\n if (decl?.type === 'ClassDeclaration') {\n wrapInlineClassExport(node, decl as ClassDeclarationNode, ctx, state);\n return;\n }\n\n // ---- Specifier export of a local class (`export { Foo as MyDO }`) ----\n // Re-exports from another module carry a `source` — nothing local to wrap.\n if (node.source) return;\n for (const specifier of node.specifiers ?? []) {\n wrapSpecifierExport(specifier, ctx, state);\n }\n}\n\nfunction collectManuallyWrappedClassExports(\n varDecl: VariableDeclarationNode,\n ctx: TransformContext,\n state: TransformState,\n): void {\n for (const declarator of varDecl.declarations ?? []) {\n const name = declarator.id?.type === 'Identifier' ? declarator.id.name : undefined;\n const kind = name ? ctx.classWrappers.get(name) : undefined;\n if (!name || !kind || !declarator.init) continue;\n\n // A hand-wrapped Agent is configured as a Durable Object, so accept either helper there —\n // otherwise an already-instrumented Agent would be reported as unwrapped.\n const accepted =\n kind === 'durableObject' ? [WRAPPER_METHODS.durableObject, WRAPPER_METHODS.agent] : [WRAPPER_METHODS[kind]];\n\n if (accepted.some(method => isCallToMethod(declarator.init as BaseNode, method))) {\n state.wrappedClasses.add(name);\n }\n }\n}\n\nfunction wrapInlineClassExport(\n exportNode: ExportNamedNode,\n classDecl: ClassDeclarationNode,\n ctx: TransformContext,\n state: TransformState,\n): void {\n const classId = classDecl.id;\n // Inline export: the exported name and the local class name are the same.\n const kind = classId ? resolveWrapperKind(classId.name, classId.name, state) : undefined;\n if (!classId || !kind) return;\n\n const className = classId.name;\n const renamedClass = `__SENTRY_ORIGINAL_${className}__`;\n\n // Strip the `export ` keyword\n state.ms.overwrite(exportNode.start, classDecl.start, '');\n\n // Rename the class to avoid a duplicate binding\n state.ms.overwrite(classId.start, classId.end, renamedClass);\n\n // Insert the wrapped re-export after the class body\n state.ms.appendLeft(\n exportNode.end,\n `\\nexport const ${className} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});\\n`,\n );\n\n state.wrappedClasses.add(className);\n state.renamedLocals.add(className);\n state.needsImport = true;\n}\n\nfunction wrapSpecifierExport(specifier: ExportSpecifierNode, ctx: TransformContext, state: TransformState): void {\n if (specifier.type !== 'ExportSpecifier' || specifier.exported?.type !== 'Identifier') return;\n const exportedName = specifier.exported.name;\n if (!exportedName) return;\n\n const localName = specifier.local?.type === 'Identifier' ? specifier.local.name : undefined;\n const kind = resolveWrapperKind(exportedName, localName, state);\n if (!kind) return;\n\n const localClass = localName ? state.topLevelClasses.get(localName) : undefined;\n if (!localName || !localClass?.id) return;\n\n state.wrappedClasses.add(exportedName);\n state.needsImport = true;\n if (state.renamedLocals.has(localName)) return;\n state.renamedLocals.add(localName);\n\n const renamedClass = `__SENTRY_ORIGINAL_${localName}__`;\n state.ms.overwrite(localClass.id.start, localClass.id.end, renamedClass);\n // The existing `export { ... }` statement keeps exporting the (now\n // wrapped) `localName` binding, so the wrapper is NOT exported here.\n state.ms.appendLeft(\n localClass.end,\n `\\nconst ${localName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${ctx.optionsFn}, ${renamedClass});\\n`,\n );\n}\n"],"names":["MagicString","detectWorkerEntrypointClasses"],"mappings":";;;;;AA4DA,SAAS,cAAA,CAAe,MAAgB,UAAA,EAA6B;AACnE,EAAA,I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AAA,GAAI,MAAA;AACtE,EAAA,IAAI,CAAC,SAAA,IAAa,CAAC,UAAA,EAAY,EAAA,EAAI;AAEnC,EAAA,KAAA,CAAM,cAAA,CAAe,IAAI,YAAY,CAAA;AACrC,EAAA,KAAA,CAAM,WAAA,GAAc,IAAA;AACpB,EAAA,IAAI,KAAA,CAAM,aAAA,CAAc,GAAA,CAAI,SAAS,CAAA,EAAG;AACxC,EAAA,KAAA,CAAM,aAAA,CAAc,IAAI,SAAS,CAAA;AAEjC,EAAA,MAAM,YAAA,GAAe,qBAAqB,SAAS,CAAA,EAAA,CAAA;AACnD,EAAA,KAAA,CAAM,EAAA,CAAG,UAAU,UAAA,CAAW,EAAA,CAAG,OAAO,UAAA,CAAW,EAAA,CAAG,KAAK,YAAY,CAAA;AAGvE,EAAA,KAAA,CAAM,EAAA,CAAG,UAAA;AAAA,IACP,UAAA,CAAW,GAAA;AAAA,IACX;AAAA,MAAA,EAAW,SAAS,iBAAiB,eAAA,CAAgB,IAAI,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,SAAS,CAAA,EAAA,EAAK,YAAY,CAAA;AAAA;AAAA,GAC9F;AACF;;;;"}
@@ -0,0 +1,66 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ function detectWorkerEntrypointClasses(ast) {
4
+ const bases = collectWorkerEntrypointImports(ast);
5
+ if (bases.named.size === 0 && bases.namespaces.size === 0) {
6
+ return /* @__PURE__ */ new Set();
7
+ }
8
+ const classes = /* @__PURE__ */ new Map();
9
+ for (const node of ast.body) {
10
+ const classNode = asClassDeclaration(node);
11
+ if (classNode?.id?.name) classes.set(classNode.id.name, classNode);
12
+ }
13
+ const entrypoints = /* @__PURE__ */ new Set();
14
+ let changed = true;
15
+ while (changed) {
16
+ changed = false;
17
+ for (const [name, classNode] of classes) {
18
+ if (entrypoints.has(name)) continue;
19
+ if (extendsWorkerEntrypoint(classNode.superClass, bases, entrypoints)) {
20
+ entrypoints.add(name);
21
+ changed = true;
22
+ }
23
+ }
24
+ }
25
+ return entrypoints;
26
+ }
27
+ function asClassDeclaration(node) {
28
+ if (node.type === "ClassDeclaration") return node;
29
+ if (node.type === "ExportNamedDeclaration") {
30
+ const decl = node.declaration;
31
+ if (decl?.type === "ClassDeclaration") return decl;
32
+ }
33
+ return void 0;
34
+ }
35
+ function collectWorkerEntrypointImports(ast) {
36
+ const named = /* @__PURE__ */ new Set();
37
+ const namespaces = /* @__PURE__ */ new Set();
38
+ for (const node of ast.body) {
39
+ if (node.type !== "ImportDeclaration") continue;
40
+ const importNode = node;
41
+ if (importNode.source?.value !== "cloudflare:workers") continue;
42
+ for (const specifier of importNode.specifiers ?? []) {
43
+ if (specifier.type === "ImportSpecifier" && specifier.imported?.name === "WorkerEntrypoint" && specifier.local?.name) {
44
+ named.add(specifier.local.name);
45
+ } else if (specifier.type === "ImportNamespaceSpecifier" && specifier.local?.name) {
46
+ namespaces.add(specifier.local.name);
47
+ }
48
+ }
49
+ }
50
+ return { named, namespaces };
51
+ }
52
+ function extendsWorkerEntrypoint(superClass, bases, detected) {
53
+ if (!superClass) return false;
54
+ if (superClass.type === "Identifier") {
55
+ const name = superClass.name;
56
+ return bases.named.has(name) || detected.has(name);
57
+ }
58
+ if (superClass.type === "MemberExpression") {
59
+ const member = superClass;
60
+ return member.object?.type === "Identifier" && !!member.object.name && bases.namespaces.has(member.object.name) && member.property?.name === "WorkerEntrypoint";
61
+ }
62
+ return false;
63
+ }
64
+
65
+ exports.detectWorkerEntrypointClasses = detectWorkerEntrypointClasses;
66
+ //# sourceMappingURL=workerEntrypoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerEntrypoint.js","sources":["../../../src/vite/workerEntrypoint.ts"],"sourcesContent":["import type { BaseNode, ProgramBody } from './transform';\n\n// ---------------------------------------------------------------------------\n// Minimal ESTree node shapes for structural WorkerEntrypoint detection.\n// ---------------------------------------------------------------------------\n\ninterface IdentifierNode extends BaseNode {\n name: string;\n}\n\ninterface MemberExpressionNode extends BaseNode {\n object?: { type: string; name?: string };\n property?: { type: string; name?: string };\n}\n\ninterface ClassDeclarationNode extends BaseNode {\n id?: IdentifierNode | null;\n superClass?: BaseNode | null;\n}\n\ninterface ExportNamedDeclNode extends BaseNode {\n declaration?: BaseNode | null;\n}\n\ninterface ImportSpecifierNode {\n type: string;\n imported?: { type: string; name?: string };\n local?: { type: string; name?: string };\n}\n\ninterface ImportDeclarationNode extends BaseNode {\n source?: { value?: unknown };\n specifiers?: ImportSpecifierNode[];\n}\n\ninterface WorkerEntrypointBases {\n /** Local identifiers bound to the named `WorkerEntrypoint` import. */\n named: Set<string>;\n /** Local identifiers bound to a `* as ns` import of `cloudflare:workers`. */\n namespaces: Set<string>;\n}\n\n/**\n * Find top-level classes that (transitively, within this module) extend\n * `WorkerEntrypoint` imported from `cloudflare:workers`. esbuild has already\n * stripped TypeScript by transform time, so a superclass is a plain identifier\n * (`extends WorkerEntrypoint`) or member access (`extends cf.WorkerEntrypoint`).\n *\n * Only same-file base chains are resolvable here; a base class imported from\n * another module is invisible and relies on the config self-binding fallback.\n */\nexport function detectWorkerEntrypointClasses(ast: ProgramBody): Set<string> {\n const bases = collectWorkerEntrypointImports(ast);\n if (bases.named.size === 0 && bases.namespaces.size === 0) {\n return new Set<string>();\n }\n\n // Every top-level class, including the `export class Foo {}` form (where the\n // class is nested inside an ExportNamedDeclaration) so directly-exported\n // entrypoints are seen too.\n const classes = new Map<string, ClassDeclarationNode>();\n for (const node of ast.body) {\n const classNode = asClassDeclaration(node);\n if (classNode?.id?.name) classes.set(classNode.id.name, classNode);\n }\n\n const entrypoints = new Set<string>();\n // Iterate to a fixed point so an indirect chain (A extends B extends WE) is\n // fully resolved regardless of declaration order.\n let changed = true;\n while (changed) {\n changed = false;\n for (const [name, classNode] of classes) {\n if (entrypoints.has(name)) continue;\n if (extendsWorkerEntrypoint(classNode.superClass, bases, entrypoints)) {\n entrypoints.add(name);\n changed = true;\n }\n }\n }\n return entrypoints;\n}\n\n/** Unwrap `export class Foo {}` to its ClassDeclaration; pass bare classes through. */\nfunction asClassDeclaration(node: BaseNode): ClassDeclarationNode | undefined {\n if (node.type === 'ClassDeclaration') return node as ClassDeclarationNode;\n if (node.type === 'ExportNamedDeclaration') {\n const decl = (node as ExportNamedDeclNode).declaration;\n if (decl?.type === 'ClassDeclaration') return decl as ClassDeclarationNode;\n }\n return undefined;\n}\n\nfunction collectWorkerEntrypointImports(ast: ProgramBody): WorkerEntrypointBases {\n const named = new Set<string>();\n const namespaces = new Set<string>();\n for (const node of ast.body) {\n if (node.type !== 'ImportDeclaration') continue;\n const importNode = node as ImportDeclarationNode;\n if (importNode.source?.value !== 'cloudflare:workers') continue;\n for (const specifier of importNode.specifiers ?? []) {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported?.name === 'WorkerEntrypoint' &&\n specifier.local?.name\n ) {\n named.add(specifier.local.name);\n } else if (specifier.type === 'ImportNamespaceSpecifier' && specifier.local?.name) {\n namespaces.add(specifier.local.name);\n }\n }\n }\n return { named, namespaces };\n}\n\n/**\n * Whether a superclass expression resolves to `WorkerEntrypoint` — either a bare\n * identifier from the named import (or an already-detected local subclass), or a\n * `ns.WorkerEntrypoint` member access off a namespace import.\n */\nfunction extendsWorkerEntrypoint(\n superClass: BaseNode | null | undefined,\n bases: WorkerEntrypointBases,\n detected: Set<string>,\n): boolean {\n if (!superClass) return false;\n if (superClass.type === 'Identifier') {\n const name = (superClass as IdentifierNode).name;\n return bases.named.has(name) || detected.has(name);\n }\n if (superClass.type === 'MemberExpression') {\n const member = superClass as MemberExpressionNode;\n return (\n member.object?.type === 'Identifier' &&\n !!member.object.name &&\n bases.namespaces.has(member.object.name) &&\n member.property?.name === 'WorkerEntrypoint'\n );\n }\n return false;\n}\n"],"names":[],"mappings":";;AAmDO,SAAS,8BAA8B,GAAA,EAA+B;AAC3E,EAAA,MAAM,KAAA,GAAQ,+BAA+B,GAAG,CAAA;AAChD,EAAA,IAAI,MAAM,K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A,KAAS,gBACxB,CAAC,CAAC,OAAO,MAAA,CAAO,IAAA,IAChB,KAAA,CAAM,UAAA,CAAW,IAAI,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,IACvC,MAAA,CAAO,UAAU,IAAA,KAAS,kBAAA;AAAA,EAE9B;AACA,EAAA,OAAO,KAAA;AACT;;;;"}
@@ -0,0 +1,54 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const node_fs = require('node:fs');
4
+ const node_path = require('node:path');
5
+ const wrangler = require('wrangler');
6
+
7
+ function resolveWranglerConfig(root, explicitPath) {
8
+ const configPath = explicitPath ? node_path.resolve(root, explicitPath) : ["wrangler.json", "wrangler.jsonc", "wrangler.toml"].map((name) => node_path.resolve(root, name)).find(node_fs.existsSync);
9
+ if (!configPath || !node_fs.existsSync(configPath)) {
10
+ return void 0;
11
+ }
12
+ let raw;
13
+ try {
14
+ raw = wrangler.unstable_readConfig({ config: configPath }, { hideWarnings: true });
15
+ } catch {
16
+ return void 0;
17
+ }
18
+ return {
19
+ config: {
20
+ main: raw.main,
21
+ durableObjects: collectClassBindings(raw.durable_objects?.bindings),
22
+ workflows: collectClassBindings(raw.workflows),
23
+ workerEntrypoints: collectSelfBoundEntrypoints(raw)
24
+ },
25
+ configDir: node_path.dirname(raw.configPath ?? configPath)
26
+ };
27
+ }
28
+ function collectSelfBoundEntrypoints(raw) {
29
+ if (!raw.name) {
30
+ return [];
31
+ }
32
+ const entrypoints = /* @__PURE__ */ new Set();
33
+ for (const binding of raw.services ?? []) {
34
+ if (binding?.service === raw.name && typeof binding.entrypoint === "string") {
35
+ entrypoints.add(binding.entrypoint);
36
+ }
37
+ }
38
+ return [...entrypoints];
39
+ }
40
+ function collectClassBindings(bindings) {
41
+ const result = [];
42
+ const seenClassNames = /* @__PURE__ */ new Set();
43
+ for (const binding of bindings ?? []) {
44
+ if (typeof binding?.class_name !== "string" || binding.script_name || seenClassNames.has(binding.class_name)) {
45
+ continue;
46
+ }
47
+ seenClassNames.add(binding.class_name);
48
+ result.push({ name: binding.name, className: binding.class_name });
49
+ }
50
+ return result;
51
+ }
52
+
53
+ exports.resolveWranglerConfig = resolveWranglerConfig;
54
+ //# sourceMappingURL=wranglerConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wranglerConfig.js","sources":["../../../src/vite/wranglerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { type Unstable_Config, unstable_readConfig } from 'wrangler';\n\n/**\n * The slice of the wrangler configuration the auto-instrument plugin cares\n * about. `main` is an absolute path (wrangler resolves it against the config\n * file's directory).\n */\nexport interface WranglerConfig {\n main?: string;\n durableObjects: Array<{ name: string; className: string }>;\n workflows: Array<{ name: string; className: string }>;\n /**\n * Named `WorkerEntrypoint` exports this worker binds to itself via a service\n * binding (`services[]` whose `service` is this worker's own `name`). Only\n * self-bindings appear here: a service binding's `entrypoint` otherwise names\n * an export on a *different* worker, which this build can't wrap.\n */\n workerEntrypoints: string[];\n}\n\n/**\n * Locate and resolve the wrangler configuration via wrangler's own\n * `unstable_readConfig` — the API `@cloudflare/vite-plugin` uses.\n *\n * We only locate the file (probing `wrangler.json`, `.jsonc`, `.toml` inside\n * `root` with wrangler's own precedence, since it discovers from `cwd` rather\n * than an arbitrary root); wrangler then parses it, flattens the active\n * environment (honoring `CLOUDFLARE_ENV`), and resolves `main` to an absolute\n * path. Durable Object and Workflow bindings are the active environment's,\n * matching what the deployed Worker actually binds.\n *\n * Returns `undefined` when no config file is found or it can't be read/parsed\n * (the caller warns and disables auto-instrumentation rather than failing the\n * whole build).\n */\nexport function resolveWranglerConfig(\n root: string,\n explicitPath?: string,\n): { config: WranglerConfig; configDir: string } | undefined {\n const configPath = explicitPath\n ? resolve(root, explicitPath)\n : ['wrangler.json', 'wrangler.jsonc', 'wrangler.toml'].map(name => resolve(root, name)).find(existsSync);\n\n if (!configPath || !existsSync(configPath)) {\n return undefined;\n }\n\n let raw: Unstable_Config;\n try {\n // `hideWarnings` keeps wrangler's config diagnostics (e.g. missing DO\n // migrations) out of the Vite build output.\n raw = unstable_readConfig({ config: configPath }, { hideWarnings: true });\n } catch {\n return undefined;\n }\n\n return {\n config: {\n main: raw.main,\n durableObjects: collectClassBindings(raw.durable_objects?.bindings),\n workflows: collectClassBindings(raw.workflows),\n workerEntrypoints: collectSelfBoundEntrypoints(raw),\n },\n configDir: dirname(raw.configPath ?? configPath),\n };\n}\n\n/**\n * Collect named `WorkerEntrypoint` exports the worker binds to itself. A service\n * binding's `entrypoint` normally names an export on the *target* worker, so it\n * is only ours when `service` equals this worker's own `name`. Without a `name`\n * there is nothing to match against, so no entrypoints are derivable.\n */\nfunction collectSelfBoundEntrypoints(raw: Unstable_Config): string[] {\n if (!raw.name) {\n return [];\n }\n const entrypoints = new Set<string>();\n for (const binding of raw.services ?? []) {\n if (binding?.service === raw.name && typeof binding.entrypoint === 'string') {\n entrypoints.add(binding.entrypoint);\n }\n }\n return [...entrypoints];\n}\n\n/**\n * Map wrangler class bindings (Durable Objects, Workflows — same shape) to the\n * `{ name, className }` the transform needs, skipping duplicates and bindings\n * with a `script_name` (those reference a class exported by a *different*\n * worker, so there is nothing to wrap in this worker's entry file).\n */\nfunction collectClassBindings(\n bindings: ReadonlyArray<{ name: string; class_name?: string; script_name?: string }> | undefined,\n): Array<{ name: string; className: string }> {\n const result: Array<{ name: string; className: string }> = [];\n const seenClassNames = new Set<string>();\n for (const binding of bindings ?? []) {\n if (typeof binding?.class_name !== 'string' || binding.script_name || seenClassNames.has(binding.class_name)) {\n continue;\n }\n seenClassNames.add(binding.class_name);\n result.push({ name: binding.name, className: binding.class_name });\n }\n return result;\n}\n"],"names":["resolve","existsSync","unstable_readConfig","dirname"],"mappings":";;;;;;AAqCO,SAAS,qBAAA,CACd,MACA,YAAA,EAC2D;AAC3D,EAAA,MAAM,aAAa,YAAA,GACfA,iBAAA,CAAQ,MAAM,YAAY,CAAA,GAC1B,CAAC,e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AAG,WAAW,CAAA;AACxB;AAQA,SAAS,qBACP,QAAA,EAC4C;AAC5C,EAAA,MAAM,SAAqD,EAAC;AAC5D,EAAA,MAAM,cAAA,uBAAqB,GAAA,EAAY;AACvC,EAAA,KAAA,MAAW,OAAA,IAAW,QAAA,IAAY,EAAC,EAAG;AACpC,IAAA,IAAI,OAAO,OAAA,EAAS,UAAA,KAAe,QAAA,IAAY,OAAA,CAAQ,eAAe,cAAA,CAAe,GAAA,CAAI,OAAA,CAAQ,UAAU,CAAA,EAAG;AAC5G,MAAA;AAAA,IACF;AACA,IAAA,cAAA,CAAe,GAAA,CAAI,QAAQ,UAAU,CAAA;AACrC,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,CAAQ,MAAM,SAAA,EAAW,OAAA,CAAQ,YAAY,CAAA;AAAA,EACnE;AACA,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -1,4 +1,4 @@
1
- import { ServerRuntimeClient, applySdkMetadata, debug, spanIsSampled } from '@sentry/core';
1
+ import { ServerRuntimeClient, applySdkMetadata, debug, spanIsSampled, _INTERNAL_clearAiProviderSkips } from '@sentry/core';
2
2
  import { DEBUG_BUILD } from './debug-build.js';
3
3
 
4
4
  class CloudflareClient extends ServerRuntimeClient {
@@ -101,6 +101,11 @@ class CloudflareClient extends ServerRuntimeClient {
101
101
  this._resetSpanCompletionPromise();
102
102
  this._flushLock = void 0;
103
103
  }
104
+ /** @inheritDoc */
105
+ _setupIntegrations() {
106
+ _INTERNAL_clearAiProviderSkips();
107
+ super._setupIntegrations();
108
+ }
104
109
  /**
105
110
  * Resets the span completion promise and resolve function.
106
111
  */
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sources":["../../src/client.ts"],"sourcesContent":["import type { ClientOptions, Options, ServerRuntimeClientOptions } from '@sentry/core';\nimport { applySdkMetadata, debug, ServerRuntimeClient, spanIsSampled } 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 /**\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, however, we set up some OpenTelemetry compatibility\n * via a custom trace provider.\n * This ensures that any spans emitted via `@opentelemetry/api` will be captured by Sentry.\n * HOWEVER, big caveat: This does not handle custom context handling, it will always work off the current scope.\n * This should be good enough for many, but not all integrations.\n *\n * If you want to opt-out of setting up the OpenTelemetry compatibility tracer, set this to `true`.\n *\n * @default false\n */\n skipOpenTelemetrySetup?: 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 should be enabled on **both sides** for full trace propagation.\n *\n * @default false\n * @example\n * ```ts\n * // Worker side (caller)\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * enableRpcTracePropagation: true,\n * }),\n * handler,\n * );\n *\n * // Durable Object side (receiver)\n * export const MyDO = Sentry.instrumentDurableObjectWithSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * enableRpcTracePropagation: true,\n * }),\n * MyDOBase,\n * );\n *\n * // WorkerEntrypoint side (receiver)\n * export const MyEntrypoint = Sentry.withSentry(\n * env => ({ dsn: env.SENTRY_DSN, enableRpcTracePropagation: true }),\n * MyEntrypointBase,\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 * @deprecated Use `enableRpcTracePropagation` instead. This option will be removed in a future major version.\n *\n * Enable instrumentation of prototype methods for DurableObjects.\n *\n * When `true`, the SDK will wrap all methods on the DurableObject prototype chain\n * to automatically create spans and capture errors for RPC method calls.\n *\n * When an array of strings is provided, only the specified method names will be instrumented.\n *\n * @default false\n */\n instrumentPrototypeMethods?: 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":[],"mappings":";;;AAaO,MAAM,yBAAyB,mBAAA,CAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAajD,YAAY,OAAA,EAAkC;AACnD,IAAA,gBAAA,CAAiB,SAAS,YAAY,CAAA;AACtC,IAAA,OAAA,CAAQ,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,EAAC;AAC1C,IAAA,MAAM,EAAE,SAA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R;AAEA,IAAA,OAAO,KAAA,CAAM,MAAM,OAAO,CAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWgB,OAAA,GAAgB;AAC9B,IAAA,WAAA,IAAe,KAAA,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;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, 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, however, we set up some OpenTelemetry compatibility\n * via a custom trace provider.\n * This ensures that any spans emitted via `@opentelemetry/api` will be captured by Sentry.\n * HOWEVER, big caveat: This does not handle custom context handling, it will always work off the current scope.\n * This should be good enough for many, but not all integrations.\n *\n * If you want to opt-out of setting up the OpenTelemetry compatibility tracer, set this to `true`.\n *\n * @default false\n */\n skipOpenTelemetrySetup?: 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 should be enabled on **both sides** for full trace propagation.\n *\n * @default false\n * @example\n * ```ts\n * // Worker side (caller)\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * enableRpcTracePropagation: true,\n * }),\n * handler,\n * );\n *\n * // Durable Object side (receiver)\n * export const MyDO = Sentry.instrumentDurableObjectWithSentry(\n * (env) => ({\n * dsn: env.SENTRY_DSN,\n * enableRpcTracePropagation: true,\n * }),\n * MyDOBase,\n * );\n *\n * // WorkerEntrypoint side (receiver)\n * export const MyEntrypoint = Sentry.withSentry(\n * env => ({ dsn: env.SENTRY_DSN, enableRpcTracePropagation: true }),\n * MyEntrypointBase,\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 * @deprecated Use `enableRpcTracePropagation` instead. This option will be removed in a future major version.\n *\n * Enable instrumentation of prototype methods for DurableObjects.\n *\n * When `true`, the SDK will wrap all methods on the DurableObject prototype chain\n * to automatically create spans and capture errors for RPC method calls.\n *\n * When an array of strings is provided, only the specified method names will be instrumented.\n *\n * @default false\n */\n instrumentPrototypeMethods?: boolean | 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/**\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":[],"mappings":";;;AAmBO,MAAM,yBAAyB,mBAAA,CAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAajD,YAAY,OAAA,EAAkC;AACnD,IAAA,gBAAA,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,MACH,QAAA,EAAU,YAAA;AAAA;AAAA,MAEV,OAAA,EAAS,EAAE,IAAA,EAAM,YAAA,EAAa;AAAA;AAAA,MAE9B,cAAA,EAAgB;AAAA,KAClB;AAEA,IAAA,KAAA,CAAM,aAAa,CAAA;AAzBrB,IAAA,IAAA,CAAQ,aAAA,uBAAiC,GAAA,EAAI;AAC7C,IAAA,IAAA,CAAQ,sBAAA,GAA+C,IAAA;AACvD,IAAA,IAAA,CAAQ,sBAAA,GAA8C,IAAA;AAEtD,IAAA,IAAA,CAAQ,qBAAA,GAA6C,IAAA;AACrD,IAAA,IAAA,CAAQ,mBAAA,GAA2C,IAAA;AAqBjD,IAAA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A,IAAA,IAAA,CAAK,2BAAA,EAA4B;AACjC,IAAC,KAA4E,UAAA,GAAa,MAAA;AAAA,EAC5F;AAAA;AAAA,EAGmB,kBAAA,GAA2B;AAK5C,IAAA,8BAAA,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;;;;"}
@@ -0,0 +1,9 @@
1
+ function defineCloudflareOptions(optionsOrCallback) {
2
+ if (typeof optionsOrCallback === "function") {
3
+ return optionsOrCallback;
4
+ }
5
+ return () => optionsOrCallback;
6
+ }
7
+
8
+ export { defineCloudflareOptions };
9
+ //# sourceMappingURL=defineCloudflareOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineCloudflareOptions.js","sources":["../../src/defineCloudflareOptions.ts"],"sourcesContent":["import type { env as cloudflareEnv } from 'cloudflare:workers';\nimport type { CloudflareOptions } from './client';\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 = typeof cloudflareEnv>(\n optionsOrCallback: CloudflareOptions | ((env: Env) => CloudflareOptions | undefined),\n): (env: Env) => CloudflareOptions | undefined {\n if (typeof optionsOrCallback === 'function') {\n return optionsOrCallback as (env: Env) => CloudflareOptions | undefined;\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;;;;"}