Skip to content

Cloudflare Durable Object instrumentDurableObjectWithSentry throwing errors #17094

Closed

Description

@danieljvdm

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

9.40.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

export const CallAgent = CallAgentBase;

export const CallAgent = Sentry.instrumentDurableObjectWithSentry(
  () => ({
    dsn: "REDACTED",
    tracesSampleRate: 1.0,
  }),
  CallAgentBase
);

I get no errors with the first line, I get

✘ [ERROR] Uncaught Error: #<Promise> 


✘ [ERROR] Uncaught Error: #<Promise> 


✘ [ERROR] Uncaught Error: #<Promise> 


✘ [ERROR] Uncaught Error: #<Promise> 


✘ [ERROR] Uncaught Error: #<Promise> 

From wrangler with the second line.

Additional context is that this is wrapping a cloudflare agent (which is just a DO)

Expected Result

No errors when using instrumentDurableObjectWithSentry

Actual Result

Uncaught error

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 19, 2025
  2. danieljvdm commented on Jul 21, 2025

    @danieljvdm
    Author

    I debugged this with claude code and got the following:

    I’ve identified the root cause: Sentry’s instrumentation is wrapping the sql method inherited from the Agent base class, but the wrapping is breaking the method’s return value. The sql method should return an array, but after wrapping, it’s returning something non-iterable (likely a Promise).

    ⸻

    The Problem

    1. The Agent class has a sql method that uses template literals and returns an array
    2. Sentry wraps all methods on the Durable Object instance, including inherited ones
    3. The wrapper uses Reflect.apply inside an async scope, which may cause the return value to become a Promise
    4. When alarm() tries to iterate over the result with for (const row of result || []), it fails because Promises aren’t iterable

    I'm not sure what the best fix is, we could add method === 'sql' to https://github.com/getsentry/sentry-javascript/blob/master/packages/cloudflare/src/durableobject.ts#L213 or wrapMethodWithSentry would need to be updated to support the synchronous callback.

    Agents sql method: https://github.com/cloudflare/agents/blob/main/packages/agents/src/index.ts#L364

  3. AbhiPrasad commented on Jul 21, 2025

    @AbhiPrasad
    Contributor

    We should update wrapMethodWithSentry not async everything. @danieljvdm would you be interested in opening a PR?

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 21, 2025
  5. aroman commented on Jul 27, 2025

    @aroman

    Sentry's DurableObject integration will silently break everyone's code unless it so happens every single one of their DurableObject's methods is async. Most of our are not. I can't believe this shipped.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 27, 2025
  7. added a commit that references this issue on Jul 28, 2025
    273cef9
  8. andreiborza commented on Jul 28, 2025

    @andreiborza
    Member

    A fix for this has been released with 9.42.1, thanks for reporting this and apologies for the inconvenience.

    If this is still an issue, please feel free to raise it again or comment here.

  9. github-actions commented on Jul 31, 2025

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #17184, which was included in the 10.0.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions