Title: `@sentry/cloudflare`: Child spans inside transactions from Durable Objects are not indexed by Sentry · Issue #20030 · getsentry/sentry-javascript · GitHub
Open Graph Title: `@sentry/cloudflare`: Child spans inside transactions from Durable Objects are not indexed by Sentry · Issue #20030 · getsentry/sentry-javascript
X Title: `@sentry/cloudflare`: Child spans inside transactions from Durable Objects are not indexed by Sentry · Issue #20030 · getsentry/sentry-javascript
Description: Description Package + Version @sentry/cloudflare@10.42.0 wrangler@4.71.0 Tested with both raw DurableObject and agents framework (Agent base class) Description When a Durable Object instrumented with instrumentDurableObjectWithSentry cre...
Open Graph Description: Description Package + Version @sentry/cloudflare@10.42.0 wrangler@4.71.0 Tested with both raw DurableObject and agents framework (Agent base class) Description When a Durable Object instrumented wi...
X Description: Description Package + Version @sentry/cloudflare@10.42.0 wrangler@4.71.0 Tested with both raw DurableObject and agents framework (Agent base class) Description When a Durable Object instrumented wi...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/20030
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@sentry/cloudflare`: Child spans inside transactions from Durable Objects are not indexed by Sentry","articleBody":"### Description\n\n## Package + Version\n\n* `@sentry/cloudflare@10.42.0`\n* `wrangler@4.71.0`\n* Tested with both raw `DurableObject` and `agents` framework (`Agent` base class)\n\n## Description\n\nWhen a Durable Object instrumented with `instrumentDurableObjectWithSentry` creates child spans (via `Sentry.startSpan`) during request handling, the transaction is delivered to Sentry but **only the root transaction span is indexed**. The child spans embedded in the transaction's `spans` array are silently dropped.\n\nThis was confirmed using a `beforeSendTransaction` hook which shows the correct span count (e.g., 51 spans) before the transaction is sent. The transaction arrives in Sentry (visible in the traces explorer), but only the root span appears — the 50 child spans are missing.\n\n### Evidence\n\n**With the** `agents` framework (`Agent` base class):\n\n* `beforeSendTransaction` fires: `tx=GET /agents/stream-with-spans spans=51`\n* Sentry shows: 1 span in trace (just the root `http.server` span)\n\n**With a plain** `DurableObject`:\n\n* Each `Sentry.startSpan` call creates its own transaction (not a child span)\n* `beforeSendTransaction` fires 50 times, each with `spans=0`\n* Sentry shows: 50+ spans in trace (because each is a separate transaction/root span)\n\nThis suggests that child spans embedded inside a transaction envelope are not being extracted/indexed by Sentry's span ingestion pipeline, at least for transactions originating from `@sentry/cloudflare` Durable Objects.\n\n### Impact\n\nThis blocks AI monitoring for Cloudflare DO-based applications. The Vercel AI SDK integration (`vercelAIIntegration`) correctly enriches spans with `gen_ai.*` attributes, and `beforeSendTransaction` confirms the spans are present in the transaction. But since child spans aren't indexed, they never appear in Sentry's traces explorer or AI monitoring views.\n\n## Minimal Reproduction\n\n### Files\n\n**wrangler.toml:**\n\n```toml\nname = \"sentry-do-streaming-repro\"\nmain = \"worker.ts\"\ncompatibility_date = \"2026-03-01\"\ncompatibility_flags = [\"nodejs_compat\"]\n\n[durable_objects]\nbindings = [\n { name = \"PLAIN_DO\", class_name = \"PlainDO\" },\n { name = \"AGENT_DO\", class_name = \"AgentDO\" }\n]\n\n[[migrations]]\ntag = \"v1\"\nnew_sqlite_classes = [\"PlainDO\", \"AgentDO\"]\n```\n\n**worker.ts:**\n\n```typescript\nimport * as Sentry from '@sentry/cloudflare';\nimport { DurableObject } from 'cloudflare:workers';\nimport { Agent, getAgentByName } from 'agents';\n\nfunction makeStream(): ReadableStream {\n return new ReadableStream({\n start(controller) {\n let i = 0;\n const interval = setInterval(() => {\n controller.enqueue(new TextEncoder().encode(`chunk ${i}\\n`));\n i++;\n if (i >= 5) {\n clearInterval(interval);\n controller.close();\n }\n }, 200);\n },\n });\n}\n\nfunction handlePath(path: string): Response {\n if (path.endsWith('/no-stream')) {\n return new Response('ok');\n }\n\n if (path.endsWith('/stream-with-spans')) {\n // Create 50 child spans — these should appear in the trace but don't\n for (let i = 0; i \u003c 50; i++) {\n Sentry.startSpan({ name: `work-${i}`, op: 'db' }, () => {});\n }\n return new Response(makeStream(), {\n headers: { 'content-type': 'text/event-stream; charset=utf-8' },\n });\n }\n\n return new Response('not found', { status: 404 });\n}\n\n// ─── Plain DurableObject ───\n\nclass PlainDOBase extends DurableObject\u003cEnv> {\n async fetch(request: Request): Promise\u003cResponse> {\n return handlePath(new URL(request.url).pathname);\n }\n}\n\nexport const PlainDO = Sentry.instrumentDurableObjectWithSentry(\n (env: Env) => ({\n dsn: env.SENTRY_DSN || 'https://example@sentry.io/0',\n tracesSampleRate: 1.0,\n enabled: !!env.SENTRY_DSN,\n beforeSendTransaction(event: any) {\n console.log(`[plain] tx=${event.transaction} spans=${(event.spans ?? []).length}`);\n return event;\n },\n }),\n PlainDOBase,\n);\n\n// ─── Agent-based DO ───\n\nclass AgentDOBase extends Agent\u003cEnv> {\n async onRequest(request: Request): Promise\u003cResponse> {\n return handlePath(new URL(request.url).pathname);\n }\n}\n\nexport const AgentDO = Sentry.instrumentDurableObjectWithSentry(\n (env: Env) => ({\n dsn: env.SENTRY_DSN || 'https://example@sentry.io/0',\n tracesSampleRate: 1.0,\n enabled: !!env.SENTRY_DSN,\n beforeSendTransaction(event: any) {\n console.log(`[agent] tx=${event.transaction} spans=${(event.spans ?? []).length}`);\n return event;\n },\n }),\n AgentDOBase,\n);\n\n// ─── Worker ───\n\ninterface Env {\n SENTRY_DSN: string;\n PLAIN_DO: DurableObjectNamespace;\n AGENT_DO: DurableObjectNamespace;\n}\n\nconst worker = {\n async fetch(request: Request, env: Env): Promise\u003cResponse> {\n const url = new URL(request.url);\n if (url.pathname.startsWith('/agents/')) {\n const agent = await getAgentByName(env.AGENT_DO, 'test');\n return agent.fetch(request);\n }\n const id = env.PLAIN_DO.idFromName('test');\n const stub = env.PLAIN_DO.get(id);\n return stub.fetch(request);\n },\n};\n\nexport default Sentry.withSentry(\n (env: Env) => ({\n dsn: env.SENTRY_DSN || 'https://example@sentry.io/0',\n tracesSampleRate: 1.0,\n enabled: !!env.SENTRY_DSN,\n }),\n worker,\n);\n```\n\n### Steps to Reproduce\n\n1. `npm init -y && npm install @sentry/cloudflare agents`\n2. Deploy: `npx wrangler deploy`\n3. Set secret: `npx wrangler secret put SENTRY_DSN`\n4. Monitor logs: `npx wrangler tail`\n\n**Test the agents framework path:**\n\n```bash\ncurl https://\u003cyour-url>/agents/stream-with-spans\n```\n\n**Observe in wrangler tail:**\n\n```\n[agent] tx=GET /agents/stream-with-spans spans=51\n```\n\n→ 51 spans in `beforeSendTransaction`\n\n**Check Sentry traces explorer:**\u003cbr>→ Transaction appears with **1 span** (root only). The 50 child `work-*` spans are missing.\n\n**Compare with plain DO path:**\n\n```bash\ncurl https://\u003cyour-url>/stream-with-spans\n```\n\n**Observe in wrangler tail:**\n\n```\n[plain] tx=work-0 spans=0\n[plain] tx=work-1 spans=0\n... (50 separate transactions)\n```\n\n→ Each span becomes its own transaction (not a child span). All 50 appear in Sentry individually.\n\n### Expected Behavior\n\nThe 50 child spans created inside `Sentry.startSpan` should appear as children of the request transaction in Sentry's traces explorer, the same as they would in a Node.js application using `@sentry/node`.\n\n### Actual Behavior\n\n* The transaction is delivered to Sentry (root span visible)\n* `beforeSendTransaction` confirms 51 spans are in the transaction envelope\n* Only the root span is indexed; 50 child spans are silently dropped\n\n### Additional Context\n\nIn a plain `DurableObject` (not using the `agents` framework), `Sentry.startSpan` creates separate transactions instead of child spans. This suggests `instrumentDurableObjectWithSentry` may not be correctly establishing a parent span context for the DO's `fetch` handler, so each `startSpan` call becomes a root span/transaction.\n\nThe `agents` framework DOES correctly parent spans (the `beforeSendTransaction` shows 51 spans under one transaction), but the child spans aren't indexed by Sentry after delivery.\n\n## Related Issues\n\n* [#15342](\u003chttps://github.com/getsentry/sentry-javascript/issues/15342>) — Original issue about DO support (led to `instrumentDurableObjectWithSentry`)\n* [#15975](\u003chttps://github.com/getsentry/sentry-javascript/issues/15975>) — WebSocket DO events not captured\n* [JS-889](https://linear.app/getsentry/issue/JS-889/sentry-does-not-capture-errors-or-spans-from-cloudflare-workers) — `waitUntil` spans/errors lost in Workers","author":{"url":"https://github.com/jameskranz","@type":"Person","name":"jameskranz"},"datePublished":"2026-03-28T19:42:18Z","url":"https://github.com/getsentry/sentry-javascript/issues/20030"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d7a953c8-f108-e6a8-d280-4fefa6bda083 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B316:3EF53B:709928:94D709:6B04C8CC |
| html-safe-nonce | d5e26e416a96904953a3238c4d7cc790356733fccea58c86397d6102524b3a22 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzE2OjNFRjUzQjo3MDk5Mjg6OTRENzA5OjZCMDRDOENDIiwidmlzaXRvcl9pZCI6IjIwMDc1ODY5NjAzOTcyOTM1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 46a11c7fd260e7f02ce5d5339da37a88c4c3a090bdaa375550aacf389a4b8779 |
| hovercard-subject-tag | issue:4161448047 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/20030/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3aacefb693975b28a86e0768c9e92d46e362506906e4946b58b4d65d7d683274/getsentry/sentry-javascript/issues/20030 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3aacefb693975b28a86e0768c9e92d46e362506906e4946b58b4d65d7d683274/getsentry/sentry-javascript/issues/20030 |
| og:image:alt | Description Package + Version @sentry/cloudflare@10.42.0 wrangler@4.71.0 Tested with both raw DurableObject and agents framework (Agent base class) Description When a Durable Object instrumented wi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jameskranz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85dd75377eb77313206b8fc108bcee6a3a029286d94bf32bf9b4426e4d92e0c4 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0d64fa748a2bab9a5b587a967ac4da1cfa8da6dd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width