Skip to content

feat(cloudflare): Add docs for durable objects instrumentation #13626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Cloudflare Durable Objects
description: "Learn how to add Sentry instrumentation for Cloudflare Durable Objects."
---

_(Available in version [9.16.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.16.0) and above)_

You can use the `instrumentDurableObjectWithSentry` method to instrument [Cloudflare Durable Objects](https://developers.cloudflare.com/durable-objects/).

```javascript
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) => ({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
}),
MyDurableObjectBase,
);
```
12 changes: 9 additions & 3 deletions docs/platforms/javascript/guides/cloudflare/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin((context) => ({
dsn: "___PUBLIC_DSN___",

// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#sendDefaultPii
sendDefaultPii: true,

// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
// Learn more at
Expand Down Expand Up @@ -118,7 +118,7 @@ If you do not have access to the `onRequest` middleware API, you can use the `wr

```javascript
// hooks.server.js
import * as Sentry from '@sentry/cloudflare';
import * as Sentry from "@sentry/cloudflare";

export const handle = ({ event, resolve }) => {
const requestHandlerOptions = {
Expand All @@ -133,6 +133,12 @@ export const handle = ({ event, resolve }) => {
};
```

### Cloudflare Durable Objects

You can use the `instrumentDurableObjectWithSentry` method to instrument [Cloudflare Durable Objects](https://developers.cloudflare.com/durable-objects/). This will need to be done alongside the worker setup.

See the [Cloudflare Durable Objects](features/durableobject/) guide for more information.

## Add Readable Stack Traces to Errors

Depending on how you've set up your project, the stack traces in your Sentry errors probably don't look like your actual code.
Expand Down
Loading