Skip to content

Commit 3fa1c35

Browse files
fix: properly serialize error objects in PostHog tracking (#709)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent f37eea3 commit 3fa1c35

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
Fix error tracking in PostHog by properly serializing error objects

packages/cli/src/cli/utils/observability.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ export default async function trackEvent(distinctId: string, event: string, prop
77
}
88

99
try {
10+
const safeProperties = properties ? JSON.parse(JSON.stringify(
11+
properties,
12+
(key, value) => {
13+
if (value instanceof Error) {
14+
return {
15+
name: value.name,
16+
message: value.message,
17+
stack: value.stack,
18+
};
19+
}
20+
return value;
21+
}
22+
)) : {};
23+
1024
const posthog = new PostHog("phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk", {
1125
host: "https://eu.i.posthog.com",
1226
flushAt: 1,
@@ -17,7 +31,7 @@ export default async function trackEvent(distinctId: string, event: string, prop
1731
distinctId,
1832
event,
1933
properties: {
20-
...properties,
34+
...safeProperties,
2135
meta: {
2236
version: process.env.npm_package_version,
2337
isCi: process.env.CI === "true",

0 commit comments

Comments
 (0)