feat(init): propagate sentry-trace headers to wizard API calls#567
feat(init): propagate sentry-trace headers to wizard API calls#567
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Dashboard
Init
Other
Bug Fixes 🐛Dashboard
Other
Internal Changes 🔧Coverage
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1273 uncovered lines. 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 |
f69a5b8 to
d6cdb9d
Compare
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.
d6cdb9d to
1c0641b
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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), |
There was a problem hiding this comment.
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.


When
sentry initruns, the CLI makes three types of calls to the wizard API:create-run,start-async, and aresume-asyncper 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
fetchinterceptor toMastraClientthat injectssentry-traceandbaggageheaders into every request. These come fromgetTraceData()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 initrun = one full trace, with CLI spans and all server-side Worker spans connected.Test plan
sentry initagainst a test project with Sentry instrumentedsentry.inittransaction in Sentryinvoke_workflow sentry-wizard,POST /api/workflows/sentry-wizard/*) should appear nested under it