Cloudflare Bindings
Learn which Cloudflare bindings Sentry instruments automatically and what each binding captures.
The Sentry Cloudflare SDK instruments the bindings on your env object automatically. You don't have to wrap a binding or call a function. When your code reads a binding from env, the SDK detects its type and returns an instrumented version.
| Binding | What Sentry captures |
|---|---|
| D1 | Database queries |
| R2 | Bucket operations, such as reads and uploads |
| Queues | Messages that you send to a queue |
| Workers AI | Model calls, see Workers AI |
| Durable Objects | Traces that continue in the Durable Object, see Cloudflare Durable Objects |
| Service bindings | Traces that continue in the other Worker, if it also uses Sentry |
For RPC calls to Durable Objects and service bindings, add the binding to rpcTracePropagationBindings. The Vite plugin adds the bindings to classes in the same Worker for you.
The SDK instruments the env object that Cloudflare gives to the handlers and classes that Sentry wraps, such as your Worker, Durable Objects, and Workflows. The Vite plugin wraps these for you at build time.
The global env that you import from cloudflare:workers is not instrumented. Bindings that you read from it don't create spans. Use the env argument of your handler or class instead:
import { env as globalEnv } from "cloudflare:workers";
export default {
async fetch(request, env) {
// Creates a span: `env` is the handler argument
await env.DB.prepare("SELECT * FROM users").all();
// Does not create a span: `globalEnv` is the global env
await globalEnv.DB.prepare("SELECT * FROM users").all();
return new Response("OK");
},
};
import { env as globalEnv } from "cloudflare:workers";
export default {
async fetch(request, env) {
// Creates a span: `env` is the handler argument
await env.DB.prepare("SELECT * FROM users").all();
// Does not create a span: `globalEnv` is the global env
await globalEnv.DB.prepare("SELECT * FROM users").all();
return new Response("OK");
},
};
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").