: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
feat(replay): show log details in the inspector the way the logs viewer does (#122746)
Jon McCallum6a4cd021cda8
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex a889747be73c..a4beb1cd1a40 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2209,53 +2209,57 @@ snapshots:components-playerinspector-itemexperimentvariant--long-experiment-name--light:hash: v1.k794b7964.c0c92204824f5076d55b06c5b0d9a64176be945568ed0a25c3025b7dcd039e66.1gIa5QuAi1s0O8s5mcNEYfO6qySrDlNaoZrJUuyVXEAcomponents-playerinspector-itemlog--all-severity-levels--dark:- hash: v1.k794b7964.bc349de7519a8c5cd01fbe80bc2df528a9ed21dcaba511c5b9648a4d7ad840e9.QBGq4o7X4i54VAIuybkuHFHHpaai-1KBwT6ALeLECmw+ hash: v1.k794b7964.8c8fbc760d60b64f387d28791bc4ccfb79bacffd130c5143ef7cecdbcef25109.IN0WH8m-Ulp-st8n9zUAOuJLQrT-IMz76YeI2UPpFMEcomponents-playerinspector-itemlog--all-severity-levels--light:- hash: v1.k794b7964.eccc79d3616444299ebbb0d6f873bb2c13acbd3fbe2f6afc7b9cc539a3af682e.uS7R0c2AkF-XWcE1znzp_f928PkmVkmkdFDuCqAMHJ0+ hash: v1.k794b7964.fee7039f5a0c6d118698477d4fdff937e3f1a419c1a1a662227465ba3fe15702.BnUMhVkgqAAzrljo6G0uWkCxd8yuoouCcDe3_DES-18components-playerinspector-itemlog--debug-log--dark:- hash: v1.k794b7964.b87ec4bc8787e07496c68585bdc64956441e0663d59d87c250484b7664abe827.fRqkzz3-mwek2wqSRLLUDAUk0I5MDT6urU2O2wZg1eU+ hash: v1.k794b7964.9e0eea90d6594e0a9872dfae69b475e4b5bd9dfe19be165523c05b3333077b89.QARRmBVmmTRdv4LGCsd0wyvU3X-IRFgYS6mdwPIz8wQcomponents-playerinspector-itemlog--debug-log--light:- hash: v1.k794b7964.69cacda18581a78356d038268e51865c239b5b3db77958414d4c7240c7fe89b7.BI1CgYiiSjDu0svTtqEBzf6Mc-owb8VBIwp-WYMvOEQ+ hash: v1.k794b7964.3bada768c530f44db7b877806b0db1ddbf9e9d9762544c0f45184c13929b35d4.aNNR4Vk3lsMzs8WwttZa6y_JZunPho00t7X_j8Ul_Bscomponents-playerinspector-itemlog--error-log--dark:- hash: v1.k794b7964.d9ae3696b9157b773a57e4e7f376f8a0232d1a70e42d3a3a99ad6ebdc0cf6add.oDqIvpwhMux9KTHzcPEmtXYK5VXRT1GHBfebivaGRAo+ hash: v1.k794b7964.10624a43914a4d073160359423aa06da81619f086d586c85576fac274ed48e97.LLEbV9ioP6smUekcgJS-Kt3cx7JYWFgEJwVn8Mcta6Mcomponents-playerinspector-itemlog--error-log--light:- hash: v1.k794b7964.4961367c7078a3331c6d55dfe44ce9f5094dbecd3bbca2c5f457d1e3913ea990.-ankD4q6jJa_R5at452B1v8X9AUnNCK0NMBtVR9TskU+ hash: v1.k794b7964.63a6328ff8d8798d322defc23f7778219a2ad5f228612fd89ec439683b0c69a2.pL-cl870r8c1b4azleH8nEBCp4XOFqLoGpb_DwakjQscomponents-playerinspector-itemlog--error-log-with-badge--dark:- hash: v1.k794b7964.e958965dead9ac298cc095d3f89ee2c77c00adef6b77db9e38e6ecef7dd07fda.f96D1N0O6fLRgRdG84ECHZUgFdabZVP9oYU7-Wrb6vg+ hash: v1.k794b7964.d830269153aa42d3760c1b11f54a3d307206583c314e265c1ec7da2a1729a638.6JwXFf-1VMlk22f1KP4-Sdx0vPVUIbIFrC_d9AnJOIwcomponents-playerinspector-itemlog--error-log-with-badge--light:- hash: v1.k794b7964.b93b4627c6106588e43fd1e8166f9682edfcf69cc906841cb4d4fdae39cd2236.p1fe8O36pZeozjfdOeYqvHExeEchtsHof4XmrxgrgnM+ hash: v1.k794b7964.24ab6dd393e56ff0254e2494e2ef271ebf0f6f3eaed4a1f03a37c4235a4cc8d3.uCs-N-1SfgWRf8aT8X9K5FS0mCBXCRQaO_Zxli_7vRUcomponents-playerinspector-itemlog--fatal-log--dark:- hash: v1.k794b7964.c3b69125701968a3d81e714da50c10ac8fa4b2cbca69adac76b854dc3bd16cf1.qIBzNF0nsKNP2LehknjEx8kc15DL5_g-Sy4TkjC2ccU+ hash: v1.k794b7964.660e96b257f2a6826842d5cc39e87845ae66b69a3ec4311d0ad387dfcd964450.3B1_qAJe_HgPOoPRcWF6lRkiKCRc9Rp6AKRoZO8Td7wcomponents-playerinspector-itemlog--fatal-log--light:- hash: v1.k794b7964.b04a2d442a8bb5078152ed88524faba4df138f20c296050ba4f4673ae065d1f4.bZA23Rs1HoOyHk9BSYGsfvf3gZjeMBo7nRO3wR7GAvw+ hash: v1.k794b7964.70e5e0e700180b822c643b51fbaaf1f39905a5b81c8db11ef555fcdc31c15c53.jk3p7PwOEzNp0vAe1IhEKc3oTKB4u11h3kova3XkRewcomponents-playerinspector-itemlog--info-log--dark:- hash: v1.k794b7964.63858613715b8f6a14195607fdf441bb0826fdec8f9571d64bcff3ade2502849.HM12RyJjB92nHWCXvU7WzeNQ_zDwvuOYuwHZ-9Gnpzs+ hash: v1.k794b7964.a8d3007731791222a7e8d05693fee3e0741a360eeb1df0e151fb82cf22f6903a.Ga0S-wqS4RnYsC4qM8zl9njb7wNESrr3KDRxAJJZ_c8components-playerinspector-itemlog--info-log--light:- hash: v1.k794b7964.259713d12453dc906f8b865b137c66928424fbe59376e9f4324a84439c382ad1.5sG_X0oON4LHxrs5cn4lV7nBTNC1wWAzn1wkFzFv_zM+ hash: v1.k794b7964.7732f659049fd10774b1b2ccd0328b658d4bef9b6e206d77ca377e9496887d94.zWObesDAIGgJiuyL-mACdWoWWustrqkPzKaHwN-Wy9Qcomponents-playerinspector-itemlog--log-with-grouped-items--dark:- hash: v1.k794b7964.c1750179e2300716005f3f6e2a3a3fabf770437c891a2193f0f431aed8cf98ea.5lZZ19hm3j89bNyDURqKtfGvhbfzOArKNPe-jFQkPSc+ hash: v1.k794b7964.501dbba7006e1beba92880337461e11dedf26edc103390c38bb3182b8dd7b633.d-x2XLtFBhtJOnLRomBQrn2rYeADsMTykxVq2MkDpYEcomponents-playerinspector-itemlog--log-with-grouped-items--light:- hash: v1.k794b7964.daa400aa4f3d1a17aa7c6277af114adcb40175fe3f028bffa2948e5928d66767.hGMLoBk6LooQ0MrpWcETwq2Fpm5KLGd1l2LFmGD_0KE+ hash: v1.k794b7964.f8f307f5bd79b95c2385ad44c3736b6695363062ebc3ab550864171bab752d12.QDTXPQxfNJ8BsOe_lBy5Qbqgg5fF5_v73fbRwAuwqWM+ components-playerinspector-itemlog--log-with-json-body--dark:+ hash: v1.k794b7964.02d6683f6394e20bfae1cd3f36b03bcd7edf20d71f8cb7c14a29fa79a26e4f08.DFVonpHKB1EHJjaiSpbsTVXq8ZvY80wIawVf9PdRw1I+ components-playerinspector-itemlog--log-with-json-body--light:+ hash: v1.k794b7964.9bc43d9fccf6835307e45962062777598da8fad9fa177ec0aece37b7f013b6f6.Pjy8gXjkReHcJMNjoWHt8WwDZLTXlIynlncS3J545REcomponents-playerinspector-itemlog--log-with-long-body--dark:- hash: v1.k794b7964.43fd045f215f86d685f6b039abd622a1c7583f3407cdff54ec1484a728b99f36.Ay2JUB24wMluH3_YJlNmzxBhvBA1EVpGljI2gz0mDgk+ hash: v1.k794b7964.511e26601e7b201337cd70317f99de03c23e11220f23c53e6ca67173b3bbc7b2.sS-Hcf9aGtsycLKv378xdl91i-5kvP0h4guz6KOethscomponents-playerinspector-itemlog--log-with-long-body--light:- hash: v1.k794b7964.3a7a60dc26512acfdd90de140b5854c92d14b5b18077efcaec35cffe40f4242d.gmILyMJ-gi8MDmth7p-gHpvFmIZtHhPoTxACVJhy6sw+ hash: v1.k794b7964.7aa2c747a387691a23aeb7e7036889cd40cef76474ce545e61b358c3805c46d5.rHy8dx6UXGg1Xm26m-ds6Mkg6yhRvImXmD9UForTcwMcomponents-playerinspector-itemlog--log-with-no-attributes--dark:- hash: v1.k794b7964.6c0ecd60a15cc833b080d556aefa927cc99ab390b369f86b2d6470347122fe20.CurXAyOoPCA7LfMgRasBoy4TE1_Sl3ZLyb0_6czvB5s+ hash: v1.k794b7964.a9228eca0376f16fb22b3b960788a520590a9f7bba9e13cd05e355dae175eb17.LDFqedUPjaQ5lKS8F5oq1z4mbffcv_hziJFwSjZgMjAcomponents-playerinspector-itemlog--log-with-no-attributes--light:- hash: v1.k794b7964.c1e7a2fe85223ca6128793f9aad44799bdecffa02e871e0aff54c0630722739f.T8d9Zlc4tjmCHpEO6duUid759jbLwxjRMojzKzNOQRg+ hash: v1.k794b7964.8a5f29905874e393c15c79ddac5edba777a7abc3d89140253a907d4309824a03.UqUve3-WqrTi5a_bNJTg6oWjLvG7LzD7YUdxZUplULQcomponents-playerinspector-itemlog--log-with-session-id--dark:- hash: v1.k794b7964.55838e75051271576f0cec77ab69f7793501b3eccd83516d288195b9768065f0.UxraM06gDTgySkeTr1UV3smWs58LrvCOr_IAy-ODp2Y+ hash: v1.k794b7964.0fb6324ae539fd8f116e54383b796089728e9fed3ab72683e6cd32eb86a29967.ciuw_xX5b3zd0BV1yx3lpuJrdTlpc8pQqbFH-Z5jtnccomponents-playerinspector-itemlog--log-with-session-id--light:- hash: v1.k794b7964.6131df365b6ef21fe968066702fc06f4f70186e4fa3b75e8d0355c985cba545f.-bAptRv3g4OK09EyA4BQPvmOoduiw2YDNM88vrruNp8+ hash: v1.k794b7964.1823fb185ff3ae47637a0a5b8a1dfe462999260445d54a0e03ae70f3dfcbda8e.YLBSc9ZsjiQOratmZyPXIM-nehJo9yWevD_Ef2NHdF8components-playerinspector-itemlog--trace-log--dark:- hash: v1.k794b7964.0ad1e943e47e8b3e65a304650ab194f1d2afea8576f3d892a47bd6eb0ccd1440.K1oXnQ9fQ-Uzgp6DVgvV2X5YLImdaNJuq3X9TXsPCPk+ hash: v1.k794b7964.4729978c1ac76ed3f057216db54ae2834f02909beba6be5a1c66e909a40dfbd1.LykmpMkVCkyrjPYU8Zo1k1ckqnYq01B3FRNcAsLHtOkcomponents-playerinspector-itemlog--trace-log--light:- hash: v1.k794b7964.3885622eeb62101ca26732bf5dc337e41e6ed82430f51611679c85b07d95de53.SF7ZFggIb9Jjm0VBKY0ZoBHsn_geRfQ5mooHmldbWSs+ hash: v1.k794b7964.53151869cba8c7913da125f7ef976086982baa3897274919caa9a40329577128.bjzml1b9Pcyma7LJlP3eQEPLOMOK2M4bgbDgbNgZNykcomponents-playerinspector-itemlog--warn-log--dark:- hash: v1.k794b7964.f94fb4f077628505d52bc5dff1f5bbd4b649c8d0a1d5594c28e78ca0991bd761.F2lxWhVDbrdROnqzgYxdzfw9aALhayOHSkQHx9AIGAQ+ hash: v1.k794b7964.5138c5fcfbc6010780a3564a44d9c5be51c89717641baa7d0380506d3b5d0c00.IBcBosXwwZyGC4QF7L5rF6LOkzAyZDt8yBtr5lfZfD4components-playerinspector-itemlog--warn-log--light:- hash: v1.k794b7964.7e3344bd5c335f1f1c5cd23766c1fbb52152561f97c09ff058e2aa0df524283f.SZBjfJOySZxlFbkgh_Mjd2YYu0lZSW_uoBhHU4a1T68+ hash: v1.k794b7964.c187ba0614493f081e983fafca9da8344253f1fb1ab11207f3ef1b2c144b1507.rC9YNjnl3oLk2hI-vg9_fT_MA-y0BVXe-EtwZGYc010components-playerinspector-itemsessionchange--session-next--dark:hash: v1.k794b7964.42fa53f4451626d0e1126c04124a8bdea9fe0aefaa095a8138bfd81e22a22c5a.x0mfhdhP5rKqGWdnNU3vnctDnhEs0iE3mZtygEoJ6G8components-playerinspector-itemsessionchange--session-next--light:diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.stories.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.stories.tsxindex eae7e5c61342..39abd79a96f1 100644--- a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.stories.tsx+++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.stories.tsx@@ -206,6 +206,26 @@ export const LogWithLongBody: Story = {args: {},}+export const LogWithJsonBody: Story = {+ render: renderBasic as any,+ args: {+ item: makeItem(+ 'info',+ JSON.stringify({+ event: 'request_started',+ request: 'GET /api/projects/1/insights/',+ user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',+ worker_pid: 23,+ }),+ {+ attributes: { event: 'request_started', logger: 'django_structlog.middlewares.request' },+ resource_attributes: { 'service.name': 'web-django', 'k8s.namespace.name': 'web' },+ instrumentation_scope: '@',+ }+ ),+ },+}+export const LogWithGroupedItems: Story = {render: renderBasic as any,args: {diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsxindex 77a4e0edd318..45f058e51f13 100644--- a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx+++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx@@ -1,11 +1,12 @@import clsx from 'clsx'import { useValues } from 'kea'+import { useMemo } from 'react'import { IconLive } from '@posthog/icons'import { LemonButton, LemonDivider } from '@posthog/lemon-ui'import { CodeSnippet, Language } from 'lib/components/CodeSnippet'-import { SimpleKeyValueList } from 'lib/components/SimpleKeyValueList'+import { JSONViewer } from 'lib/components/JSONViewer'import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'import { Tooltip } from 'lib/lemon-ui/Tooltip'@@ -14,6 +15,7 @@ import { useViewLogsButton } from 'products/logs/frontend/components/ViewLogsButimport { ItemTimeDisplay } from '../../../components/ItemTimeDisplay'import { miniFiltersLogic } from '../miniFiltersLogic'import { InspectorListItemLog } from '../playerInspectorLogic'+import { ItemLogAttributes } from './ItemLogAttributes'export interface ItemLogProps {item: InspectorListItemLog@@ -22,6 +24,15 @@ export interface ItemLogProps {sessionId?: string}+function parseJsonObject(body: string): object | null {+ try {+ const parsed = JSON.parse(body)+ return parsed && typeof parsed === 'object' ? parsed : null+ } catch {+ return null+ }+}+const levelColors: Record<string, string> = {trace: 'text-secondary',debug: 'text-secondary',@@ -76,15 +87,8 @@ export function ItemLogDetail({ item, groupedItems, sessionId }: ItemLogProps):openedFrom: 'recording',})- const attributes =- item.data.attributes && typeof item.data.attributes === 'object'- ? Object.fromEntries(- Object.entries(item.data.attributes).map(([key, value]) => [- key,- typeof value === 'string' ? value : JSON.stringify(value),- ])- )- : {}+ const parsedBody = useMemo(() => parseJsonObject(item.data.body), [item.data.body])+ const serviceName = item.data.resource_attributes?.['service.name'] || item.data.instrumentation_scopereturn (<div className="w-full font-light" data-attr="item-log-detail">@@ -134,25 +138,28 @@ export function ItemLogDetail({ item, groupedItems, sessionId }: ItemLogProps):</>) : null}- <CodeSnippet language={Language.Text} wrap thing="log message">- {item.data.body}- </CodeSnippet>+ {parsedBody ? (+ <div className="p-2 bg-bg-light rounded border border-border">+ <JSONViewer src={parsedBody} collapsed={2} />+ </div>+ ) : (+ <CodeSnippet language={Language.Text} wrap thing="log message">+ {item.data.body}+ </CodeSnippet>+ )}- {item.data.instrumentation_scope ? (+ {serviceName ? (<><LemonDivider dashed /><LemonLabel>Service</LemonLabel>- <div className="font-mono text-xs">{item.data.instrumentation_scope}</div>+ <div className="font-mono text-xs">{serviceName}</div></>) : null}- {Object.keys(attributes).length > 0 ? (- <>- <LemonDivider dashed />- <LemonLabel>Attributes</LemonLabel>- <SimpleKeyValueList item={attributes} />- </>- ) : null}+ <div className="flex flex-col gap-2 mt-2">+ <ItemLogAttributes attributes={item.data.attributes} title="Log attributes" />+ <ItemLogAttributes attributes={item.data.resource_attributes} title="Resource attributes" />+ </div></div></div>)diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLogAttributes.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLogAttributes.tsxnew file mode 100644index 000000000000..bd6f2d0e07b4--- /dev/null+++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLogAttributes.tsx@@ -0,0 +1,66 @@+import { LemonTable } from '@posthog/lemon-ui'++import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'++export interface ItemLogAttributesProps {+ attributes: Record<string, unknown> | null | undefined+ title: string+}++export function ItemLogAttributes({ attributes, title }: ItemLogAttributesProps): JSX.Element | null {+ const rows =+ attributes && typeof attributes === 'object'+ ? Object.entries(attributes).map(([key, value]) => ({+ key,+ value: typeof value === 'string' ? value : JSON.stringify(value),+ }))+ : []++ if (rows.length === 0) {+ return null+ }++ return (+ <div className="bg-primary overflow-hidden rounded border border-border">+ <div className="px-3 py-2 bg-bg-light border-b border-border">+ <span className="text-xs font-semibold text-muted uppercase">{title}</span>+ </div>+ <LemonTable+ embedded+ showHeader={false}+ size="small"+ rowKey="key"+ dataSource={rows}+ columns={[+ {+ key: 'key',+ dataIndex: 'key',+ width: 0,+ render: (_, record) => (+ <span className="font-mono text-xs text-muted whitespace-nowrap">{record.key}</span>+ ),+ },+ {+ key: 'value',+ dataIndex: 'value',+ render: (_, record) =>+ record.value === '' ? (+ <span className="font-mono text-xs text-muted italic">(empty)</span>+ ) : (+ <CopyToClipboardInline+ explicitValue={record.value}+ description="attribute value"+ iconSize="xsmall"+ iconPosition="start"+ selectable+ className="gap-1 font-mono text-xs break-all !whitespace-normal"+ >+ {record.value}+ </CopyToClipboardInline>+ ),+ },+ ]}+ />+ </div>+ )+}