Skip to content

@sentry/cloudflare: Queue#metrics() throws "Illegal invocation" on the instrumented env #24590

Description

@rytkhs

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

10.75.1

Framework Version

Cloudflare Workers, compatibility_date 2026-05-25, nodejs_compat

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from '@sentry/cloudflare';

export default Sentry.withSentry(env => ({ dsn: env.SENTRY_DSN }), {
  async scheduled(_controller, env) {
    await env.MY_QUEUE.metrics();
  },
} satisfies ExportedHandler<Env>);

Steps to Reproduce

  1. Bind a Queue producer as MY_QUEUE in wrangler.jsonc.
  2. Call env.MY_QUEUE.metrics() from any handler wrapped with withSentry (we hit it in scheduled).

Expected Result

metrics() resolves with the queue's backlog metrics, as it does on the raw binding from import { env } from 'cloudflare:workers'.

Actual Result

TypeError: Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.

Additional Context

instrumentQueueProducer wraps send and sendBatch and returns every other property from the Proxy unbound. metrics is a native method, so calling it through the Proxy runs it with the Proxy as this, which workerd rejects. The Durable Object namespace/storage and Workers AI proxies bind passed-through functions to the target, which avoids this.

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 Sep 22, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 22, 2026
  3. self-assigned this
    on Sep 22, 2026
  4. JPeer264 commented on Sep 22, 2026

    @JPeer264
    Member

    Thanks a lot for letting us know. I opened a PR that fixes this and checked at the same time if other instrumentations could cause this as well.

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 22, 2026
  6. added a commit that references this issue on Sep 23, 2026
    bf7b9b2
  7. github-actions commented on Sep 23, 2026

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #24592, which was included in the 11.0.0 release.

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