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.

feat(logs): say where the session logs modal was opened from (#122562)

Jon McCallum0bfa274ca7f9
diff --git a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx
index 59fd3821f1e0..77a4e0edd318 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx
+++ b/frontend/src/scenes/session-recordings/player/inspector/components/ItemLog.tsx
@@ -70,7 +70,11 @@ export function ItemLog({ item, groupCount }: ItemLogProps): JSX.Element {
}
export function ItemLogDetail({ item, groupedItems, sessionId }: ItemLogProps): JSX.Element {
- const { onClick: openSessionLogs } = useViewLogsButton({ sessionId, timestamp: item.timestamp.toISOString() })
+ const { onClick: openSessionLogs } = useViewLogsButton({
+ sessionId,
+ timestamp: item.timestamp.toISOString(),
+ openedFrom: 'recording',
+ })
const attributes =
item.data.attributes && typeof item.data.attributes === 'object'
diff --git a/products/error_tracking/frontend/components/EventsTable/EventActions.tsx b/products/error_tracking/frontend/components/EventsTable/EventActions.tsx
index c7eba6ac0aae..6c6d2c8c21f2 100644
--- a/products/error_tracking/frontend/components/EventsTable/EventActions.tsx
+++ b/products/error_tracking/frontend/components/EventsTable/EventActions.tsx
@@ -28,7 +28,7 @@ export function EventActions({ record }: { record: ErrorEventType }): JSX.Elemen
hasRecording,
timestamp: record.timestamp,
})
- const logs = useViewLogsButton({ sessionId, timestamp: record.timestamp })
+ const logs = useViewLogsButton({ sessionId, timestamp: record.timestamp, openedFrom: 'exception' })
const recordingTooltip =
typeof recordingDisabledReason === 'string' ? recordingDisabledReason : recordingWarningReason
diff --git a/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx b/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx
index ed787af1ec7b..69a4e3260330 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx
+++ b/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx
@@ -201,6 +201,7 @@ function ExceptionCardContent({
<ViewLogsButton
sessionId={sessionId}
timestamp={timestamp}
+ openedFrom="exception"
size="xsmall"
data-attr="error-tracking-session-view-logs"
/>
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModal.tsx b/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModal.tsx
index 59ade24480c4..66c2611b9d8c 100644
--- a/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModal.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModal.tsx
@@ -10,6 +10,7 @@ import { useKeepMountedWhileOpen } from 'lib/hooks/useKeepMountedWhileOpen'
import { LogsViewer } from 'products/logs/frontend/components/LogsViewer'
import { logsViewerModalLogic } from './logsViewerModalLogic'
+import { LogsViewerModalOpenedFrom } from './LogsViewerModalOpenedFrom'
export function LogsViewerModal(): JSX.Element | null {
const { isOpen, viewerId, fullScreen, initialFilters, pinnedFilters, personId, sessionId } =
@@ -37,7 +38,8 @@ export function LogsViewerModal(): JSX.Element | null {
maxWidth={fullScreen ? undefined : 1600}
>
<FloatingContainerContext.Provider value={floatingContainer}>
- <div className="flex items-center justify-end border-b px-1 py-0.5">
+ <div className="flex items-center justify-end gap-2 border-b px-1 py-0.5">
+ <LogsViewerModalOpenedFrom />
<LemonButton icon={<IconX />} size="small" onClick={closeLogsViewerModal} tooltip="Close" />
</div>
<LemonModal.Content embedded className="flex flex-col flex-1 min-h-0 overflow-x-hidden">
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModalOpenedFrom.tsx b/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModalOpenedFrom.tsx
new file mode 100644
index 000000000000..171cddc18701
--- /dev/null
+++ b/products/logs/frontend/components/LogsViewer/LogsViewerModal/LogsViewerModalOpenedFrom.tsx
@@ -0,0 +1,51 @@
+import { useActions, useValues } from 'kea'
+
+import { IconRewindPlay, IconWarning } from '@posthog/icons'
+import { LemonButton } from '@posthog/lemon-ui'
+
+import { LogsViewerModalOrigin, logsViewerModalLogic } from './logsViewerModalLogic'
+
+const ORIGIN_COPY: Record<LogsViewerModalOrigin, { icon: JSX.Element; label: string; back: string }> = {
+ recording: { icon: <IconRewindPlay />, label: 'Opened from recording', back: 'Back to recording' },
+ exception: { icon: <IconWarning />, label: 'Opened from exception', back: 'Back to exception' },
+}
+
+export function LogsViewerModalOpenedFrom(): JSX.Element | null {
+ const { openedFrom, sessionId } = useValues(logsViewerModalLogic)
+ const { closeLogsViewerModal } = useActions(logsViewerModalLogic)
+
+ if (!openedFrom) {
+ return null
+ }
+
+ const copy = ORIGIN_COPY[openedFrom]
+
+ return (
+ <div
+ className="flex flex-1 min-w-0 flex-wrap items-center gap-2 rounded border border-accent bg-accent-highlight-secondary px-2 py-1 text-xs"
+ data-attr="logs-modal-opened-from"
+ >
+ <span className="flex items-center gap-1.5 font-semibold">
+ {copy.icon}
+ {copy.label}
+ </span>
+ {sessionId && (
+ <span className="flex items-center gap-1 text-muted min-w-0">
+ <span className="shrink-0">Showing logs from session</span>
+ <span className="font-mono truncate" translate="no" title={sessionId}>
+ {sessionId}
+ </span>
+ </span>
+ )}
+ <LemonButton
+ size="xsmall"
+ type="secondary"
+ className="ml-auto"
+ onClick={closeLogsViewerModal}
+ data-attr="logs-modal-back-to-origin"
+ >
+ {copy.back}
+ </LemonButton>
+ </div>
+ )
+}
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts
index 563e25fe9ca6..4d44200abd4a 100644
--- a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts
+++ b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts
@@ -146,13 +146,18 @@ describe('logsViewerModalLogic', () => {
})
it('drops the scope when reopened from an unscoped entry point', async () => {
- logic.actions.openLogsViewerModal({ id: 'person-1', pinnedFilters, personId: 'a-person-uuid' })
+ logic.actions.openLogsViewerModal({
+ id: 'person-1',
+ pinnedFilters,
+ personId: 'a-person-uuid',
+ openedFrom: 'recording',
+ })
await expectLogic(logic).toFinishAllListeners()
logic.actions.closeLogsViewerModal()
await expectLogic(logic, () => {
logic.actions.openLogsViewerModal({ id: 'modal' })
- }).toMatchValues({ pinnedFilters: null, personId: null })
+ }).toMatchValues({ pinnedFilters: null, personId: null, openedFrom: null })
})
})
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts
index 32a7e468dd2f..fc5178704d26 100644
--- a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts
@@ -6,9 +6,12 @@ import { UniversalFiltersGroup } from '~/types'
import { LogsViewerFilters, LogsViewerScope } from 'products/logs/frontend/components/LogsViewer/config/types'
+export type LogsViewerModalOrigin = 'recording' | 'exception'
+
export interface OpenLogsViewerModalOptions extends LogsViewerScope {
id?: string
fullScreen?: boolean
+ openedFrom?: LogsViewerModalOrigin
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -16,6 +19,7 @@ export interface logsViewerModalLogicValues {
fullScreen: boolean
initialFilters: Partial<LogsViewerFilters> | null
isOpen: boolean
+ openedFrom: LogsViewerModalOrigin | null
personId: string | null
pinnedFilters: UniversalFiltersGroup | null
sessionId: string | null
@@ -52,6 +56,7 @@ export interface logsViewerModalLogicActions {
fullScreen: boolean
id: string
initialFilters: Partial<LogsViewerFilters> | null
+ openedFrom: LogsViewerModalOrigin | null
personId: string | null
pinnedFilters: UniversalFiltersGroup | null
sessionId: string | null
@@ -73,6 +78,7 @@ export const logsViewerModalLogic = kea<logsViewerModalLogicType>([
pinnedFilters: options?.pinnedFilters ?? null,
personId: options?.personId ?? null,
sessionId: options?.sessionId ?? null,
+ openedFrom: options?.openedFrom ?? null,
}),
closeLogsViewerModal: true,
}),
@@ -126,6 +132,12 @@ export const logsViewerModalLogic = kea<logsViewerModalLogicType>([
openLogsViewerModal: (_, { sessionId }) => sessionId,
},
],
+ openedFrom: [
+ null as LogsViewerModalOrigin | null,
+ {
+ openLogsViewerModal: (_, { openedFrom }) => openedFrom,
+ },
+ ],
}),
listeners(({ values, actions, cache }) => ({
locationChanged: ({ pathname }) => {
diff --git a/products/logs/frontend/components/ViewLogsButton.tsx b/products/logs/frontend/components/ViewLogsButton.tsx
index 9a1c243a4c37..0915940a3404 100644
--- a/products/logs/frontend/components/ViewLogsButton.tsx
+++ b/products/logs/frontend/components/ViewLogsButton.tsx
@@ -5,17 +5,26 @@ import { LemonButton, LemonButtonProps } from '@posthog/lemon-ui'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
-import { logsViewerModalLogic } from 'products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic'
+import {
+ LogsViewerModalOrigin,
+ logsViewerModalLogic,
+} from 'products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic'
import { buildLogsSessionScope } from 'products/logs/frontend/utils'
export interface ViewLogsButtonProps extends Pick<LemonButtonProps, 'size' | 'type' | 'className' | 'data-attr'> {
sessionId: string | null | undefined
/** Scopes the logs date range around this time, so old sessions aren't hidden by the default range. */
timestamp?: string
+ /** Names where the modal was opened from, so it can say so and offer a way back. */
+ openedFrom: LogsViewerModalOrigin
iconOnly?: boolean
}
-export function useViewLogsButton({ sessionId, timestamp }: Pick<ViewLogsButtonProps, 'sessionId' | 'timestamp'>): {
+export function useViewLogsButton({
+ sessionId,
+ timestamp,
+ openedFrom,
+}: Pick<ViewLogsButtonProps, 'sessionId' | 'timestamp' | 'openedFrom'>): {
enabled: boolean
onClick: (() => void) | undefined
disabledReason: string | undefined
@@ -28,6 +37,7 @@ export function useViewLogsButton({ sessionId, timestamp }: Pick<ViewLogsButtonP
openLogsViewerModal({
id: `session-${sessionId}`,
fullScreen: false,
+ openedFrom,
...buildLogsSessionScope(sessionId, timestamp),
})
: undefined
@@ -43,10 +53,11 @@ export function useViewLogsButton({ sessionId, timestamp }: Pick<ViewLogsButtonP
export function ViewLogsButton({
sessionId,
timestamp,
+ openedFrom,
iconOnly,
...buttonProps
}: ViewLogsButtonProps): JSX.Element | null {
- const { enabled, onClick, disabledReason } = useViewLogsButton({ sessionId, timestamp })
+ const { enabled, onClick, disabledReason } = useViewLogsButton({ sessionId, timestamp, openedFrom })
if (!enabled) {
return null
diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts
index 9fe7ec3273d6..35b2fc450135 100644
--- a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts
+++ b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts
@@ -131,6 +131,9 @@ export interface traceDialogLogicActions {
fullScreen: boolean
id: string
initialFilters: Partial<LogsViewerFilters> | null
+ openedFrom:
+ | null
+ | import('products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic').LogsViewerModalOrigin
personId: string | null
pinnedFilters: UniversalFiltersGroup | null
sessionId: string | null
diff --git a/products/tracing/frontend/tracingViewerLogic.ts b/products/tracing/frontend/tracingViewerLogic.ts
index 0ad4a07c42c1..70a46332824c 100644
--- a/products/tracing/frontend/tracingViewerLogic.ts
+++ b/products/tracing/frontend/tracingViewerLogic.ts
@@ -91,6 +91,9 @@ export interface tracingViewerLogicActions {
initialFilters: Partial<
import('products/logs/frontend/components/LogsViewer/config/types').LogsViewerFilters
> | null
+ openedFrom:
+ | null
+ | import('products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic').LogsViewerModalOrigin
personId: string | null
pinnedFilters: null | import('~/types').UniversalFiltersGroup
sessionId: string | null