feat: external sourcemap upload for compiled binaries#518
Merged
Conversation
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Telemetry
Other
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
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 1047 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.79% 95.79% —%
==========================================
Files 180 180 —
Lines 24897 24897 —
Branches 0 0 —
==========================================
+ Hits 23850 23850 —
- Misses 1047 1047 —
- Partials 0 0 —Generated by Codecov Action |
Two-step build: bundle TS → JS+sourcemap, then compile JS → binary. The sourcemap is uploaded to Sentry for server-side stack trace resolution, never shipped to users in the binary. Verified end-to-end: stack traces in Sentry now show original function names (throwApiError, unwrapResult) and file paths (src/lib/api/infrastructure.ts:48) instead of minified names (G8, W41) and //root/bin.js. Impact vs current (no sourcemaps): Download size: +0.04 MB gzipped (+0.1%) Delta patches: +0.83 KB per release Binary size: +0.54 MB raw (+0.5%) Build changes: - script/build.ts: Step 1 bundles with external sourcemap, sentry-cli injects debug IDs + uploads with //root/ prefix, Step 2 compiles the JS without re-minifying - CI: passes SENTRY_AUTH_TOKEN to build-binary job for upload - Intermediate JS/map files cleaned up after compile
558d898 to
62d8b8e
Compare
Address Seer review: single quotes are not recognized as string delimiters by Windows cmd.exe, causing malformed arguments.
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.
Address Bugbot: double-quoted "//root/" gets expanded by POSIX shells (Seer said single quotes break Windows). Bypass the shell entirely with execFileSync + argument array — no quoting needed.
CI only runs on Linux, so single quotes safely prevent $bunfs shell expansion without Windows compat concerns. Removes the execFileSync complexity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
Compiled Bun binaries produce minified stack traces with names like
BJ8,pp1,kQ8— making Sentry issue grouping inaccurate:SeerErrorbut split into 3 issues (237 users) because different binary versions produce different minified namesInternal Error,You do not have permission) into one issue because they share the same minified function namefunc(bin)instead ofhandleResolvedTargets(issue/list.ts)Solution: Two-Step Build with External Sourcemap Upload
The sourcemap is uploaded to Sentry for server-side resolution — never embedded in or shipped with the binary.
Verified End-to-End ✅
Triggered a test error with the built binary. Sentry now shows fully resolved stack traces:
Before (minified):
After (resolved with source context):
Measured Impact (linux-x64)
For comparison, inline sourcemaps would cost +2.30 MB gzipped and +37 KB per delta — ~60× worse on download size.
Key Implementation Details
sentry-cli sourcemaps injectadds debug IDs to the JS file before compile. This provides belt-and-suspenders matching: debug ID (primary) + filename with/$bunfs/root/prefix (fallback)--url-prefix '/$bunfs/root/'matches the virtual filesystem path Bun uses in compiled binary stack tracesminify: falsein Step 2 because the JS is already minified in Step 1 — avoids double-minification producing different outputSENTRY_AUTH_TOKENstill work, just skip uploadChanges
script/build.tsBun.build()withsourcemap: "external"andminify: true→bin.js+bin.js.mapsentry-cli sourcemaps inject+uploadwith--url-prefix(non-fatal)Bun.build()withcompileandminify: false→ native binary.github/workflows/ci.ymlSENTRY_AUTH_TOKENto thebuild-binaryjob