: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(logs): stop cloning every log per live-tail tick (#68547)
Paul D'Ambraa0ad4927736f
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx b/products/logs/frontend/components/LogsViewer/LogsViewer.tsxindex ccdb81bbe37f..864fc5d9d0a6 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx+++ b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx@@ -113,6 +113,7 @@ function LogsViewerContent({const {logsLoading,parsedLogs,+ newLogUuids,sparklineData,sparklineLoading,sparklineIncompleteBarIndices,@@ -336,6 +337,7 @@ function LogsViewerContent({<VirtualizedLogsListdataSource={parsedLogs}+ newLogUuids={newLogUuids}loading={logsLoading}wrapBody={wrapBody}prettifyJson={prettifyJson}diff --git a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.test.ts b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.test.tsindex 89d241861d15..ba16c7c272a8 100644--- a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.test.ts+++ b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.test.ts@@ -106,6 +106,65 @@ describe('logsViewerDataLogic', () => {})})+ describe('live-tail identity', () => {+ const makeLog = (uuid: string, timestamp: string): any => ({+ uuid,+ timestamp,+ body: `body of ${uuid}`,+ attributes: { service: 'api' },+ severity_text: 'info',+ })++ it('keeps existing log and parsed row references across a live-tail poll', async () => {+ // The poll used to rebuild every log ({...log, new: false}) and parsedLogs re-cloned+ // them all again, so every visible row's identity churned per 1-5s tick and the whole+ // virtualized list re-rendered. Only genuinely new rows may get fresh references.+ const existingA = makeLog('log-a', '2026-01-02T00:00:00Z')+ const existingB = makeLog('log-b', '2026-01-01T00:00:00Z')+ logic.actions.setLogs([existingA, existingB])+ const parsedBefore = logic.values.parsedLogs++ useMocks({+ post: {+ '/api/environments/:team_id/logs/query/': () => [+ 200,+ {+ // The poll window overlaps: one genuinely new row plus repeats.+ results: [+ makeLog('log-c', '2026-01-03T00:00:00Z'),+ makeLog('log-a', '2026-01-02T00:00:00Z'),+ makeLog('log-b', '2026-01-01T00:00:00Z'),+ ],+ maxExportableLogs: 5000,+ },+ ],+ },+ })+ logic.actions.setLiveTailRunning(true)+ await expectLogic(logic).toFinishAllListeners()++ const logByUuid = (uuid: string): any => logic.values.logs.find((log) => log.uuid === uuid)+ expect(logic.values.logs).toHaveLength(3)+ expect(logByUuid('log-a')).toBe(existingA)+ expect(logByUuid('log-b')).toBe(existingB)++ const parsedByUuid = (list: typeof parsedBefore, uuid: string): any => list.find((log) => log.uuid === uuid)+ expect(parsedByUuid(logic.values.parsedLogs, 'log-a')).toBe(parsedByUuid(parsedBefore, 'log-a'))+ expect(parsedByUuid(logic.values.parsedLogs, 'log-b')).toBe(parsedByUuid(parsedBefore, 'log-b'))++ // Only the fresh batch is highlighted; the next poll replaces the set.+ expect([...logic.values.newLogUuids]).toEqual(['log-c'])+ })++ it('clears the arrival highlight when a fresh query result set lands', async () => {+ logic.actions.setNewLogUuids(['log-a'])+ logic.actions.fetchLogs()+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.newLogUuids.size).toBe(0)+ })+ })+describe('sparklineData selector', () => {it.each([['null', null, { labels: [], dates: [], data: [] }],diff --git a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.tsindex 470ffcd20e0e..578173a5700f 100644--- a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts+++ b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts@@ -36,6 +36,15 @@ const DEFAULT_LIVE_TAIL_POLL_INTERVAL_MS = 1000const DEFAULT_LOGS_PAGE_SIZE: number = 250export const DEFAULT_INITIAL_LOGS_LIMIT = null as number | nullconst NEW_QUERY_STARTED_ERROR_MESSAGE = 'new query started' as const++// Parse cache keyed on log object identity — leak-free by construction (entries die with their+// logs) and shared across logic instances. Parsing is pure per object, so cached entries are+// always correct as long as log objects are never mutated in place after creation (they aren't:+// `logs` is only ever replaced wholesale via `setLogs`). The same immutability contract is why+// live-tail prepends can keep existing log references untouched so their parsed rows stay+// reference-stable, and why newLogUuids is tracked as a separate set rather than a flag on each+// log — avoiding a clone of every existing log object per poll tick.+const parsedLogCache = new WeakMap<LogMessage, ParsedLogMessage>()const DEFAULT_LIVE_TAIL_POLL_INTERVAL_MAX_MS = 5000function classifyQueryError(error: unknown): { error_type: string; status_code: number | null } {@@ -157,6 +166,7 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([setLiveTailRunning: (enabled: boolean) => ({ enabled }),setLiveTailInterval: (interval: number) => ({ interval }),setLogs: (logs: LogMessage[]) => ({ logs }),+ setNewLogUuids: (newLogUuids: string[]) => ({ newLogUuids }),setSparkline: (sparkline: any[] | null) => ({ sparkline }),setNextCursor: (nextCursor: string | null) => ({ nextCursor }),expireLiveTail: () => true,@@ -168,6 +178,16 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([}),reducers({+ // UUIDs of the last live-tail batch, for the one-shot row highlight (see parsedLogCache comment above).+ newLogUuids: [+ new Set<string>(),+ {+ setNewLogUuids: (_, { newLogUuids }) => new Set(newLogUuids),+ // A fresh query result set has no "just arrived" rows.+ fetchLogsSuccess: () => new Set<string>(),+ clearLogs: () => new Set<string>(),+ },+ ],initialLogsLimit: [DEFAULT_INITIAL_LOGS_LIMIT as number | null,{@@ -405,6 +425,14 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([continue}seen.add(log.uuid)++ // Existing log references are stable across polls — cache hit = no re-render.+ const cached = parsedLogCache.get(log)+ if (cached) {+ result.push(cached)+ continue+ }+const cleanBody = colors.unstyle(log.body)let parsedBody: JsonType | null = nulltry {@@ -412,13 +440,15 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([} catch {// Not JSON, that's fine}- result.push({+ const parsed: ParsedLogMessage = {...log,attributes: stringifyLogAttributes(log.attributes),cleanBody,parsedBody,originalLog: log,- })+ }+ parsedLogCache.set(log, parsed)+ result.push(parsed)}return result@@ -721,11 +751,11 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([if (newLogs.length > 0) {actions.setLiveTailInterval(DEFAULT_LIVE_TAIL_POLL_INTERVAL_MS)+ // Prepend new logs; existing references stay untouched (see parsedLogCache comment).+ // Replacing newLogUuids highlights the new batch and un-highlights the previous one.+ actions.setNewLogUuids(newLogs.map((log) => log.uuid))actions.setLogs(- [- ...newLogs.map((log) => ({ ...log, new: true })),- ...values.logs.map((log) => ({ ...log, new: false })),- ]+ [...newLogs, ...values.logs].sort((a, b) => Date.parse(b.timestamp) - Date.parse(a.timestamp)).slice(0, DEFAULT_LOGS_PAGE_SIZE))@@ -736,6 +766,9 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([DEFAULT_LIVE_TAIL_POLL_INTERVAL_MAX_MS)actions.setLiveTailInterval(newInterval)+ // No new logs this tick — clear the previous batch's highlights so rows that+ // scroll out and back don't replay the arrival animation on a quiet stream.+ actions.setNewLogUuids([])}} catch (error) {if (signal.aborted) {diff --git a/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx b/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsxindex b7b93440d2eb..b914193fd626 100644--- a/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx+++ b/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx@@ -27,6 +27,9 @@ export interface LogRowProps {isPrettified?: booleanonTogglePrettify?: (log: ParsedLogMessage) => voidminHeight?: number+ /** Plays the one-shot arrival highlight; tracked outside the log object so live-tail polls+ * don't have to clone every existing log to clear the previous batch's flag. */+ isNew?: boolean}export function LogRow({@@ -46,9 +49,8 @@ export function LogRow({isPrettified = false,onTogglePrettify,minHeight = 32,+ isNew = false,}: LogRowProps): JSX.Element {- const isNew = 'new' in log && log.new-const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>): void => {// Only handle shift+click here to prevent text selection during range selectif (e.shiftKey && onShiftClick) {diff --git a/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx b/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsxindex bf320dcc13af..2cf9956e5c8c 100644--- a/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx+++ b/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx@@ -48,6 +48,8 @@ interface VirtualizedLogsListProps {onExpandTimeRange?: () => voidorderBy?: LogsOrderByonChangeOrderBy?: (orderBy: LogsOrderBy) => void+ /** Uuids of the latest live-tail batch — these rows play the one-shot arrival highlight. */+ newLogUuids?: Set<string>}interface LogsListRowProps {@@ -68,6 +70,7 @@ interface LogsListRowProps {prettifiedLogIds: Set<string>togglePrettifyLog: (logId: string) => voiddynamicRowHeight: ReturnType<typeof useDynamicRowHeight>+ newLogUuids?: Set<string>}function LogsListRow({@@ -90,6 +93,7 @@ function LogsListRow({prettifiedLogIds,togglePrettifyLog,dynamicRowHeight,+ newLogUuids,}: {ariaAttributes: Record<string, unknown>index: number@@ -126,6 +130,7 @@ function LogsListRow({}}isPrettified={prettifiedLogIds.has(log.uuid)}onTogglePrettify={(l) => togglePrettifyLog(l.uuid)}+ isNew={newLogUuids?.has(log.uuid) ?? false}/></div>)@@ -146,6 +151,7 @@ export function VirtualizedLogsList({onExpandTimeRange,orderBy,onChangeOrderBy,+ newLogUuids,}: VirtualizedLogsListProps): JSX.Element {const {id,@@ -305,6 +311,7 @@ export function VirtualizedLogsList({prettifiedLogIds,togglePrettifyLog,dynamicRowHeight,+ newLogUuids,}),[dataSource,@@ -323,6 +330,7 @@ export function VirtualizedLogsList({prettifiedLogIds,togglePrettifyLog,dynamicRowHeight,+ newLogUuids,])