Skip to content

Commit 9fc2c76

Browse files
committed
fix: prevent override and ensure posthog shutdown on error
1 parent f547cc9 commit 9fc2c76

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

packages/sdk/src/utils/observability.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,29 @@ async function resolveIdentityAndCapture(
5454
flushInterval: 0,
5555
});
5656

57-
await posthog.capture({
58-
distinctId: identity.distinct_id,
59-
event,
60-
properties: {
61-
...properties,
62-
$set: email ? { email } : {},
63-
tracking_version: TRACKING_VERSION,
64-
sdk_package: SDK_PACKAGE,
65-
distinct_id_source: identity.distinct_id_source,
66-
},
67-
});
68-
69-
// TODO: remove after 2026-04-30 — temporary alias to merge old email-based distinct_ids with database user ID
70-
if (email) {
71-
await posthog.alias({
57+
try {
58+
await posthog.capture({
7259
distinctId: identity.distinct_id,
73-
alias: email,
60+
event,
61+
properties: {
62+
...properties,
63+
$set: { ...(properties?.$set || {}), ...(email ? { email } : {}) },
64+
tracking_version: TRACKING_VERSION,
65+
sdk_package: SDK_PACKAGE,
66+
distinct_id_source: identity.distinct_id_source,
67+
},
7468
});
75-
}
7669

77-
await posthog.shutdown();
70+
// TODO: remove after 2026-04-30 — temporary alias to merge old email-based distinct_ids with database user ID
71+
if (email) {
72+
await posthog.alias({
73+
distinctId: identity.distinct_id,
74+
alias: email,
75+
});
76+
}
77+
} finally {
78+
await posthog.shutdown();
79+
}
7880
}
7981

8082
async function getDistinctId(

0 commit comments

Comments
 (0)