Commit 7e6689a
fix(build): enable sourcemap resolution for compiled binaries (#701)
## 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/
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent abdc5e4 commit 7e6689a
File tree
9 files changed
+361
-65
lines changed- script
- src/lib
- sourcemap
- test
- lib/sourcemap
- script
9 files changed
+361
-65
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
153 | 163 | | |
154 | | - | |
155 | 164 | | |
156 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
157 | 169 | | |
158 | 170 | | |
159 | 171 | | |
160 | 172 | | |
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
164 | 203 | | |
165 | 204 | | |
166 | 205 | | |
| |||
169 | 208 | | |
170 | 209 | | |
171 | 210 | | |
172 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
173 | 218 | | |
174 | 219 | | |
175 | 220 | | |
| |||
204 | 249 | | |
205 | 250 | | |
206 | 251 | | |
207 | | - | |
208 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
209 | 257 | | |
210 | 258 | | |
211 | 259 | | |
| |||
215 | 263 | | |
216 | 264 | | |
217 | 265 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
238 | 301 | | |
239 | | - | |
240 | | - | |
241 | 302 | | |
242 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
243 | 308 | | |
244 | 309 | | |
245 | 310 | | |
| |||
344 | 409 | | |
345 | 410 | | |
346 | 411 | | |
347 | | - | |
348 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
349 | 416 | | |
350 | 417 | | |
351 | 418 | | |
| |||
362 | 429 | | |
363 | 430 | | |
364 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
365 | 435 | | |
366 | 436 | | |
367 | 437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
154 | 166 | | |
155 | 167 | | |
156 | 168 | | |
| |||
194 | 206 | | |
195 | 207 | | |
196 | 208 | | |
| 209 | + | |
197 | 210 | | |
198 | 211 | | |
199 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
10 | 21 | | |
11 | 22 | | |
12 | 23 | | |
| |||
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
0 commit comments