fix(cloudflare): Fix instrumentDurableObjectWithSentry breaking Cloudflare Agents#21101
fix(cloudflare): Fix instrumentDurableObjectWithSentry breaking Cloudflare Agents#21101JPeer264 wants to merge 4 commits into
Conversation
| TestDurableObjectBase, | ||
| ); | ||
|
|
||
| export default { |
There was a problem hiding this comment.
note: This is needed, as without it we now don't generate rpc traces. So this was fixed as well
size-limit report 📦
|
|
Some e2e tests are not passing, moving back to draft |
7234674 to
77cce94
Compare
This came up in #21101 where the link was not set in time and the tests failed. With this PR we are waiting for the links to be actually set, before the rootspan ends. Retrieving the stored span shouldn't take too long - and the work was also before already executed during the response.
77cce94 to
0b6628f
Compare
d4dfe6d to
1dbf886
Compare
…flare Agents The fix binds ALL methods to the original object, ensuring private fields work correctly. Additionally, spans are now only created when Sentry RPC metadata (`__sentry_rpc_meta__`) is present in the arguments, which is only the case for actual RPC calls that have trace propagation enabled on the calling side. This prevents creating spans for internal framework method calls like those made by the Agents SDK over WebSocket. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…g Cloudflare Agents
1dbf886 to
19ffe51
Compare
…g Cloudflare Agents
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2d80f42. Configure here.
| // the original object. Bound functions ignore the thisArg passed via Reflect.apply. | ||
| const boundValue = (value as UncheckedMethod).bind(proxyTarget); | ||
| return boundMethod; | ||
| } |
There was a problem hiding this comment.
Bound constructor breaks identity checks via proxy
Low Severity
The removed BUILT_IN_DO_METHODS set explicitly included 'constructor' and returned its value unmodified. Now, constructor is caught by the prop in Object.prototype check and returned as a bound function via .bind(proxyTarget). This means proxy.constructor === OriginalClass is now false, breaking any identity or type-checking code that relies on the constructor property. Unlike other former BUILT_IN_DO_METHODS members (fetch, alarm, etc.) which are now own properties and caught by the hasOwnProperty check, constructor lives solely on the prototype and falls through only to the Object.prototype check.
Reviewed by Cursor Bugbot for commit 2d80f42. Configure here.


By investigating #20099 it seemed that Cloudflare Agents were not working when
enableRpcTracePropagation: truewas set. The main reason for that was that the original target was not bound to the call.By doing that I changed the logic a little to also make it more resistant. As the
rpctrace was always everywhere attached, even though it could be that it was not directly a real RPC call. No therpctrace is only attached when in the arguments the__sentry_rpc_meta__is there as last parameter - which gives an extra layer of safety.Also
BUILT_IN_DO_METHODSis not needed and got removed, as we actually ignore these with the other checks (test was added for it)The deprecated
instrumentPrototypeMethodsis still using the previous behavior.This PR also proofs that we can instrument Agents on Cloudflare (
cloudflare-agente2e test)AI text on top:
The fix binds ALL methods to the original object, ensuring private fields
work correctly. Additionally, spans are now only created when Sentry RPC
metadata (
__sentry_rpc_meta__) is present in the arguments, which is onlythe case for actual RPC calls that have trace propagation enabled on the
calling side. This prevents creating spans for internal framework method
calls like those made by the Agents SDK over WebSocket.