You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@sentry/cloudflare: withSentry proxies env and ctx.exports, so a Durable Object method called on a proxied receiver throws on #private fields #27046
Wrapping a Worker entry with withSentry makes every Durable Object method call fail when the object uses ECMAScript private fields:
TypeError: Cannot access invalid private field (evaluating 'this.#db')
at db (services/api/src/durable-objects/content.ts:525:8)
The Worker works without the wrapper and fails with it, with no DSN configured as well as with one.
Why
withSentry (@sentry/cloudflare, build/esm/prod/withSentry.js:21) wraps the handler, and the request path instruments the bindings the handler receives:
instrumentEnv (build/esm/prod/instrumentations/worker/instrumentEnv.js:34) returns new Proxy(env, …), and its get trap replaces D1, Queues, KV, R2, Workers AI and Durable Object namespaces with instrumented proxies (:34-95), plus instrumentServiceStub (:96) which proxies the stub object itself.
utils/instrumentContext.js:53 runs ctx.exports through the same instrumentEnv.
A Durable Object method invoked through a proxied stub therefore runs with a proxy as this. ECMAScript private fields (#db) are only accessible on the real instance, so the method throws before the body runs. Any class-based DO that keeps its state in #fields is affected; the docs' caveat about instrumented receivers covers RPC trace arguments, not this.
Minimal reproduction
// worker.tsclassCounter{
#n =0;// private field is the triggerincrement(){return++this.#n;}}export{Counter};exportdefaultSentry.withSentry((env)=>({dsn: env.SENTRY_DSN,tracesSampleRate: 1}),{asyncfetch(request,env){constid=env.COUNTER.idFromName('a');// env.COUNTER is the SDK's proxy; get() returns a proxied stubreturnnewResponse(String(awaitenv.COUNTER.get(id).increment()));},},);
Symptom: TypeError: Cannot access invalid private field. Same Worker without withSentry → 1.
A non-Proxied control: the same DO with this.n (a public field) works, which is why simple examples in the docs do not show it.
What would fix it
Either, in preference order:
An option on withSentry / CloudflareOptions that skips instrumentEnv for named bindings (or entirely), e.g. instrumentBindings: false. rpcTracePropagationBindings defaults to [], so nothing in the current options controls the proxying itself.
Instrumentation that preserves the receiver: wrap the methods on the stub with Reflect.apply(target, receiver), or copy the namespace's get() result with a bound this, so the DO still sees the real instance.
Impact we hit
A Hono API Worker (Durable Object for content, private #db field) could not ship exception tracking at all: its save integration tests failed with SAVE_UNAVAILABLE, and we had to leave the Worker unwrapped. Repo: waccele/favhub, PR #3277, issue #3428.
Activity
linear-code commentedon Dec 2, 2026
JS-4201
andreiborza commentedon Dec 2, 2026
Hi @kazukiiwas, thank you for filing this. We'll look into it.
fix(cloudflare): Keep Durable Object instance as `this` on non-RPC st…
github-actions commentedon Dec 2, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #27057, which was included in the 11.23.0 release.