Skip to content
Open
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
Expand Up @@ -3,7 +3,7 @@ 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)_
<AvailableSince version="9.16.0" />

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

Expand All @@ -23,3 +23,7 @@ export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
MyDurableObjectBase
);
```

## RPC Trace Propagation

To enable distributed tracing across RPC calls to your Durable Objects, see <PlatformLink to="/tracing/distributed-tracing">Distributed Tracing</PlatformLink>.
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
The Sentry Cloudflare SDK has out of the box support for distributed tracing if you've setup the SDK to send traces.
The Sentry Cloudflare SDK automatically propagates traces for incoming and outgoing HTTP requests if you've setup the SDK to send traces.

For RPC calls within Cloudflare (Worker-to-Durable Object, Worker-to-Worker via service bindings), trace propagation must be explicitly enabled. See [RPC Trace Propagation](#rpc-trace-propagation) below.

### RPC Trace Propagation

<AvailableSince version="10.51.0" />

By default, traces are not propagated across [RPC calls](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/) between Workers and Durable Objects. This is because [Cap'n Proto](https://capnproto.org/) (which powers Cloudflare RPC) has no native support for headers or metadata.

To enable trace propagation for RPC method calls, set `enableRpcTracePropagation: true` on **both** the caller and receiver sides.

<Alert level="warning" title="Performance Consideration">
RPC trace propagation requires instrumenting the environment bindings, which adds overhead to every RPC call. Only enable this option if you need distributed tracing across service boundaries.
</Alert>

**Worker Side (Caller):**

```typescript
import * as Sentry from "@sentry/cloudflare";

export default Sentry.withSentry(
(env) => ({
dsn: env.SENTRY_DSN,
tracesSampleRate: 1.0,
enableRpcTracePropagation: true,
}),
{
async fetch(request, env, ctx) {
const id = env.MY_DURABLE_OBJECT.idFromName("test");
const stub = env.MY_DURABLE_OBJECT.get(id);

// This RPC call will now propagate trace context
const result = await stub.sayHello("World");

return new Response(result);
},
}
);
```

**Durable Object Side (Receiver):**

```typescript
import * as Sentry from "@sentry/cloudflare";

class MyDurableObjectBase extends DurableObject<Env> {
sayHello(name: string): string {
return `Hello, ${name}!`;
}
}

export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
(env: Env) => ({
dsn: env.SENTRY_DSN,
tracesSampleRate: 1.0,
enableRpcTracePropagation: true,
}),
MyDurableObjectBase
);
```

The SDK appends trace data (`sentry-trace` and `baggage`) as a trailing argument object to every RPC call. On the receiving side, this argument is stripped before your method is invoked, so it's completely transparent to your code.

<Alert>
If the receiver is not instrumented with Sentry (or `enableRpcTracePropagation` is not enabled), the trailing trace argument will remain in the args array. This is usually harmless unless your method uses rest parameters (`...args`).
</Alert>

### Custom Instrumentation

Expand Down
Loading