Skip to content

Commit 6a868b3

Browse files
committed
feat(studio): add stack traces to all error telemetry events
Send `stack_trace` (up to 4KB) on crash, unhandled_error, and unhandled_promise_rejection events so PostHog captures the full JS call stack for debugging. Also bump `component_stack` from 500→2000 chars, and add `error_name` to promise rejections.
1 parent 114b83b commit 6a868b3

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

packages/studio/src/components/StudioErrorBoundary.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class StudioErrorBoundary extends Component<Props, State> {
2121
trackStudioEvent("crash", {
2222
error_message: error.message,
2323
error_name: error.name,
24-
component_stack: info.componentStack?.slice(0, 500) ?? null,
24+
stack_trace: error.stack?.slice(0, 4000) ?? null,
25+
component_stack: info.componentStack?.slice(0, 2000) ?? null,
2526
});
2627
}
2728

packages/studio/src/main.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,33 @@ import "./styles/studio.css";
77

88
trackStudioEvent("session_start");
99

10+
function errorProps(value: unknown): {
11+
error_message: string;
12+
error_name: string | null;
13+
stack_trace: string | null;
14+
} {
15+
if (value instanceof Error) {
16+
return {
17+
error_message: value.message,
18+
error_name: value.name,
19+
stack_trace: value.stack?.slice(0, 4000) ?? null,
20+
};
21+
}
22+
return { error_message: String(value), error_name: null, stack_trace: null };
23+
}
24+
1025
window.addEventListener("error", (event) => {
1126
trackStudioEvent("unhandled_error", {
27+
...errorProps(event.error),
1228
error_message: event.message,
13-
filename: event.filename ?? null,
14-
lineno: event.lineno ?? null,
15-
colno: event.colno ?? null,
29+
filename: event.filename,
30+
lineno: event.lineno,
31+
colno: event.colno,
1632
});
1733
});
1834

1935
window.addEventListener("unhandledrejection", (event) => {
20-
trackStudioEvent("unhandled_promise_rejection", {
21-
error_message: event.reason instanceof Error ? event.reason.message : String(event.reason),
22-
});
36+
trackStudioEvent("unhandled_promise_rejection", errorProps(event.reason));
2337
});
2438

2539
createRoot(document.getElementById("root")!).render(

0 commit comments

Comments
 (0)