Skip to content

Enable Workers automatic tracing (OTel) and document OTLP export to Sentry - #905

Merged
kody-bot merged 4 commits into
mainfrom
cursor/enable-workers-otel-tracing-837c
Jul 24, 2026
Merged

kody-bot merged 4 commits into
mainfrom
cursor/enable-workers-otel-tracing-837c

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

What

  • Enables Workers automatic tracing (beta) via observability.traces.enabled in packages/worker/wrangler.jsonc. The runtime emits OTel-standard spans for handler invocations, outbound fetches, and binding calls (D1, KV, R2, Durable Objects, queues) with no SDK added to the bundle. Traces land in the Workers Observability dashboard next to the existing Workers Logs, and console.* output inside a span is attributed to that span.
  • Exports production traces to Sentry: the production environment's observability.traces.destinations references the account-level sentry-otlp-traces destination, which was created via the Cloudflare API (POST /accounts/{id}/workers/observability/destinations, dataset opentelemetry-traces) and points at the kody-cloudflare Sentry project's OTLP traces endpoint with the x-sentry-auth header derived from the project DSN. Preview/test deploys inherit the top-level block without a destination, so their spans stay dashboard-only.
  • Docs: request-lifecycle.md gains a "Workers native tracing (OpenTelemetry)" section (billing/sampling notes included), setup-manifest.md is the canonical destination/provisioning reference (with the full API payload forks need), and environment-variables.md canonically documents the SENTRY_TRACES_SAMPLE_RATE=0 follow-up that avoids duplicate SDK traces. The other pages link out instead of restating, per the docs gardening principle.

Why

Kody had no OpenTelemetry story: observability was Sentry SDK tracing, Workers Logs, structured mcp-event lines, and Analytics Engine usage metering. Native tracing adds request-flow visibility across the DO/D1/queue fan-out with zero runtime dependencies, and the OTLP export lands the same traces in Sentry alongside existing error reports.

Notes

  • Wrangler env observability overrides the top-level key wholesale, so the production block restates enabled: true. Local dev and tests ignore observability config. The CI-generated production/preview configs are parsed from this file with only resource IDs rewritten, so the block carries through (tools/ci/resource-utils.ts, writeGeneratedWranglerConfig).
  • Spans share the Workers Logs event quota (10M/month included on Workers Paid); head_sampling_rate defaults to full sampling, fine at current traffic.
  • Follow-up after export delivery is confirmed: set SENTRY_TRACES_SAMPLE_RATE=0 to stop duplicate SDK traces.

Verification

  • npx wrangler deploy --dry-run passes for both production and preview envs.
  • npm run validate passed in full (format, lint, typecheck, unit, Playwright E2E, MCP E2E, structure checks); pre-push re-ran 1289 unit tests + 18 E2E on each commit: green.
  • Destination verified live via GET /accounts/{id}/workers/observability/destinations: sentry-otlp-traces, dataset opentelemetry-traces, enabled.
  • CodeRabbit feedback addressed: export scoped to production only; fork docs now include the full destination-creation payload.
System recap — composes existing primitives (low risk)

Mode: recap · Base: main @ a73035bc · Head: 6e84d3e8

Classification: composes — no primitives added or changed. The diff touches only Worker platform configuration (packages/worker/wrangler.jsonc) and contributor docs; the primitives classifier matches zero primitives. Runtime code paths are unchanged. The paired infrastructure change (the sentry-otlp-traces OTLP destination) lives in the Cloudflare account, not the repo.

Primitives touched

None — platform tracing is enabled in wrangler config and instrumented by the Workers runtime itself; no application primitive changes behavior.

Before / after

// packages/worker/wrangler.jsonc — before
"observability": { "enabled": true }

// after (top level; inherited by preview/test)
"observability": {
	"enabled": true,
	"traces": { "enabled": true },
}

// after (env.production override)
"observability": {
	"enabled": true,
	"traces": {
		"enabled": true,
		"destinations": ["sentry-otlp-traces"], // account-level OTLP export → Sentry
	},
}
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features

    • Enabled Workers native tracing (OpenTelemetry) and documented automatic span coverage, including attribution for console.* output and export to Sentry via an account-level OTLP destination.
  • Documentation

    • Expanded observability/tracing documentation to cover Workers tracing and production-only export behavior.
    • Updated SENTRY_TRACES_SAMPLE_RATE guidance to prevent duplicate in-Worker trace emission after OTLP export is active (errors unaffected).
    • Added/clarified setup-manifest instructions for provisioning the OTLP destination and handling fork deployments.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Workers tracing is configured to export through a Sentry OTLP destination. Documentation describes native tracing, setup requirements, fork behavior, sampling configuration, and disabling in-Worker trace capture after OTLP ingestion.

Changes

Workers tracing export

Layer / File(s) Summary
Tracing export configuration
packages/worker/wrangler.jsonc
Adds the sentry-otlp-traces destination to Workers observability tracing and documents deployment requirements.
Tracing export and sampling guidance
docs/contributing/architecture/request-lifecycle.md, docs/contributing/environment-variables.md, docs/contributing/setup-manifest.md
Documents Workers native tracing, Sentry OTLP export, fork setup, sampling behavior, and setting SENTRY_TRACES_SAMPLE_RATE=0 to prevent duplicate traces.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enabling Workers automatic tracing and documenting OTLP export to Sentry.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/enable-workers-otel-tracing-837c

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kody-bot
kody-bot marked this pull request as ready for review July 24, 2026 05:36
@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-905.kody-a99.workers.dev

Worker: kody-pr-905
D1: kody-pr-905-db
KV: kody-pr-905-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/contributing/setup-manifest.md`:
- Around line 75-80: Update the fork destination creation guidance in the setup
manifest to include the complete required POST payload: name, enabled,
configuration.type set to "logpush", configuration.url, configuration.headers,
and configuration.logpushDataset set to "opentelemetry-traces". Preserve the
existing dashboard instructions and warning about matching or removing the
destinations entry.

In `@packages/worker/wrangler.jsonc`:
- Around line 97-105: The top-level traces configuration currently sends preview
and test deployments to the production Sentry destination. Move
“sentry-otlp-traces” from the shared observability.traces.destinations
configuration into the production Wrangler environment, or replace it with
separately provisioned preview and test destinations while preserving tracing
for production.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f38072f9-4843-4cb6-9dee-f5d4032c6224

📥 Commits

Reviewing files that changed from the base of the PR and between a73035b and 4ba0459.

📒 Files selected for processing (4)
  • docs/contributing/architecture/request-lifecycle.md
  • docs/contributing/environment-variables.md
  • docs/contributing/setup-manifest.md
  • packages/worker/wrangler.jsonc

Comment thread docs/contributing/setup-manifest.md Resolved
Comment thread packages/worker/wrangler.jsonc Resolved
@kody-bot
kody-bot merged commit 0d2a36f into main Jul 24, 2026
5 checks passed
@kody-bot
kody-bot deleted the cursor/enable-workers-otel-tracing-837c branch July 24, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants