Skip to content
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
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.52.0" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The <AvailableSince> tag for enableRpcTracePropagation incorrectly states version 10.52.0 instead of the correct version 10.51.0.
Severity: LOW

Suggested Fix

Update the <AvailableSince> tag in javascript.cloudflare.mdx to reflect the correct version. Change <AvailableSince version="10.52.0" /> to <AvailableSince version="10.51.0" />.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: platform-includes/distributed-tracing/how-to-use/javascript.cloudflare.mdx#L7

Potential issue: The documentation file `javascript.cloudflare.mdx` specifies that the
`enableRpcTracePropagation` feature is available since version `10.52.0`. However,
according to the pull request description and the sentry-javascript changelog, full
support for this feature was introduced in version `10.51.0`. This discrepancy will
mislead users on version `10.51.0`, making them believe they need to upgrade
unnecessarily to use the feature.

Did we get this right? 👍 / 👎 to inform future reviews.


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 propagates trace context (`sentry-trace` and `baggage`) by appending a trailing argument to outgoing RPC calls. The receiving SDK automatically strips it before your method is executed. Your method signatures are unaffected.

<Alert>
If the receiving Worker is not instrumented with Sentry (or `enableRpcTracePropagation` is not enabled), the trailing trace argument won't be stripped and will be passed through to your method. This is harmless for methods with fixed parameter lists, but may cause unexpected behavior if your method relies on rest parameters `(...args)` or `arguments.length`.
</Alert>

### Custom Instrumentation

Expand Down
Loading