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

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