Title: instrumentDurableObjectStorage Proxy breaks native `storage.sql` getter (Illegal invocation) · Issue #19661 · getsentry/sentry-javascript · GitHub
Open Graph Title: instrumentDurableObjectStorage Proxy breaks native `storage.sql` getter (Illegal invocation) · Issue #19661 · getsentry/sentry-javascript
X Title: instrumentDurableObjectStorage Proxy breaks native `storage.sql` getter (Illegal invocation) · Issue #19661 · getsentry/sentry-javascript
Description: Problem Since 10.39.0, instrumentDurableObjectWithSentry breaks any DurableObject that accesses ctx.storage.sql (SQLite storage API). Both production workerd and miniflare are affected. Error: SqlError: SQL query failed: Illegal invocati...
Open Graph Description: Problem Since 10.39.0, instrumentDurableObjectWithSentry breaks any DurableObject that accesses ctx.storage.sql (SQLite storage API). Both production workerd and miniflare are affected. Error: SqlE...
X Description: Problem Since 10.39.0, instrumentDurableObjectWithSentry breaks any DurableObject that accesses ctx.storage.sql (SQLite storage API). Both production workerd and miniflare are affected. Error: SqlE...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/19661
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"instrumentDurableObjectStorage Proxy breaks native `storage.sql` getter (Illegal invocation)","articleBody":"## Problem\n\nSince 10.39.0, `instrumentDurableObjectWithSentry` breaks any DurableObject that accesses `ctx.storage.sql` (SQLite storage API). Both production workerd and miniflare are affected.\n\n**Error:**\n```\nSqlError: SQL query failed: Illegal invocation: function called with incorrect `this` reference.\n```\n\n10.38.0 works. 10.39.0+ does not.\n\n## Root Cause\n\n`instrumentDurableObjectStorage` (in `packages/cloudflare/src/instrumentations/instrumentDurableObjectStorage.ts`) wraps `DurableObjectStorage` in a Proxy whose `get` trap uses `Reflect.get(target, prop, receiver)` where `receiver` is the proxy:\n\n```ts\nget(target, prop, receiver) {\n const original = Reflect.get(target, prop, receiver); // receiver = proxy\n```\n\nWhen accessing `storage.sql`, the native getter on `DurableObjectStorage` validates `this` via internal slots (brand check). Passing the proxy as `receiver` means the getter executes with `this` = proxy instead of the real native storage object, failing the brand check.\n\nNon-function properties like `sql` (a getter returning `SqlStorage`) hit the `typeof original !== 'function'` early return and are returned directly — but by then the getter has already been called with the wrong `this`.\n\n**Why KV methods (`get`/`put`/`delete`/`list`) are unaffected:** they are functions, so the proxy explicitly `.bind(target)`s them or wraps them with `Reflect.apply(original, target, args)`. The `this` is correct for functions, but not for getters.\n\n## Fix\n\nOne-line change — use `target` as the receiver:\n\n```diff\n- get(target, prop, receiver) {\n- const original = Reflect.get(target, prop, receiver);\n+ get(target, prop, _receiver) {\n+ const original = Reflect.get(target, prop, target);\n```\n\nThis ensures native getters execute with the real storage object as `this`.\n\n## Minimal Reproduction\n\n```ts\nimport { DurableObject } from \"cloudflare:workers\";\nimport { instrumentDurableObjectWithSentry } from \"@sentry/cloudflare\";\n\nclass CounterBase extends DurableObject {\n constructor(ctx: DurableObjectState, env: Env) {\n super(ctx, env);\n // Throws: SqlError: Illegal invocation\n this.ctx.storage.sql.exec(\n \"CREATE TABLE IF NOT EXISTS counts (name TEXT PRIMARY KEY, value INTEGER DEFAULT 0)\"\n );\n }\n}\n\nexport const Counter = instrumentDurableObjectWithSentry(\n (env) => ({ dsn: env.SENTRY_DSN }),\n CounterBase,\n);\n```\n\n## Related\n\n- #17094 — similar `instrumentContext` issue, but about sync methods being wrapped async. Fixed in v9.42.1/v10.0.0 via #17184. The `Reflect.get` receiver issue is a different root cause not addressed by that fix.\n\n## Environment\n\n- `@sentry/cloudflare` 10.39.0+ (any version with `instrumentDurableObjectStorage`)\n- Both production workerd and miniflare\n- Any DurableObject using SQLite storage API (`ctx.storage.sql`)","author":{"url":"https://github.com/dmmulroy","@type":"Person","name":"dmmulroy"},"datePublished":"2026-03-05T21:00:56Z","url":"https://github.com/getsentry/sentry-javascript/issues/19661"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9771821e-1305-2fa0-be59-2e6a99e82d37 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D3E2:2CBDB8:246404:308298:6B04E8AF |
| html-safe-nonce | 079cce7b54f6f443f4617cc325fd7280deba8ddbb58a871d3025acd00b93c3a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0UyOjJDQkRCODoyNDY0MDQ6MzA4Mjk4OjZCMDRFOEFGIiwidmlzaXRvcl9pZCI6IjIzOTk3MzA1Nzk0ODc5MTAwNjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3856591c78cd83d68d674d2c2dfcb54dd362665a005524d5bec53cd43ff79e5a |
| hovercard-subject-tag | issue:4030591619 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/19661/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c41e076d1f8bcf57b06b03a0f15e6ceaaa8b9a7e8509e16337a6e11d7fa27805/getsentry/sentry-javascript/issues/19661 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c41e076d1f8bcf57b06b03a0f15e6ceaaa8b9a7e8509e16337a6e11d7fa27805/getsentry/sentry-javascript/issues/19661 |
| og:image:alt | Problem Since 10.39.0, instrumentDurableObjectWithSentry breaks any DurableObject that accesses ctx.storage.sql (SQLite storage API). Both production workerd and miniflare are affected. Error: SqlE... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dmmulroy |
| hostname | github.com |
| expected-hostname | github.com |
| None | f3851aad500d8e8dce736722ddc6fa9596e17d9fce3c53581eba968664c0bc32 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e29c922455fd8137f27e1cfcdf6a1e8b920b1926 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width