Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(error-tracking): handle non-string $session_id in issue scene (#68696)

Aleksander Błaszkiewicz26c47145f060
diff --git a/frontend/src/lib/components/Errors/utils.test.ts b/frontend/src/lib/components/Errors/utils.test.ts
index 43a8982d1a81..0391964caa30 100644
--- a/frontend/src/lib/components/Errors/utils.test.ts
+++ b/frontend/src/lib/components/Errors/utils.test.ts
@@ -1,5 +1,5 @@
-import { ExceptionAttributes } from './types'
-import { getExceptionAttributes, getExceptionList } from './utils'
+import { ErrorEventProperties, ExceptionAttributes } from './types'
+import { getExceptionAttributes, getExceptionList, getSessionId } from './utils'
describe('Error Display', () => {
it('can read sentry stack trace when $exception_list is not present', () => {
@@ -170,4 +170,16 @@ describe('Error Display', () => {
handled: true,
})
})
+
+ // A non-string $session_id (e.g. a numeric timestamp from a misbehaving SDK) must not leak
+ // through as a number — it used to crash the issue scene via a ts-pattern exhaustive match.
+ it.each([
+ ['valid string session id', { $session_id: 'the-session-id' }, 'the-session-id'],
+ ['numeric session id', { $session_id: 1783346787081 }, undefined],
+ ['empty string session id', { $session_id: '' }, undefined],
+ ['missing session id', {}, undefined],
+ ['null session id', { $session_id: null }, undefined],
+ ])('getSessionId normalizes %s', (_name, properties, expected) => {
+ expect(getSessionId(properties as ErrorEventProperties)).toEqual(expected)
+ })
})
diff --git a/frontend/src/lib/components/Errors/utils.ts b/frontend/src/lib/components/Errors/utils.ts
index 23c1527d6a76..3162c834e3b5 100644
--- a/frontend/src/lib/components/Errors/utils.ts
+++ b/frontend/src/lib/components/Errors/utils.ts
@@ -184,7 +184,10 @@ export function getAdditionalProperties(
}
export function getSessionId(properties: ErrorEventProperties): string | undefined {
- return properties['$session_id'] as string | undefined
+ const sessionId = properties['$session_id']
+ // $session_id can arrive malformed (e.g. a numeric timestamp) from misbehaving SDKs.
+ // Only a non-empty string is a usable session id; anything else means "no session".
+ return typeof sessionId === 'string' && sessionId.length > 0 ? sessionId : undefined
}
export function getRecordingStatus(properties: ErrorEventProperties): string | undefined {