Skip to content

fix(build): enable sourcemap resolution for compiled binaries#701

Merged
BYK merged 5 commits intomainfrom
fix/sourcemap-resolution
Apr 9, 2026
Merged

fix(build): enable sourcemap resolution for compiled binaries#701
BYK merged 5 commits intomainfrom
fix/sourcemap-resolution

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 9, 2026

Summary

Fixes sourcemap resolution for the Sentry CLI's Bun-compiled binaries. Error events now show original TypeScript file paths, line numbers, and function names instead of minified code.

Before: at ySt (/$bunfs/root/bin.js:40106:19)
After: at resolveProjectSearchFallback (../src/commands/issue/utils.ts:165:15)

What was wrong

Four distinct issues prevented sourcemaps from working:

1. No debug_meta in events

The debug ID IIFE snippet was injected before ESM import declarations, creating invalid ESM that Bun's compiler dropped. Events had no debug_meta — the server couldn't even attempt resolution.

Fix: Register debug IDs at module scope in constants.ts via a build-time __SENTRY_DEBUG_ID__ constant (esbuild define with placeholder UUID, replaced after sourcemap hash computation).

2. Artifact bundle ZIP format

Our ZipWriter produced plain ZIPs. The symbolicator uses the symbolic crate which requires an 8-byte SYSB magic header before the ZIP data.

Fix: ZipWriter.create() writes the SYSB header.

3. Line/column position mismatch

Bun.build({ compile: true }) reformats code (3.7k lines → 40k lines), making esbuild's sourcemap positions invalid.

Fix: sourcemap: "linked" in Bun.build embeds a map in the binary. Bun's runtime auto-resolves Error.stack positions back to esbuild output coordinates. The esbuild map is saved before Bun.build (which overwrites bin.js.map) and restored after.

4. Symbolicator silently skips relative paths

Bun's embedded map resolves to relative paths (dist-bin/bin.js). The symbolicator's URL candidate generator produces ~dist-bin/bin.js (missing / after ~) for relative paths, which never matches uploaded artifacts.

Fix: beforeSend normalizes relative frame paths and debug_meta.images[].code_file to absolute by prepending /.

Verification

Built locally, triggered an error, verified in Sentry:

  • Original function name: resolveProjectSearchFallback
  • Original source file: ../src/commands/issue/utils.ts:165:15
  • No processing errors

Event: https://sentry.sentry.io/issues/7398675564/events/0192a9a1d94f43519ee697e566f08b92/

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 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 ✨

Bug Fixes 🐛

Dashboard

  • Add --layout flag to widget add for predictable placement by BYK in #700
  • Render tracemetrics widgets in dashboard view by BYK in #695

Other

  • (build) Enable sourcemap resolution for compiled binaries by BYK in #701
  • (init) Narrow command validation to actual shell injection vectors by betegon in #697
  • (init,feedback) Default to tracing only in feature select and attach user email to feedback by MathurAditya724 in #688

Internal Changes 🔧

  • (docs) Gitignore generated command docs, extract fragments by BYK in #696
  • (eval) Replace OpenAI with Anthropic SDK in init-eval judge by betegon in #683
  • (init) Use markdown pipeline for spinner messages by betegon in #686
  • Regenerate skill files and command docs by github-actions[bot] in 584ec0e0

🤖 This preview updates automatically when you update the PR.

BYK and others added 4 commits April 9, 2026 12:47
…isting (#632)

Add a top-level 'event list' command that lists events for a Sentry issue,
equivalent to 'issue events' but living in the event route. The 'sentry events'
plural alias now points to this list command (Pattern A).

Changes:
- Extract shared types, formatters, and flag defs into event/shared-events.ts
- Create event/list.ts with its own command identity (pagination hints,
  pagination key, and error messages say 'sentry event list')
- Make buildCommandHint and resolveIssue accept optional commandBase param
- Update event route to include list alongside view
- Switch events plural alias from eventRoute to eventListCommand
- Remove stale event/list synonym from command-suggestions.ts
- Add 6 func tests verifying output, pagination hints, and command identity
…_MIN_LIMIT/LIST_DEFAULT_LIMIT

Every list command duplicated MAX_LIMIT (1000), MIN_LIMIT (1), and
DEFAULT_LIMIT (varying 20-100) locally. Move them to list-command.ts as
LIST_MAX_LIMIT, LIST_MIN_LIMIT, and LIST_DEFAULT_LIMIT (standardized to 25).

- trace list default: 20 → 25
- trace logs default: 100 → 25
- log list default: 100 → 25
- buildListLimitFlag default: 30 → 25
- issue list: remove redundant explicit "25" (now the default)
@BYK BYK force-pushed the fix/sourcemap-resolution branch from db23972 to f073da7 Compare April 9, 2026 12:50
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-701/

Built to branch gh-pages at 2026-04-09 13:23 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Codecov Results 📊

134 passed | Total: 134 | 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 72.09%. Project has 1525 uncovered lines.
❌ Project coverage is 95.35%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/lib/constants.ts 11.11% ⚠️ 8 Missing
src/lib/telemetry.ts 85.71% ⚠️ 4 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.38%    95.35%    -0.03%
==========================================
  Files          225       225         —
  Lines        32783     32825       +42
  Branches         0         0         —
==========================================
+ Hits         31269     31300       +31
- Misses        1514      1525       +11
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK force-pushed the fix/sourcemap-resolution branch from f073da7 to 1d5c768 Compare April 9, 2026 13:10
@BYK BYK marked this pull request as ready for review April 9, 2026 13:11
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.

Reviewed by Cursor Bugbot for commit 1d5c768. Configure here.

Fix four issues preventing sourcemaps from working in Bun-compiled binaries:

1. Events had no debug_meta because the IIFE snippet was placed before
   ESM imports (invalid ESM). Register debug IDs at module scope via
   build-time constant instead.

2. Artifact bundle ZIPs lacked the SYSB magic header required by
   the symbolic crate's SourceBundle parser. Add the 8-byte header
   in ZipWriter.

3. Bun.build reformats code (3.7k → 40k lines), breaking sourcemap
   positions. Use sourcemap: "linked" to embed a map in the binary
   that Bun's runtime uses to auto-resolve Error.stack positions
   back to esbuild output coordinates.

4. Bun's embedded map produces relative paths in Error.stack (e.g.,
   "dist-bin/bin.js"). The symbolicator's URL candidate generator
   skips relative paths silently. Normalize to absolute in beforeSend.
@BYK BYK force-pushed the fix/sourcemap-resolution branch from 1d5c768 to f9dffc6 Compare April 9, 2026 13:22
@BYK BYK merged commit 7e6689a into main Apr 9, 2026
27 checks passed
@BYK BYK deleted the fix/sourcemap-resolution branch April 9, 2026 13:34
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