Skip to content

Commit

Permalink
feat: a little doctor tab tidying (#25306)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pauldambra and github-actions[bot] authored Oct 1, 2024
1 parent 954852f commit 4008edf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LemonButton } from '@posthog/lemon-ui'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { SimpleKeyValueList } from 'scenes/session-recordings/player/inspector/components/SimpleKeyValueList'

import { InspectorListItemDoctor } from '../playerInspectorLogic'

Expand All @@ -23,13 +23,7 @@ export function ItemDoctor({ item, expanded, setExpanded }: ItemDoctorProps): JS
</LemonButton>

{expanded && (
<div className="p-2 text-xs border-t">
{item.data && (
<CodeSnippet language={Language.JSON} wrap thing={`custom event - ${item.tag}`}>
{JSON.stringify(item.data, null, 2)}
</CodeSnippet>
)}
</div>
<div className="p-2 text-xs border-t">{item.data && <SimpleKeyValueList item={item.data} />}</div>
)}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import api from 'lib/api'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { Dayjs, dayjs } from 'lib/dayjs'
import { getCoreFilterDefinition } from 'lib/taxonomy'
import { eventToDescription, objectsEqual, toParams } from 'lib/utils'
import { eventToDescription, humanizeBytes, objectsEqual, toParams } from 'lib/utils'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import {
InspectorListItemPerformance,
Expand Down Expand Up @@ -137,6 +137,29 @@ function timeRelativeToStart(
return { timestamp, timeInRecording }
}

function niceify(tag: string): string {
return tag.replace(/\$/g, '').replace(/_/g, ' ')
}

function estimateSize(snapshot: unknown): number {
return new Blob([JSON.stringify(snapshot || '')]).size
}

function getPayloadFor(customEvent: customEvent, tag: string): Record<string, any> {
if (tag === '$posthog_config') {
return (customEvent.data.payload as any)?.config as Record<string, any>
}

if (tag === '$session_options') {
return {
...((customEvent.data.payload as any)?.sessionRecordingOptions as Record<string, any>),
activePlugins: (customEvent.data.payload as any)?.activePlugins,
}
}

return customEvent.data.payload as Record<string, any>
}

export const playerInspectorLogic = kea<playerInspectorLogicType>([
path((key) => ['scenes', 'session-recordings', 'player', 'playerInspectorLogic', key]),
props({} as PlayerInspectorLogicProps),
Expand Down Expand Up @@ -336,7 +359,15 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([
const customEvent = snapshot as customEvent
const tag = customEvent.data.tag

if (['$pageview', 'window hidden', 'browser offline', 'browser online'].includes(tag)) {
if (
[
'$pageview',
'window hidden',
'browser offline',
'browser online',
'window visible',
].includes(tag)
) {
return
}

Expand All @@ -346,10 +377,10 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([
type: SessionRecordingPlayerTab.DOCTOR,
timestamp,
timeInRecording,
tag,
search: tag,
tag: niceify(tag),
search: niceify(tag),
window_id: windowId,
data: customEvent.data.payload as Record<string, any>,
data: getPayloadFor(customEvent, tag),
})
}
if (isFullSnapshotEvent(snapshot)) {
Expand All @@ -359,10 +390,10 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([
type: SessionRecordingPlayerTab.DOCTOR,
timestamp,
timeInRecording,
tag: 'fullSnapshotEvent',
search: 'fullSnapshotEvent',
tag: 'full snapshot event',
search: 'full snapshot event',
window_id: windowId,
data: {},
data: { snapshotSize: humanizeBytes(estimateSize(snapshot)) },
})
}
})
Expand Down

0 comments on commit 4008edf

Please sign in to comment.