@sentry/cloudflare 10.68.0 → 10.70.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 (177) hide show
  1. package/build/cjs/client.js +5 -0
  2. package/build/cjs/client.js.map +1 -1
  3. package/build/cjs/durableobject.js +210 -97
  4. package/build/cjs/durableobject.js.map +1 -1
  5. package/build/cjs/flush.js.map +1 -1
  6. package/build/cjs/index.js +3 -0
  7. package/build/cjs/index.js.map +1 -1
  8. package/build/cjs/instrumentations/agents/index.js +16 -0
  9. package/build/cjs/instrumentations/agents/index.js.map +1 -0
  10. package/build/cjs/instrumentations/agents/instrumentAgentCallableRpc.js +52 -0
  11. package/build/cjs/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -0
  12. package/build/cjs/instrumentations/agents/instrumentAgentRequestConversation.js +19 -0
  13. package/build/cjs/instrumentations/agents/instrumentAgentRequestConversation.js.map +1 -0
  14. package/build/cjs/instrumentations/agents/instrumentChatAgentConversation.js +31 -0
  15. package/build/cjs/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -0
  16. package/build/cjs/instrumentations/agents/types.js +77 -0
  17. package/build/cjs/instrumentations/agents/types.js.map +1 -0
  18. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js +6 -0
  19. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  20. package/build/cjs/instrumentations/instrumentSqlStorage.js +1 -1
  21. package/build/cjs/instrumentations/instrumentSqlStorage.js.map +1 -1
  22. package/build/cjs/integrations/spotlight.js +64 -0
  23. package/build/cjs/integrations/spotlight.js.map +1 -0
  24. package/build/cjs/nodejs_compat/index.js +5 -2
  25. package/build/cjs/nodejs_compat/index.js.map +1 -1
  26. package/build/cjs/options.js +14 -1
  27. package/build/cjs/options.js.map +1 -1
  28. package/build/cjs/request.js +3 -2
  29. package/build/cjs/request.js.map +1 -1
  30. package/build/cjs/sdk.js +8 -0
  31. package/build/cjs/sdk.js.map +1 -1
  32. package/build/cjs/utils/internalSqlQuery.js +13 -7
  33. package/build/cjs/utils/internalSqlQuery.js.map +1 -1
  34. package/build/cjs/utils/internalStorageKey.js +44 -0
  35. package/build/cjs/utils/internalStorageKey.js.map +1 -0
  36. package/build/cjs/utils/invocationScope.js +12 -0
  37. package/build/cjs/utils/invocationScope.js.map +1 -0
  38. package/build/cjs/utils/rpcMeta.js +4 -0
  39. package/build/cjs/utils/rpcMeta.js.map +1 -1
  40. package/build/cjs/vite/agentClass.js +114 -0
  41. package/build/cjs/vite/agentClass.js.map +1 -0
  42. package/build/cjs/vite/autoInstrument.js +17 -4
  43. package/build/cjs/vite/autoInstrument.js.map +1 -1
  44. package/build/cjs/vite/index.js +1 -1
  45. package/build/cjs/vite/index.js.map +1 -1
  46. package/build/cjs/vite/moduleShape.js +231 -0
  47. package/build/cjs/vite/moduleShape.js.map +1 -0
  48. package/build/cjs/vite/transform.js +6 -1
  49. package/build/cjs/vite/transform.js.map +1 -1
  50. package/build/cjs/vite/wranglerConfig.js +1 -1
  51. package/build/cjs/vite/wranglerConfig.js.map +1 -1
  52. package/build/cjs/workflows.js +1 -1
  53. package/build/cjs/workflows.js.map +1 -1
  54. package/build/cjs/wrapMethodWithSentry.js +2 -3
  55. package/build/cjs/wrapMethodWithSentry.js.map +1 -1
  56. package/build/esm/client.js +6 -1
  57. package/build/esm/client.js.map +1 -1
  58. package/build/esm/durableobject.js +211 -101
  59. package/build/esm/durableobject.js.map +1 -1
  60. package/build/esm/flush.js.map +1 -1
  61. package/build/esm/index.js +2 -1
  62. package/build/esm/index.js.map +1 -1
  63. package/build/esm/instrumentations/agents/index.js +14 -0
  64. package/build/esm/instrumentations/agents/index.js.map +1 -0
  65. package/build/esm/instrumentations/agents/instrumentAgentCallableRpc.js +50 -0
  66. package/build/esm/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -0
  67. package/build/esm/instrumentations/agents/instrumentAgentRequestConversation.js +17 -0
  68. package/build/esm/instrumentations/agents/instrumentAgentRequestConversation.js.map +1 -0
  69. package/build/esm/instrumentations/agents/instrumentChatAgentConversation.js +29 -0
  70. package/build/esm/instrumentations/agents/instrumentChatAgentConversation.js.map +1 -0
  71. package/build/esm/instrumentations/agents/types.js +69 -0
  72. package/build/esm/instrumentations/agents/types.js.map +1 -0
  73. package/build/esm/instrumentations/instrumentDurableObjectStorage.js +7 -1
  74. package/build/esm/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  75. package/build/esm/instrumentations/instrumentSqlStorage.js +1 -1
  76. package/build/esm/instrumentations/instrumentSqlStorage.js.map +1 -1
  77. package/build/esm/integrations/spotlight.js +61 -0
  78. package/build/esm/integrations/spotlight.js.map +1 -0
  79. package/build/esm/nodejs_compat/index.js +2 -1
  80. package/build/esm/nodejs_compat/index.js.map +1 -1
  81. package/build/esm/options.js +14 -1
  82. package/build/esm/options.js.map +1 -1
  83. package/build/esm/package.json +1 -1
  84. package/build/esm/request.js +4 -3
  85. package/build/esm/request.js.map +1 -1
  86. package/build/esm/sdk.js +8 -0
  87. package/build/esm/sdk.js.map +1 -1
  88. package/build/esm/utils/internalSqlQuery.js +13 -7
  89. package/build/esm/utils/internalSqlQuery.js.map +1 -1
  90. package/build/esm/utils/internalStorageKey.js +41 -0
  91. package/build/esm/utils/internalStorageKey.js.map +1 -0
  92. package/build/esm/utils/invocationScope.js +10 -0
  93. package/build/esm/utils/invocationScope.js.map +1 -0
  94. package/build/esm/utils/rpcMeta.js +4 -1
  95. package/build/esm/utils/rpcMeta.js.map +1 -1
  96. package/build/esm/utils/traceLinks.js +1 -1
  97. package/build/esm/vite/agentClass.js +111 -0
  98. package/build/esm/vite/agentClass.js.map +1 -0
  99. package/build/esm/vite/autoInstrument.js +17 -4
  100. package/build/esm/vite/autoInstrument.js.map +1 -1
  101. package/build/esm/vite/index.js +1 -1
  102. package/build/esm/vite/index.js.map +1 -1
  103. package/build/esm/vite/moduleShape.js +227 -0
  104. package/build/esm/vite/moduleShape.js.map +1 -0
  105. package/build/esm/vite/transform.js +6 -1
  106. package/build/esm/vite/transform.js.map +1 -1
  107. package/build/esm/vite/wranglerConfig.js +1 -1
  108. package/build/esm/vite/wranglerConfig.js.map +1 -1
  109. package/build/esm/workflows.js +2 -2
  110. package/build/esm/workflows.js.map +1 -1
  111. package/build/esm/wrapMethodWithSentry.js +3 -4
  112. package/build/esm/wrapMethodWithSentry.js.map +1 -1
  113. package/build/types/client.d.ts +37 -0
  114. package/build/types/client.d.ts.map +1 -1
  115. package/build/types/durableobject.d.ts +90 -0
  116. package/build/types/durableobject.d.ts.map +1 -1
  117. package/build/types/flush.d.ts +1 -1
  118. package/build/types/flush.d.ts.map +1 -1
  119. package/build/types/index.d.ts +2 -1
  120. package/build/types/index.d.ts.map +1 -1
  121. package/build/types/instrumentations/agents/index.d.ts +25 -0
  122. package/build/types/instrumentations/agents/index.d.ts.map +1 -0
  123. package/build/types/instrumentations/agents/instrumentAgentCallableRpc.d.ts +14 -0
  124. package/build/types/instrumentations/agents/instrumentAgentCallableRpc.d.ts.map +1 -0
  125. package/build/types/instrumentations/agents/instrumentAgentRequestConversation.d.ts +16 -0
  126. package/build/types/instrumentations/agents/instrumentAgentRequestConversation.d.ts.map +1 -0
  127. package/build/types/instrumentations/agents/instrumentChatAgentConversation.d.ts +23 -0
  128. package/build/types/instrumentations/agents/instrumentChatAgentConversation.d.ts.map +1 -0
  129. package/build/types/instrumentations/agents/types.d.ts +94 -0
  130. package/build/types/instrumentations/agents/types.d.ts.map +1 -0
  131. package/build/types/instrumentations/instrumentDurableObjectStorage.d.ts.map +1 -1
  132. package/build/types/integrations/spotlight.d.ts +22 -0
  133. package/build/types/integrations/spotlight.d.ts.map +1 -0
  134. package/build/types/options.d.ts.map +1 -1
  135. package/build/types/request.d.ts.map +1 -1
  136. package/build/types/sdk.d.ts.map +1 -1
  137. package/build/types/utils/internalSqlQuery.d.ts +4 -2
  138. package/build/types/utils/internalSqlQuery.d.ts.map +1 -1
  139. package/build/types/utils/internalStorageKey.d.ts +22 -0
  140. package/build/types/utils/internalStorageKey.d.ts.map +1 -0
  141. package/build/types/utils/invocationScope.d.ts +24 -0
  142. package/build/types/utils/invocationScope.d.ts.map +1 -0
  143. package/build/types/utils/rpcMeta.d.ts +8 -0
  144. package/build/types/utils/rpcMeta.d.ts.map +1 -1
  145. package/build/types/vite/agentClass.d.ts +41 -0
  146. package/build/types/vite/agentClass.d.ts.map +1 -0
  147. package/build/types/vite/autoInstrument.d.ts +7 -6
  148. package/build/types/vite/autoInstrument.d.ts.map +1 -1
  149. package/build/types/vite/index.d.ts +14 -4
  150. package/build/types/vite/index.d.ts.map +1 -1
  151. package/build/types/vite/moduleShape.d.ts +52 -0
  152. package/build/types/vite/moduleShape.d.ts.map +1 -0
  153. package/build/types/vite/transform.d.ts +6 -1
  154. package/build/types/vite/transform.d.ts.map +1 -1
  155. package/build/types/wrapMethodWithSentry.d.ts +1 -1
  156. package/build/types/wrapMethodWithSentry.d.ts.map +1 -1
  157. package/build/types-ts3.8/client.d.ts +37 -0
  158. package/build/types-ts3.8/durableobject.d.ts +90 -0
  159. package/build/types-ts3.8/flush.d.ts +1 -1
  160. package/build/types-ts3.8/index.d.ts +2 -1
  161. package/build/types-ts3.8/instrumentations/agents/index.d.ts +25 -0
  162. package/build/types-ts3.8/instrumentations/agents/instrumentAgentCallableRpc.d.ts +14 -0
  163. package/build/types-ts3.8/instrumentations/agents/instrumentAgentRequestConversation.d.ts +16 -0
  164. package/build/types-ts3.8/instrumentations/agents/instrumentChatAgentConversation.d.ts +23 -0
  165. package/build/types-ts3.8/instrumentations/agents/types.d.ts +94 -0
  166. package/build/types-ts3.8/integrations/spotlight.d.ts +22 -0
  167. package/build/types-ts3.8/utils/internalSqlQuery.d.ts +4 -2
  168. package/build/types-ts3.8/utils/internalStorageKey.d.ts +22 -0
  169. package/build/types-ts3.8/utils/invocationScope.d.ts +24 -0
  170. package/build/types-ts3.8/utils/rpcMeta.d.ts +8 -0
  171. package/build/types-ts3.8/vite/agentClass.d.ts +41 -0
  172. package/build/types-ts3.8/vite/autoInstrument.d.ts +7 -6
  173. package/build/types-ts3.8/vite/index.d.ts +14 -4
  174. package/build/types-ts3.8/vite/moduleShape.d.ts +52 -0
  175. package/build/types-ts3.8/vite/transform.d.ts +6 -1
  176. package/build/types-ts3.8/wrapMethodWithSentry.d.ts +1 -1
  177. package/package.json +3 -3
@@ -0,0 +1,94 @@
1
+ import { InstrumentedDurableObjectState } from '../../wrapMethodWithSentry';
2
+ export declare const AGENT_SPAN_ORIGIN = "auto.faas.cloudflare.agents";
3
+ /** DO storage key under which the conversation id is persisted so it survives hibernation. */
4
+ export declare const AGENT_CONVERSATION_ID_STORAGE_KEY = "__SENTRY_AGENT_CONVERSATION_ID__";
5
+ /**
6
+ * Instance keys for our conversation-id bookkeeping, keyed by symbol so the state stays invisible
7
+ * to anything enumerating the user-owned agent instance (`Object.keys`, `JSON.stringify`, spread).
8
+ * Exported because the exported `AgentInternals` interface references them.
9
+ */
10
+ export declare const AGENT_CONVERSATION_ID_SYMBOL: unique symbol;
11
+ export declare const AGENT_APPLIED_CONVERSATION_ID_SYMBOL: unique symbol;
12
+ /**
13
+ * The subset of the `agents` `Agent` instance internals that we instrument. These are runtime
14
+ * implementation details of the `agents` package (v0.13.x) rather than part of its public type
15
+ * surface, so every access is guarded and wrapping degrades gracefully if a name changes upstream.
16
+ */
17
+ export interface AgentInternals {
18
+ /** Central choke-point through which all `agents:*` observability events are published. */
19
+ _emit?: (type: string, payload?: Record<string, unknown>) => void;
20
+ /** WebSocket message handler; dispatches `@callable()` RPC requests. */
21
+ onMessage?: (...args: unknown[]) => unknown;
22
+ /**
23
+ * Chat-turn handler. Only `AIChatAgent` (from `@cloudflare/ai-chat`) defines this; a plain `Agent`
24
+ * does not, so its presence discriminates a chat agent.
25
+ */
26
+ onChatMessage?: (...args: unknown[]) => unknown;
27
+ /** HTTP request handler; the router sends every non-WebSocket request here. */
28
+ onRequest?: (...args: unknown[]) => unknown;
29
+ /** The user's Agent class (used by the SDK for the observability event `agent` field). */
30
+ _ParentClass?: {
31
+ name?: string;
32
+ };
33
+ /** The Agent instance name, reported as the `cloudflare.agent.name` span attribute. */
34
+ name?: string;
35
+ /**
36
+ * The Durable Object state of the instance. Present on every real Agent; guarded like the other
37
+ * internals so partially-mocked instances keep working.
38
+ */
39
+ ctx?: InstrumentedDurableObjectState;
40
+ /**
41
+ * The current conversation id for this agent instance. It is cached in memory after being loaded
42
+ * from Durable Object storage and updated when the conversation rotates. `undefined` means storage
43
+ * has not been read yet.
44
+ */
45
+ [AGENT_CONVERSATION_ID_SYMBOL]?: string;
46
+ /**
47
+ * The conversation id this instrumentation most recently applied to the isolation scope. It lets
48
+ * subsequent units of work distinguish an SDK-applied id, which may be replaced after rotation,
49
+ * from an id explicitly set by the user, which must be preserved.
50
+ */
51
+ [AGENT_APPLIED_CONVERSATION_ID_SYMBOL]?: string;
52
+ }
53
+ /** Reads best-effort agent identity attributes from the instance, tolerating missing internals. */
54
+ export declare function getAgentAttributes(instance: AgentInternals): Record<string, string>;
55
+ /**
56
+ * Persists the conversation id to Durable Object storage, so it survives hibernation, and updates
57
+ * the in-memory cache synchronously so the current wake is immediately consistent even if the
58
+ * write fails. Uses the async storage API, which exists on KV- and SQLite-backed DOs alike.
59
+ * The write is fire-and-forget: DO storage writes are tracked by the runtime and land without
60
+ * awaiting (`waitUntil` is a no-op in Durable Objects), and the catch keeps a rejection from
61
+ * surfacing as unhandled — a failed write just means the next wake starts a new conversation,
62
+ * which must never throw into user code. Uses the original uninstrumented storage so internal
63
+ * bookkeeping doesn't create spans.
64
+ */
65
+ export declare function storeAgentConversationId(instance: AgentInternals, conversationId: string): void;
66
+ /**
67
+ * Sets the agent instance's conversation id on the active scope for the duration of the
68
+ * surrounding unit of work (chat turn, callable RPC call, HTTP request). In the Agents model one
69
+ * instance is one long-lived conversation, so the id is minted once per instance and persisted to
70
+ * DO storage — for chat and plain agents alike, since plain agents run LLM calls too (e.g. inside
71
+ * `@callable()` methods). The instance `name` is deliberately not used: it is caller-chosen and can
72
+ * be a stable, guessable, or shared value, whereas a conversation id should identify exactly one
73
+ * conversation. Clearing the chat rotates it (see `storeAgentConversationId`) so subsequent LLM
74
+ * calls group under the fresh conversation.
75
+ *
76
+ * Every handler wrapper awaits this before invoking the original, so the id is on the scope before
77
+ * the unit of work — and any `gen_ai` span it creates — starts. Only the first unit of work per wake
78
+ * pays the storage read; the rest resolve from the in-memory cache. Awaiting is safe on all three
79
+ * paths because the `agents` `Agent` constructor already replaces `onMessage` and `onRequest` with
80
+ * `async` wrappers of its own, and `onChatMessage` is async by contract, so every caller upstream
81
+ * already handles a promise.
82
+ *
83
+ * An id the user set explicitly outranks this inferred one, in either order: a `setConversationId()`
84
+ * call that already happened is detected here and left alone, and one made inside the handler lands
85
+ * on the same scope afterwards and therefore wins. That is why the write targets the isolation scope
86
+ * — it is the scope the public `Sentry.setConversationId()` writes to, and `conversationIdIntegration`
87
+ * prefers the current scope over it, so writing there would make a user's call unoverridable.
88
+ *
89
+ * `conversationIdIntegration` reads the id off the scope at `spanStart` and stamps
90
+ * `gen_ai.conversation.id` onto AI spans created within the unit of work, correlating its model and
91
+ * tool calls.
92
+ */
93
+ export declare function setAgentConversationId(instance: AgentInternals): Promise<void>;
94
+ //# sourceMappingURL=types.d.ts.map
@@ -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
@@ -12,7 +12,9 @@
12
12
  *
13
13
  * The check operates on the query summary produced by `getSqlQuerySummary` (`{operation} {table} ...`,
14
14
  * the same value used as the span name), so table targets are already isolated from the rest of the
15
- * query.
15
+ * query. The one exception is `CREATE INDEX`: its summary carries the index name, not the indexed
16
+ * table (upstream OTel convention), so the `cf_` target only appears in the ON clause of the full
17
+ * statement, which `queryText` is needed for.
16
18
  */
17
- export declare function targetsCloudflareInternalTable(querySummary: string | undefined, allowlist?: Array<string | RegExp>): boolean;
19
+ export declare function targetsCloudflareInternalTable(querySummary: string | undefined, allowlist?: Array<string | RegExp>, queryText?: string): boolean;
18
20
  //# sourceMappingURL=internalSqlQuery.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Cloudflare frameworks that build on Durable Objects (`agents`, `partyserver`, ...) also manage
3
+ * their own internal KV entries alongside their internal SQLite tables, namespaced with a reserved
4
+ * prefix — e.g. `cf_agents_state`, `cf_agents_mcp_servers`, `__ps_name`. Reads/writes of these
5
+ * (message persistence, MCP connection bookkeeping, name hydration) are framework implementation
6
+ * details that otherwise flood traces with dozens of zero-signal `durable_object_storage_*` spans
7
+ * per request, so we match the reserved prefixes rather than an enumerated list. This mirrors the
8
+ * `cf_` convention used for internal SQL tables (see `targetsCloudflareInternalTable`).
9
+ *
10
+ * The prefixes are a reserved convention for framework-managed entries, so user keys should not use
11
+ * them. In case a user key does collide, the `durableObjectStorageSpanAllowlist` option lets them
12
+ * opt those keys back into instrumentation.
13
+ */
14
+ export declare function targetsCloudflareInternalKey(key: string | undefined, allowlist?: Array<string | RegExp>): boolean;
15
+ /**
16
+ * Extracts the KV keys a Durable Object storage call targets, so the caller can decide whether the
17
+ * operation only touches framework-internal entries. Returns `undefined` when the keys can't be
18
+ * determined from the arguments (e.g. `list()` without a prefix), in which case the call is treated
19
+ * as user work and stays instrumented.
20
+ */
21
+ export declare function getStorageKeys(methodName: string, args: unknown[]): string[] | undefined;
22
+ //# sourceMappingURL=internalStorageKey.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { Scope } from '@sentry/core';
2
+ /**
3
+ * Runs `callback` on the isolation scope for the current invocation.
4
+ *
5
+ * An instrumented handler is either the entry point of an invocation or reentrant — reached from
6
+ * another instrumented handler already serving the same invocation (a Durable Object method calling
7
+ * its own `fetch`, an RPC method reaching a sibling method). Only the entry point may fork:
8
+ *
9
+ * - Forking at the entry point is mandatory. `setUser`/`setTag` write to the isolation scope, and a
10
+ * Durable Object's isolation scope outlives the invocation that touched it, so without a fork one
11
+ * invocation's user and tags reappear on the next invocation's events in the same isolate.
12
+ * Forking clones, so request data set by an enclosing wrapper is still inherited.
13
+ * - Forking again when reentrant would be wrong. Everything below the entry point is one logical
14
+ * unit of work: a nested call must see what the caller set and be able to add to it, the way it
15
+ * would if the SDK were not wrapping it at all.
16
+ *
17
+ * The AsyncLocalStorage strategy hands the default isolation scope back whenever no invocation is in
18
+ * flight, and a forked one while inside `withIsolationScope`. Reference-comparing against the default
19
+ * is therefore enough to tell the two cases apart. The stack fallback does not fork, so it reports the
20
+ * default scope even inside an invocation; there the fork degrades to a no-op, which the stack strategy
21
+ * tolerates. This matches the approach used by `patchEventHandler` in Nuxt.
22
+ */
23
+ export declare function withInvocationIsolationScope<T>(callback: (scope: Scope) => T): T;
24
+ //# sourceMappingURL=invocationScope.d.ts.map
@@ -4,6 +4,14 @@ import { SerializedTraceData } from '@sentry/core';
4
4
  * If no active trace exists, returns the original args unchanged.
5
5
  */
6
6
  export declare function appendRpcMeta(args: unknown[]): unknown[];
7
+ /**
8
+ * Whether the trailing argument carries Sentry RPC metadata.
9
+ *
10
+ * Separate from {@link extractRpcMeta} because the RPC method wrappers run this check on every
11
+ * call — including the instance's own internal method calls, which never carry metadata — and
12
+ * must not allocate on that path.
13
+ */
14
+ export declare function hasRpcMeta(args: unknown[]): boolean;
7
15
  /**
8
16
  * Extracts Sentry RPC metadata from the trailing argument of an args array.
9
17
  * Returns cleaned args (without meta) and the extracted trace data if found.
@@ -0,0 +1,41 @@
1
+ import { ProgramBody } from './transform';
2
+ /**
3
+ * The subset of the Vite/Rollup plugin context needed to walk the module graph.
4
+ *
5
+ * `resolve` is optional: without it detection still works, but only for base-class chains declared
6
+ * inside the entry module itself. `readFile` is injectable for tests and defaults to reading disk.
7
+ *
8
+ * Deliberately **no `load`**: awaiting the plugin context's `load()` from inside a `transform` hook
9
+ * deadlocks the build — the module cannot finish loading while its own transform is still pending
10
+ * (Rollup documents this hazard, and Vite's Rolldown pipeline is stricter still). Sibling modules
11
+ * are therefore read straight off disk; see {@link getModuleShape}.
12
+ */
13
+ export interface ModuleResolver {
14
+ parse(code: string): ProgramBody;
15
+ resolve?(source: string, importer: string): Promise<{
16
+ id: string;
17
+ } | null | undefined>;
18
+ readFile?(id: string): string | undefined;
19
+ }
20
+ /**
21
+ * Find which of `candidates` (top-level class names in the entry module) are Cloudflare
22
+ * [`agents`](https://www.npmjs.com/package/agents) Agents.
23
+ *
24
+ * An Agent is a Durable Object under the hood, so wrangler configures it as one and the transform
25
+ * would otherwise reach for `instrumentDurableObjectWithSentry`. Detecting the Agent base chain lets
26
+ * it pick `instrumentAgentWithSentry` instead, which adds the Agent-specific telemetry on top.
27
+ *
28
+ * Unlike `WorkerEntrypoint` detection, the chain is followed *across* modules: base classes commonly
29
+ * live in their own file (`import { MyBase } from './base'`), and there is no runtime fallback that
30
+ * would catch a missed one. Resolution stops at package boundaries — a base class imported from
31
+ * `node_modules` is only recognized when it is one of {@link AGENT_BASE_CLASSES}.
32
+ */
33
+ export declare function detectAgentClasses(ast: ProgramBody, entryId: string, candidates: Iterable<string>, resolver: ModuleResolver): Promise<Set<string>>;
34
+ /**
35
+ * The local class names in the entry that a configured class name could refer to — either declared
36
+ * under that name directly, or aliased to it by an `export { Local as Configured }` specifier.
37
+ *
38
+ * Keeps detection (which reads and scans other modules) off classes that no binding points at.
39
+ */
40
+ export declare function collectAgentCandidates(ast: ProgramBody, configuredNames: Iterable<string>): Set<string>;
41
+ //# sourceMappingURL=agentClass.d.ts.map
@@ -1,5 +1,7 @@
1
- import { ProgramBody } from './transform';
2
- export declare function sentryCloudflareAutoInstrumentPlugin(): {
1
+ import { ModuleResolver } from './agentClass';
2
+ export declare function sentryCloudflareAutoInstrumentPlugin(options?: {
3
+ wranglerConfigPath?: string;
4
+ }): {
3
5
  name: string;
4
6
  configResolved(config: {
5
7
  root: string;
@@ -7,15 +9,14 @@ export declare function sentryCloudflareAutoInstrumentPlugin(): {
7
9
  warn(msg: string): void;
8
10
  };
9
11
  }): void;
10
- transform(this: {
11
- parse(code: string): ProgramBody;
12
+ transform(this: ModuleResolver & {
12
13
  warn?(msg: string): void;
13
14
  environment?: {
14
15
  name?: string;
15
16
  };
16
- }, code: string, id: string): {
17
+ }, code: string, id: string): Promise<{
17
18
  code: string;
18
19
  map: unknown;
19
- } | undefined;
20
+ } | undefined>;
20
21
  };
21
22
  //# sourceMappingURL=autoInstrument.d.ts.map
@@ -2,6 +2,17 @@
2
2
  * Options for {@link sentryCloudflareVitePlugin}.
3
3
  */
4
4
  export interface SentryCloudflareVitePluginOptions {
5
+ /**
6
+ * Path to the wrangler config, relative to the Vite root (or absolute).
7
+ * Set this when your config doesn't use a default name — e.g. when you
8
+ * pass `configPath: './wrangler.agent.jsonc'` to `@cloudflare/vite-plugin`,
9
+ * which the Sentry plugin cannot see. When set, only this file is read
10
+ * (no default-name probing), and a warning is emitted if it is missing or
11
+ * unparseable.
12
+ *
13
+ * @default undefined (probes `wrangler.json`, `wrangler.jsonc`, `wrangler.toml` at the Vite root)
14
+ */
15
+ wranglerConfigPath?: string;
5
16
  /**
6
17
  * Experimental options that may change or be removed without notice.
7
18
  */
@@ -74,15 +85,14 @@ export declare function sentryCloudflareVitePlugin(options?: SentryCloudflareVit
74
85
  warn(msg: string): void;
75
86
  };
76
87
  }): void;
77
- transform(this: {
78
- parse(code: string): import("./transform").ProgramBody;
88
+ transform(this: import("./agentClass").ModuleResolver & {
79
89
  warn?(msg: string): void;
80
90
  environment?: {
81
91
  name?: string;
82
92
  };
83
- }, code: string, id: string): {
93
+ }, code: string, id: string): Promise<{
84
94
  code: string;
85
95
  map: unknown;
86
- } | undefined;
96
+ } | undefined>;
87
97
  } | import("vite").Plugin<any>)[];
88
98
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { ProgramBody } from './transform';
2
+ /** Binding name used for a module's default export. */
3
+ export declare const DEFAULT_EXPORT = "default";
4
+ /** A resolved superclass reference: a bare identifier or a `ns.Member` expression. */
5
+ export type SuperRef = {
6
+ kind: 'identifier';
7
+ name: string;
8
+ } | {
9
+ kind: 'member';
10
+ object: string;
11
+ property: string;
12
+ };
13
+ /** The declarations of a single module that binding resolution needs. */
14
+ export interface ModuleShape {
15
+ /** Top-level class names → their superclass reference (absent when the class has no `extends`). */
16
+ classes: Map<string, SuperRef | undefined>;
17
+ /** Local binding name → the import it came from (`imported` is `default` for a default import). */
18
+ imports: Map<string, {
19
+ source: string;
20
+ imported: string;
21
+ }>;
22
+ /** Local binding name → module specifier, for `import * as ns from '...'`. */
23
+ namespaces: Map<string, string>;
24
+ /** Exported name → the re-export it came from, for `export { x as y } from '...'`. */
25
+ reexports: Map<string, {
26
+ source: string;
27
+ imported: string;
28
+ }>;
29
+ /** Exported name → local binding name, for `export { x as y }` without a source. */
30
+ localExports: Map<string, string>;
31
+ /** Module specifiers of bare `export * from '...'` declarations. */
32
+ starExports: string[];
33
+ /** `export default <Identifier>` — the local name it refers to. */
34
+ defaultExportName?: string;
35
+ /** True when the module's default export is a class declaration/expression. */
36
+ defaultExportIsClass?: boolean;
37
+ /** Superclass of an anonymous `export default class extends X`. */
38
+ defaultExportSuper?: SuperRef;
39
+ }
40
+ /** Collect the shape of a module from its parsed AST — used for the already-parsed entry module. */
41
+ export declare function shapeFromAst(ast: ProgramBody): ModuleShape;
42
+ /**
43
+ * Extract the module shape from **unprocessed source**.
44
+ *
45
+ * Sibling modules are read straight from disk (the plugin context's `load()` would deadlock inside a
46
+ * transform hook), so they may still be TypeScript — which no JS parser will accept. Only
47
+ * import/export statements and `class X extends Y` headers matter here, and those are
48
+ * declaration-level syntax a scan can pick out reliably; class bodies, type annotations and generics
49
+ * are irrelevant and simply skipped.
50
+ */
51
+ export declare function shapeFromSource(rawCode: string): ModuleShape;
52
+ //# sourceMappingURL=moduleShape.d.ts.map
@@ -18,7 +18,7 @@ export interface ProgramBody {
18
18
  * config providing only a fallback for self-bound entrypoints whose base class
19
19
  * lives in another module.
20
20
  */
21
- export type ClassWrapperKind = 'durableObject' | 'workflow' | 'workerEntrypoint';
21
+ export type ClassWrapperKind = 'durableObject' | 'agent' | 'workflow' | 'workerEntrypoint';
22
22
  export interface TransformContext {
23
23
  /**
24
24
  * Exported class name → the kind of Sentry wrapper to apply. Populated from
@@ -26,6 +26,11 @@ export interface TransformContext {
26
26
  * each class's base type.
27
27
  */
28
28
  classWrappers: Map<string, ClassWrapperKind>;
29
+ /**
30
+ * Local class names detected as `agents` Agents. An Agent is configured as a Durable Object in
31
+ * wrangler, so this upgrades those entries from `durableObject` to `agent`.
32
+ */
33
+ agentClasses?: ReadonlySet<string>;
29
34
  optionsFn: string;
30
35
  /** Import statement prepended when `optionsFn` references a separate module. */
31
36
  optionsImport?: string;
@@ -1,7 +1,7 @@
1
1
  import { DurableObjectStorage } from '@cloudflare/workers-types';
2
2
  import { CloudflareOptions } from './client';
3
3
  /** Extended DurableObjectState with originalStorage exposed by instrumentContext */
4
- interface InstrumentedDurableObjectState extends DurableObjectState {
4
+ export interface InstrumentedDurableObjectState extends DurableObjectState {
5
5
  originalStorage?: DurableObjectStorage;
6
6
  }
7
7
  type MethodWrapperOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/cloudflare",
3
- "version": "10.68.0",
3
+ "version": "10.70.0",
4
4
  "description": "Official Sentry SDK for Cloudflare Workers and Pages",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare",
@@ -70,8 +70,8 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@opentelemetry/api": "^1.9.1",
73
- "@sentry/core": "10.68.0",
74
- "@sentry/server-utils": "10.68.0",
73
+ "@sentry/core": "10.70.0",
74
+ "@sentry/server-utils": "10.70.0",
75
75
  "magic-string": "~0.30.21"
76
76
  },
77
77
  "peerDependencies": {