Skip to content

Commit a0cbbf9

Browse files
authored
fix(telemetry): enable sourcemap resolution in Sentry (#144)
## Summary Sourcemaps were being uploaded to Sentry but stack traces still showed minified code (e.g., `t.with`, `br`, `bin.cjs:486:1136`). **Root cause**: The `beforeSend` path normalization was modifying stack frame filenames (replacing `/home/user` with `~`), which broke Sentry's ability to match frames against the uploaded sourcemaps via debug IDs. ## Changes - Remove path normalization in `beforeSend` that broke sourcemap matching - Replace `@sentry/esbuild-plugin` with `sentry-cli` commands for more reliable debug ID injection - Keep default SDK integrations (filtering instead of disabling all) to preserve debug ID support ## Before ``` at t.with (~/.../dist/bin.cjs:28:108124) at br (~/.../dist/bin.cjs:40:4319) at <unknown> (~/.../dist/bin.cjs:486:1136) ``` ## After ``` ../src/bin.ts:14:13 (callback) throw new Error("Sourcemap test error from bin.ts"); ../src/lib/telemetry.ts:79:24 (callback) return await callback(span); ```
1 parent 5ab5ef8 commit a0cbbf9

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

‎src/lib/telemetry.ts‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,29 @@ export async function withTelemetry<T>(
108108
*
109109
* @internal Exported for testing
110110
*/
111+
/**
112+
* Integrations to exclude for CLI.
113+
* These add overhead without benefit for short-lived CLI processes.
114+
*/
115+
const EXCLUDED_INTEGRATIONS = new Set([
116+
"Console", // Captures console output - too noisy for CLI
117+
"ContextLines", // Reads source files - we rely on uploaded sourcemaps instead
118+
"LocalVariables", // Captures local variables - adds significant overhead
119+
"Modules", // Lists all loaded modules - unnecessary for CLI telemetry
120+
]);
121+
111122
export function initSentry(enabled: boolean): Sentry.BunClient | undefined {
112123
const environment = process.env.NODE_ENV ?? "development";
113124

114125
const client = Sentry.init({
115126
dsn: SENTRY_CLI_DSN,
116127
enabled,
117-
// CLI is short-lived - disable integrations that add overhead with no benefit
118-
// (console, context, modules, etc). Only keep http to capture API requests.
119-
defaultIntegrations: false,
120-
integrations: [Sentry.httpIntegration()],
128+
// Keep default integrations but filter out ones that add overhead without benefit
129+
// Important: Don't use defaultIntegrations: false as it may break debug ID support
130+
integrations: (defaults) =>
131+
defaults.filter(
132+
(integration) => !EXCLUDED_INTEGRATIONS.has(integration.name)
133+
),
121134
environment,
122135
// Sample all events for CLI telemetry (low volume)
123136
tracesSampleRate: 1,
@@ -133,33 +146,18 @@ export function initSentry(enabled: boolean): Sentry.BunClient | undefined {
133146
},
134147

135148
beforeSend: (event) => {
136-
// Replace home directory with ~ in stack traces to remove PII
137-
const homeDir = process.env.HOME || process.env.USERPROFILE;
138-
for (const exception of event.exception?.values ?? []) {
139-
if (!exception.stacktrace?.frames) {
140-
continue;
141-
}
142-
for (const frame of exception.stacktrace.frames) {
143-
if (frame.filename && homeDir) {
144-
frame.filename = frame.filename.replace(homeDir, "~");
145-
}
146-
}
147-
}
148149
// Remove server_name which may contain hostname (PII)
149150
event.server_name = undefined;
150151
return event;
151152
},
152153
});
153154

154155
if (client?.getOptions().enabled) {
155-
// Set global tags for all events
156-
Sentry.setTag("platform", process.platform);
157-
Sentry.setTag("arch", process.arch);
158-
// Detect runtime: bun binary vs node (npm package)
156+
// Tag whether running as bun binary or node (npm package)
157+
// This is CLI-specific context not provided by the Context integration
159158
const runtime =
160159
typeof process.versions.bun !== "undefined" ? "bun" : "node";
161-
Sentry.setTag("runtime", runtime);
162-
Sentry.setTag("runtime.version", process.version);
160+
Sentry.setTag("cli.runtime", runtime);
163161
}
164162

165163
return client;

0 commit comments

Comments
 (0)