Skip to content

fix(cloudflare): Instrument Durable Object handlers installed as read-only properties - #23759

Merged
JPeer264 merged 2 commits into
developfrom
jp/cloudflare-do-handler-writable
Aug 31, 2026
Merged

fix(cloudflare): Instrument Durable Object handlers installed as read-only properties#23759
JPeer264 merged 2 commits into
developfrom
jp/cloudflare-do-handler-writable

Conversation

@JPeer264

@JPeer264JPeer264 commented Aug 31, 2026

Copy link
Copy Markdown
Member

closes#23758

agents 0.22.0 installs the built-in Durable Object handlers on the instance with Object.defineProperty(instance, name, { value, configurable: true }), which leaves writable at false. The SDK replaced those handlers by assignment, so instrumenting an Agent threw Cannot assign to read only property 'webSocketMessage' and every request to the Agent failed with a 500.

Handlers are now installed through a helper that redefines a read-only property instead of assigning to it, and that leaves the handler untouched when the property can be neither assigned nor redefined.

instrumentDurableObjectHandlers moves into its own module, because the added helper pushed durableobject.ts over the max-lines limit.

I also changed the E2E test to be latest to catch that bug early on. As agents is in v0 the previous range, ^0.20.0, would only stay within 0.20.x.

@JPeer264JPeer264 self-assigned this Aug 31, 2026
@JPeer264
JPeer264 requested a review from a team as a code ownerAugust 31, 2026 09:28
@JPeer264
JPeer264 requested review from isaacs and mydea and removed request for a teamAugust 31, 2026 09:28
@github-actions

github-actionsBot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser28.56 kB--
@sentry/browser - with treeshaking flags26.92 kB--
@sentry/browser - with treeshaking flags tracing without tracing26.82 kB--
@sentry/browser (incl. Tracing)48.75 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.76 kB--
@sentry/browser (incl. Tracing, Profiling)51.68 kB--
@sentry/browser (incl. Tracing, Replay)88.23 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags77.63 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)92.93 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)105.85 kB--
@sentry/browser (incl. Feedback)46.05 kB--
@sentry/browser (incl. sendFeedback)33.62 kB--
@sentry/browser (incl. FeedbackAsync)38.73 kB--
@sentry/browser (incl. Metrics)29.51 kB--
@sentry/browser (incl. Logs)29.8 kB--
@sentry/browser (incl. Metrics & Logs)30.43 kB--
@sentry/react30.3 kB--
@sentry/react (incl. Tracing)50.94 kB--
@sentry/vue35.73 kB--
@sentry/vue (incl. Tracing)51.02 kB--
@sentry/svelte28.59 kB--
CDN Bundle30.35 kB--
CDN Bundle (incl. Tracing)49.38 kB--
CDN Bundle (incl. Logs, Metrics)32.58 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)51.25 kB--
CDN Bundle (incl. Replay, Logs, Metrics)73.17 kB--
CDN Bundle (incl. Tracing, Replay)86.86 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)88.73 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)92.8 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)94.64 kB--
CDN Bundle - uncompressed89.95 kB--
CDN Bundle (incl. Tracing) - uncompressed147.2 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed96.24 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed152.89 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed225.41 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed266.69 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed272.37 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed280.4 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed286.06 kB--
@sentry/nextjs (client)53.51 kB--
@sentry/sveltekit (client)49.19 kB--
@sentry/core/server65.67 kB--
@sentry/core/browser51.86 kB--
@sentry/node123.51 kB+0.02%+19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection)85.23 kB--
@sentry/node - without tracing87.76 kB+0.02%+11 B 🔺
@sentry/node - without channel injection103.18 kB+0.02%+19 B 🔺
@sentry/aws-serverless96.12 kB+0.03%+24 B 🔺
@sentry/cloudflare (withSentry) - minified201.04 kB+0.16%+314 B 🔺
@sentry/cloudflare (withSentry)500.26 kB+0.21%+1.01 kB 🔺

View base workflow run

…-only properties
`agents` 0.22.0 installs the built-in Durable Object handlers on the instance with
`Object.defineProperty(instance, name, { value, configurable: true })`, which leaves
`writable` at `false`. The SDK replaced those handlers by assignment, so instrumenting
an Agent threw `Cannot assign to read only property 'webSocketMessage'` and every
request to the Agent failed with a 500.
Handlers are now installed through a helper that redefines a read-only property instead
of assigning to it, and that leaves the handler untouched when the property can be
neither assigned nor redefined.
`instrumentDurableObjectHandlers` moves into its own module, because the added helper
pushed `durableobject.ts` over the `max-lines` limit.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@JPeer264
JPeer264force-pushed the jp/cloudflare-do-handler-writable branch from efc4221 to dd7ea05CompareAugust 31, 2026 09:41
@JPeer264
JPeer264 enabled auto-merge (squash) August 31, 2026 12:02
@JPeer264
JPeer264 merged commit 9225664 into developAug 31, 2026
552 of 554 checks passed
@JPeer264
JPeer264 deleted the jp/cloudflare-do-handler-writable branch August 31, 2026 12:40
JPeer264 added a commit that referenced this pull request Aug 31, 2026
…read-only properties (#23769)
Backport of: #23759
## Differences to the original PR
The fix itself (`setInstanceHandler`) and both new tests are identical
to the original. The moved
`instrumentDurableObjectHandlers` keeps v10's existing semantics,
because v10 lacks the APIs
`develop` uses:
-
`packages/cloudflare/src/instrumentations/instrumentDurableObjectHandlers.ts`:
uses
`wrapRequestHandler` from `../request` instead of
`wrapRequestHandlerWithInit` + `init`, which
do not exist on v10.
-
`packages/cloudflare/src/instrumentations/instrumentDurableObjectHandlers.ts`:
`alarm` keeps
`spanOp: 'function'` and the `webSocket*` handlers keep no `spanOp`,
instead of the
`FUNCTION` / `WEBSOCKET` constants from `@sentry/conventions/op`. v10
does not use those
constants here.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudflare SDK fails with latest agents SDK v0.22.0

2 participants

@JPeer264@andreiborza