Skip to content

@sentry/cloudflare: errors an Agent's RPC method catches are captured as unhandled when it calls an inherited Agent method #26673

Open

Description

@nwalters512

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare

SDK Version

11.15.0

Framework Version

agents 0.33.0, wrangler 4.156.0, compatibility date 2026-09-17 with nodejs_compat

Link to Sentry event

No response

Reproduction Example/SDK Setup

worker.js, run with wrangler dev. It needs a Durable Object binding C (class C, SQLite) and any slow text/event-stream server on 127.0.0.1:8797.

import * as Sentry from '@sentry/cloudflare';
import { Agent } from 'agents';

const opts = () => ({
  dsn: 'https://abc@o0.ingest.sentry.io/0',
  beforeSend(event) {
    console.log('captured', JSON.stringify(event.exception?.values?.[0]));
    return null;
  },
});

class Conv extends Agent {
  aborts = new Set();

  async proxy() {
    const abort = new AbortController();
    this.aborts.add(abort);
    const response = await fetch('http://127.0.0.1:8797/', { signal: abort.signal });
    const [forwarded, metered] = response.body.tee();
    void this.keepAliveWhile(async () => {
      const reader = metered.getReader();
      for (;;) if ((await reader.read()).done) break;
    }).catch((error) => console.log('handled', String(error)));
    return new Response(forwarded);
  }

  async stop() {
    for (const abort of this.aborts) abort.abort();
  }
}

export class C extends Sentry.instrumentAgentWithSentry(opts, Conv) {}

export default Sentry.withSentry(opts, {
  async fetch(request, env) {
    const stub = env.C.getByName('x');
    const response = await stub.proxy();
    const reader = response.body.getReader();
    await reader.read();
    setTimeout(() => stub.stop(), 300);
    try {
      for (;;) if ((await reader.read()).done) break;
    } catch {}
    return new Response('ok');
  },
});

Steps to Reproduce

  1. Start a server on 127.0.0.1:8797 that streams text/event-stream chunks slowly.
  2. Run the Worker above with wrangler dev and request /.
  3. proxy() is called over RPC and returns the upstream stream. stop() then aborts the upstream fetch, so the callback passed to the inherited keepAliveWhile() rejects with an AbortError, and proxy()'s .catch handles it.

Expected Result

Nothing is captured: the Agent catches the rejection itself.

Actual Result

The rejection is captured as unhandled before the Agent's own .catch runs:

captured {"type":"AbortError","value":"The operation was aborted","mechanism":{"type":"auto.faas.cloudflare.durable_object","handled":false}}
handled AbortError: The operation was aborted

In production the event has no stack frames, because the AbortError is created by the runtime's stream implementation.

Additional Context

The Agents SDK's _autoWrapCustomMethods() replaces the subclass's own methods on the prototype during construction. instrumentAgentWithSentry treats them as framework-managed and leaves them out of RPC instrumentation, so an incoming RPC call to proxy() runs on the default isolation scope. Inherited Agent methods such as keepAliveWhile() are not replaced, so they keep the RPC prototype wrapper. When proxy() calls one, createRpcPrototypeWrapper finds no trace metadata on the default isolation scope, treats the internal call as a new untraced RPC entry (startNewTrace), and captures its rejection as unhandled.

This looks like the failure fixed for constructor work in #24735 / #24829, reached here through framework-managed RPC entry points. One fix would be to give framework-managed methods an invocation scope when they are entered over RPC, without starting a span, so calls they make are not treated as new entries.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Activity

  1. linear-code commented on Nov 19, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 19, 2026
  3. andreiborza commented on Nov 19, 2026

    @andreiborza
    Member

    Hi Nathan, thanks for filing this. We'll look into it.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 19, 2026
  5. self-assigned this
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions