: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay-vision): render non-string pinned property values (#95305)
Kim Svatos Duganf181d31402eb
diff --git a/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.test.ts b/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.test.tsnew file mode 100644index 000000000000..8a1ae7ee77c3--- /dev/null+++ b/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.test.ts@@ -0,0 +1,60 @@+import { expectLogic } from 'kea-test-utils'++import api from '~/lib/api'+import { initKeaTests } from '~/test/init'++import { observationPinnedPropertiesLogic } from './observationPinnedPropertiesLogic'+import { observationSessionPropertiesLogic, toDisplayValue } from './observationSessionPropertiesLogic'++jest.mock('~/lib/api')++const SESSION_ID = '01994a1e-4a3f-7000-8000-000000000000'++describe('observationSessionPropertiesLogic', () => {+ let logic: ReturnType<typeof observationSessionPropertiesLogic.build>++ const mockApi = api as jest.Mocked<typeof api>++ beforeEach(() => {+ initKeaTests()+ jest.resetAllMocks()+ })++ afterEach(() => {+ logic?.unmount()+ })++ // A property keeps its own type through HogQL, so the strip used to call startsWith on the+ // number $browser_version reads back as.+ it.each([+ [143, '143'],+ [0, '0'],+ [false, 'false'],+ ['Chrome', 'Chrome'],+ [['a', 'b'], '["a","b"]'],+ [null, null],+ [undefined, null],+ ['', null],+ ])('reads %p as %p', (value, expected) => {+ expect(toDisplayValue(value)).toBe(expected)+ })++ it('renders non-string property values as text', async () => {+ observationPinnedPropertiesLogic.mount()+ observationPinnedPropertiesLogic.actions.setPinnedProperties([+ { key: '$browser_version', type: 'event' },+ { key: '$browser', type: 'event' },+ ])+ mockApi.queryHogQL.mockResolvedValue({ results: [[143, 'Chrome']] } as any)++ logic = observationSessionPropertiesLogic({ sessionId: SESSION_ID })+ logic.mount()++ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.sessionProperties).toEqual({+ 'event:$browser_version': '143',+ 'event:$browser': 'Chrome',+ })+ })+})diff --git a/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.ts b/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.tsindex 6e574de30051..6ebf72152cc8 100644--- a/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.ts+++ b/products/replay_vision/frontend/observations/observationSessionPropertiesLogic.ts@@ -21,6 +21,23 @@ export function pinnedPropertyId(property: PinnedProperty): string {return `${property.type}:${property.key}`}+/**+ * A property keeps its own type through HogQL, so a pin like $browser_version comes back as a+ * number and a flag as a boolean. The strip renders text, so everything is stringified here.+ */+export function toDisplayValue(value: unknown): string | null {+ if (value === null || value === undefined || value === '') {+ return null+ }+ if (typeof value === 'string') {+ return value+ }+ if (typeof value === 'number' || typeof value === 'boolean') {+ return String(value)+ }+ return JSON.stringify(value)+}+function selectExpression(property: PinnedProperty): string {const identifier = escapePropertyAsHogQLIdentifier(property.key)if (property.type === 'session') {@@ -68,12 +85,12 @@ export interface observationSessionPropertiesLogicActions {}loadSessionPropertiesSuccess: (sessionProperties: {- [k: string]: any+ [k: string]: string | null} | null,payload?: any) => {sessionProperties: {- [k: string]: any+ [k: string]: string | null} | nullpayload?: any}@@ -132,7 +149,7 @@ export const observationSessionPropertiesLogic = kea<observationSessionPropertie}return Object.fromEntries(// An event carrying the key with an empty value reads the same as never carrying it.- properties.map((property, index) => [pinnedPropertyId(property), row[index] || null])+ properties.map((property, index) => [pinnedPropertyId(property), toDisplayValue(row[index])]))},},