Skip to content

feat(init): propagate sentry-trace headers to wizard API calls#567

Merged
betegon merged 1 commit intomainfrom
feat/init-distributed-tracing
Mar 26, 2026
Merged

feat(init): propagate sentry-trace headers to wizard API calls#567
betegon merged 1 commit intomainfrom
feat/init-distributed-tracing

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented Mar 26, 2026

When sentry init runs, the CLI makes three types of calls to the wizard API: create-run, start-async, and a resume-async per suspend/resume cycle. Each call spins up a fresh Cloudflare Worker which currently creates its own isolated Sentry transaction — there's no link back to the CLI's root span.

What this does

Adds a custom fetch interceptor to MastraClient that injects sentry-trace and baggage headers into every request. These come from getTraceData() which reads the currently active Sentry span, so each Worker invocation inherits the CLI's trace context and shows up as part of the same distributed trace.

Result: one sentry init run = one full trace, with CLI spans and all server-side Worker spans connected.

Test plan

  • Run sentry init against a test project with Sentry instrumented
  • Open the sentry.init transaction in Sentry
  • Server-side spans (invoke_workflow sentry-wizard, POST /api/workflows/sentry-wizard/*) should appear nested under it

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Dashboard

  • Add pagination and glob filtering to dashboard list by BYK in #560
  • Rich terminal chart rendering for dashboard view by BYK in #555

Init

  • Propagate sentry-trace headers to wizard API calls by betegon in #567
  • Treat bare slug as new project name when not found by BYK in #554

Other

  • (formatters) Colorize SQL in DB span descriptions by BYK in #546
  • (telemetry) Report unknown commands to Sentry by BYK in #563
  • Add sentry sourcemap inject and sentry sourcemap upload commands by BYK in #547
  • Native debug ID injection and sourcemap upload by BYK in #543

Bug Fixes 🐛

Dashboard

  • Scale timeseries bar width to fill chart area by BYK in #562
  • Resolve dashboard by ID/slug in addition to title by BYK in #559

Other

  • (event-view) Auto-redirect issue short IDs in two-arg form (CLI-MP) by BYK in #558
  • (help) Show help when user passes help as positional arg by BYK in #561
  • Reject @-selectors in parseOrgProjectArg with helpful redirect by BYK in #557

Internal Changes 🔧

Coverage

  • Use informational-patch input instead of sed hack by BYK in #544
  • Make checks informational on release branches by BYK in #541

Other

  • (api) Collapse stats on issue detail endpoints to save 100-300ms by BYK in #551
  • (ci) Upgrade GitHub Actions to Node 24 runtime by BYK in #542
  • (db) DRY up database layer with shared helpers and lint enforcement by BYK in #550
  • (issue-list) Use collapse parameter to skip unused Snuba queries by BYK in #545
  • Bump Bun from 1.3.9 to 1.3.11 by BYK in #552
  • Regenerate skill files by github-actions[bot] in ec1ffe28

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1273 uncovered lines.
❌ Project coverage is 95.4%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.41%    95.40%    -0.01%
==========================================
  Files          194       194         —
  Lines        27655     27656        +1
  Branches         0         0         —
==========================================
+ Hits         26384     26383        -1
- Misses        1271      1273        +2
- Partials         0         0         —

Generated by Codecov Action

@betegon betegon force-pushed the feat/init-distributed-tracing branch from f69a5b8 to d6cdb9d Compare March 26, 2026 12:24
Injects sentry-trace and baggage headers into every MastraClient
request so each Cloudflare Worker invocation for a sentry init run
is linked to the CLI's root transaction in Sentry.

Without this, create-run / start-async / resume-async each appear as
isolated transactions with no connection to the CLI command span.
@betegon betegon force-pushed the feat/init-distributed-tracing branch from d6cdb9d to 1c0641b Compare March 26, 2026 12:27
@betegon betegon marked this pull request as ready for review March 26, 2026 12:33
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

return fetch(url, {
...init,
headers: {
...(init?.headers as Record<string, string> | undefined),
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.

Spreading Headers instance silently drops all existing headers

High Severity

The cast init?.headers as Record<string, string> is unsafe because MastraClient may pass init.headers as a Headers instance (the library uses new Headers() internally). Spreading a Headers instance with ... yields an empty object {}, silently dropping all previously configured headers — including the Authorization: Bearer token. This would cause all wizard API calls to fail authentication. A safe approach is converting via Object.fromEntries(new Headers(init?.headers)) or similar, which handles all HeadersInit subtypes correctly.

Fix in Cursor Fix in Web

@betegon betegon merged commit 14ad6b1 into main Mar 26, 2026
22 checks passed
@betegon betegon deleted the feat/init-distributed-tracing branch March 26, 2026 14:36
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.

1 participant