|
| 1 | +--- |
| 2 | +title: Cloudflare Workers Observability |
| 3 | +sidebar_order: 75 |
| 4 | +description: Learn how to set up Cloudflare Workers Observability to send forward logs and traces data to Sentry. |
| 5 | +--- |
| 6 | + |
| 7 | +Cloudflare Workers supports [exporting OpenTelemetry (OTEL)-compliant](https://developers.cloudflare.com/workers/observability/exporting-opentelemetry-data/) to send logs and traces to Sentry. |
| 8 | + |
| 9 | +- Logs: Application logs including `console.log()` output and system-generated logs |
| 10 | +- Traces: Traces showing request flows through your Worker and connected services |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +Before you begin, ensure you have: |
| 15 | + |
| 16 | +- A deployed Worker that you want to monitor |
| 17 | +- A Sentry project you want to send data to |
| 18 | + |
| 19 | +## Step 1: Set up destination in the Cloudflare dashboard |
| 20 | + |
| 21 | +To set up a destination in the Cloudflare dashboard, navigate to your Cloudflare account's [Workers Observability](https://dash.cloudflare.com/?to=/:account/workers-and-pages/observability/pipelines) section. Then click **Add destination** and configure either a traces or logs destination. |
| 22 | + |
| 23 | +### Logs Destination |
| 24 | + |
| 25 | +To configure your logs destination, click **Add destination** and configure the following: |
| 26 | + |
| 27 | +1. Destination Name: `sentry-logs` (or any descriptive name) |
| 28 | +2. Destination Type: Select Logs |
| 29 | +3. OTLP Endpoint: Your Sentry OTLP logs endpoint (e.g., `https://{HOST}/api/{PROJECT_ID}/integration/otlp/v1/logs`) |
| 30 | + |
| 31 | +``` |
| 32 | +___OTLP_LOGS_URL___ |
| 33 | +``` |
| 34 | + |
| 35 | +4. Custom Headers: Add the Sentry authentication header: |
| 36 | + - Header name: `x-sentry-auth` |
| 37 | + - Header value: `sentry sentry_key={SENTRY_PUBLIC_KEY}` where `{SENTRY_PUBLIC_KEY}` is your Sentry project's public key |
| 38 | + |
| 39 | +``` |
| 40 | +sentry sentry_key=___PUBLIC_KEY___ |
| 41 | +``` |
| 42 | + |
| 43 | +You can find your Sentry OTLP logs endpoint and authentication header value in your [Sentry Project Settings](https://sentry.io/settings/projects/) under **Client Keys (DSN)** > **OpenTelemetry (OTLP)** under the **OTLP Logs Endpoint** section. |
| 44 | + |
| 45 | +### Traces Destination |
| 46 | + |
| 47 | +To configure your traces destination, click **Add destination** and configure the following: |
| 48 | + |
| 49 | +1. Destination Name: `sentry-traces` (or any descriptive name) |
| 50 | +2. Destination Type: Select Traces |
| 51 | +3. OTLP Endpoint: Your Sentry OTLP traces endpoint (e.g., `https://{HOST}/api/{PROJECT_ID}/integration/otlp/v1/traces`) |
| 52 | + |
| 53 | +``` |
| 54 | +___OTLP_TRACES_URL___ |
| 55 | +``` |
| 56 | + |
| 57 | +4. Custom Headers: Add the Sentry authentication header: |
| 58 | + - Header name: `x-sentry-auth` |
| 59 | + - Header value: `sentry sentry_key={SENTRY_PUBLIC_KEY}` where `{SENTRY_PUBLIC_KEY}` is your Sentry project's public key |
| 60 | + |
| 61 | +``` |
| 62 | +sentry sentry_key=___PUBLIC_KEY___ |
| 63 | +``` |
| 64 | + |
| 65 | +You can find your Sentry OTLP traces endpoint and authentication header value in your [Sentry Project Settings](https://sentry.io/settings/projects/) under **Client Keys (DSN)** > **OpenTelemetry (OTLP)** under the **OTLP Traces Endpoint** section. |
| 66 | + |
| 67 | +## Step 2: Configure your Worker |
| 68 | + |
| 69 | +With your destinations created in the Cloudflare dashboard, update your Worker's configuration to enable telemetry export. |
| 70 | + |
| 71 | +```toml {filename:wrangler.toml} |
| 72 | +[observability.traces] |
| 73 | +enabled = true |
| 74 | +# Must match the destination name in the dashboard |
| 75 | +destinations = [ "sentry-traces" ] |
| 76 | + |
| 77 | +[observability.logs] |
| 78 | +enabled = true |
| 79 | +# Must match the destination name in the dashboard |
| 80 | +destinations = [ "sentry-logs" ] |
| 81 | +``` |
| 82 | + |
| 83 | +```jsonc {filename:wrangler.jsonc} |
| 84 | +{ |
| 85 | + "observability": { |
| 86 | + "traces": { |
| 87 | + "enabled": true, |
| 88 | + // Must match the destination name in the dashboard |
| 89 | + "destinations": ["sentry-traces"], |
| 90 | + }, |
| 91 | + "logs": { |
| 92 | + "enabled": true, |
| 93 | + // Must match the destination name in the dashboard |
| 94 | + "destinations": ["sentry-logs"], |
| 95 | + }, |
| 96 | + }, |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +After updating your configuration, deploy your Worker for the changes to take effect. |
0 commit comments