fix(cloudflare): Honor newTarget in instrumentDurableObjectWithSentry construct trap#22104
Merged
andreiborza merged 1 commit intoJul 8, 2026
Conversation
… 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>
andreiborza
approved these changes
Jul 8, 2026
andreiborza
left a comment
Member
There was a problem hiding this comment.
hi @martijnwalraven, thanks for fixing this, looks good!
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>
49 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
instrumentDurableObjectWithSentryreturns aProxywhoseconstructtrap creates the instance withnew target(context, instrumentedEnv), ignoring the trap'snewTargetargument.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 Subclassis false. This breaks tooling that subclasses the exported (instrumented) Durable Object class — for example miniflare's local-explorer wrapper (do-wrapper.worker.tswraps every user Durable Object class inclass Wrapper extends UserClasswith 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,
instanceofholds, and the built-in handlers remain instrumented.🤖 Generated with Claude Code