@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
@@ -1 +1 @@
1
- {"version":3,"file":"flush.js","sources":["../../src/flush.ts"],"sourcesContent":["import type { ExecutionContext } from '@cloudflare/workers-types';\nimport type { Client } from '@sentry/core';\nimport { debug, flush } from '@sentry/core';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { ExecutionContextCompat } from './executionContext';\n\ntype FlushLock = {\n readonly ready: Promise<void>;\n readonly finalize: () => Promise<void>;\n};\n\ntype FlushLockRegistry = {\n readonly locks: Set<FlushLockInternal>;\n readonly originalWaitUntil: ExecutionContext['waitUntil'];\n};\n\ntype FlushLockInternal = FlushLock & {\n readonly acquire: () => void;\n readonly release: () => void;\n};\n\nconst flushLockRegistries = new WeakMap<ExecutionContext['waitUntil'], FlushLockRegistry>();\n\n/**\n * Returns the original (un-instrumented) waitUntil function for a context.\n * This should be used when calling waitUntil with flushAndDispose to avoid deadlock.\n *\n * The flush lock mechanism wraps context.waitUntil to track pending tasks.\n * If we call waitUntil(flushAndDispose(client)) through the instrumented version,\n * it creates a deadlock because:\n * 1. The instrumented waitUntil acquires the flush lock\n * 2. flushAndDispose calls client.flush() which waits for the lock to be released\n * 3. The lock won't be released until the waitUntil promise completes\n * 4. The waitUntil promise won't complete until flush() returns\n *\n * By using the original waitUntil for flush operations, we bypass this issue.\n */\nexport function getOriginalWaitUntil(context: ExecutionContextCompat): ExecutionContext['waitUntil'] | undefined {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const currentWaitUntil = context.waitUntil;\n const original = flushLockRegistries.get(currentWaitUntil)?.originalWaitUntil;\n return original ?? currentWaitUntil;\n}\n\n/**\n * Enhances the given execution context by wrapping its `waitUntil` method with a proxy\n * to monitor pending tasks, and provides a flusher function to ensure all tasks\n * have been completed before executing any subsequent logic.\n *\n * @param {ExecutionContext} context - The execution context to be enhanced. If no context is provided, the function returns undefined.\n * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.\n */\nexport function makeFlushLock(context: ExecutionContextCompat): FlushLock {\n const registry = getOrCreateFlushLockRegistry(context);\n let resolveAllDone: () => void = () => undefined;\n const allDone = new Promise<void>(res => {\n resolveAllDone = res;\n });\n let pending = 0;\n\n const lock: FlushLockInternal = {\n ready: allDone,\n acquire: () => {\n pending++;\n },\n release: () => {\n if (--pending === 0) {\n registry.locks.delete(lock);\n resolveAllDone();\n }\n },\n finalize: () => {\n if (pending === 0) {\n registry.locks.delete(lock);\n resolveAllDone();\n }\n return allDone;\n },\n };\n\n registry.locks.add(lock);\n return Object.freeze(lock);\n}\n\nfunction getOrCreateFlushLockRegistry(context: ExecutionContextCompat): FlushLockRegistry {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const waitUntil = context.waitUntil;\n const existingRegistry = flushLockRegistries.get(waitUntil);\n\n if (existingRegistry) {\n return existingRegistry;\n }\n\n const originalWaitUntil = context.waitUntil.bind(context) as typeof context.waitUntil;\n const registry: FlushLockRegistry = { locks: new Set(), originalWaitUntil };\n const instrumentedWaitUntil: typeof context.waitUntil = promise => {\n // Snapshot active locks so locks created after this call do not wait for earlier waitUntil work.\n const locks = [...registry.locks];\n\n for (const lock of locks) {\n lock.acquire();\n }\n\n return originalWaitUntil(\n promise.finally(() => {\n for (const lock of locks) {\n lock.release();\n }\n }),\n );\n };\n\n flushLockRegistries.set(instrumentedWaitUntil, registry);\n context.waitUntil = instrumentedWaitUntil;\n\n return registry;\n}\n\n/**\n * Flushes the client and then disposes of it to allow garbage collection.\n * This should be called at the end of each request to prevent memory leaks.\n *\n * This function never rejects. On Workers, a rejected promise passed to\n * `ctx.waitUntil` marks the whole invocation as `outcome: exception` even when\n * the handler itself completed successfully. Since flush/dispose is internal\n * SDK housekeeping, a failure here must not fail the user's invocation.\n *\n * @param client - The CloudflareClient instance to flush and dispose\n * @param timeout - Timeout in milliseconds for the flush operation\n * @returns A promise that resolves when flush and dispose are complete\n */\nexport async function flushAndDispose(client: Client | undefined, timeout = 2000): Promise<void> {\n try {\n if (!client) {\n await flush(timeout);\n return;\n }\n await client.flush(timeout);\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to flush client', e);\n } finally {\n try {\n client?.dispose();\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to dispose client', e);\n }\n }\n}\n"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"flush.js","sources":["../../src/flush.ts"],"sourcesContent":["import type { ExecutionContext } from '@cloudflare/workers-types';\nimport type { Client } from '@sentry/core';\nimport { debug, flush } from '@sentry/core';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { ExecutionContextCompat } from './executionContext';\n\ntype FlushLock = {\n readonly ready: Promise<void>;\n readonly finalize: () => Promise<void>;\n};\n\ntype FlushLockRegistry = {\n readonly locks: Set<FlushLockInternal>;\n readonly originalWaitUntil: ExecutionContext['waitUntil'];\n};\n\ntype FlushLockInternal = FlushLock & {\n readonly acquire: () => void;\n readonly release: () => void;\n};\n\nconst flushLockRegistries = new WeakMap<ExecutionContext['waitUntil'], FlushLockRegistry>();\n\n/**\n * Returns the original (un-instrumented) waitUntil function for a context.\n * This should be used when calling waitUntil with flushAndDispose to avoid deadlock.\n *\n * The flush lock mechanism wraps context.waitUntil to track pending tasks.\n * If we call waitUntil(flushAndDispose(client)) through the instrumented version,\n * it creates a deadlock because:\n * 1. The instrumented waitUntil acquires the flush lock\n * 2. flushAndDispose calls client.flush() which waits for the lock to be released\n * 3. The lock won't be released until the waitUntil promise completes\n * 4. The waitUntil promise won't complete until flush() returns\n *\n * By using the original waitUntil for flush operations, we bypass this issue.\n */\nexport function getOriginalWaitUntil(context: ExecutionContextCompat): ExecutionContext['waitUntil'] {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const currentWaitUntil = context.waitUntil;\n const original = flushLockRegistries.get(currentWaitUntil)?.originalWaitUntil;\n return original ?? currentWaitUntil;\n}\n\n/**\n * Enhances the given execution context by wrapping its `waitUntil` method with a proxy\n * to monitor pending tasks, and provides a flusher function to ensure all tasks\n * have been completed before executing any subsequent logic.\n *\n * @param {ExecutionContext} context - The execution context to be enhanced. If no context is provided, the function returns undefined.\n * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.\n */\nexport function makeFlushLock(context: ExecutionContextCompat): FlushLock {\n const registry = getOrCreateFlushLockRegistry(context);\n let resolveAllDone: () => void = () => undefined;\n const allDone = new Promise<void>(res => {\n resolveAllDone = res;\n });\n let pending = 0;\n\n const lock: FlushLockInternal = {\n ready: allDone,\n acquire: () => {\n pending++;\n },\n release: () => {\n if (--pending === 0) {\n registry.locks.delete(lock);\n resolveAllDone();\n }\n },\n finalize: () => {\n if (pending === 0) {\n registry.locks.delete(lock);\n resolveAllDone();\n }\n return allDone;\n },\n };\n\n registry.locks.add(lock);\n return Object.freeze(lock);\n}\n\nfunction getOrCreateFlushLockRegistry(context: ExecutionContextCompat): FlushLockRegistry {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const waitUntil = context.waitUntil;\n const existingRegistry = flushLockRegistries.get(waitUntil);\n\n if (existingRegistry) {\n return existingRegistry;\n }\n\n const originalWaitUntil = context.waitUntil.bind(context) as typeof context.waitUntil;\n const registry: FlushLockRegistry = { locks: new Set(), originalWaitUntil };\n const instrumentedWaitUntil: typeof context.waitUntil = promise => {\n // Snapshot active locks so locks created after this call do not wait for earlier waitUntil work.\n const locks = [...registry.locks];\n\n for (const lock of locks) {\n lock.acquire();\n }\n\n return originalWaitUntil(\n promise.finally(() => {\n for (const lock of locks) {\n lock.release();\n }\n }),\n );\n };\n\n flushLockRegistries.set(instrumentedWaitUntil, registry);\n context.waitUntil = instrumentedWaitUntil;\n\n return registry;\n}\n\n/**\n * Flushes the client and then disposes of it to allow garbage collection.\n * This should be called at the end of each request to prevent memory leaks.\n *\n * This function never rejects. On Workers, a rejected promise passed to\n * `ctx.waitUntil` marks the whole invocation as `outcome: exception` even when\n * the handler itself completed successfully. Since flush/dispose is internal\n * SDK housekeeping, a failure here must not fail the user's invocation.\n *\n * @param client - The CloudflareClient instance to flush and dispose\n * @param timeout - Timeout in milliseconds for the flush operation\n * @returns A promise that resolves when flush and dispose are complete\n */\nexport async function flushAndDispose(client: Client | undefined, timeout = 2000): Promise<void> {\n try {\n if (!client) {\n await flush(timeout);\n return;\n }\n await client.flush(timeout);\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to flush client', e);\n } finally {\n try {\n client?.dispose();\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to dispose client', e);\n }\n }\n}\n"],"names":[],"mappings":"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"}
@@ -1,13 +1,14 @@
1
1
  export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, bindScopeToEmitter, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, close, consoleIntegration, consoleLoggingIntegration, continueTrace, createConsolaReporter, createLangChainCallbackHandler, createTransport, dedupeIntegration, eventFiltersIntegration, extraErrorDataIntegration, featureFlagsIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, growthbookIntegration, inboundFiltersIntegration, instrumentAnthropicAiClient, instrumentCreateReactAgent, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, instrumentLangGraph, instrumentOpenAiClient, instrumentPostgresJsSql, instrumentStateGraph, instrumentSupabaseClient, isEnabled, isInitialized, lastEventId, linkedErrorsIntegration, logger, metrics, moduleMetadataIntegration, requestDataIntegration, rewriteFramesIntegration, setAttribute, setAttributes, setContext, setConversationId, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanStreamingIntegration, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSpan, startSpanManual, supabaseIntegration, suppressTracing, trpcMiddleware, updateSpanName, withActiveSpan, withIsolationScope, withMonitor, withScope, withStreamedSpan, wrapMcpServerWithSentry, zodErrorsIntegration } from '@sentry/core';
2
2
  export { withSentry } from './withSentry.js';
3
3
  export { defineCloudflareOptions } from './defineCloudflareOptions.js';
4
- export { instrumentDurableObjectWithSentry } from './durableobject.js';
4
+ export { instrumentAgentWithSentry, instrumentDurableObjectWithSentry } from './durableobject.js';
5
5
  export { sentryPagesPlugin } from './pages-plugin.js';
6
6
  export { wrapRequestHandler } from './request.js';
7
7
  export { CloudflareClient } from './client.js';
8
8
  export { getDefaultIntegrations } from './sdk.js';
9
9
  export { httpServerIntegration } from './integrations/httpServer.js';
10
10
  export { fetchIntegration } from './integrations/fetch.js';
11
+ export { spotlightIntegration } from './integrations/spotlight.js';
11
12
  export { vercelAIIntegration } from './integrations/tracing/vercelai.js';
12
13
  export { honoIntegration } from './integrations/hono.js';
13
14
  export { instrumentD1WithSentry } from './instrumentations/worker/instrumentD1.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -0,0 +1,14 @@
1
+ import { instrumentAgentCallableRpc } from './instrumentAgentCallableRpc.js';
2
+ import { instrumentAgentRequestConversation } from './instrumentAgentRequestConversation.js';
3
+ import { instrumentChatAgentConversation } from './instrumentChatAgentConversation.js';
4
+
5
+ function instrumentCloudflareAgent(agent) {
6
+ const internals = agent;
7
+ instrumentAgentCallableRpc(internals);
8
+ instrumentChatAgentConversation(internals);
9
+ instrumentAgentRequestConversation(internals);
10
+ return agent;
11
+ }
12
+
13
+ export { instrumentCloudflareAgent };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/instrumentations/agents/index.ts"],"sourcesContent":["import { instrumentAgentCallableRpc } from './instrumentAgentCallableRpc';\nimport { instrumentAgentRequestConversation } from './instrumentAgentRequestConversation';\nimport { instrumentChatAgentConversation } from './instrumentChatAgentConversation';\nimport type { AgentInternals } from './types';\n\n/**\n * Instruments an instance of a Cloudflare [`agents`](https://www.npmjs.com/package/agents) `Agent`\n * with Sentry, adding telemetry that is specific to the Agent's runtime behavior:\n *\n * - **Callable RPC spans** — a span (op `rpc`) for each `@callable()` method invoked over WebSocket.\n * - **Conversation correlation** — sets the conversation id on the scope for each unit of agent\n * work — chat turn, callable RPC call, or HTTP request — so `gen_ai` spans created within it are\n * correlated, for chat and plain agents alike. The id is minted once per agent instance and\n * rotated when the chat is cleared (the `message:clear` observability event); it is persisted to\n * Durable Object storage so it survives hibernation.\n *\n * It only hooks the `agents` package internals and uses Sentry's tracing primitives. On Cloudflare\n * Workers, prefer `instrumentAgentWithSentry`, which additionally instruments the Durable Object\n * handlers and initializes the SDK; that function calls this one internally.\n *\n * The hooks replace own-properties on the instance and defer to the original implementation, so\n * they compose with any other instrumentation applied to the same instance.\n *\n * @param agent The `agents` `Agent` instance to instrument.\n * @returns The same instance, instrumented.\n *\n * @internal Use `instrumentAgentWithSentry` instead — this is called internally by it.\n */\nexport function instrumentCloudflareAgent<T extends object>(agent: T): T {\n const internals = agent as T & AgentInternals;\n\n instrumentAgentCallableRpc(internals);\n instrumentChatAgentConversation(internals);\n instrumentAgentRequestConversation(internals);\n\n return agent;\n}\n"],"names":[],"mappings":";;;;AA4BO,SAAS,0BAA4C,KAAA,EAAa;AACvE,EAAA,MAAM,SAAA,GAAY,KAAA;AAElB,EAAA,0BAAA,CAA2B,SAAS,CAAA;AACpC,EAAA,+BAAA,CAAgC,SAAS,CAAA;AACzC,EAAA,kCAAA,CAAmC,SAAS,CAAA;AAE5C,EAAA,OAAO,KAAA;AACT;;;;"}
@@ -0,0 +1,50 @@
1
+ import { debug, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
2
+ import { DEBUG_BUILD } from '../../debug-build.js';
3
+ import { AGENT_SPAN_ORIGIN, getAgentAttributes, setAgentConversationId } from './types.js';
4
+
5
+ function instrumentAgentCallableRpc(obj) {
6
+ const original = obj.onMessage;
7
+ if (typeof original !== "function") {
8
+ DEBUG_BUILD && debug.log("[Sentry] Agent `onMessage` not found \u2014 callable RPC span instrumentation skipped.");
9
+ return;
10
+ }
11
+ obj.onMessage = new Proxy(original, {
12
+ apply(target, thisArg, args) {
13
+ const method = extractCallableMethod(args[1]);
14
+ if (!method) {
15
+ return Reflect.apply(target, thisArg, args);
16
+ }
17
+ return startSpan(
18
+ {
19
+ name: method,
20
+ attributes: {
21
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "rpc",
22
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: AGENT_SPAN_ORIGIN,
23
+ ...getAgentAttributes(thisArg)
24
+ }
25
+ },
26
+ async () => {
27
+ await setAgentConversationId(thisArg);
28
+ return Reflect.apply(target, thisArg, args);
29
+ }
30
+ );
31
+ }
32
+ });
33
+ }
34
+ function extractCallableMethod(message) {
35
+ const text = typeof message === "string" ? message : message instanceof ArrayBuffer ? new TextDecoder().decode(message) : void 0;
36
+ if (!text) {
37
+ return void 0;
38
+ }
39
+ try {
40
+ const parsed = JSON.parse(text);
41
+ if (parsed.type === "rpc" && typeof parsed.method === "string" && Array.isArray(parsed.args)) {
42
+ return parsed.method;
43
+ }
44
+ } catch {
45
+ }
46
+ return void 0;
47
+ }
48
+
49
+ export { instrumentAgentCallableRpc };
50
+ //# sourceMappingURL=instrumentAgentCallableRpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentAgentCallableRpc.js","sources":["../../../../src/instrumentations/agents/instrumentAgentCallableRpc.ts"],"sourcesContent":["import { debug, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { AGENT_SPAN_ORIGIN, type AgentInternals, getAgentAttributes, setAgentConversationId } from './types';\n\n/**\n * Wraps the Agent's `onMessage` handler to create a span for each `@callable()` RPC invocation.\n * RPC requests arrive as WebSocket messages, so this span nests under the active transaction for\n * the WebSocket message (on Cloudflare, the instrumented Durable Object `webSocketMessage` hook).\n *\n * Also sets the conversation id on the scope for the duration of the call: callable methods are the\n * unit of work for plain (non-chat) agents, which run LLM calls just like chat turns do. It is\n * awaited so the id is on the scope before the method body creates any span; the `agents`\n * `onMessage` own property this wraps is already `async`, so the promise return is nothing new to\n * the WebSocket dispatch upstream.\n */\nexport function instrumentAgentCallableRpc(obj: AgentInternals): void {\n const original = obj.onMessage;\n if (typeof original !== 'function') {\n DEBUG_BUILD && debug.log('[Sentry] Agent `onMessage` not found — callable RPC span instrumentation skipped.');\n return;\n }\n\n obj.onMessage = new Proxy(original, {\n apply(target, thisArg: AgentInternals, args: unknown[]): unknown {\n const method = extractCallableMethod(args[1]);\n\n if (!method) {\n return Reflect.apply(target, thisArg, args);\n }\n\n return startSpan(\n {\n name: method,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'rpc',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: AGENT_SPAN_ORIGIN,\n ...getAgentAttributes(thisArg),\n },\n },\n async () => {\n await setAgentConversationId(thisArg);\n return Reflect.apply(target, thisArg, args);\n },\n );\n },\n });\n}\n\n/** Extracts the RPC method name from a WebSocket message, mirroring the SDK's `isRPCRequest`. */\nfunction extractCallableMethod(message: unknown): string | undefined {\n const text =\n typeof message === 'string'\n ? message\n : message instanceof ArrayBuffer\n ? new TextDecoder().decode(message)\n : undefined;\n\n if (!text) {\n return undefined;\n }\n\n try {\n const parsed = JSON.parse(text) as { type?: unknown; method?: unknown; args?: unknown };\n if (parsed.type === 'rpc' && typeof parsed.method === 'string' && Array.isArray(parsed.args)) {\n return parsed.method;\n }\n } catch {\n // Not JSON, or not an RPC request — no span.\n }\n\n return undefined;\n}\n"],"names":[],"mappings":";;;;AAeO,SAAS,2BAA2B,GAAA,EAA2B;AACpE,EAAA,MAAM,WAAW,GAAA,CAAI,SAAA;AACrB,EAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,IAAA,WAAA,IAAe,KAAA,CAAM,IAAI,wFAAmF,CAAA;AAC5G,IAAA;AAAA,EACF;AAEA,EAAA,GAAA,CAAI,SAAA,GAAY,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,IAClC,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAyB,IAAA,EAA0B;AAC/D,MAAA,MAAM,MAAA,GAAS,qBAAA,CAAsB,IAAA,CAAK,CAAC,CAAC,CAAA;AAE5C,MAAA,IAAI,CAAC,MAAA,EAAQ;AACX,QAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAAA,MAC5C;AAEA,MAAA,OAAO,SAAA;AAAA,QACL;AAAA,UACE,IAAA,EAAM,MAAA;AAAA,UACN,UAAA,EAAY;AAAA,YACV,CAAC,4BAA4B,GAAG,KAAA;AAAA,YAChC,CAAC,gCAAgC,GAAG,iBAAA;AAAA,YACpC,GAAG,mBAAmB,OAAO;AAAA;AAC/B,SACF;AAAA,QACA,YAAY;AACV,UAAA,MAAM,uBAAuB,OAAO,CAAA;AACpC,UAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAAA,QAC5C;AAAA,OACF;AAAA,IACF;AAAA,GACD,CAAA;AACH;AAGA,SAAS,sBAAsB,OAAA,EAAsC;AACnE,EAAA,MAAM,IAAA,GACJ,OAAO,OAAA,KAAY,QAAA,GACf,OAAA,GACA,OAAA,YAAmB,WAAA,GACjB,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,OAAO,CAAA,GAChC,MAAA;AAER,EAAA,IAAI,CAAC,IAAA,EAAM;AACT,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AAC9B,IAAA,IAAI,MAAA,CAAO,IAAA,KAAS,KAAA,IAAS,OAAO,MAAA,CAAO,MAAA,KAAW,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,CAAA,EAAG;AAC5F,MAAA,OAAO,MAAA,CAAO,MAAA;AAAA,IAChB;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -0,0 +1,17 @@
1
+ import { setAgentConversationId } from './types.js';
2
+
3
+ function instrumentAgentRequestConversation(obj) {
4
+ const original = obj.onRequest;
5
+ if (typeof original !== "function") {
6
+ return;
7
+ }
8
+ obj.onRequest = new Proxy(original, {
9
+ async apply(target, thisArg, args) {
10
+ await setAgentConversationId(thisArg);
11
+ return Reflect.apply(target, thisArg, args);
12
+ }
13
+ });
14
+ }
15
+
16
+ export { instrumentAgentRequestConversation };
17
+ //# sourceMappingURL=instrumentAgentRequestConversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentAgentRequestConversation.js","sources":["../../../../src/instrumentations/agents/instrumentAgentRequestConversation.ts"],"sourcesContent":["import { type AgentInternals, setAgentConversationId } from './types';\n\n/**\n * Correlates the AI spans of an HTTP-driven agent turn with a conversation id on the active scope.\n *\n * `onRequest` is the third unit of agent work, alongside chat turns and `@callable()` RPC: the\n * `agents` router sends every non-WebSocket request to it, which is how REST endpoints and webhooks\n * reach an agent.\n *\n * `agents` installs `onRequest` as an own property in the `Agent` constructor (as it does\n * `onMessage`), and we instrument after construction, so wrapping the own property is what the\n * router ends up calling. That own property is already `async`, and partyserver's `fetch` awaits it,\n * so returning a promise from this wrapper — to get the conversation id onto the scope before the\n * request handler creates any span — keeps the existing contract.\n */\nexport function instrumentAgentRequestConversation(obj: AgentInternals): void {\n const original = obj.onRequest;\n\n if (typeof original !== 'function') {\n return;\n }\n\n obj.onRequest = new Proxy(original, {\n async apply(target, thisArg: AgentInternals, args: unknown[]): Promise<unknown> {\n await setAgentConversationId(thisArg);\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n}\n"],"names":[],"mappings":";;AAeO,SAAS,mCAAmC,GAAA,EAA2B;AAC5E,EAAA,MAAM,WAAW,GAAA,CAAI,SAAA;AAErB,EAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,IAAA;AAAA,EACF;AAEA,EAAA,GAAA,CAAI,SAAA,GAAY,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,IAClC,MAAM,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAyB,IAAA,EAAmC;AAC9E,MAAA,MAAM,uBAAuB,OAAO,CAAA;AAEpC,MAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAAA,IAC5C;AAAA,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,29 @@
1
+ import { uuid4 } from '@sentry/core';
2
+ import { storeAgentConversationId, setAgentConversationId } from './types.js';
3
+
4
+ function instrumentChatAgentConversation(obj) {
5
+ const originalEmit = obj._emit;
6
+ if (typeof originalEmit === "function") {
7
+ obj._emit = new Proxy(originalEmit, {
8
+ apply(target, thisArg, args) {
9
+ if (args[0] === "message:clear") {
10
+ storeAgentConversationId(thisArg, uuid4());
11
+ }
12
+ return Reflect.apply(target, thisArg, args);
13
+ }
14
+ });
15
+ }
16
+ const original = obj.onChatMessage;
17
+ if (typeof original !== "function") {
18
+ return;
19
+ }
20
+ obj.onChatMessage = new Proxy(original, {
21
+ async apply(target, thisArg, args) {
22
+ await setAgentConversationId(thisArg);
23
+ return Reflect.apply(target, thisArg, args);
24
+ }
25
+ });
26
+ }
27
+
28
+ export { instrumentChatAgentConversation };
29
+ //# sourceMappingURL=instrumentChatAgentConversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentChatAgentConversation.js","sources":["../../../../src/instrumentations/agents/instrumentChatAgentConversation.ts"],"sourcesContent":["import { uuid4 } from '@sentry/core';\nimport { type AgentInternals, setAgentConversationId, storeAgentConversationId } from './types';\n\n/**\n * For chat agents (`AIChatAgent` from `@cloudflare/ai-chat`), correlates each chat turn's AI spans\n * with a conversation id on the active scope.\n *\n * In the Agents model one agent instance is one long-lived conversation, so the conversation id is\n * minted once per instance and persisted to Durable Object storage, which is what carries it across\n * hibernation (that destroys the in-memory instance). When the user clears the chat, they expect a\n * fresh conversation — but recreating the Durable Object for that would also drop the MCP/OAuth\n * state stored per instance (GitHub/Sentry sign-in). To get a fresh conversation id *without*\n * losing that state, we rotate the persisted id when the SDK reports a cleared chat.\n *\n * The id itself is not attached to spans here — `setAgentConversationId` resolves it, and the SDK's\n * `conversationIdIntegration` picks it off the scope at `spanStart` to stamp\n * `gen_ai.conversation.id` onto the AI spans created inside the turn (e.g. by the Workers AI\n * instrumentation), which correlates a turn's model and tool calls.\n *\n * Plain (non-chat) `Agent`s do not define `onChatMessage`, so they are skipped here — their unit\n * of work is the callable RPC method, where `instrumentAgentCallableRpc` sets the conversation id\n * instead.\n */\nexport function instrumentChatAgentConversation(obj: AgentInternals): void {\n // Rotate the conversation id when the chat is cleared. `_emit` is the central choke-point through\n // which all `agents:*` observability events are published, and it already exists on the base\n // `Agent` class — so this hook composes with the RPC instrumentation, which keys off the same\n // surface. We shadow it with an own property so the original stays reachable on the prototype.\n const originalEmit = obj._emit;\n\n if (typeof originalEmit === 'function') {\n obj._emit = new Proxy(originalEmit, {\n apply(target, thisArg: AgentInternals, args: [string, Record<string, unknown>?]) {\n if (args[0] === 'message:clear') {\n storeAgentConversationId(thisArg, uuid4());\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n }\n\n const original = obj.onChatMessage;\n\n if (typeof original !== 'function') {\n return;\n }\n\n obj.onChatMessage = new Proxy(original, {\n async apply(target, thisArg: AgentInternals, args: unknown[]): Promise<unknown> {\n await setAgentConversationId(thisArg);\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n}\n"],"names":[],"mappings":";;;AAuBO,SAAS,gCAAgC,GAAA,EAA2B;AAKzE,EAAA,MAAM,eAAe,GAAA,CAAI,KAAA;AAEzB,EAAA,IAAI,OAAO,iBAAiB,UAAA,EAAY;AACtC,IAAA,GAAA,CAAI,KAAA,GAAQ,IAAI,KAAA,CAAM,YAAA,EAAc;AAAA,MAClC,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAyB,IAAA,EAA0C;AAC/E,QAAA,IAAI,IAAA,CAAK,CAAC,CAAA,KAAM,eAAA,EAAiB;AAC/B,UAAA,wBAAA,CAAyB,OAAA,EAAS,OAAO,CAAA;AAAA,QAC3C;AAEA,QAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAAA,MAC5C;AAAA,KACD,CAAA;AAAA,EACH;AAEA,EAAA,MAAM,WAAW,GAAA,CAAI,aAAA;AAErB,EAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,IAAA;AAAA,EACF;AAEA,EAAA,GAAA,CAAI,aAAA,GAAgB,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,IACtC,MAAM,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAyB,IAAA,EAAmC;AAC9E,MAAA,MAAM,uBAAuB,OAAO,CAAA;AAEpC,MAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAAA,IAC5C;AAAA,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,69 @@
1
+ import { getIsolationScope, getCurrentScope, debug, uuid4 } from '@sentry/core';
2
+ import { DEBUG_BUILD } from '../../debug-build.js';
3
+
4
+ const GEN_AI_AGENT_NAME_ATTRIBUTE = "gen_ai.agent.name";
5
+ const AGENT_SPAN_ORIGIN = "auto.faas.cloudflare.agents";
6
+ const AGENT_CONVERSATION_ID_STORAGE_KEY = "__SENTRY_AGENT_CONVERSATION_ID__";
7
+ const AGENT_CONVERSATION_ID_SYMBOL = /* @__PURE__ */ Symbol("sentryAgentConversationId");
8
+ const AGENT_APPLIED_CONVERSATION_ID_SYMBOL = /* @__PURE__ */ Symbol("sentryAgentAppliedConversationId");
9
+ function getAgentAttributes(instance) {
10
+ const attributes = {};
11
+ const agentClass = instance._ParentClass?.name;
12
+ if (typeof agentClass === "string" && agentClass) {
13
+ attributes[GEN_AI_AGENT_NAME_ATTRIBUTE] = agentClass;
14
+ }
15
+ return attributes;
16
+ }
17
+ function storeAgentConversationId(instance, conversationId) {
18
+ instance[AGENT_CONVERSATION_ID_SYMBOL] = conversationId;
19
+ const storage = resolveStorage(instance);
20
+ if (!storage) {
21
+ return;
22
+ }
23
+ try {
24
+ storage.put(AGENT_CONVERSATION_ID_STORAGE_KEY, conversationId).catch((error) => DEBUG_BUILD && debug.log("[Sentry] Failed to persist agent conversation id", error));
25
+ } catch (error) {
26
+ DEBUG_BUILD && debug.log("[Sentry] Failed to persist agent conversation id", error);
27
+ }
28
+ }
29
+ async function setAgentConversationId(instance) {
30
+ const isolationScope = getIsolationScope();
31
+ const existing = isolationScope.getScopeData().conversationId ?? getCurrentScope().getScopeData().conversationId;
32
+ if (existing && existing !== instance[AGENT_APPLIED_CONVERSATION_ID_SYMBOL]) {
33
+ return;
34
+ }
35
+ const conversationId = instance[AGENT_CONVERSATION_ID_SYMBOL] ?? await loadAgentConversationId(instance);
36
+ instance[AGENT_APPLIED_CONVERSATION_ID_SYMBOL] = conversationId;
37
+ isolationScope.setConversationId(conversationId);
38
+ }
39
+ async function loadAgentConversationId(instance) {
40
+ let stored;
41
+ let readFailed = false;
42
+ try {
43
+ stored = await resolveStorage(instance)?.get(AGENT_CONVERSATION_ID_STORAGE_KEY);
44
+ } catch (error) {
45
+ readFailed = true;
46
+ DEBUG_BUILD && debug.log("[Sentry] Failed to read agent conversation id from storage", error);
47
+ }
48
+ const cached = instance[AGENT_CONVERSATION_ID_SYMBOL];
49
+ if (cached !== void 0) {
50
+ return cached;
51
+ }
52
+ if (typeof stored === "string" && stored) {
53
+ instance[AGENT_CONVERSATION_ID_SYMBOL] = stored;
54
+ return stored;
55
+ }
56
+ const conversationId = uuid4();
57
+ if (readFailed) {
58
+ instance[AGENT_CONVERSATION_ID_SYMBOL] = conversationId;
59
+ } else {
60
+ storeAgentConversationId(instance, conversationId);
61
+ }
62
+ return conversationId;
63
+ }
64
+ function resolveStorage(instance) {
65
+ return instance.ctx?.originalStorage ?? instance.ctx?.storage;
66
+ }
67
+
68
+ export { AGENT_APPLIED_CONVERSATION_ID_SYMBOL, AGENT_CONVERSATION_ID_STORAGE_KEY, AGENT_CONVERSATION_ID_SYMBOL, AGENT_SPAN_ORIGIN, getAgentAttributes, setAgentConversationId, storeAgentConversationId };
69
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../../../src/instrumentations/agents/types.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport { debug, getCurrentScope, getIsolationScope, uuid4 } from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type { InstrumentedDurableObjectState } from '../../wrapMethodWithSentry';\n\n// v10 predates `@sentry/conventions` and doesn't expose this from `@sentry/core`, so keep the\n// standard semantic attribute name locally.\nconst GEN_AI_AGENT_NAME_ATTRIBUTE = 'gen_ai.agent.name';\n\nexport const AGENT_SPAN_ORIGIN = 'auto.faas.cloudflare.agents';\n\n/** DO storage key under which the conversation id is persisted so it survives hibernation. */\nexport const AGENT_CONVERSATION_ID_STORAGE_KEY = '__SENTRY_AGENT_CONVERSATION_ID__';\n\n/**\n * Instance keys for our conversation-id bookkeeping, keyed by symbol so the state stays invisible\n * to anything enumerating the user-owned agent instance (`Object.keys`, `JSON.stringify`, spread).\n * Exported because the exported `AgentInternals` interface references them.\n */\nexport const AGENT_CONVERSATION_ID_SYMBOL: unique symbol = Symbol('sentryAgentConversationId');\nexport const AGENT_APPLIED_CONVERSATION_ID_SYMBOL: unique symbol = Symbol('sentryAgentAppliedConversationId');\n\n/**\n * The subset of the `agents` `Agent` instance internals that we instrument. These are runtime\n * implementation details of the `agents` package (v0.13.x) rather than part of its public type\n * surface, so every access is guarded and wrapping degrades gracefully if a name changes upstream.\n */\nexport interface AgentInternals {\n /** Central choke-point through which all `agents:*` observability events are published. */\n _emit?: (type: string, payload?: Record<string, unknown>) => void;\n /** WebSocket message handler; dispatches `@callable()` RPC requests. */\n onMessage?: (...args: unknown[]) => unknown;\n /**\n * Chat-turn handler. Only `AIChatAgent` (from `@cloudflare/ai-chat`) defines this; a plain `Agent`\n * does not, so its presence discriminates a chat agent.\n */\n onChatMessage?: (...args: unknown[]) => unknown;\n /** HTTP request handler; the router sends every non-WebSocket request here. */\n onRequest?: (...args: unknown[]) => unknown;\n /** The user's Agent class (used by the SDK for the observability event `agent` field). */\n _ParentClass?: { name?: string };\n /** The Agent instance name, reported as the `cloudflare.agent.name` span attribute. */\n name?: string;\n /**\n * The Durable Object state of the instance. Present on every real Agent; guarded like the other\n * internals so partially-mocked instances keep working.\n */\n ctx?: InstrumentedDurableObjectState;\n /**\n * The current conversation id for this agent instance. It is cached in memory after being loaded\n * from Durable Object storage and updated when the conversation rotates. `undefined` means storage\n * has not been read yet.\n */\n [AGENT_CONVERSATION_ID_SYMBOL]?: string;\n /**\n * The conversation id this instrumentation most recently applied to the isolation scope. It lets\n * subsequent units of work distinguish an SDK-applied id, which may be replaced after rotation,\n * from an id explicitly set by the user, which must be preserved.\n */\n [AGENT_APPLIED_CONVERSATION_ID_SYMBOL]?: string;\n}\n\n/** Reads best-effort agent identity attributes from the instance, tolerating missing internals. */\nexport function getAgentAttributes(instance: AgentInternals): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n const agentClass = instance._ParentClass?.name;\n if (typeof agentClass === 'string' && agentClass) {\n attributes[GEN_AI_AGENT_NAME_ATTRIBUTE] = agentClass;\n }\n\n return attributes;\n}\n\n/**\n * Persists the conversation id to Durable Object storage, so it survives hibernation, and updates\n * the in-memory cache synchronously so the current wake is immediately consistent even if the\n * write fails. Uses the async storage API, which exists on KV- and SQLite-backed DOs alike.\n * The write is fire-and-forget: DO storage writes are tracked by the runtime and land without\n * awaiting (`waitUntil` is a no-op in Durable Objects), and the catch keeps a rejection from\n * surfacing as unhandled — a failed write just means the next wake starts a new conversation,\n * which must never throw into user code. Uses the original uninstrumented storage so internal\n * bookkeeping doesn't create spans.\n */\nexport function storeAgentConversationId(instance: AgentInternals, conversationId: string): void {\n instance[AGENT_CONVERSATION_ID_SYMBOL] = conversationId;\n\n const storage = resolveStorage(instance);\n if (!storage) {\n return;\n }\n\n try {\n storage\n .put(AGENT_CONVERSATION_ID_STORAGE_KEY, conversationId)\n .catch(error => DEBUG_BUILD && debug.log('[Sentry] Failed to persist agent conversation id', error));\n } catch (error) {\n DEBUG_BUILD && debug.log('[Sentry] Failed to persist agent conversation id', error);\n }\n}\n\n/**\n * Sets the agent instance's conversation id on the active scope for the duration of the\n * surrounding unit of work (chat turn, callable RPC call, HTTP request). In the Agents model one\n * instance is one long-lived conversation, so the id is minted once per instance and persisted to\n * DO storage — for chat and plain agents alike, since plain agents run LLM calls too (e.g. inside\n * `@callable()` methods). The instance `name` is deliberately not used: it is caller-chosen and can\n * be a stable, guessable, or shared value, whereas a conversation id should identify exactly one\n * conversation. Clearing the chat rotates it (see `storeAgentConversationId`) so subsequent LLM\n * calls group under the fresh conversation.\n *\n * Every handler wrapper awaits this before invoking the original, so the id is on the scope before\n * the unit of work — and any `gen_ai` span it creates — starts. Only the first unit of work per wake\n * pays the storage read; the rest resolve from the in-memory cache. Awaiting is safe on all three\n * paths because the `agents` `Agent` constructor already replaces `onMessage` and `onRequest` with\n * `async` wrappers of its own, and `onChatMessage` is async by contract, so every caller upstream\n * already handles a promise.\n *\n * An id the user set explicitly outranks this inferred one, in either order: a `setConversationId()`\n * call that already happened is detected here and left alone, and one made inside the handler lands\n * on the same scope afterwards and therefore wins. That is why the write targets the isolation scope\n * — it is the scope the public `Sentry.setConversationId()` writes to, and `conversationIdIntegration`\n * prefers the current scope over it, so writing there would make a user's call unoverridable.\n *\n * `conversationIdIntegration` reads the id off the scope at `spanStart` and stamps\n * `gen_ai.conversation.id` onto AI spans created within the unit of work, correlating its model and\n * tool calls.\n */\nexport async function setAgentConversationId(instance: AgentInternals): Promise<void> {\n const isolationScope = getIsolationScope();\n const existing = isolationScope.getScopeData().conversationId ?? getCurrentScope().getScopeData().conversationId;\n\n // An id that isn't the one we put there ourselves came from the user — never override it.\n if (existing && existing !== instance[AGENT_APPLIED_CONVERSATION_ID_SYMBOL]) {\n return;\n }\n\n const conversationId = instance[AGENT_CONVERSATION_ID_SYMBOL] ?? (await loadAgentConversationId(instance));\n\n instance[AGENT_APPLIED_CONVERSATION_ID_SYMBOL] = conversationId;\n isolationScope.setConversationId(conversationId);\n}\n\n/**\n * Reads the persisted id into the instance cache, minting and persisting a fresh one when storage\n * holds none, so subsequent units of work resolve from memory. The async `get` exists on KV- and\n * SQLite-backed DOs alike, so this one path covers both.\n *\n * Anything already cached by the time the read lands wins over the read: that covers a rotation\n * (cleared chat) racing the read, and a second concurrent unit of work that must not mint and\n * persist a competing id for the same conversation.\n */\nasync function loadAgentConversationId(instance: AgentInternals): Promise<string> {\n let stored: unknown;\n let readFailed = false;\n\n try {\n stored = await resolveStorage(instance)?.get<string>(AGENT_CONVERSATION_ID_STORAGE_KEY);\n } catch (error) {\n readFailed = true;\n DEBUG_BUILD && debug.log('[Sentry] Failed to read agent conversation id from storage', error);\n }\n\n const cached = instance[AGENT_CONVERSATION_ID_SYMBOL];\n\n if (cached !== undefined) {\n return cached;\n }\n\n if (typeof stored === 'string' && stored) {\n instance[AGENT_CONVERSATION_ID_SYMBOL] = stored;\n\n return stored;\n }\n\n const conversationId = uuid4();\n\n if (readFailed) {\n // Cache without persisting: a read that failed may still have an id behind it, and overwriting\n // it would split the conversation for good instead of just for this wake.\n instance[AGENT_CONVERSATION_ID_SYMBOL] = conversationId;\n } else {\n storeAgentConversationId(instance, conversationId);\n }\n\n return conversationId;\n}\n\n/**\n * Resolves the uninstrumented DO storage for internal reads/writes, so they don't create spans of\n * their own. Falls back to the instance's regular storage when the uninstrumented one isn't\n * exposed (e.g. when `instrumentCloudflareAgent` is used directly, without `instrumentContext`).\n */\nfunction resolveStorage(instance: AgentInternals): DurableObjectStorage | undefined {\n return instance.ctx?.originalStorage ?? instance.ctx?.storage;\n}\n"],"names":[],"mappings":";;;AAOA,MAAM,2BAAA,GAA8B,mBAAA;AAE7B,MAAM,iBAAA,GAAoB;AAG1B,MAAM,iCAAA,GAAoC;AAO1C,MAAM,4BAAA,0BAAqD,2BAA2B;AACtF,MAAM,oCAAA,0BAA6D,kCAAkC;AA2CrG,SAAS,mBAAmB,QAAA,EAAkD;AACnF,EAAA,MAAM,aAAqC,EAAC;AAE5C,EAAA,MAAM,UAAA,GAAa,SAAS,YAAA,EAAc,IAAA;AAC1C,EAAA,IAAI,OAAO,UAAA,KAAe,QAAA,IAAY,UAAA,EAAY;AAChD,IAAA,UAAA,CAAW,2BAA2B,CAAA,GAAI,UAAA;AAAA,EAC5C;AAEA,EAAA,OAAO,UAAA;AACT;AAYO,SAAS,wBAAA,CAAyB,UAA0B,cAAA,EAA8B;AAC/F,EAAA,QAAA,CAAS,4BAA4B,CAAA,GAAI,cAAA;AAEzC,EAAA,MAAM,OAAA,GAAU,eAAe,QAAQ,CAAA;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,OAAA,CACG,GAAA,CAAI,iCAAA,EAAmC,cAAc,CAAA,CACrD,KAAA,CAAM,CAAA,KAAA,KAAS,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,kDAAA,EAAoD,KAAK,CAAC,CAAA;AAAA,EACvG,SAAS,KAAA,EAAO;AACd,IAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,kDAAA,EAAoD,KAAK,CAAA;AAAA,EACpF;AACF;AA6BA,eAAsB,uBAAuB,QAAA,EAAyC;AACpF,EAAA,MAAM,iBAAiB,iBAAA,EAAkB;AACzC,EAAA,MAAM,QAAA,GAAW,eAAe,YAAA,EAAa,CAAE,kBAAkB,eAAA,EAAgB,CAAE,cAAa,CAAE,cAAA;AAGlG,EAAA,IAAI,QAAA,IAAY,QAAA,KAAa,QAAA,CAAS,oCAAoC,CAAA,EAAG;AAC3E,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,iBAAiB,QAAA,CAAS,4BAA4B,CAAA,IAAM,MAAM,wBAAwB,QAAQ,CAAA;AAExG,EAAA,QAAA,CAAS,oCAAoC,CAAA,GAAI,cAAA;AACjD,EAAA,cAAA,CAAe,kBAAkB,cAAc,CAAA;AACjD;AAWA,eAAe,wBAAwB,QAAA,EAA2C;AAChF,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI,UAAA,GAAa,KAAA;AAEjB,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,MAAM,cAAA,CAAe,QAAQ,CAAA,EAAG,IAAY,iCAAiC,CAAA;AAAA,EACxF,SAAS,KAAA,EAAO;AACd,IAAA,UAAA,GAAa,IAAA;AACb,IAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,4DAAA,EAA8D,KAAK,CAAA;AAAA,EAC9F;AAEA,EAAA,MAAM,MAAA,GAAS,SAAS,4BAA4B,CAAA;AAEpD,EAAA,IAAI,WAAW,MAAA,EAAW;AACxB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,EAAQ;AACxC,IAAA,QAAA,CAAS,4BAA4B,CAAA,GAAI,MAAA;AAEzC,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,iBAAiB,KAAA,EAAM;AAE7B,EAAA,IAAI,UAAA,EAAY;AAGd,IAAA,QAAA,CAAS,4BAA4B,CAAA,GAAI,cAAA;AAAA,EAC3C,CAAA,MAAO;AACL,IAAA,wBAAA,CAAyB,UAAU,cAAc,CAAA;AAAA,EACnD;AAEA,EAAA,OAAO,cAAA;AACT;AAOA,SAAS,eAAe,QAAA,EAA4D;AAClF,EAAA,OAAO,QAAA,CAAS,GAAA,EAAK,eAAA,IAAmB,QAAA,CAAS,GAAA,EAAK,OAAA;AACxD;;;;"}
@@ -1,4 +1,5 @@
1
- import { startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, isThenable } from '@sentry/core';
1
+ import { getClient, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, isThenable } from '@sentry/core';
2
+ import { getStorageKeys, targetsCloudflareInternalKey } from '../utils/internalStorageKey.js';
2
3
  import { storeSpanContext } from '../utils/traceLinks.js';
3
4
  import { instrumentDurableObjectSyncKvStorage } from './instrumentDurableObjectSyncKvStorage.js';
4
5
  import { instrumentSqlStorage } from './instrumentSqlStorage.js';
@@ -22,6 +23,11 @@ function instrumentDurableObjectStorage(storage, waitUntil) {
22
23
  return original.bind(target);
23
24
  }
24
25
  return function(...args) {
26
+ const allowlist = getClient()?.getOptions()?.durableObjectStorageSpanAllowlist;
27
+ const keys = getStorageKeys(methodName, args);
28
+ if (keys && keys.length > 0 && keys.every((key) => targetsCloudflareInternalKey(key, allowlist))) {
29
+ return original.apply(target, args);
30
+ }
25
31
  return startSpan(
26
32
  {
27
33
  // Use underscore naming to match Cloudflare's native instrumentation (e.g., "durable_object_storage_get")
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentDurableObjectStorage.js","sources":["../../../src/instrumentations/instrumentDurableObjectStorage.ts"],"sourcesContent":["import type { DurableObjectStorage, SyncKvStorage, SqlStorage } from '@cloudflare/workers-types';\nimport { isThenable, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';\nimport { storeSpanContext } from '../utils/traceLinks';\nimport { instrumentDurableObjectSyncKvStorage } from './instrumentDurableObjectSyncKvStorage';\nimport { instrumentSqlStorage } from './instrumentSqlStorage';\n\nconst STORAGE_METHODS_TO_INSTRUMENT = ['get', 'put', 'delete', 'list', 'setAlarm', 'getAlarm', 'deleteAlarm'] as const;\n\ntype StorageMethod = (typeof STORAGE_METHODS_TO_INSTRUMENT)[number];\n\ntype WaitUntil = (promise: Promise<unknown>) => void;\n\n/**\n * Instruments DurableObjectStorage methods with Sentry spans.\n *\n * Wraps the following async methods:\n * - get, put, delete, list (KV API)\n * - setAlarm, getAlarm, deleteAlarm (Alarm API)\n *\n * When setAlarm is called, it also stores the current span context so that when\n * the alarm fires later, it can link back to the trace that called setAlarm.\n *\n * @param storage - The DurableObjectStorage instance to instrument\n * @param waitUntil - Optional waitUntil function to defer span context storage\n * @returns An instrumented DurableObjectStorage instance\n */\nexport function instrumentDurableObjectStorage(\n storage: DurableObjectStorage,\n waitUntil?: WaitUntil,\n): DurableObjectStorage {\n return new Proxy(storage, {\n get(target, prop, _receiver) {\n // Use `target` as the receiver instead of the proxy (`_receiver`).\n // Native workerd getters (e.g., `storage.sql`) validate `this` via\n // internal slots. Passing the proxy as receiver breaks that check,\n // causing \"Illegal invocation: function called with incorrect `this`\n // reference\" errors.\n const original = Reflect.get(target, prop, target);\n\n if (prop === 'kv' && original != null && 'get' in original && 'put' in original) {\n return instrumentDurableObjectSyncKvStorage(original as SyncKvStorage);\n }\n\n if (prop === 'sql' && original != null && 'databaseSize' in original && 'exec' in original) {\n return instrumentSqlStorage(original as SqlStorage);\n }\n\n if (typeof original !== 'function') {\n return original;\n }\n\n const methodName = prop as string;\n if (!STORAGE_METHODS_TO_INSTRUMENT.includes(methodName as StorageMethod)) {\n return (original as (...args: unknown[]) => unknown).bind(target);\n }\n\n return function (this: unknown, ...args: unknown[]) {\n return startSpan(\n {\n // Use underscore naming to match Cloudflare's native instrumentation (e.g., \"durable_object_storage_get\")\n name: `durable_object_storage_${methodName}`,\n op: 'db',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object',\n 'db.system.name': 'cloudflare.durable_object.storage',\n 'db.operation.name': methodName,\n },\n },\n () => {\n const teardown = async (): Promise<void> => {\n // When setAlarm is called, store the current span context so that when the alarm\n // fires later, it can link back to the trace that called setAlarm.\n // We use the original (uninstrumented) storage (target) to avoid creating a span\n // for this internal operation. The storage is deferred via waitUntil to not block.\n if (methodName === 'setAlarm') {\n storeSpanContext(target, 'alarm');\n }\n };\n\n const result = (original as (...args: unknown[]) => unknown).apply(target, args);\n\n if (!isThenable(result)) {\n waitUntil?.(teardown());\n\n return result;\n }\n\n return result.then(\n res => {\n waitUntil?.(teardown());\n return res;\n },\n e => {\n throw e;\n },\n );\n },\n );\n };\n },\n });\n}\n"],"names":[],"mappings":";;;;;AAMA,MAAM,6BAAA,GAAgC,CAAC,KAAA,EAAO,KAAA,EAAO,UAAU,MAAA,EAAQ,UAAA,EAAY,YAAY,aAAa,CAAA;AAoBrG,SAAS,8BAAA,CACd,SACA,SAAA,EACsB;AACtB,EAAA,OAAO,IAAI,MAAM,OAAA,EAAS;AAAA,IACxB,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAW;AAM3B,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,MAAM,MAAM,CAAA;AAEjD,MAAA,IAAI,SAAS,IAAA,IAAQ,QAAA,IAAY,QAAQ,KAAA,IAAS,QAAA,IAAY,SAAS,QAAA,EAAU;AAC/E,QAAA,OAAO,qCAAqC,QAAyB,CAAA;AAAA,MACvE;AAEA,MAAA,IAAI,SAAS,KAAA,IAAS,QAAA,IAAY,QAAQ,cAAA,IAAkB,QAAA,IAAY,UAAU,QAAA,EAAU;AAC1F,QAAA,OAAO,qBAAqB,QAAsB,CAAA;AAAA,MACpD;AAEA,MAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,QAAA,OAAO,QAAA;AAAA,MACT;AAEA,MAAA,MAAM,UAAA,GAAa,IAAA;AACnB,MAAA,IAAI,CAAC,6BAAA,CAA8B,QAAA,CAAS,UAA2B,CAAA,EAAG;AACxE,QAAA,OAAQ,QAAA,CAA6C,KAAK,MAAM,CAAA;AAAA,MAClE;AAEA,MAAA,OAAO,YAA4B,IAAA,EAAiB;AAClD,QAAA,OAAO,SAAA;AAAA,UACL;AAAA;AAAA,YAEE,IAAA,EAAM,0BAA0B,UAAU,CAAA,CAAA;AAAA,YAC1C,EAAA,EAAI,IAAA;AAAA,YACJ,UAAA,EAAY;AAAA,cACV,CAAC,gCAAgC,GAAG,mCAAA;AAAA,cACpC,gBAAA,EAAkB,mCAAA;AAAA,cAClB,mBAAA,EAAqB;AAAA;AACvB,WACF;AAAA,UACA,MAAM;AACJ,YAAA,MAAM,WAAW,YAA2B;AAK1C,cAAA,IAAI,eAAe,UAAA,EAAY;AAC7B,gBAAA,gBAAA,CAAiB,QAAQ,OAAO,CAAA;AAAA,cAClC;AAAA,YACF,CAAA;AAEA,YAAA,MAAM,MAAA,GAAU,QAAA,CAA6C,KAAA,CAAM,MAAA,EAAQ,IAAI,CAAA;AAE/E,YAAA,IAAI,CAAC,UAAA,CAAW,MAAM,CAAA,EAAG;AACvB,cAAA,SAAA,GAAY,UAAU,CAAA;AAEtB,cAAA,OAAO,MAAA;AAAA,YACT;AAEA,YAAA,OAAO,MAAA,CAAO,IAAA;AAAA,cACZ,CAAA,GAAA,KAAO;AACL,gBAAA,SAAA,GAAY,UAAU,CAAA;AACtB,gBAAA,OAAO,GAAA;AAAA,cACT,CAAA;AAAA,cACA,CAAA,CAAA,KAAK;AACH,gBAAA,MAAM,CAAA;AAAA,cACR;AAAA,aACF;AAAA,UACF;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"instrumentDurableObjectStorage.js","sources":["../../../src/instrumentations/instrumentDurableObjectStorage.ts"],"sourcesContent":["import type { DurableObjectStorage, SyncKvStorage, SqlStorage } from '@cloudflare/workers-types';\nimport { getClient, isThenable, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';\nimport type { CloudflareClientOptions } from '../client';\nimport { getStorageKeys, targetsCloudflareInternalKey } from '../utils/internalStorageKey';\nimport { storeSpanContext } from '../utils/traceLinks';\nimport { instrumentDurableObjectSyncKvStorage } from './instrumentDurableObjectSyncKvStorage';\nimport { instrumentSqlStorage } from './instrumentSqlStorage';\n\nconst STORAGE_METHODS_TO_INSTRUMENT = ['get', 'put', 'delete', 'list', 'setAlarm', 'getAlarm', 'deleteAlarm'] as const;\n\ntype StorageMethod = (typeof STORAGE_METHODS_TO_INSTRUMENT)[number];\n\ntype WaitUntil = (promise: Promise<unknown>) => void;\n\n/**\n * Instruments DurableObjectStorage methods with Sentry spans.\n *\n * Wraps the following async methods:\n * - get, put, delete, list (KV API)\n * - setAlarm, getAlarm, deleteAlarm (Alarm API)\n *\n * When setAlarm is called, it also stores the current span context so that when\n * the alarm fires later, it can link back to the trace that called setAlarm.\n *\n * @param storage - The DurableObjectStorage instance to instrument\n * @param waitUntil - Optional waitUntil function to defer span context storage\n * @returns An instrumented DurableObjectStorage instance\n */\nexport function instrumentDurableObjectStorage(\n storage: DurableObjectStorage,\n waitUntil?: WaitUntil,\n): DurableObjectStorage {\n return new Proxy(storage, {\n get(target, prop, _receiver) {\n // Use `target` as the receiver instead of the proxy (`_receiver`).\n // Native workerd getters (e.g., `storage.sql`) validate `this` via\n // internal slots. Passing the proxy as receiver breaks that check,\n // causing \"Illegal invocation: function called with incorrect `this`\n // reference\" errors.\n const original = Reflect.get(target, prop, target);\n\n if (prop === 'kv' && original != null && 'get' in original && 'put' in original) {\n return instrumentDurableObjectSyncKvStorage(original as SyncKvStorage);\n }\n\n if (prop === 'sql' && original != null && 'databaseSize' in original && 'exec' in original) {\n return instrumentSqlStorage(original as SqlStorage);\n }\n\n if (typeof original !== 'function') {\n return original;\n }\n\n const methodName = prop as string;\n if (!STORAGE_METHODS_TO_INSTRUMENT.includes(methodName as StorageMethod)) {\n return (original as (...args: unknown[]) => unknown).bind(target);\n }\n\n return function (this: unknown, ...args: unknown[]) {\n // KV entries managed by the DO framework itself (agents/partyserver state) are bookkeeping\n // rather than user work — skip the span, mirroring how `cf_` SQL tables are treated.\n const allowlist = (getClient()?.getOptions() as CloudflareClientOptions | undefined)\n ?.durableObjectStorageSpanAllowlist;\n const keys = getStorageKeys(methodName, args);\n if (keys && keys.length > 0 && keys.every(key => targetsCloudflareInternalKey(key, allowlist))) {\n return (original as (...a: unknown[]) => unknown).apply(target, args);\n }\n\n return startSpan(\n {\n // Use underscore naming to match Cloudflare's native instrumentation (e.g., \"durable_object_storage_get\")\n name: `durable_object_storage_${methodName}`,\n op: 'db',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object',\n 'db.system.name': 'cloudflare.durable_object.storage',\n 'db.operation.name': methodName,\n },\n },\n () => {\n const teardown = async (): Promise<void> => {\n // When setAlarm is called, store the current span context so that when the alarm\n // fires later, it can link back to the trace that called setAlarm.\n // We use the original (uninstrumented) storage (target) to avoid creating a span\n // for this internal operation. The storage is deferred via waitUntil to not block.\n if (methodName === 'setAlarm') {\n storeSpanContext(target, 'alarm');\n }\n };\n\n const result = (original as (...args: unknown[]) => unknown).apply(target, args);\n\n if (!isThenable(result)) {\n waitUntil?.(teardown());\n\n return result;\n }\n\n return result.then(\n res => {\n waitUntil?.(teardown());\n return res;\n },\n e => {\n throw e;\n },\n );\n },\n );\n };\n },\n });\n}\n"],"names":[],"mappings":";;;;;;AAQA,MAAM,6BAAA,GAAgC,CAAC,KAAA,EAAO,KAAA,EAAO,UAAU,MAAA,EAAQ,UAAA,EAAY,YAAY,aAAa,CAAA;AAoBrG,SAAS,8BAAA,CACd,SACA,SAAA,EACsB;AACtB,EAAA,OAAO,IAAI,MAAM,OAAA,EAAS;AAAA,IACxB,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAW;AAM3B,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,MAAM,MAAM,CAAA;AAEjD,MAAA,IAAI,SAAS,IAAA,IAAQ,QAAA,IAAY,QAAQ,KAAA,IAAS,QAAA,IAAY,SAAS,QAAA,EAAU;AAC/E,QAAA,OAAO,qCAAqC,QAAyB,CAAA;AAAA,MACvE;AAEA,MAAA,IAAI,SAAS,KAAA,IAAS,QAAA,IAAY,QAAQ,cAAA,IAAkB,QAAA,IAAY,UAAU,QAAA,EAAU;AAC1F,QAAA,OAAO,qBAAqB,QAAsB,CAAA;AAAA,MACpD;AAEA,MAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,QAAA,OAAO,QAAA;AAAA,MACT;AAEA,MAAA,MAAM,UAAA,GAAa,IAAA;AACnB,MAAA,IAAI,CAAC,6BAAA,CAA8B,QAAA,CAAS,UAA2B,CAAA,EAAG;AACxE,QAAA,OAAQ,QAAA,CAA6C,KAAK,MAAM,CAAA;AAAA,MAClE;AAEA,MAAA,OAAO,YAA4B,IAAA,EAAiB;AAGlD,QAAA,MAAM,SAAA,GAAa,SAAA,EAAU,EAAG,UAAA,EAAW,EACvC,iCAAA;AACJ,QAAA,MAAM,IAAA,GAAO,cAAA,CAAe,UAAA,EAAY,IAAI,CAAA;AAC5C,QAAA,IAAI,IAAA,IAAQ,IAAA,CAAK,MAAA,GAAS,CAAA,IAAK,IAAA,CAAK,KAAA,CAAM,CAAA,GAAA,KAAO,4BAAA,CAA6B,GAAA,EAAK,SAAS,CAAC,CAAA,EAAG;AAC9F,UAAA,OAAQ,QAAA,CAA0C,KAAA,CAAM,MAAA,EAAQ,IAAI,CAAA;AAAA,QACtE;AAEA,QAAA,OAAO,SAAA;AAAA,UACL;AAAA;AAAA,YAEE,IAAA,EAAM,0BAA0B,UAAU,CAAA,CAAA;AAAA,YAC1C,EAAA,EAAI,IAAA;AAAA,YACJ,UAAA,EAAY;AAAA,cACV,CAAC,gCAAgC,GAAG,mCAAA;AAAA,cACpC,gBAAA,EAAkB,mCAAA;AAAA,cAClB,mBAAA,EAAqB;AAAA;AACvB,WACF;AAAA,UACA,MAAM;AACJ,YAAA,MAAM,WAAW,YAA2B;AAK1C,cAAA,IAAI,eAAe,UAAA,EAAY;AAC7B,gBAAA,gBAAA,CAAiB,QAAQ,OAAO,CAAA;AAAA,cAClC;AAAA,YACF,CAAA;AAEA,YAAA,MAAM,MAAA,GAAU,QAAA,CAA6C,KAAA,CAAM,MAAA,EAAQ,IAAI,CAAA;AAE/E,YAAA,IAAI,CAAC,UAAA,CAAW,MAAM,CAAA,EAAG;AACvB,cAAA,SAAA,GAAY,UAAU,CAAA;AAEtB,cAAA,OAAO,MAAA;AAAA,YACT;AAEA,YAAA,OAAO,MAAA,CAAO,IAAA;AAAA,cACZ,CAAA,GAAA,KAAO;AACL,gBAAA,SAAA,GAAY,UAAU,CAAA;AACtB,gBAAA,OAAO,GAAA;AAAA,cACT,CAAA;AAAA,cACA,CAAA,CAAA,KAAK;AACH,gBAAA,MAAM,CAAA;AAAA,cACR;AAAA,aACF;AAAA,UACF;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
@@ -13,7 +13,7 @@ function instrumentSqlStorage(sql) {
13
13
  const sanitizedQuery = _INTERNAL_sanitizeSqlQuery(query);
14
14
  const querySummary = _INTERNAL_getSqlQuerySummary(sanitizedQuery);
15
15
  const allowlist = getClient()?.getOptions()?.durableObjectSqlSpanAllowlist;
16
- if (targetsCloudflareInternalTable(querySummary, allowlist)) {
16
+ if (targetsCloudflareInternalTable(querySummary, allowlist, sanitizedQuery)) {
17
17
  return original.apply(target, args);
18
18
  }
19
19
  return startSpan(
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentSqlStorage.js","sources":["../../../src/instrumentations/instrumentSqlStorage.ts"],"sourcesContent":["import type { SqlStorage } from '@cloudflare/workers-types';\nimport {\n _INTERNAL_getSqlQuerySummary,\n _INTERNAL_sanitizeSqlQuery,\n getClient,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n} from '@sentry/core';\nimport type { CloudflareClientOptions } from '../client';\nimport { targetsCloudflareInternalTable } from '../utils/internalSqlQuery';\n\n/**\n * Instruments the Durable Object SqlStorage `exec` method with Sentry spans.\n *\n * @param sql - The SqlStorage instance to instrument\n * @returns An instrumented SqlStorage instance\n */\nexport function instrumentSqlStorage(sql: SqlStorage): SqlStorage {\n return new Proxy(sql, {\n get(target, prop, _receiver) {\n const original = Reflect.get(target, prop, target);\n\n if (prop !== 'exec' || typeof original !== 'function') {\n return original;\n }\n\n return function (this: unknown, ...args: unknown[]) {\n const [query, ...bindings] = args as [string, ...unknown[]];\n\n const sanitizedQuery = _INTERNAL_sanitizeSqlQuery(query);\n const querySummary = _INTERNAL_getSqlQuerySummary(sanitizedQuery);\n\n const allowlist = (getClient()?.getOptions() as CloudflareClientOptions | undefined)\n ?.durableObjectSqlSpanAllowlist;\n\n if (targetsCloudflareInternalTable(querySummary, allowlist)) {\n return (original as (...a: unknown[]) => ReturnType<SqlStorage['exec']>).apply(target, args);\n }\n\n return startSpan(\n {\n op: 'db.query',\n name: querySummary || sanitizedQuery,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object.sql',\n 'db.system.name': 'cloudflare-durable-object-sql',\n 'db.operation.name': 'exec',\n 'db.query.text': sanitizedQuery,\n 'db.query.summary': querySummary,\n 'cloudflare.durable_object.query.bindings': bindings.length,\n },\n },\n () => (original as (...a: unknown[]) => ReturnType<SqlStorage['exec']>).apply(target, args),\n );\n };\n },\n });\n}\n"],"names":[],"mappings":";;;AAiBO,SAAS,qBAAqB,GAAA,EAA6B;AAChE,EAAA,OAAO,IAAI,MAAM,GAAA,EAAK;AAAA,IACpB,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAW;AAC3B,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,MAAM,MAAM,CAAA;AAEjD,MAAA,IAAI,IAAA,KAAS,MAAA,IAAU,OAAO,QAAA,KAAa,UAAA,EAAY;AACrD,QAAA,OAAO,QAAA;AAAA,MACT;AAEA,MAAA,OAAO,YAA4B,IAAA,EAAiB;AAClD,QAAA,MAAM,CAAC,KAAA,EAAO,GAAG,QAAQ,CAAA,GAAI,IAAA;AAE7B,QAAA,MAAM,cAAA,GAAiB,2BAA2B,KAAK,CAAA;AACvD,QAAA,MAAM,YAAA,GAAe,6BAA6B,cAAc,CAAA;AAEhE,QAAA,MAAM,SAAA,GAAa,SAAA,EAAU,EAAG,UAAA,EAAW,EACvC,6BAAA;AAEJ,QAAA,IAAI,8BAAA,CAA+B,YAAA,EAAc,SAAS,CAAA,EAAG;AAC3D,UAAA,OAAQ,QAAA,CAAiE,KAAA,CAAM,MAAA,EAAQ,IAAI,CAAA;AAAA,QAC7F;AAEA,QAAA,OAAO,SAAA;AAAA,UACL;AAAA,YACE,EAAA,EAAI,UAAA;AAAA,YACJ,MAAM,YAAA,IAAgB,cAAA;AAAA,YACtB,UAAA,EAAY;AAAA,cACV,CAAC,gCAAgC,GAAG,uCAAA;AAAA,cACpC,gBAAA,EAAkB,+BAAA;AAAA,cAClB,mBAAA,EAAqB,MAAA;AAAA,cACrB,eAAA,EAAiB,cAAA;AAAA,cACjB,kBAAA,EAAoB,YAAA;AAAA,cACpB,4CAA4C,QAAA,CAAS;AAAA;AACvD,WACF;AAAA,UACA,MAAO,QAAA,CAAiE,KAAA,CAAM,MAAA,EAAQ,IAAI;AAAA,SAC5F;AAAA,MACF,CAAA;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"instrumentSqlStorage.js","sources":["../../../src/instrumentations/instrumentSqlStorage.ts"],"sourcesContent":["import type { SqlStorage } from '@cloudflare/workers-types';\nimport {\n _INTERNAL_getSqlQuerySummary,\n _INTERNAL_sanitizeSqlQuery,\n getClient,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n} from '@sentry/core';\nimport type { CloudflareClientOptions } from '../client';\nimport { targetsCloudflareInternalTable } from '../utils/internalSqlQuery';\n\n/**\n * Instruments the Durable Object SqlStorage `exec` method with Sentry spans.\n *\n * @param sql - The SqlStorage instance to instrument\n * @returns An instrumented SqlStorage instance\n */\nexport function instrumentSqlStorage(sql: SqlStorage): SqlStorage {\n return new Proxy(sql, {\n get(target, prop, _receiver) {\n const original = Reflect.get(target, prop, target);\n\n if (prop !== 'exec' || typeof original !== 'function') {\n return original;\n }\n\n return function (this: unknown, ...args: unknown[]) {\n const [query, ...bindings] = args as [string, ...unknown[]];\n\n const sanitizedQuery = _INTERNAL_sanitizeSqlQuery(query);\n const querySummary = _INTERNAL_getSqlQuerySummary(sanitizedQuery);\n\n const allowlist = (getClient()?.getOptions() as CloudflareClientOptions | undefined)\n ?.durableObjectSqlSpanAllowlist;\n\n if (targetsCloudflareInternalTable(querySummary, allowlist, sanitizedQuery)) {\n return (original as (...a: unknown[]) => ReturnType<SqlStorage['exec']>).apply(target, args);\n }\n\n return startSpan(\n {\n op: 'db.query',\n name: querySummary || sanitizedQuery,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object.sql',\n 'db.system.name': 'cloudflare-durable-object-sql',\n 'db.operation.name': 'exec',\n 'db.query.text': sanitizedQuery,\n 'db.query.summary': querySummary,\n 'cloudflare.durable_object.query.bindings': bindings.length,\n },\n },\n () => (original as (...a: unknown[]) => ReturnType<SqlStorage['exec']>).apply(target, args),\n );\n };\n },\n });\n}\n"],"names":[],"mappings":";;;AAiBO,SAAS,qBAAqB,GAAA,EAA6B;AAChE,EAAA,OAAO,IAAI,MAAM,GAAA,EAAK;AAAA,IACpB,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAW;AAC3B,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,MAAM,MAAM,CAAA;AAEjD,MAAA,IAAI,IAAA,KAAS,MAAA,IAAU,OAAO,QAAA,KAAa,UAAA,EAAY;AACrD,QAAA,OAAO,QAAA;AAAA,MACT;AAEA,MAAA,OAAO,YAA4B,IAAA,EAAiB;AAClD,QAAA,MAAM,CAAC,KAAA,EAAO,GAAG,QAAQ,CAAA,GAAI,IAAA;AAE7B,QAAA,MAAM,cAAA,GAAiB,2BAA2B,KAAK,CAAA;AACvD,QAAA,MAAM,YAAA,GAAe,6BAA6B,cAAc,CAAA;AAEhE,QAAA,MAAM,SAAA,GAAa,SAAA,EAAU,EAAG,UAAA,EAAW,EACvC,6BAAA;AAEJ,QAAA,IAAI,8BAAA,CAA+B,YAAA,EAAc,SAAA,EAAW,cAAc,CAAA,EAAG;AAC3E,UAAA,OAAQ,QAAA,CAAiE,KAAA,CAAM,MAAA,EAAQ,IAAI,CAAA;AAAA,QAC7F;AAEA,QAAA,OAAO,SAAA;AAAA,UACL;AAAA,YACE,EAAA,EAAI,UAAA;AAAA,YACJ,MAAM,YAAA,IAAgB,cAAA;AAAA,YACtB,UAAA,EAAY;AAAA,cACV,CAAC,gCAAgC,GAAG,uCAAA;AAAA,cACpC,gBAAA,EAAkB,+BAAA;AAAA,cAClB,mBAAA,EAAqB,MAAA;AAAA,cACrB,eAAA,EAAiB,cAAA;AAAA,cACjB,kBAAA,EAAoB,YAAA;AAAA,cACpB,4CAA4C,QAAA,CAAS;AAAA;AACvD,WACF;AAAA,UACA,MAAO,QAAA,CAAiE,KAAA,CAAM,MAAA,EAAQ,IAAI;AAAA,SAC5F;AAAA,MACF,CAAA;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,61 @@
1
+ import { defineIntegration, debug, serializeEnvelope, suppressTracing } from '@sentry/core';
2
+ import { DEBUG_BUILD } from '../debug-build.js';
3
+
4
+ const INTEGRATION_NAME = "Spotlight";
5
+ const _spotlightIntegration = ((options = {}) => {
6
+ const sidecarUrl = options.sidecarUrl || "http://localhost:8969/stream";
7
+ return {
8
+ name: INTEGRATION_NAME,
9
+ setup(client) {
10
+ DEBUG_BUILD && debug.log("[Spotlight] Using Sidecar URL", sidecarUrl);
11
+ setupSidecarForwarding(client, sidecarUrl);
12
+ }
13
+ };
14
+ });
15
+ const spotlightIntegration = defineIntegration(_spotlightIntegration);
16
+ function setupSidecarForwarding(client, sidecarUrl) {
17
+ const parsedUrl = parseSidecarUrl(sidecarUrl);
18
+ if (!parsedUrl) {
19
+ return;
20
+ }
21
+ let failCount = 0;
22
+ client.on("beforeEnvelope", (envelope) => {
23
+ if (failCount > 3) {
24
+ DEBUG_BUILD && debug.warn("[Spotlight] Disabled Sentry -> Spotlight forwarding due to too many failed requests");
25
+ return;
26
+ }
27
+ const body = serializeEnvelope(envelope);
28
+ suppressTracing(() => {
29
+ fetch(parsedUrl.href, {
30
+ method: "POST",
31
+ body,
32
+ headers: {
33
+ "Content-Type": "application/x-sentry-envelope"
34
+ }
35
+ }).then(
36
+ (res) => {
37
+ res.text().catch(() => {
38
+ });
39
+ if (res.status >= 200 && res.status < 400) {
40
+ failCount = 0;
41
+ }
42
+ },
43
+ () => {
44
+ failCount++;
45
+ DEBUG_BUILD && debug.warn("[Spotlight] Failed to send envelope to Spotlight Sidecar");
46
+ }
47
+ );
48
+ });
49
+ });
50
+ }
51
+ function parseSidecarUrl(url) {
52
+ try {
53
+ return new URL(url);
54
+ } catch {
55
+ DEBUG_BUILD && debug.warn(`[Spotlight] Invalid sidecar URL: ${url}`);
56
+ return void 0;
57
+ }
58
+ }
59
+
60
+ export { INTEGRATION_NAME, spotlightIntegration };
61
+ //# sourceMappingURL=spotlight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spotlight.js","sources":["../../../src/integrations/spotlight.ts"],"sourcesContent":["import type { Client, Envelope, IntegrationFn } from '@sentry/core';\nimport { debug, defineIntegration, serializeEnvelope, suppressTracing } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\ntype SpotlightConnectionOptions = {\n /**\n * Set this if the Spotlight Sidecar is not running on localhost:8969.\n * By default, the URL is set to http://localhost:8969/stream\n */\n sidecarUrl?: string;\n};\n\nexport const INTEGRATION_NAME = 'Spotlight' as const;\n\nconst _spotlightIntegration = ((options: Partial<SpotlightConnectionOptions> = {}) => {\n const sidecarUrl = options.sidecarUrl || 'http://localhost:8969/stream';\n\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n DEBUG_BUILD && debug.log('[Spotlight] Using Sidecar URL', sidecarUrl);\n setupSidecarForwarding(client, sidecarUrl);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Use this integration to send errors and transactions to Spotlight.\n *\n * Learn more about spotlight at https://spotlightjs.com\n *\n * Important: This integration is intended for local development only.\n * Each forwarded envelope counts as a Worker subrequest (50 free / 1000 paid\n * per invocation), so it should not be enabled in production.\n */\nexport const spotlightIntegration = defineIntegration(_spotlightIntegration);\n\nfunction setupSidecarForwarding(client: Client, sidecarUrl: string): void {\n const parsedUrl = parseSidecarUrl(sidecarUrl);\n if (!parsedUrl) {\n return;\n }\n\n let failCount = 0;\n\n client.on('beforeEnvelope', (envelope: Envelope) => {\n if (failCount > 3) {\n DEBUG_BUILD && debug.warn('[Spotlight] Disabled Sentry -> Spotlight forwarding due to too many failed requests');\n return;\n }\n\n const body = serializeEnvelope(envelope);\n\n suppressTracing(() => {\n fetch(parsedUrl.href, {\n method: 'POST',\n body,\n headers: {\n 'Content-Type': 'application/x-sentry-envelope',\n },\n }).then(\n res => {\n // Consume the response body to satisfy Cloudflare Workers' requirement\n // that all fetch response bodies are read or cancelled.\n res.text().catch(() => {\n // no-op\n });\n\n if (res.status >= 200 && res.status < 400) {\n failCount = 0;\n }\n },\n () => {\n failCount++;\n DEBUG_BUILD && debug.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar');\n },\n );\n });\n });\n}\n\nfunction parseSidecarUrl(url: string): URL | undefined {\n try {\n return new URL(url);\n } catch {\n DEBUG_BUILD && debug.warn(`[Spotlight] Invalid sidecar URL: ${url}`);\n return undefined;\n }\n}\n"],"names":[],"mappings":";;;AAYO,MAAM,gBAAA,GAAmB;AAEhC,MAAM,qBAAA,IAAyB,CAAC,OAAA,GAA+C,EAAC,KAAM;AACpF,EAAA,MAAM,UAAA,GAAa,QAAQ,UAAA,IAAc,8BAAA;AAEzC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,MAAM,MAAA,EAAQ;AACZ,MAAA,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,+BAAA,EAAiC,UAAU,CAAA;AACpE,MAAA,sBAAA,CAAuB,QAAQ,UAAU,CAAA;AAAA,IAC3C;AAAA,GACF;AACF,CAAA,CAAA;AAWO,MAAM,oBAAA,GAAuB,kBAAkB,qBAAqB;AAE3E,SAAS,sBAAA,CAAuB,QAAgB,UAAA,EAA0B;AACxE,EAAA,MAAM,SAAA,GAAY,gBAAgB,UAAU,CAAA;AAC5C,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,SAAA,GAAY,CAAA;AAEhB,EAAA,MAAA,CAAO,EAAA,CAAG,gBAAA,EAAkB,CAAC,QAAA,KAAuB;AAClD,IAAA,IAAI,YAAY,CAAA,EAAG;AACjB,MAAA,WAAA,IAAe,KAAA,CAAM,KAAK,qFAAqF,CAAA;AAC/G,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,IAAA,GAAO,kBAAkB,QAAQ,CAAA;AAEvC,IAAA,eAAA,CAAgB,MAAM;AACpB,MAAA,KAAA,CAAM,UAAU,IAAA,EAAM;AAAA,QACpB,MAAA,EAAQ,MAAA;AAAA,QACR,IAAA;AAAA,QACA,OAAA,EAAS;AAAA,UACP,cAAA,EAAgB;AAAA;AAClB,OACD,CAAA,CAAE,IAAA;AAAA,QACD,CAAA,GAAA,KAAO;AAGL,UAAA,GAAA,CAAI,IAAA,EAAK,CAAE,KAAA,CAAM,MAAM;AAAA,UAEvB,CAAC,CAAA;AAED,UAAA,IAAI,GAAA,CAAI,MAAA,IAAU,GAAA,IAAO,GAAA,CAAI,SAAS,GAAA,EAAK;AACzC,YAAA,SAAA,GAAY,CAAA;AAAA,UACd;AAAA,QACF,CAAA;AAAA,QACA,MAAM;AACJ,UAAA,SAAA,EAAA;AACA,UAAA,WAAA,IAAe,KAAA,CAAM,KAAK,0DAA0D,CAAA;AAAA,QACtF;AAAA,OACF;AAAA,IACF,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AACH;AAEA,SAAS,gBAAgB,GAAA,EAA8B;AACrD,EAAA,IAAI;AACF,IAAA,OAAO,IAAI,IAAI,GAAG,CAAA;AAAA,EACpB,CAAA,CAAA,MAAQ;AACN,IAAA,WAAA,IAAe,KAAA,CAAM,IAAA,CAAK,CAAA,iCAAA,EAAoC,GAAG,CAAA,CAAE,CAAA;AACnE,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
@@ -7,11 +7,12 @@ export { fetchIntegration } from '../integrations/fetch.js';
7
7
  export { getDefaultIntegrations } from '../sdk.js';
8
8
  export { honoIntegration } from '../integrations/hono.js';
9
9
  export { httpServerIntegration } from '../integrations/httpServer.js';
10
+ export { instrumentAgentWithSentry, instrumentDurableObjectWithSentry } from '../durableobject.js';
10
11
  export { instrumentD1WithSentry } from '../instrumentations/worker/instrumentD1.js';
11
- export { instrumentDurableObjectWithSentry } from '../durableobject.js';
12
12
  export { instrumentWorkflowWithSentry } from '../workflows.js';
13
13
  export { sentryPagesPlugin } from '../pages-plugin.js';
14
14
  export { setAsyncLocalStorageAsyncContextStrategy } from '../async.js';
15
+ export { spotlightIntegration } from '../integrations/spotlight.js';
15
16
  export { withSentry } from '../withSentry.js';
16
17
  export { wrapRequestHandler } from '../request.js';
17
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
@@ -12,6 +12,7 @@ function getFinalOptions(userOptions = {}, env) {
12
12
  }
13
13
  const release = "SENTRY_RELEASE" in env && typeof env.SENTRY_RELEASE === "string" ? env.SENTRY_RELEASE : "CF_VERSION_METADATA" in env && isVersionMetadata(env.CF_VERSION_METADATA) ? env.CF_VERSION_METADATA.id : void 0;
14
14
  const tracesSampleRate = userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, "SENTRY_TRACES_SAMPLE_RATE") ?? "");
15
+ const spotlight = getSpotlightFromEnv(userOptions.spotlight, getEnvVar(env, "SENTRY_SPOTLIGHT"));
15
16
  return {
16
17
  release,
17
18
  ...userOptions,
@@ -19,9 +20,21 @@ function getFinalOptions(userOptions = {}, env) {
19
20
  environment: userOptions.environment ?? getEnvVar(env, "SENTRY_ENVIRONMENT"),
20
21
  tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : void 0,
21
22
  debug: userOptions.debug ?? envToBool(getEnvVar(env, "SENTRY_DEBUG")),
22
- tunnel: userOptions.tunnel ?? getEnvVar(env, "SENTRY_TUNNEL")
23
+ tunnel: userOptions.tunnel ?? getEnvVar(env, "SENTRY_TUNNEL"),
24
+ spotlight
23
25
  };
24
26
  }
27
+ function getSpotlightFromEnv(optionsSpotlight, envVar) {
28
+ if (optionsSpotlight === false) {
29
+ return false;
30
+ }
31
+ if (typeof optionsSpotlight === "string") {
32
+ return optionsSpotlight;
33
+ }
34
+ const envBool = envToBool(envVar, { strict: true });
35
+ const envUrl = envBool === null && envVar ? envVar : void 0;
36
+ return optionsSpotlight === true ? envUrl ?? true : envBool ?? envUrl;
37
+ }
25
38
 
26
39
  export { getFinalOptions };
27
40
  //# sourceMappingURL=options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sources":["../../src/options.ts"],"sourcesContent":["import { isObjectLike, envToBool } from '@sentry/core';\nimport type { CloudflareOptions } from './client';\n\n/**\n * Cloudflare's version metadata binding structure.\n * @see https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata/\n */\ninterface CfVersionMetadata {\n id: string;\n tag?: string;\n timestamp?: string;\n}\n\n/**\n * Checks if the value is a valid CF_VERSION_METADATA binding.\n */\nfunction isVersionMetadata(value: unknown): value is CfVersionMetadata {\n return isObjectLike(value) && 'id' in value && typeof value.id === 'string';\n}\n\nfunction getEnvVar<T extends Record<string, unknown>>(env: unknown, varName: keyof T): string | undefined {\n return isObjectLike(env) && varName in env && typeof (env as T)[varName] === 'string'\n ? ((env as T)[varName] as string)\n : undefined;\n}\n\n/**\n * Merges the options passed in from the user with the options we read from\n * the Cloudflare `env` environment variable object.\n *\n * Release is determined with the following priority (highest to lowest):\n * 1. User-provided release option\n * 2. SENTRY_RELEASE environment variable\n * 3. CF_VERSION_METADATA.id binding (if configured in the wrangler config)\n *\n * @param userOptions - The options passed in from the user.\n * @param env - The environment variables.\n *\n * @returns The final options.\n */\nexport function getFinalOptions(userOptions: CloudflareOptions = {}, env: unknown): CloudflareOptions {\n if (typeof env !== 'object' || env === null) {\n return userOptions;\n }\n\n // Priority: userOptions.release > SENTRY_RELEASE > CF_VERSION_METADATA.id\n const release =\n 'SENTRY_RELEASE' in env && typeof env.SENTRY_RELEASE === 'string'\n ? env.SENTRY_RELEASE\n : 'CF_VERSION_METADATA' in env && isVersionMetadata(env.CF_VERSION_METADATA)\n ? env.CF_VERSION_METADATA.id\n : undefined;\n\n const tracesSampleRate =\n userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, 'SENTRY_TRACES_SAMPLE_RATE') ?? '');\n\n return {\n release,\n ...userOptions,\n dsn: userOptions.dsn ?? getEnvVar(env, 'SENTRY_DSN'),\n environment: userOptions.environment ?? getEnvVar(env, 'SENTRY_ENVIRONMENT'),\n tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : undefined,\n debug: userOptions.debug ?? envToBool(getEnvVar(env, 'SENTRY_DEBUG')),\n tunnel: userOptions.tunnel ?? getEnvVar(env, 'SENTRY_TUNNEL'),\n };\n}\n"],"names":[],"mappings":";;AAgBA,SAAS,kBAAkB,KAAA,EAA4C;AACrE,EAAA,OAAO,aAAa,KAAK,CAAA,IAAK,QAAQ,KAAA,IAAS,OAAO,MAAM,EAAA,KAAO,QAAA;AACrE;AAEA,SAAS,SAAA,CAA6C,KAAc,OAAA,EAAsC;AACxG,EAAA,OAAO,YAAA,CAAa,GAAG,CAAA,IAAK,OAAA,IAAW,GAAA,IAAO,OAAQ,GAAA,CAAU,OAAO,CAAA,KAAM,QAAA,GACvE,GAAA,CAAU,OAAO,CAAA,GACnB,MAAA;AACN;AAgBO,SAAS,eAAA,CAAgB,WAAA,GAAiC,EAAC,EAAG,GAAA,EAAiC;AACpG,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,IAAA,EAAM;AAC3C,IAAA,OAAO,WAAA;AAAA,EACT;AAGA,EAAA,MAAM,UACJ,gBAAA,IAAoB,GAAA,IAAO,OAAO,GAAA,CAAI,mBAAmB,QAAA,GACrD,GAAA,CAAI,cAAA,GACJ,qBAAA,IAAyB,OAAO,iBAAA,CAAkB,GAAA,CAAI,mBAAmB,CAAA,GACvE,GAAA,CAAI,oBAAoB,EAAA,GACxB,MAAA;AAER,EAAA,MAAM,gBAAA,GACJ,YAAY,gBAAA,IAAoB,UAAA,CAAW,UAAU,GAAA,EAAK,2BAA2B,KAAK,EAAE,CAAA;AAE9F,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,GAAG,WAAA;AAAA,IACH,GAAA,EAAK,WAAA,CAAY,GAAA,IAAO,SAAA,CAAU,KAAK,YAAY,CAAA;AAAA,IACnD,WAAA,EAAa,WAAA,CAAY,WAAA,IAAe,SAAA,CAAU,KAAK,oBAAoB,CAAA;AAAA,IAC3E,gBAAA,EAAkB,QAAA,CAAS,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,MAAA;AAAA,IAClE,OAAO,WAAA,CAAY,KAAA,IAAS,UAAU,SAAA,CAAU,GAAA,EAAK,cAAc,CAAC,CAAA;AAAA,IACpE,MAAA,EAAQ,WAAA,CAAY,MAAA,IAAU,SAAA,CAAU,KAAK,eAAe;AAAA,GAC9D;AACF;;;;"}
1
+ {"version":3,"file":"options.js","sources":["../../src/options.ts"],"sourcesContent":["import { isObjectLike, envToBool } from '@sentry/core';\nimport type { CloudflareOptions } from './client';\n\n/**\n * Cloudflare's version metadata binding structure.\n * @see https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata/\n */\ninterface CfVersionMetadata {\n id: string;\n tag?: string;\n timestamp?: string;\n}\n\n/**\n * Checks if the value is a valid CF_VERSION_METADATA binding.\n */\nfunction isVersionMetadata(value: unknown): value is CfVersionMetadata {\n return isObjectLike(value) && 'id' in value && typeof value.id === 'string';\n}\n\nfunction getEnvVar<T extends Record<string, unknown>>(env: unknown, varName: keyof T): string | undefined {\n return isObjectLike(env) && varName in env && typeof (env as T)[varName] === 'string'\n ? ((env as T)[varName] as string)\n : undefined;\n}\n\n/**\n * Merges the options passed in from the user with the options we read from\n * the Cloudflare `env` environment variable object.\n *\n * Release is determined with the following priority (highest to lowest):\n * 1. User-provided release option\n * 2. SENTRY_RELEASE environment variable\n * 3. CF_VERSION_METADATA.id binding (if configured in the wrangler config)\n *\n * @param userOptions - The options passed in from the user.\n * @param env - The environment variables.\n *\n * @returns The final options.\n */\nexport function getFinalOptions(userOptions: CloudflareOptions = {}, env: unknown): CloudflareOptions {\n if (typeof env !== 'object' || env === null) {\n return userOptions;\n }\n\n // Priority: userOptions.release > SENTRY_RELEASE > CF_VERSION_METADATA.id\n const release =\n 'SENTRY_RELEASE' in env && typeof env.SENTRY_RELEASE === 'string'\n ? env.SENTRY_RELEASE\n : 'CF_VERSION_METADATA' in env && isVersionMetadata(env.CF_VERSION_METADATA)\n ? env.CF_VERSION_METADATA.id\n : undefined;\n\n const tracesSampleRate =\n userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, 'SENTRY_TRACES_SAMPLE_RATE') ?? '');\n\n // Spotlight precedence (mirrors node-core's getSpotlightConfig):\n // - false or explicit string from options: use as-is\n // - true: enable, but prefer a custom URL from the env var if set\n // - undefined: defer entirely to the env var (bool or URL)\n const spotlight = getSpotlightFromEnv(userOptions.spotlight, getEnvVar(env, 'SENTRY_SPOTLIGHT'));\n\n return {\n release,\n ...userOptions,\n dsn: userOptions.dsn ?? getEnvVar(env, 'SENTRY_DSN'),\n environment: userOptions.environment ?? getEnvVar(env, 'SENTRY_ENVIRONMENT'),\n tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : undefined,\n debug: userOptions.debug ?? envToBool(getEnvVar(env, 'SENTRY_DEBUG')),\n tunnel: userOptions.tunnel ?? getEnvVar(env, 'SENTRY_TUNNEL'),\n spotlight,\n };\n}\n\n/**\n * Resolve the spotlight option from a user-supplied value and an env binding string.\n * Mirrors node-core's `getSpotlightConfig` precedence:\n * - `false` or explicit string from options → use as-is\n * - `true` → enable, but prefer a custom URL from the env var if set\n * - `undefined` → defer entirely to the env var (bool or URL)\n */\nfunction getSpotlightFromEnv(\n optionsSpotlight: boolean | string | undefined,\n envVar: string | undefined,\n): boolean | string | undefined {\n if (optionsSpotlight === false) {\n return false;\n }\n if (typeof optionsSpotlight === 'string') {\n return optionsSpotlight;\n }\n\n // optionsSpotlight is true or undefined\n const envBool = envToBool(envVar, { strict: true });\n const envUrl = envBool === null && envVar ? envVar : undefined;\n\n return optionsSpotlight === true\n ? (envUrl ?? true) // true: use env URL if present, otherwise true\n : (envBool ?? envUrl); // undefined: use env var (bool or URL)\n}\n"],"names":[],"mappings":";;AAgBA,SAAS,kBAAkB,KAAA,EAA4C;AACrE,EAAA,OAAO,aAAa,KAAK,CAAA,IAAK,QAAQ,KAAA,IAAS,OAAO,MAAM,EAAA,KAAO,QAAA;AACrE;AAEA,SAAS,SAAA,CAA6C,KAAc,OAAA,EAAsC;AACxG,EAAA,OAAO,YAAA,CAAa,GAAG,CAAA,IAAK,OAAA,IAAW,GAAA,IAAO,OAAQ,GAAA,CAAU,OAAO,CAAA,KAAM,QAAA,GACvE,GAAA,CAAU,OAAO,CAAA,GACnB,MAAA;AACN;AAgBO,SAAS,eAAA,CAAgB,WAAA,GAAiC,EAAC,EAAG,GAAA,EAAiC;AACpG,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,IAAA,EAAM;AAC3C,IAAA,OAAO,WAAA;AAAA,EACT;AAGA,EAAA,MAAM,UACJ,gBAAA,IAAoB,GAAA,IAAO,OAAO,GAAA,CAAI,mBAAmB,QAAA,GACrD,GAAA,CAAI,cAAA,GACJ,qBAAA,IAAyB,OAAO,iBAAA,CAAkB,GAAA,CAAI,mBAAmB,CAAA,GACvE,GAAA,CAAI,oBAAoB,EAAA,GACxB,MAAA;AAER,EAAA,MAAM,gBAAA,GACJ,YAAY,gBAAA,IAAoB,UAAA,CAAW,UAAU,GAAA,EAAK,2BAA2B,KAAK,EAAE,CAAA;AAM9F,EAAA,MAAM,YAAY,mBAAA,CAAoB,WAAA,CAAY,WAAW,SAAA,CAAU,GAAA,EAAK,kBAAkB,CAAC,CAAA;AAE/F,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,GAAG,WAAA;AAAA,IACH,GAAA,EAAK,WAAA,CAAY,GAAA,IAAO,SAAA,CAAU,KAAK,YAAY,CAAA;AAAA,IACnD,WAAA,EAAa,WAAA,CAAY,WAAA,IAAe,SAAA,CAAU,KAAK,oBAAoB,CAAA;AAAA,IAC3E,gBAAA,EAAkB,QAAA,CAAS,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,MAAA;AAAA,IAClE,OAAO,WAAA,CAAY,KAAA,IAAS,UAAU,SAAA,CAAU,GAAA,EAAK,cAAc,CAAC,CAAA;AAAA,IACpE,MAAA,EAAQ,WAAA,CAAY,MAAA,IAAU,SAAA,CAAU,KAAK,eAAe,CAAA;AAAA,IAC5D;AAAA,GACF;AACF;AASA,SAAS,mBAAA,CACP,kBACA,MAAA,EAC8B;AAC9B,EAAA,IAAI,qBAAqB,KAAA,EAAO;AAC9B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAO,qBAAqB,QAAA,EAAU;AACxC,IAAA,OAAO,gBAAA;AAAA,EACT;AAGA,EAAA,MAAM,UAAU,SAAA,CAAU,MAAA,EAAQ,EAAE,MAAA,EAAQ,MAAM,CAAA;AAClD,EAAA,MAAM,MAAA,GAAS,OAAA,KAAY,IAAA,IAAQ,MAAA,GAAS,MAAA,GAAS,MAAA;AAErD,EAAA,OAAO,gBAAA,KAAqB,IAAA,GACvB,MAAA,IAAU,IAAA,GACV,OAAA,IAAW,MAAA;AAClB;;;;"}
@@ -1 +1 @@
1
- {"type":"module","version":"10.68.0","sideEffects":false}
1
+ {"type":"module","version":"10.70.0","sideEffects":false}
@@ -1,18 +1,19 @@
1
- import { withIsolationScope, parseStringToURLObject, getHttpSpanDetailsFromUrlObject, httpHeadersToSpanAttributes, winterCGHeadersToDict, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, captureException, continueTrace, startSpanManual, setHttpStatus } from '@sentry/core';
1
+ import { parseStringToURLObject, getHttpSpanDetailsFromUrlObject, httpHeadersToSpanAttributes, winterCGHeadersToDict, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, captureException, continueTrace, startSpanManual, setHttpStatus } from '@sentry/core';
2
2
  import { captureIncomingRequestBody } from './integrations/httpServer.js';
3
3
  import { getOriginalWaitUntil, flushAndDispose } from './flush.js';
4
4
  import { addCloudResourceContext, addRequest, addCultureContext } from './scope-utils.js';
5
5
  import { init } from './sdk.js';
6
+ import { withInvocationIsolationScope } from './utils/invocationScope.js';
6
7
  import { classifyResponseStreaming } from './utils/streaming.js';
7
8
 
8
9
  function getRequestErrorMechanismType(context) {
9
10
  return context && "storage" in context ? "auto.faas.cloudflare.durable_object" : "auto.http.cloudflare";
10
11
  }
11
12
  function wrapRequestHandler(wrapperOptions, handler) {
12
- return withIsolationScope(async (isolationScope) => {
13
+ return withInvocationIsolationScope(async (isolationScope) => {
13
14
  const { options, request, captureErrors = true } = wrapperOptions;
14
15
  const context = wrapperOptions.context;
15
- const waitUntil = context ? getOriginalWaitUntil(context)?.bind(context) : void 0;
16
+ const waitUntil = context ? getOriginalWaitUntil(context).bind(context) : void 0;
16
17
  const errorMechanismType = getRequestErrorMechanismType(context);
17
18
  const client = init({ ...options, ctx: context });
18
19
  isolationScope.setClient(client);