Title: [cloudflare] Events captured in detached work inside Durable Objects are silently dropped (per-invocation client disposal + flush-only transport) · Issue #22545 · getsentry/sentry-javascript · GitHub
Open Graph Title: [cloudflare] Events captured in detached work inside Durable Objects are silently dropped (per-invocation client disposal + flush-only transport) · Issue #22545 · getsentry/sentry-javascript
X Title: [cloudflare] Events captured in detached work inside Durable Objects are silently dropped (per-invocation client disposal + flush-only transport) · Issue #22545 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/22545
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[cloudflare] Events captured in detached work inside Durable Objects are silently dropped (per-invocation client disposal + flush-only transport)","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/cloudflare\n\n### SDK Version\n\n10.62.0\n\n### Framework Version\n\nwrangler 4.113.0, compatibility_date 2026-06-16, compatibility_flags = [\"nodejs_compat\"]\n\n### Link to Sentry event\n\n(events never arrive — that is the bug; org stats show 0 received / 0 filtered for the affected captures)\n\n### Reproduction Example/SDK Setup\n\nDurable Object instrumented with `instrumentDurableObjectWithSentry`. The DO's fetch handler kicks off background work that outlives the invocation — a common DO pattern (queue drains, agent runloops; e.g. the `agents` SDK runs \"fibers\" exactly like this):\n\n```js\nclass RoomBase extends DurableObject {\n async fetch(request) {\n // fire-and-forget continuation (same shape as agents-SDK fibers)\n void (async () => {\n await new Promise((r) => setTimeout(r, 3000));\n Sentry.captureException(new Error(\"captured from detached work\"));\n })();\n return Response.json({ ok: true });\n }\n}\nexport const Room = instrumentDurableObjectWithSentry(sentryOptions, RoomBase);\n```\n\nDeployed verbatim (minus names) and verified: **the event never arrives** — not delayed, never. `captureException` inside the detached continuation is a silent no-op. Captures from the fetch handler itself, and even from `ctx.waitUntil`-registered work, arrive fine in the same worker.\n\n### Steps to Reproduce\n\n1. Instrument a DO with `instrumentDurableObjectWithSentry`.\n2. From `fetch`, start a detached async continuation (not awaited, not passed to `ctx.waitUntil`) that captures an exception after the invocation settles.\n3. Trigger the fetch.\n\n### Expected Result\n\nThe event is delivered, or at minimum the SDK surfaces (debug log) that a capture hit a disposed client so the drop isn't silent.\n\n### Actual Result\n\nNothing is sent and nothing is logged. Mechanism, as far as we can tell from reading the SDK:\n\n1. `wrapRequestHandler` / `wrapMethodWithSentry` create a per-invocation client and dispose it via `waitUntil(flushAndDispose(client))` when the invocation settles.\n2. The detached continuation inherits the invocation's isolation scope through AsyncLocalStorage, so later `captureException` calls run against the **disposed** client.\n3. `makeCloudflareTransport` uses `IsolatedPromiseBuffer`, so events are only ever transmitted on `flush()` — any capture that misses its scope's flush window is unrecoverable.\n\nReal-world impact: our production DO (a chat agent on the cloudflare `agents` SDK, where every turn runs as a detached fiber) reported **zero errors for 13 days** — every `captureException` from turn code was dropped — while the same code paths kept logging to Workers Logs. Nothing in the SDK hinted at the drop; we found it by diffing org ingest stats (0 received) against console output.\n\nTwo follow-up observations from building a workaround, in case they're useful:\n\n- Workaround that works: wrap the detached body in `wrapRequestHandler({ options, request: new Request(\"https://do.detached/\u003cname>\"), context: this.ctx }, body)` to give it a body-scoped client. **However**, in our production DO the wrapper's own teardown flush (`waitUntil(flushAndDispose)`) still did not deliver — we additionally had to drain the transport explicitly inside the handler (`getClient()?.getTransport()?.flush(...)`) before it settles. In a minimal DO the teardown path delivered fine, so there seems to be a further interaction (flush-lock vs. long-lived `ctx.waitUntil` registrations?) we could not minimize. Happy to run diagnostics if useful.\n- While doing that we also noticed `CloudflareClient.flush()` awaits pending-span completion; calling it from inside an active request span therefore always stalls for the full timeout — worth a doc note, since flushing \"before the invocation ends\" is exactly what a detached-work workaround wants to do.\n\nFeature-ask version of this issue: a supported primitive for detached/background DO work (e.g. `Sentry.withDetachedScope(name, fn)` that binds a body-scoped client and flushes on settle), plus a debug-mode warning when `captureException` resolves to a disposed client.","author":{"url":"https://github.com/Soju06","@type":"Person","name":"Soju06"},"datePublished":"2026-07-23T10:18:13Z","url":"https://github.com/getsentry/sentry-javascript/issues/22545"}
| 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:4e5b2847-7193-feb3-2bd4-0580e7daf9c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88B8:14562A:3F3334:559590:6B0438D3 |
| html-safe-nonce | 3e0b2fc2e30a6b1754fbf42a8ab568156bd3f50008c331ff7fea5b2bf1e70813 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEI4OjE0NTYyQTozRjMzMzQ6NTU5NTkwOjZCMDQzOEQzIiwidmlzaXRvcl9pZCI6IjM2NjIzMjQ0Mjk0NTk0Mzc2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fd4bd949b033502c59577133d5312fa6452246f2062fb97ebbe06235e6b5a822 |
| hovercard-subject-tag | issue:4957819601 |
| 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/22545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3b733cf9580e80ebe4f2a2903012e40ea4f3a8a1c981acdace84a10c04b7797/getsentry/sentry-javascript/issues/22545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3b733cf9580e80ebe4f2a2903012e40ea4f3a8a1c981acdace84a10c04b7797/getsentry/sentry-javascript/issues/22545 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Soju06 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64 |
| 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 | 06dc448a76fe4751ac1db26524aefa3aa3e889a8 |
| 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