---
title: "Workers Observability"
description: "Learn how the Sentry Cloudflare SDK links errors and logs to Cloudflare Workers traces when you use Sentry for error monitoring only."
url: https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/workers-observability/
---

# Cloudflare Workers Observability

Available since: `v11.13.0`

If you use Sentry for error monitoring only and have [Workers tracing](https://developers.cloudflare.com/workers/observability/traces/) turned on in Cloudflare, the SDK gives your errors and logs the trace ID of the Cloudflare invocation. Search for that trace ID in Workers Observability to see the Cloudflare spans and logs that led up to an error.

##### Error Monitoring Only

The SDK only uses the Cloudflare trace when both of these are true:

* Sentry tracing isn't set up: your Sentry options don't contain `tracesSampleRate` or `tracesSampler`. If you set either one, even `tracesSampleRate: 0`, the SDK uses its own trace instead.
* Cloudflare traces the invocation: `observability.traces.enabled` is `true` in your wrangler config, and the invocation is sampled by its `head_sampling_rate`.

With Sentry tracing set up, the SDK starts its own traces, as before. A trace always comes from one source, either Sentry or Cloudflare, so Sentry never gets the same request spans twice.

[Sentry tracing](https://docs.sentry.io/platforms/javascript/guides/cloudflare/tracing.md) is still the best way to connect your errors to what happened before them. It traces your requests, bindings, and AI calls, connects them across services, and shows it all in Sentry next to your errors. Use the Cloudflare trace when you don't want to send spans from the SDK yet.

## [Set Up](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/workers-observability.md#set-up)

1. Turn on Workers tracing in your wrangler config:

   ```jsonc
   {
     "observability": {
       "traces": {
         "enabled": true,
       },
     },
   }
   ```

   *Other available variations of the above snippet: toml*

2. Leave `tracesSampleRate` and `tracesSampler` out of your Sentry options:

   ```typescript
   import { defineCloudflareOptions } from "@sentry/cloudflare";

   export default defineCloudflareOptions((env) => ({
     dsn: env.SENTRY_DSN,
     // No `tracesSampleRate` or `tracesSampler`, so errors and logs
     // get the trace ID of the Cloudflare invocation
   }));
   ```

## [Supported Handlers](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/workers-observability.md#supported-handlers)

The SDK uses the Cloudflare trace in `fetch`, `scheduled`, `queue`, and `email` handlers, and in `WorkerEntrypoint` RPC methods. Durable Objects keep the trace ID that the SDK creates, because the Durable Object state doesn't expose the Cloudflare trace.

An incoming Sentry trace, such as a `sentry-trace` header or the RPC trace data of another instrumented Worker, always takes precedence over the Cloudflare trace.

## [See the Cloudflare Spans in Sentry](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/workers-observability.md#see-the-cloudflare-spans-in-sentry)

The parent span of these errors and logs is a Cloudflare span. Sentry only has that span if you export your Workers traces to Sentry. Otherwise, the trace in Sentry shows the error without its parent span.

To send your Workers traces to Sentry, set up a traces destination as described in [Cloudflare Workers Observability](https://docs.sentry.io/product/drains/cloudflare.md).

## [Requirements](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/workers-observability.md#requirements)

The Cloudflare runtime must be workerd `1.20261009.1` or newer, which added `Span.spanContext()`. On older runtimes, errors and logs keep the trace ID that the SDK creates.

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
