@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 @@
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":[],"mappings":";;;AA4DA,SAAS,cAAA,CAAe,MAAgB,UAAA,EAA6B;AACnE,EAAA,IAAI,IAAA,CAAK,IAAA,KAAS,gBAAA,EAAkB,OAAO,KAAA;A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AAA,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,64 @@
1
+ function detectWorkerEntrypointClasses(ast) {
2
+ const bases = collectWorkerEntrypointImports(ast);
3
+ if (bases.named.size === 0 && bases.namespaces.size === 0) {
4
+ return /* @__PURE__ */ new Set();
5
+ }
6
+ const classes = /* @__PURE__ */ new Map();
7
+ for (const node of ast.body) {
8
+ const classNode = asClassDeclaration(node);
9
+ if (classNode?.id?.name) classes.set(classNode.id.name, classNode);
10
+ }
11
+ const entrypoints = /* @__PURE__ */ new Set();
12
+ let changed = true;
13
+ while (changed) {
14
+ changed = false;
15
+ for (const [name, classNode] of classes) {
16
+ if (entrypoints.has(name)) continue;
17
+ if (extendsWorkerEntrypoint(classNode.superClass, bases, entrypoints)) {
18
+ entrypoints.add(name);
19
+ changed = true;
20
+ }
21
+ }
22
+ }
23
+ return entrypoints;
24
+ }
25
+ function asClassDeclaration(node) {
26
+ if (node.type === "ClassDeclaration") return node;
27
+ if (node.type === "ExportNamedDeclaration") {
28
+ const decl = node.declaration;
29
+ if (decl?.type === "ClassDeclaration") return decl;
30
+ }
31
+ return void 0;
32
+ }
33
+ function collectWorkerEntrypointImports(ast) {
34
+ const named = /* @__PURE__ */ new Set();
35
+ const namespaces = /* @__PURE__ */ new Set();
36
+ for (const node of ast.body) {
37
+ if (node.type !== "ImportDeclaration") continue;
38
+ const importNode = node;
39
+ if (importNode.source?.value !== "cloudflare:workers") continue;
40
+ for (const specifier of importNode.specifiers ?? []) {
41
+ if (specifier.type === "ImportSpecifier" && specifier.imported?.name === "WorkerEntrypoint" && specifier.local?.name) {
42
+ named.add(specifier.local.name);
43
+ } else if (specifier.type === "ImportNamespaceSpecifier" && specifier.local?.name) {
44
+ namespaces.add(specifier.local.name);
45
+ }
46
+ }
47
+ }
48
+ return { named, namespaces };
49
+ }
50
+ function extendsWorkerEntrypoint(superClass, bases, detected) {
51
+ if (!superClass) return false;
52
+ if (superClass.type === "Identifier") {
53
+ const name = superClass.name;
54
+ return bases.named.has(name) || detected.has(name);
55
+ }
56
+ if (superClass.type === "MemberExpression") {
57
+ const member = superClass;
58
+ return member.object?.type === "Identifier" && !!member.object.name && bases.namespaces.has(member.object.name) && member.property?.name === "WorkerEntrypoint";
59
+ }
60
+ return false;
61
+ }
62
+
63
+ export { detectWorkerEntrypointClasses };
64
+ //# 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,KAAA,CAAM,IAAA,KAAS,KAAK,KAAA,CAAM,UAAA,CAAW,SAAS,CAAA,EAAG;AACzD,IAAA,2BAAW,GAAA,EAAY;AAAA,EACzB;AAKA,EAAA,MAA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MAAA,CAAO,UAAU,IAAA,KAAS,kBAAA;AAAA,EAE9B;AACA,EAAA,OAAO,KAAA;AACT;;;;"}
@@ -0,0 +1,52 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { resolve, dirname } from 'node:path';
3
+ import { unstable_readConfig } from 'wrangler';
4
+
5
+ function resolveWranglerConfig(root, explicitPath) {
6
+ const configPath = explicitPath ? resolve(root, explicitPath) : ["wrangler.json", "wrangler.jsonc", "wrangler.toml"].map((name) => resolve(root, name)).find(existsSync);
7
+ if (!configPath || !existsSync(configPath)) {
8
+ return void 0;
9
+ }
10
+ let raw;
11
+ try {
12
+ raw = unstable_readConfig({ config: configPath }, { hideWarnings: true });
13
+ } catch {
14
+ return void 0;
15
+ }
16
+ return {
17
+ config: {
18
+ main: raw.main,
19
+ durableObjects: collectClassBindings(raw.durable_objects?.bindings),
20
+ workflows: collectClassBindings(raw.workflows),
21
+ workerEntrypoints: collectSelfBoundEntrypoints(raw)
22
+ },
23
+ configDir: dirname(raw.configPath ?? configPath)
24
+ };
25
+ }
26
+ function collectSelfBoundEntrypoints(raw) {
27
+ if (!raw.name) {
28
+ return [];
29
+ }
30
+ const entrypoints = /* @__PURE__ */ new Set();
31
+ for (const binding of raw.services ?? []) {
32
+ if (binding?.service === raw.name && typeof binding.entrypoint === "string") {
33
+ entrypoints.add(binding.entrypoint);
34
+ }
35
+ }
36
+ return [...entrypoints];
37
+ }
38
+ function collectClassBindings(bindings) {
39
+ const result = [];
40
+ const seenClassNames = /* @__PURE__ */ new Set();
41
+ for (const binding of bindings ?? []) {
42
+ if (typeof binding?.class_name !== "string" || binding.script_name || seenClassNames.has(binding.class_name)) {
43
+ continue;
44
+ }
45
+ seenClassNames.add(binding.class_name);
46
+ result.push({ name: binding.name, className: binding.class_name });
47
+ }
48
+ return result;
49
+ }
50
+
51
+ export { resolveWranglerConfig };
52
+ //# 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":[],"mappings":";;;;AAqCO,SAAS,qBAAA,CACd,MACA,YAAA,EAC2D;AAC3D,EAAA,MAAM,aAAa,YAAA,GACf,OAAA,CAAQ,MAAM,YAAY,CAAA,GAC1B,CAAC,eAAA,EAAiB,gBAAA,EAAkB,eAAe,CAAA,CAAE,GAAA,CAAI,UAAQ,OAAA,CAAQ,IAAA,EAAM,IAAI,CAAC,CAAA,CAAE,KAAK,UAAU,CAAA;AAEzG,EAAA,IAAI,CAAC,UAAA,IAAc,CAAC,UAAA,CAAW,UAAU,CAAA,EAAG;AAC1C,IAAA,OAAO,MAAA;AAAA,EACT;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AY,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;;;;"}
@@ -41,6 +41,8 @@ export declare class CloudflareClient extends ServerRuntimeClient {
41
41
  * After calling dispose(), the client should not be used anymore.
42
42
  */
43
43
  dispose(): void;
44
+ /** @inheritDoc */
45
+ protected _setupIntegrations(): void;
44
46
  /**
45
47
  * Resets the span completion promise and resolve function.
46
48
  */
@@ -132,6 +134,30 @@ interface BaseCloudflareOptions {
132
134
  * ```
133
135
  */
134
136
  durableObjectSqlSpanAllowlist?: Array<string | RegExp>;
137
+ /**
138
+ * KV keys that should stay instrumented even though they match a reserved prefix used by Durable
139
+ * Object frameworks (`agents`, `partyserver`, ...) for their internal storage entries.
140
+ *
141
+ * By default, KV reads/writes (`get`, `put`, `delete`, `list`) of `cf_`- or `__ps_`-prefixed keys
142
+ * are treated as framework noise and no `durable_object_storage_*` span is created for them,
143
+ * mirroring how `cf_`-prefixed SQL tables are handled (see {@link durableObjectSqlSpanAllowlist}).
144
+ * If one of your own keys happens to use such a prefix, add it here to opt it back into
145
+ * instrumentation. Strings must match exactly, while regular expressions give you prefix/pattern
146
+ * matching.
147
+ *
148
+ * @default []
149
+ * @example
150
+ * ```ts
151
+ * export default Sentry.withSentry(
152
+ * (env) => ({
153
+ * dsn: env.SENTRY_DSN,
154
+ * durableObjectStorageSpanAllowlist: ['cf_my_key', /^cf_reports_/],
155
+ * }),
156
+ * handler,
157
+ * );
158
+ * ```
159
+ */
160
+ durableObjectStorageSpanAllowlist?: Array<string | RegExp>;
135
161
  /**
136
162
  * @deprecated Use `enableRpcTracePropagation` instead. This option will be removed in a future major version.
137
163
  *
@@ -145,6 +171,17 @@ interface BaseCloudflareOptions {
145
171
  * @default false
146
172
  */
147
173
  instrumentPrototypeMethods?: boolean | string[];
174
+ /**
175
+ * If you use Spotlight by Sentry during development, use
176
+ * this option to forward captured Sentry events to Spotlight.
177
+ *
178
+ * Either set it to true, or provide a specific Spotlight Sidecar URL.
179
+ *
180
+ * More details: https://spotlightjs.com/
181
+ *
182
+ * IMPORTANT: Only set this option to `true` while developing, not in production!
183
+ */
184
+ spotlight?: boolean | string;
148
185
  }
149
186
  /**
150
187
  * Configuration options for the Sentry Cloudflare SDK
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAA8B,MAAM,cAAc,CAAC;AACvF,OAAO,EAA2B,mBAAmB,EAAiB,MAAM,cAAc,CAAC;AAE3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE9D;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,mBAAmB;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0C;IACrE,OAAO,CAAC,aAAa,CAA0B;IAC/C,OAAO,CAAC,sBAAsB,CAA8B;IAC5D,OAAO,CAAC,sBAAsB,CAA6B;IAE3D,OAAO,CAAC,qBAAqB,CAA6B;IAC1D,OAAO,CAAC,mBAAmB,CAA6B;IAExD;;;OAGG;gBACgB,OAAO,EAAE,uBAAuB;IAqDnD;;;;;;;;OAQG;IACU,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA2BtD;;;;;;;;OAQG;IACa,OAAO,IAAI,IAAI;IAkB/B;;OAE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E,qBAAqB;IAC/G,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;CAC9C"}
@@ -0,0 +1,38 @@
1
+ import type { env as cloudflareEnv } from 'cloudflare:workers';
2
+ import type { CloudflareOptions } from './client';
3
+ /**
4
+ * Define the Sentry options for a Cloudflare Worker in a dedicated module.
5
+ *
6
+ * This is the recommended way to configure the SDK when using the Vite plugin's
7
+ * auto-instrumentation: place an `instrument.server.{ts,js,mjs}` file next to
8
+ * the worker entry whose **default export** is the result of this function. The
9
+ * plugin picks it up automatically and hands it to `withSentry`.
10
+ *
11
+ * Unlike Node's `Sentry.init(...)`, the options cannot be applied at module
12
+ * load time on Cloudflare: the DSN and other settings typically come from the
13
+ * per-request `env`, which only exists inside the handler. Pass a callback to
14
+ * read from `env`, or a static object when no `env` access is needed — either
15
+ * way you get full type-checking and autocomplete on {@link CloudflareOptions}.
16
+ *
17
+ * At runtime this is a thin pass-through; it only normalizes a static object
18
+ * into a callback so the plugin always imports a `(env) => options` function.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // src/instrument.server.ts
23
+ * import { defineCloudflareOptions } from '@sentry/cloudflare';
24
+ *
25
+ * export default defineCloudflareOptions((env) => ({
26
+ * dsn: env.SENTRY_DSN,
27
+ * tracesSampleRate: 1.0,
28
+ * }));
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // Static options — no `env` access needed
34
+ * export default defineCloudflareOptions({ tracesSampleRate: 1.0 });
35
+ * ```
36
+ */
37
+ export declare function defineCloudflareOptions<Env = typeof cloudflareEnv>(optionsOrCallback: CloudflareOptions | ((env: Env) => CloudflareOptions | undefined)): (env: Env) => CloudflareOptions | undefined;
38
+ //# sourceMappingURL=defineCloudflareOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineCloudflareOptions.d.ts","sourceRoot":"","sources":["../../src/defineCloudflareOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,GAAG,OAAO,aAAa,EAChE,iBAAiB,EAAE,iBAAiB,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,iBAAiB,GAAG,SAAS,CAAC,GACnF,CAAC,GAAG,EAAE,GAAG,KAAK,iBAAiB,GAAG,SAAS,CAM7C"}
@@ -1,5 +1,44 @@
1
1
  import type { DurableObject } from 'cloudflare:workers';
2
2
  import type { CloudflareOptions } from './client';
3
+ /**
4
+ * The instrumented context passed between the shared construction helpers.
5
+ *
6
+ * This is intentionally `any` rather than `ReturnType<typeof instrumentContext<DurableObjectState>>`.
7
+ * A concrete `DurableObjectState` here forces `tsc` to structurally relate its `storage: SqlStorage`
8
+ * graph against the `ExecutionContext | InstrumentedDurableObjectState` parameter of
9
+ * `wrapMethodWithSentry`, while the RPC-branded `DurableObject` from `cloudflare:workers` is also in
10
+ * scope. That union comparison explodes (1296×1296) and hangs the type build. The original inline
11
+ * implementation avoided this only incidentally, because `ctx` reached it as `any` through the Proxy
12
+ * `construct` trap. Keeping the shared context `any` preserves that behavior.
13
+ */
14
+ type InstrumentedDurableObjectContext = any;
15
+ /**
16
+ * Constructs a Durable Object instance and instruments its built-in handler methods
17
+ * (`fetch`, `alarm`, `webSocketMessage`, `webSocketClose`, `webSocketError`).
18
+ *
19
+ * This is the shared construction path used by both {@link instrumentDurableObjectWithSentry}
20
+ * and {@link instrumentAgentWithSentry}. It intentionally does NOT apply the RPC prototype-method
21
+ * proxy — callers apply that last via {@link finalizeWithRpcInstrumentation}, after any additional
22
+ * per-instance instrumentation has been layered onto the returned object.
23
+ *
24
+ * @internal
25
+ */
26
+ export declare function constructInstrumentedDurableObject<E, T extends DurableObject<E>>(target: new (state: DurableObjectState, env: E) => T, ctx: DurableObjectState, env: E, newTarget: NewableFunction, optionsCallback: (env: E) => CloudflareOptions): {
27
+ obj: T;
28
+ options: CloudflareOptions;
29
+ context: InstrumentedDurableObjectContext;
30
+ };
31
+ /**
32
+ * Wraps a constructed (and already handler-instrumented) Durable Object instance with the RPC
33
+ * prototype-method proxy, when RPC trace propagation is enabled. Returns the object unchanged when
34
+ * RPC instrumentation is disabled.
35
+ *
36
+ * This must be applied last, so that any per-instance instrumentation (own properties such as
37
+ * `fetch`, `alarm`, or Agent-specific handlers) is excluded from RPC method tracing.
38
+ *
39
+ * @internal
40
+ */
41
+ export declare function finalizeWithRpcInstrumentation<T extends object>(obj: T, options: CloudflareOptions, context: InstrumentedDurableObjectContext): T;
3
42
  /**
4
43
  * Instruments a Durable Object class to capture errors and performance data.
5
44
  *
@@ -34,4 +73,46 @@ import type { CloudflareOptions } from './client';
34
73
  * ```
35
74
  */
36
75
  export declare function instrumentDurableObjectWithSentry<E, T extends DurableObject<E>, C extends new (state: DurableObjectState, env: E) => T>(optionsCallback: (env: E) => CloudflareOptions, DurableObjectClass: C): C;
76
+ /**
77
+ * Instruments a Cloudflare [`agents`](https://www.npmjs.com/package/agents) Agent class with Sentry.
78
+ *
79
+ * An `Agent` is a Durable Object under the hood, so this applies the same instrumentation as
80
+ * {@link instrumentDurableObjectWithSentry} (request transactions, `alarm`, WebSocket handlers, RPC
81
+ * trace propagation, SQL spans) and additionally captures Agent-specific telemetry via
82
+ * `instrumentCloudflareAgent`:
83
+ *
84
+ * - **Callable RPC spans** — a span (op `rpc`) for each `@callable()` method invoked over WebSocket.
85
+ * - **Breadcrumbs** — for every Agent observability event (`rpc`, `state:update`, `connect`,
86
+ * `disconnect`, `schedule:*`, `queue:*`, `workflow:*`, `email:*`, `mcp:*`, ...).
87
+ *
88
+ * Cloudflare Workers cannot auto-instrument, so the Agent class must be wrapped manually.
89
+ *
90
+ * @param optionsCallback Function that returns the options for the SDK initialization.
91
+ * @param AgentClass The Agent class to instrument.
92
+ * @returns The instrumented Agent class.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { Agent, callable, routeAgentRequest } from 'agents';
97
+ * import * as Sentry from '@sentry/cloudflare';
98
+ *
99
+ * class MyAgentBase extends Agent<Env> {
100
+ * @callable()
101
+ * async greet(name: string): Promise<string> {
102
+ * return `Hello, ${name}!`;
103
+ * }
104
+ * }
105
+ *
106
+ * export const MyAgent = Sentry.instrumentAgentWithSentry(
107
+ * env => ({
108
+ * dsn: env.SENTRY_DSN,
109
+ * tracesSampleRate: 1.0,
110
+ * enableRpcTracePropagation: true,
111
+ * }),
112
+ * MyAgentBase,
113
+ * );
114
+ * ```
115
+ */
116
+ export declare function instrumentAgentWithSentry<E, T extends DurableObject<E>, C extends new (state: DurableObjectState, env: E) => T>(optionsCallback: (env: E) => CloudflareOptions, AgentClass: C): C;
117
+ export {};
37
118
  //# sourceMappingURL=durableobject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"durableobject.d.ts","sourceRoot":"","sources":["../../src/durableobject.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAUlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,iCAAiC,CAC/C,CAAC,EACD,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,EAC1B,CAAC,SAAS,KAAK,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,EACtD,eAAe,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,iBAAiB,EAAE,kBAAkB,EAAE,CAAC,GAAG,CAAC,CAuK1E"}
1
+ {"version":3,"file":"durableobject.d.ts","sourceRoot":"","sources":["../../src/durableobject.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK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EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,iBAAiB,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,CAkBlE"}
@@ -1,14 +1,16 @@
1
1
  export type { Breadcrumb, BreadcrumbHint, PolymorphicRequest, RequestEventData, SdkInfo, Event, EventHint, ErrorEvent, Exception, FeatureFlagsIntegration, Session, SeverityLevel, Span, StackFrame, Stacktrace, Thread, User, Metric, ExclusiveEventHintOrCaptureContext, CaptureContext, } from '@sentry/core';
2
2
  export type { CloudflareOptions } from './client';
3
- export { addEventProcessor, addBreadcrumb, addIntegration, captureException, captureEvent, captureMessage, captureFeedback, close, createTransport, lastEventId, flush, getClient, isInitialized, isEnabled, getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, Scope, SDK_VERSION, setContext, setExtra, setExtras, setTag, setTags, setAttribute, setAttributes, setUser, setConversationId, getSpanStatusFromHttpCode, setHttpStatus, withScope, withIsolationScope, captureCheckIn, withMonitor, setMeasurement, getActiveSpan, getRootSpan, getTraceData, getTraceMetaTags, startSpan, startInactiveSpan, startSpanManual, startNewTrace, bindScopeToEmitter, suppressTracing, withActiveSpan, getSpanDescendants, continueTrace, functionToStringIntegration, inboundFiltersIntegration, instrumentOpenAiClient, instrumentGoogleGenAIClient, instrumentAnthropicAiClient, eventFiltersIntegration, linkedErrorsIntegration, requestDataIntegration, extraErrorDataIntegration, dedupeIntegration, rewriteFramesIntegration, captureConsoleIntegration, moduleMetadataIntegration, supabaseIntegration, instrumentSupabaseClient, instrumentPostgresJsSql, zodErrorsIntegration, consoleIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, trpcMiddleware, spanToJSON, spanToTraceHeader, spanToBaggageHeader, updateSpanName, wrapMcpServerWithSentry, consoleLoggingIntegration, createConsolaReporter, createLangChainCallbackHandler, instrumentLangChainEmbeddings, featureFlagsIntegration, growthbookIntegration, logger, metrics, withStreamedSpan, spanStreamingIntegration, instrumentLangGraph, instrumentCreateReactAgent, } from '@sentry/core';
3
+ export { addEventProcessor, addBreadcrumb, addIntegration, captureException, captureEvent, captureMessage, captureFeedback, close, createTransport, lastEventId, flush, getClient, isInitialized, isEnabled, getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, Scope, SDK_VERSION, setContext, setExtra, setExtras, setTag, setTags, setAttribute, setAttributes, setUser, setConversationId, getSpanStatusFromHttpCode, setHttpStatus, withScope, withIsolationScope, captureCheckIn, withMonitor, setMeasurement, getActiveSpan, getRootSpan, getTraceData, getTraceMetaTags, startSpan, startInactiveSpan, startSpanManual, startNewTrace, bindScopeToEmitter, suppressTracing, withActiveSpan, getSpanDescendants, continueTrace, functionToStringIntegration, inboundFiltersIntegration, instrumentOpenAiClient, instrumentGoogleGenAIClient, instrumentAnthropicAiClient, eventFiltersIntegration, linkedErrorsIntegration, requestDataIntegration, extraErrorDataIntegration, dedupeIntegration, rewriteFramesIntegration, captureConsoleIntegration, moduleMetadataIntegration, supabaseIntegration, instrumentSupabaseClient, instrumentPostgresJsSql, zodErrorsIntegration, consoleIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, trpcMiddleware, spanToJSON, spanToTraceHeader, spanToBaggageHeader, updateSpanName, wrapMcpServerWithSentry, consoleLoggingIntegration, createConsolaReporter, createLangChainCallbackHandler, instrumentLangChainEmbeddings, featureFlagsIntegration, growthbookIntegration, logger, metrics, withStreamedSpan, spanStreamingIntegration, instrumentStateGraph, instrumentLangGraph, instrumentCreateReactAgent, } from '@sentry/core';
4
4
  export { withSentry } from './withSentry';
5
- export { instrumentDurableObjectWithSentry } from './durableobject';
5
+ export { defineCloudflareOptions } from './defineCloudflareOptions';
6
+ export { instrumentAgentWithSentry, instrumentDurableObjectWithSentry } from './durableobject';
6
7
  export { sentryPagesPlugin } from './pages-plugin';
7
8
  export { wrapRequestHandler } from './request';
8
9
  export { CloudflareClient } from './client';
9
10
  export { getDefaultIntegrations } from './sdk';
10
11
  export { httpServerIntegration } from './integrations/httpServer';
11
12
  export { fetchIntegration } from './integrations/fetch';
13
+ export { spotlightIntegration } from './integrations/spotlight';
12
14
  export { vercelAIIntegration } from './integrations/tracing/vercelai';
13
15
  export { honoIntegration } from './integrations/hono';
14
16
  export { instrumentD1WithSentry } from './instrumentations/worker/instrumentD1';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,uBAAuB,EACvB,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,IAAI,EACJ,MAAM,EACN,kCAAkC,EAClC,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,KAAK,EACL,eAAe,EACf,WAAW,EACX,KAAK,EACL,SAAS,EACT,aAAa,EACb,SAAS,EACT,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,MAAM,EACN,OAAO,EACP,YAAY,EACZ,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,yBAAyB,EACzB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,WAAW,EAC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qBAAqB,CAAC;AAGtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,wCAAwC,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,uBAAuB,EACvB,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,IAAI,EACJ,MAAM,EACN,kCAAkC,EAClC,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,KAAK,EACL,eAAe,EACf,WAAW,EACX,KAAK,EACL,SAAS,EACT,aAAa,EACb,SAAS,EACT,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,MAAM,EACN,OAAO,EACP,YAAY,EACZ,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,yBAAyB,EACzB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,2BAA2B,EAE3B,yBAAyB,EACzB,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC3B,uBA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O,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,wCAAwC,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Instruments an instance of a Cloudflare [`agents`](https://www.npmjs.com/package/agents) `Agent`
3
+ * with Sentry, adding telemetry that is specific to the Agent's runtime behavior:
4
+ *
5
+ * - **Callable RPC spans** — a span (op `rpc`) for each `@callable()` method invoked over WebSocket.
6
+ * - **Conversation correlation** — sets the conversation id on the scope for each unit of agent
7
+ * work — chat turn or callable RPC call — so `gen_ai` spans created within it are correlated, for
8
+ * chat and plain agents alike. Defaults to the instance `name` and is rotated when the chat is
9
+ * cleared (the `message:clear` observability event).
10
+ *
11
+ * It only hooks the `agents` package internals and uses Sentry's tracing primitives. On Cloudflare
12
+ * Workers, prefer `instrumentAgentWithSentry`, which additionally instruments the Durable Object
13
+ * handlers and initializes the SDK; that function calls this one internally.
14
+ *
15
+ * The hooks replace own-properties on the instance and defer to the original implementation, so
16
+ * they compose with any other instrumentation applied to the same instance.
17
+ *
18
+ * @param agent The `agents` `Agent` instance to instrument.
19
+ * @returns The same instance, instrumented.
20
+ *
21
+ * @internal Use `instrumentAgentWithSentry` instead — this is called internally by it.
22
+ */
23
+ export declare function instrumentCloudflareAgent<T extends object>(agent: T): T;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/instrumentations/agents/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAOvE"}
@@ -0,0 +1,11 @@
1
+ import { type AgentInternals } from './types';
2
+ /**
3
+ * Wraps the Agent's `onMessage` handler to create a span for each `@callable()` RPC invocation.
4
+ * RPC requests arrive as WebSocket messages, so this span nests under the active transaction for
5
+ * the WebSocket message (on Cloudflare, the instrumented Durable Object `webSocketMessage` hook).
6
+ *
7
+ * Also sets the conversation id on the scope for the duration of the call: callable methods are the
8
+ * unit of work for plain (non-chat) agents, which run LLM calls just like chat turns do.
9
+ */
10
+ export declare function instrumentAgentCallableRpc(obj: AgentInternals): void;
11
+ //# sourceMappingURL=instrumentAgentCallableRpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentAgentCallableRpc.d.ts","sourceRoot":"","sources":["../../../../src/instrumentations/agents/instrumentAgentCallableRpc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,KAAK,cAAc,EAA8C,MAAM,SAAS,CAAC;AAE7G;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CA+BpE"}
@@ -0,0 +1,22 @@
1
+ import { type AgentInternals } from './types';
2
+ /**
3
+ * For chat agents (`AIChatAgent` from `@cloudflare/ai-chat`), correlates each chat turn's AI spans
4
+ * with a conversation id on the active scope.
5
+ *
6
+ * In the Agents model one agent instance is one long-lived conversation, so the instance `name` is
7
+ * the base conversation id. When the user clears the chat, they expect a fresh conversation — but
8
+ * recreating the Durable Object for that would also drop the MCP/OAuth state stored per instance
9
+ * (GitHub/Sentry sign-in). To get a fresh conversation id *without* losing that state, we rotate an
10
+ * in-memory id on the instance when the SDK reports a cleared chat, and stamp that (falling back to
11
+ * the instance `name` before the first clear).
12
+ *
13
+ * The id itself is not attached to spans here — the SDK's `conversationIdIntegration` reads it off
14
+ * the scope at `spanStart` and stamps `gen_ai.conversation.id` onto the AI spans created inside the
15
+ * turn (e.g. by the Workers AI instrumentation), which correlates a turn's model and tool calls.
16
+ *
17
+ * Plain (non-chat) `Agent`s do not define `onChatMessage`, so they are skipped here — their unit
18
+ * of work is the callable RPC method, where `instrumentAgentCallableRpc` sets the conversation id
19
+ * instead.
20
+ */
21
+ export declare function instrumentChatAgentConversation(obj: AgentInternals): void;
22
+ //# sourceMappingURL=instrumentChatAgentConversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentChatAgentConversation.d.ts","sourceRoot":"","sources":["../../../../src/instrumentations/agents/instrumentChatAgentConversation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAA0B,MAAM,SAAS,CAAC;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CAgCzE"}
@@ -0,0 +1,49 @@
1
+ export declare const AGENT_SPAN_ORIGIN = "auto.faas.cloudflare.agents";
2
+ export declare const AGENT_CLASS_ATTRIBUTE = "cloudflare.agent.class";
3
+ export declare const AGENT_NAME_ATTRIBUTE = "cloudflare.agent.name";
4
+ /**
5
+ * The subset of the `agents` `Agent` instance internals that we instrument. These are runtime
6
+ * implementation details of the `agents` package (v0.13.x) rather than part of its public type
7
+ * surface, so every access is guarded and wrapping degrades gracefully if a name changes upstream.
8
+ */
9
+ export interface AgentInternals {
10
+ /** Central choke-point through which all `agents:*` observability events are published. */
11
+ _emit?: (type: string, payload?: Record<string, unknown>) => void;
12
+ /** WebSocket message handler; dispatches `@callable()` RPC requests. */
13
+ onMessage?: (...args: unknown[]) => unknown;
14
+ /**
15
+ * Chat-turn handler. Only `AIChatAgent` (from `@cloudflare/ai-chat`) defines this; a plain `Agent`
16
+ * does not, so its presence discriminates a chat agent.
17
+ */
18
+ onChatMessage?: (...args: unknown[]) => unknown;
19
+ /** The user's Agent class (used by the SDK for the observability event `agent` field). */
20
+ _ParentClass?: {
21
+ name?: string;
22
+ };
23
+ /** The Agent instance name, which in the Agents model identifies the conversation/thread. */
24
+ name?: string;
25
+ /**
26
+ * Internal: the active conversation id, rotated when the chat is cleared (the `message:clear`
27
+ * observability event) so a reset chat groups as a fresh conversation while the instance (and its
28
+ * MCP/OAuth state) stays put. Set by `instrumentChatAgentConversation`; falls back to `name`
29
+ * before the first clear.
30
+ */
31
+ __sentryConversationId?: string;
32
+ }
33
+ /** Reads best-effort agent identity attributes from the instance, tolerating missing internals. */
34
+ export declare function getAgentAttributes(instance: AgentInternals): Record<string, string>;
35
+ /**
36
+ * Sets the agent instance's conversation id on the current scope for the duration of the
37
+ * surrounding unit of work (chat turn, callable RPC call). In the Agents model one instance is one
38
+ * conversation, so the instance `name` is the natural conversation id — for chat and plain agents
39
+ * alike, since plain agents run LLM calls too (e.g. inside `@callable()` methods). Once the chat
40
+ * has been cleared, the rotated `__sentryConversationId` takes precedence so LLM calls from any
41
+ * unit of work group under the fresh conversation.
42
+ *
43
+ * `conversationIdIntegration` reads the id off the scope at `spanStart` and stamps
44
+ * `gen_ai.conversation.id` onto AI spans created within the unit of work, correlating its model
45
+ * and tool calls. Callers run inside a per-event forked scope (`wrapMethodWithSentry`), so the id
46
+ * does not leak into unrelated events.
47
+ */
48
+ export declare function setAgentConversationId(instance: AgentInternals): void;
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instrumentations/agents/types.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,gCAAgC,CAAC;AAC/D,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAC9D,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,2FAA2F;IAC3F,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAClE,wEAAwE;IACxE,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAC5C;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAChD,0FAA0F;IAC1F,YAAY,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjC,6FAA6F;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcnF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAMrE"}
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentDurableObjectStorage.d.ts","sourceRoot":"","sources":["../../../src/instrumentations/instrumentDurableObjectStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAA6B,MAAM,2BAA2B,CAAC;AAUjG,KAAK,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,SAAS,CAAC,EAAE,SAAS,GACpB,oBAAoB,CAwEtB"}
1
+ {"version":3,"file":"instrumentDurableObjectStorage.d.ts","sourceRoot":"","sources":["../../../src/instrumentations/instrumentDurableObjectStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAA6B,MAAM,2BAA2B,CAAC;AAYjG,KAAK,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,SAAS,CAAC,EAAE,SAAS,GACpB,oBAAoB,CAiFtB"}
@@ -0,0 +1,22 @@
1
+ type SpotlightConnectionOptions = {
2
+ /**
3
+ * Set this if the Spotlight Sidecar is not running on localhost:8969.
4
+ * By default, the URL is set to http://localhost:8969/stream
5
+ */
6
+ sidecarUrl?: string;
7
+ };
8
+ export declare const INTEGRATION_NAME: "Spotlight";
9
+ /**
10
+ * Use this integration to send errors and transactions to Spotlight.
11
+ *
12
+ * Learn more about spotlight at https://spotlightjs.com
13
+ *
14
+ * Important: This integration is intended for local development only.
15
+ * Each forwarded envelope counts as a Worker subrequest (50 free / 1000 paid
16
+ * per invocation), so it should not be enabled in production.
17
+ */
18
+ export declare const spotlightIntegration: (options?: Partial<SpotlightConnectionOptions> | undefined) => import("@sentry/core").Integration & {
19
+ name: "Spotlight";
20
+ };
21
+ export {};
22
+ //# sourceMappingURL=spotlight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spotlight.d.ts","sourceRoot":"","sources":["../../../src/integrations/spotlight.ts"],"names":[],"mappings":"AAIA,KAAK,0BAA0B,GAAG;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAG,WAAoB,CAAC;AAcrD;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB;;CAA2C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"vercelai.d.ts","sourceRoot":"","sources":["../../../../src/integrations/tracing/vercelai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,UAAU,eAAe;IACvB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB;;CAA0C,CAAC"}
1
+ {"version":3,"file":"vercelai.d.ts","sourceRoot":"","sources":["../../../../src/integrations/tracing/vercelai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,UAAU,eAAe;IACvB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAM5B;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB;;CAA0C,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export * from '../index';
2
- export { prismaIntegration } from '@sentry/node';
2
+ export { prismaIntegration } from '@sentry/server-utils';
3
3
  export { vercelAIIntegration } from './integrations/tracing/vercelai';
4
4
  //# sourceMappingURL=index.d.ts.map