Cloudflare Durable Objects
Learn how to add Sentry instrumentation for Cloudflare Durable Objects.
Available since: v9.16.0
You can use the instrumentDurableObjectWithSentry method to instrument Cloudflare Durable Objects.
import * as Sentry from "@sentry/cloudflare";
class MyDurableObjectBase extends DurableObject<Env> {
// impl
}
// Export your named class as defined in your wrangler config
export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
(env: Env) => ({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
}),
MyDurableObjectBase,
);
import * as Sentry from "@sentry/cloudflare";
class MyDurableObjectBase extends DurableObject<Env> {
// impl
}
// Export your named class as defined in your wrangler config
export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
(env: Env) => ({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
}),
MyDurableObjectBase,
);
instrumentDurableObjectWithSentry works with any class that extends DurableObject, not only those that extend it directly. This includes classes built on top of Durable Objects by other libraries.
For classes built on the Cloudflare Agents SDK (Agent, AIChatAgent, McpAgent), use the dedicated instrumentAgentWithSentry wrapper instead (SDK version 10.69.0 or higher). It applies the same Durable Object instrumentation and adds spans for @callable() RPC methods as well as automatic conversation IDs. See Cloudflare Agents SDK.
instrumentDurableObjectWithSentry automatically instruments Durable Object storage operations (get, put, delete, list). Each storage operation creates a span.
The SDK also filters out framework-internal storage operations (version 10.69.0 or higher): keys prefixed with cf_, cf:, __ps_, or / (used internally by the Agents SDK and PartyServer) don't create spans, so your traces show only your own storage access.
To enable distributed tracing across RPC calls to your Durable Objects, see Distributed Tracing.
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").