feat: add distributed tracing for Sentry backend#455
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 116 passed | Total: 116 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 90.91%. Project has 1138 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.21% 95.19% -0.02%
==========================================
Files 175 175 —
Lines 23653 23673 +20
Branches 0 0 —
==========================================
+ Hits 22519 22535 +16
- Misses 1134 1138 +4
- Partials 0 0 —Generated by Codecov Action |
934cb44 to
372490c
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.
BYK
left a comment
There was a problem hiding this comment.
Re: Seer review on getTraceData() when telemetry is disabled
This is a false positive. When SENTRY_CLI_NO_TELEMETRY=1:
initSentry()is called withenabled: falseSentry.init({ enabled: false })disables the SDK entirelygetTraceData()returns{}(empty object) — no headers are injected
Verified empirically:
$ bun -e "import * as Sentry from '@sentry/bun'; Sentry.init({ dsn: '...', enabled: false }); console.log(Sentry.getTraceData());"
{}
The comment in the code already documents this: "When telemetry is disabled, getTraceData() returns {} — no headers injected."
…ckend
Inject sentry-trace and baggage headers into all outgoing Sentry API
requests so CLI traces are connected to backend traces.
Manual injection in prepareHeaders() is required because Bun's fetch
does not fire undici diagnostics channels, so the SDK's
nativeNodeFetchIntegration auto-injection cannot work.
Changes:
- telemetry.ts: Add getSentryTracePropagationTargets() matching
*.sentry.io, sentry.io, and self-hosted URLs. Update
tracePropagationTargets from [] to use the new function.
- sentry-client.ts: Import getTraceData from @sentry/bun and inject
sentry-trace/baggage headers in prepareHeaders(). When telemetry is
disabled, getTraceData() returns {} so no headers are injected.
- telemetry.test.ts: Add tests for URL pattern matching (SaaS regional,
bare sentry.io, non-sentry URLs, self-hosted, no SaaS duplication).
Closes #389
372490c to
86ba28a
Compare
BYK
left a comment
There was a problem hiding this comment.
Re: Cursor Bugbot — regex TLD boundary
Good catch! Fixed by adding (\/|$) anchors to both regexes:
-const SENTRY_SAAS_SUBDOMAIN_RE = /^https:\/\/[^/]*\.sentry\.io/;
-const SENTRY_SAAS_ROOT_RE = /^https:\/\/sentry\.io/;
+const SENTRY_SAAS_SUBDOMAIN_RE = /^https:\/\/[^/]*\.sentry\.io(\/|$)/;
+const SENTRY_SAAS_ROOT_RE = /^https:\/\/sentry\.io(\/|$)/;Added a test confirming sentry.io.evil.com and us.sentry.io.evil.com are rejected.

Inject
sentry-traceandbaggageheaders into all outgoing Sentry API requests so CLI traces connect to backend traces.What
Manual header injection in
prepareHeaders()is required because Bun's fetch doesn't fire undici diagnostics channels, so the SDK'snativeNodeFetchIntegrationauto-injection cannot work.Changes
telemetry.ts: AddgetSentryTracePropagationTargets()matching*.sentry.io,sentry.io, and self-hosted URLs. UpdatetracePropagationTargetsfrom[]to use the new function.sentry-client.ts: ImportgetTraceDatafrom@sentry/bunand injectsentry-trace/baggageheaders inprepareHeaders(). When telemetry is disabled,getTraceData()returns{}so no headers are injected.telemetry.test.ts: Add tests for URL pattern matching (SaaS regional, bare sentry.io, non-sentry URLs, self-hosted, no SaaS duplication).Closes #389