Skip to content

fix(cloudflare): Honor newTarget in instrumentDurableObjectWithSentry construct trap#22104

Merged
andreiborza merged 1 commit into
getsentry:developfrom
martijnwalraven:fix/cloudflare-do-instrument-newtarget
Jul 8, 2026
Merged

fix(cloudflare): Honor newTarget in instrumentDurableObjectWithSentry construct trap#22104
andreiborza merged 1 commit into
getsentry:developfrom
martijnwalraven:fix/cloudflare-do-instrument-newtarget

Conversation

@martijnwalraven

Copy link
Copy Markdown
Contributor

instrumentDurableObjectWithSentry returns a Proxy whose construct trap creates the instance with new target(context, instrumentedEnv), ignoring the trap's newTarget argument.

When a subclass of the instrumented class is constructed, the instance therefore gets the base class's prototype instead of the subclass's: subclass prototype methods disappear and instanceof Subclass is false. This breaks tooling that subclasses the exported (instrumented) Durable Object class — for example miniflare's local-explorer wrapper (do-wrapper.worker.ts wraps every user Durable Object class in class Wrapper extends UserClass with introspection methods on the wrapper prototype), whose methods become unreachable when the wrapped class is Sentry-instrumented.

Fix: construct through Reflect.construct(target, [context, instrumentedEnv], newTarget) so the subclass prototype is preserved. The instrumented Durable Object methods (fetch, alarm, webSocket*) are assigned as own properties on the instance, so instrumentation behavior is unchanged; the existing "preserves constructor identity on the proxy" test still passes.

Added a regression test that subclasses the instrumented class and asserts the subclass method is callable, instanceof holds, and the built-in handlers remain instrumented.

🤖 Generated with Claude Code

… construct trap

The construct trap created instances with `new target(...)`, ignoring
newTarget. Subclasses of the instrumented class - such as miniflare's
local-explorer wrapper, which extends every user Durable Object class to
add introspection methods - lost their own prototype: subclass methods
disappeared and instanceof checks against the subclass failed. Construct
through Reflect.construct with newTarget so the subclass prototype is
preserved.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@martijnwalraven martijnwalraven requested a review from a team as a code owner July 8, 2026 15:52
@martijnwalraven martijnwalraven requested review from JPeer264, andreiborza and mydea and removed request for a team July 8, 2026 15:52

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @martijnwalraven, thanks for fixing this, looks good!

@andreiborza andreiborza merged commit 58e2656 into getsentry:develop Jul 8, 2026
154 of 157 checks passed
andreiborza added a commit that referenced this pull request Jul 8, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #22104

Co-authored-by: andreiborza <168741329+andreiborza@users.noreply.github.com>
Sign up for free to 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.

2 participants