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(tracing): track trace dialog usage from open to close (#117065)

Jon McCallumfad710da714f
diff --git a/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx b/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx
index 13b7d5a75d19..6143d41705a9 100644
--- a/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx
@@ -16,6 +16,7 @@ import { logsConfigLogic } from 'products/logs/frontend/logsConfigLogic'
import { ParsedLogMessage } from 'products/logs/frontend/types'
import { getDistinctIdWithKey, getSessionIdFromLogAttributes } from 'products/logs/frontend/utils'
import { PersonDisplay } from 'products/persons/frontend/components/PersonDisplay'
+import type { TraceDialogEntryPoint } from 'products/tracing/frontend/components/TraceDialog/traceDialogLogic'
import { useOpenTraceDialog } from 'products/tracing/frontend/components/TraceDialog/useOpenTraceDialog'
import { type ErrorScope } from 'products/tracing/frontend/errorCorrelation'
@@ -31,6 +32,11 @@ const TRACE_DATA_ATTR: Record<LogContextLinksSurface, string> = {
row: 'logs-row-view-trace',
}
+const TRACE_DIALOG_ENTRY_POINT: Record<LogContextLinksSurface, TraceDialogEntryPoint> = {
+ drawer: 'log_details',
+ row: 'log_expanded_row',
+}
+
export interface LogContextLinksProps {
log: ParsedLogMessage
surface: LogContextLinksSurface
@@ -78,7 +84,10 @@ export function LogContextLinks({
openTraceDialog(
event,
{ traceId, spanId: log.span_id, ts: log.timestamp },
- { openedFrom: { body: log.cleanBody, severity: log.severity_text } }
+ {
+ entryPoint: TRACE_DIALOG_ENTRY_POINT[surface],
+ openedFrom: { body: log.cleanBody, severity: log.severity_text },
+ }
)
}
size="xsmall"
diff --git a/products/tracing/frontend/components/TraceDialog/TraceDialog.tsx b/products/tracing/frontend/components/TraceDialog/TraceDialog.tsx
index 639f4053fc37..3b1769fab340 100644
--- a/products/tracing/frontend/components/TraceDialog/TraceDialog.tsx
+++ b/products/tracing/frontend/components/TraceDialog/TraceDialog.tsx
@@ -51,7 +51,7 @@ export function TraceDialog(): JSX.Element | null {
traceIdentity,
traceSessionId,
} = useValues(traceDialogLogic)
- const { closeTraceDialog, loadTraceSpans, setInspectorTab } = useActions(traceDialogLogic)
+ const { closeTraceDialog, loadTraceSpans, setInspectorTab, openInTracing } = useActions(traceDialogLogic)
// The dialog sits above popovers, so the inspector's menus and drawers, and the person popover,
// portal inside it instead.
const [floatingContainer, setFloatingContainer] = useState<HTMLDivElement | null>(null)
@@ -64,7 +64,8 @@ export function TraceDialog(): JSX.Element | null {
return (
<LemonModal
isOpen={isOpen}
- onClose={closeTraceDialog}
+ // The close button hands onClose its click event, which must not land in the reason argument.
+ onClose={() => closeTraceDialog('dismissed')}
title={<span translate="no">{summary.rootSpan?.name ?? 'Trace'}</span>}
description={
<div className="flex flex-wrap items-center gap-2">
@@ -95,7 +96,7 @@ export function TraceDialog(): JSX.Element | null {
type="secondary"
icon={<IconExternal />}
to={traceUrl(trace)}
- onClick={closeTraceDialog}
+ onClick={openInTracing}
data-attr="trace-dialog-open-in-tracing"
>
Open in Tracing
diff --git a/products/tracing/frontend/components/TraceDialog/TraceDialogOpenedFromLog.tsx b/products/tracing/frontend/components/TraceDialog/TraceDialogOpenedFromLog.tsx
index c10acb752dca..a8d3a6a08d46 100644
--- a/products/tracing/frontend/components/TraceDialog/TraceDialogOpenedFromLog.tsx
+++ b/products/tracing/frontend/components/TraceDialog/TraceDialogOpenedFromLog.tsx
@@ -52,7 +52,12 @@ export function TraceDialogOpenedFromLog(): JSX.Element | null {
)}
</span>
)}
- <LemonButton size="xsmall" type="secondary" onClick={closeTraceDialog} data-attr="trace-dialog-back-to-log">
+ <LemonButton
+ size="xsmall"
+ type="secondary"
+ onClick={() => closeTraceDialog('back_to_log')}
+ data-attr="trace-dialog-back-to-log"
+ >
Back to log
</LemonButton>
</div>
diff --git a/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.test.tsx b/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.test.tsx
index 75d29f5f1be2..0dafadd05fe2 100644
--- a/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.test.tsx
+++ b/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.test.tsx
@@ -55,7 +55,7 @@ describe('TraceDialogSpanTree', () => {
const logic = traceDialogLogic()
logic.mount()
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'A' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'A' }, { entryPoint: 'log_details' })
}).toDispatchActions(['loadTraceSpansSuccess'])
const { container } = render(
diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts
index 2c0235d05be3..40839d1d651c 100644
--- a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts
+++ b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts
@@ -1,5 +1,6 @@
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
@@ -70,7 +71,7 @@ describe('traceDialogLogic', () => {
})
it('keeps the trace after close so the exit animation does not flash an empty dialog', async () => {
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'def456' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'def456' }, { entryPoint: 'log_details' })
await expectLogic(logic, () => {
logic.actions.closeTraceDialog()
@@ -82,7 +83,7 @@ describe('traceDialogLogic', () => {
['stays open on a hash-only change', '/logs#panel', true],
['closes on a new pathname', '/insights', false],
])('%s', async (_name, url, expectedOpen) => {
- logic.actions.openTraceDialog({ traceId: 'abc123' })
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
await expectLogic(logic, () => {
router.actions.push(url)
@@ -97,10 +98,10 @@ describe('traceDialogLogic', () => {
getTraceSpy.mockResolvedValueOnce({ results: [span('A1'), span('B1')], hasMore: false, nextOffset: null })
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: openedSpanId })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: openedSpanId }, { entryPoint: 'log_details' })
}).toDispatchActions(['loadTraceSpansSuccess'])
- expect(logic.values.selectedSpanId).toBe('B1')
+ expect(logic.values.selectedSpan?.span_id).toBe('B1')
})
it.each([
@@ -117,7 +118,7 @@ describe('traceDialogLogic', () => {
pages.forEach((p) => getTraceSpy.mockResolvedValueOnce(p))
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123' })
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
}).toDispatchActions(['loadTraceSpansSuccess'])
expect(logic.values.traceSpans?.spans.map((s) => s.span_id)).toEqual(expectedSpanIds)
@@ -129,7 +130,7 @@ describe('traceDialogLogic', () => {
let resolveFirstPage: (p: TracePage) => void = () => {}
getTraceSpy.mockReturnValueOnce(new Promise<TracePage>((resolve) => (resolveFirstPage = resolve)))
- logic.actions.openTraceDialog({ traceId: 'abc123' })
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
logic.actions.closeTraceDialog()
await expectLogic(logic, () => {
resolveFirstPage(page(['a'], 1))
@@ -142,9 +143,9 @@ describe('traceDialogLogic', () => {
let rejectFirstTrace: (error: Error) => void = () => {}
getTraceSpy.mockReturnValueOnce(new Promise<TracePage>((_, reject) => (rejectFirstTrace = reject)))
- logic.actions.openTraceDialog({ traceId: 'first' })
+ logic.actions.openTraceDialog({ traceId: 'first' }, { entryPoint: 'log_details' })
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'second' })
+ logic.actions.openTraceDialog({ traceId: 'second' }, { entryPoint: 'log_details' })
}).toDispatchActions(['loadTraceSpansSuccess'])
rejectFirstTrace(new Error('boom'))
@@ -164,7 +165,7 @@ describe('traceDialogLogic', () => {
nextOffset: null,
})
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'A1' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'A1' }, { entryPoint: 'log_details' })
}).toDispatchActions(['loadTraceSpansSuccess'])
logic.actions.toggleSpanCollapsed('A')
@@ -176,7 +177,7 @@ describe('traceDialogLogic', () => {
it('clears the failure once a retry succeeds', async () => {
getTraceSpy.mockRejectedValueOnce(new Error('boom'))
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123' })
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
})
.toDispatchActions(['loadTraceSpansFailure'])
.toMatchValues({ traceSpansFailed: true })
@@ -195,7 +196,7 @@ describe('traceDialogLogic', () => {
getTraceSpy.mockResolvedValueOnce({ results: [span('a', statusCode)], hasMore: false, nextOffset: null })
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' }, { entryPoint: 'log_details' })
})
.toDispatchActions(['loadTraceSpansSuccess'])
.toMatchValues({ activeInspectorTab: expectedTab })
@@ -203,7 +204,7 @@ describe('traceDialogLogic', () => {
it('keeps a picked tab across spans, and drops it for the next trace', async () => {
getTraceSpy.mockResolvedValue({ results: [span('a', 2), span('b')], hasMore: false, nextOffset: null })
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' }, { entryPoint: 'log_details' })
await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
logic.actions.setInspectorTab('attributes')
@@ -212,7 +213,7 @@ describe('traceDialogLogic', () => {
}).toMatchValues({ activeInspectorTab: 'attributes' })
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'def456', spanId: 'a' })
+ logic.actions.openTraceDialog({ traceId: 'def456', spanId: 'a' }, { entryPoint: 'log_details' })
})
.toDispatchActions(['loadTraceSpansSuccess'])
.toMatchValues({ activeInspectorTab: 'errors' })
@@ -221,7 +222,7 @@ describe('traceDialogLogic', () => {
it('treats a missing parent row as its own selection, not the root span', async () => {
const orphan = { ...span('child'), parent_span_id: 'GONE' }
getTraceSpy.mockResolvedValueOnce({ results: [span('a'), orphan], hasMore: false, nextOffset: null })
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' }, { entryPoint: 'log_details' })
await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
await expectLogic(logic, () => {
@@ -237,7 +238,7 @@ describe('traceDialogLogic', () => {
['a recording opens', () => sessionPlayerModalLogic.actions.openSessionPlayer({ id: 'session-1' })],
['the full-screen logs viewer opens', () => logsViewerModalLogic.actions.openLogsViewerModal()],
])('closes when %s, since that modal sits behind the dialog', async (_name, open) => {
- logic.actions.openTraceDialog({ traceId: 'abc123' })
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
await expectLogic(logic, open).toMatchValues({ isOpen: false })
})
@@ -245,13 +246,16 @@ describe('traceDialogLogic', () => {
it('drops the log from a previous open, so a later open has no stale strip or marker', async () => {
logic.actions.openTraceDialog(
{ traceId: 'abc123', ts: '2026-05-01T12:00:00.000Z' },
- { body: 'run_sql failed', severity: 'error' }
+ { entryPoint: 'log_details', openedFrom: { body: 'run_sql failed', severity: 'error' } }
)
expect(logic.values.openedAtUs).not.toBeNull()
// A metrics link passes a time near the trace, which is no point in it to mark.
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'def456', ts: '2026-05-01T12:00:00.000Z' })
+ logic.actions.openTraceDialog(
+ { traceId: 'def456', ts: '2026-05-01T12:00:00.000Z' },
+ { entryPoint: 'metric_exemplar' }
+ )
}).toMatchValues({ openedFrom: null, openedAtUs: null })
})
@@ -260,7 +264,7 @@ describe('traceDialogLogic', () => {
beforeEach(async () => {
getTraceSpy.mockResolvedValue({ results: [span('a'), span('b')], hasMore: false, nextOffset: null })
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' }, { entryPoint: 'log_details' })
await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
// Stands in for the logs list under the dialog, which binds J and K on window too.
pageListener = jest.fn()
@@ -286,7 +290,7 @@ describe('traceDialogLogic', () => {
it('steps onto a missing parent row and on past it', async () => {
const orphan = { ...span('b'), parent_span_id: 'GONE' }
getTraceSpy.mockResolvedValue({ results: [span('a'), orphan], hasMore: false, nextOffset: null })
- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' }, { entryPoint: 'log_details' })
await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
press('j')
@@ -346,9 +350,91 @@ describe('traceDialogLogic', () => {
}
await expectLogic(logic, () => {
- logic.actions.openTraceDialog({ traceId: 'abc123' })
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
})
.toDispatchActions(['loadTraceSpansSuccess'])
.toMatchValues({ traceIdentity: expectedIdentity })
})
+
+ describe('usage events', () => {
+ let captureSpy: jest.SpyInstance
+
+ beforeEach(() => {
+ captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)
+ })
+
+ afterEach(() => {
+ captureSpy.mockRestore()
+ })
+
+ const closeReasons = (): string[] =>
+ captureSpy.mock.calls
+ .filter(([event]) => event === 'tracing trace dialog closed')
+ .map(([, properties]) => properties.reason)
+
+ it.each([
+ ['dismissed', () => logic.actions.closeTraceDialog(), ['dismissed']],
+ ['back to log', () => logic.actions.closeTraceDialog('back_to_log'), ['back_to_log']],
+ ['navigated away', () => router.actions.push('/insights'), ['navigated']],
+ // The Open in Tracing link navigates too, but the close has to say why.
+ [
+ 'open in tracing',
+ () => {
+ logic.actions.openInTracing()
+ router.actions.push('/tracing')
+ },
+ ['open_in_tracing'],
+ ],
+ [
+ 'open in tracing without a pathname change',
+ () => {
+ logic.actions.openInTracing()
+ router.actions.push(router.values.location.pathname, { trace: 'abc123' })
+ expect(logic.values.isOpen).toBe(false)
+ },
+ ['open_in_tracing'],
+ ],
+ [
+ 'another trace opened over it',
+ () => logic.actions.openTraceDialog({ traceId: 'def456' }, { entryPoint: 'metric_sample' }),
+ // The second dialog closes on the final dismiss.
+ ['replaced', 'dismissed'],
+ ],
+ ])('records one close for %s', async (_name, exit, expectedReasons) => {
+ logic.actions.openTraceDialog({ traceId: 'abc123' }, { entryPoint: 'log_details' })
+ await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
+
+ exit()
+ // A second close of an already-closed dialog must not record another session.
+ logic.actions.closeTraceDialog()
+
+ expect(closeReasons()).toEqual(expectedReasons)
+ })
+
+ it('reports the entry point and how the person moved through the trace', async () => {
+ getTraceSpy.mockResolvedValue({ results: [span('a'), span('b')], hasMore: false, nextOffset: null })
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: 'a' }, { entryPoint: 'log_row_action' })
+ await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
+
+ logic.actions.selectNextSpan()
+ logic.actions.setInspectorTab('attributes')
+ logic.actions.closeTraceDialog()
+
+ expect(captureSpy).toHaveBeenCalledWith('tracing trace dialog opened', {
+ entry_point: 'log_row_action',
+ has_span: true,
+ has_log: false,
+ })
+ expect(captureSpy).toHaveBeenCalledWith(
+ 'tracing trace dialog closed',
+ expect.objectContaining({
+ entry_point: 'log_row_action',
+ reason: 'dismissed',
+ spans_selected: 1,
+ keyboard_steps: 1,
+ tabs_viewed: ['attributes'],
+ })
+ )
+ })
+ })
})
diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts
index a74394a74887..b13b5982ea84 100644
--- a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts
+++ b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts
@@ -2,6 +2,7 @@ import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, redu
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
import type { LocationChangedPayload } from 'kea-router/lib/types'
+import posthog from 'posthog-js'
import api from 'lib/api'
import type { TraceLinkParams } from 'lib/components/ViewTraceButton/traceUrl'
@@ -70,6 +71,42 @@ export interface TraceDialogSource {
severity: LogSeverityLevel
}
+/** Where a trace dialog was opened from. Sent with every dialog event, so keep the values stable. */
+export type TraceDialogEntryPoint =
+ | 'log_details'
+ | 'log_expanded_row'
+ | 'log_row_action'
+ | 'log_trace_id_cell'
+ | 'metric_sample'
+ | 'metric_exemplar'
+
+export type TraceDialogCloseReason = 'dismissed' | 'back_to_log' | 'open_in_tracing' | 'navigated' | 'replaced'
+
+export interface OpenTraceDialogOptions {
+ entryPoint: TraceDialogEntryPoint
+ openedFrom?: TraceDialogSource | null
+}
+
+interface TraceDialogSession {
+ entryPoint: TraceDialogEntryPoint
+ openedAtMs: number
+ loadStartedAtMs: number
+ spansSelected: number
+ keyboardSteps: number
+ tabsViewed: Set<SpanInspectorTab>
+}
+
+function captureClosed(session: TraceDialogSession, reason: TraceDialogCloseReason): void {
+ posthog.capture('tracing trace dialog closed', {
+ entry_point: session.entryPoint,
+ reason,
+ seconds_open: Math.round((Date.now() - session.openedAtMs) / 1000),
+ spans_selected: session.spansSelected,
+ keyboard_steps: session.keyboardSteps,
+ tabs_viewed: [...session.tabsViewed],
+ })
+}
+
export interface TraceDialogTimeline {
startUs: number
durationUs: number
@@ -155,8 +192,8 @@ export interface traceDialogLogicActions {
modalContext: SessionPlayerModalContext
sessionRecording: Pick<SessionRecordingType, 'id' | 'matching_events'>
} // sessionPlayerModalLogic
- closeTraceDialog: () => {
- value: true
+ closeTraceDialog: (reason?: TraceDialogCloseReason) => {
+ reason: TraceDialogCloseReason
}
loadTraceSpans: (trace: TraceLinkParams) => TraceLinkParams
loadTraceSpansFailure: (
@@ -173,10 +210,14 @@ export interface traceDialogLogicActions {
traceSpans: TraceDialogSpans | null
payload?: TraceLinkParams
}
+ openInTracing: () => {
+ value: true
+ }
openTraceDialog: (
trace: TraceLinkParams,
- openedFrom?: TraceDialogSource | null
+ options: OpenTraceDialogOptions
) => {
+ entryPoint: TraceDialogEntryPoint
openedFrom: TraceDialogSource | null
trace: {
spanId: string | null
@@ -277,13 +318,15 @@ export const traceDialogLogic = kea<traceDialogLogicType>([
],
})),
actions({
- openTraceDialog: (trace: TraceLinkParams, openedFrom?: TraceDialogSource | null) => ({
+ openTraceDialog: (trace: TraceLinkParams, options: OpenTraceDialogOptions) => ({
trace: { ...trace, spanId: inApiCase(trace.spanId) },
- openedFrom: openedFrom ?? null,
+ openedFrom: options.openedFrom ?? null,
+ entryPoint: options.entryPoint,
}),
+ openInTracing: true,
selectNextSpan: true,
selectPreviousSpan: true,
- closeTraceDialog: true,
+ closeTraceDialog: (reason: TraceDialogCloseReason = 'dismissed') => ({ reason }),
selectSpan: (spanId: string) => ({ spanId }),
toggleSpanCollapsed: (spanId: string) => ({ spanId }),
showAllChildren: (spanId: string) => ({ spanId }),
@@ -535,8 +578,27 @@ export const traceDialogLogic = kea<traceDialogLogicType>([
openedFrom && trace?.ts && dayjs(trace.ts).isValid() ? parseTimestampUs(trace.ts) : null,
],
}),
+ // pinned: analytics event names and properties. Renaming one breaks the dashboards built on it.
listeners(({ values, actions, cache }) => ({
- openTraceDialog: ({ trace }) => {
+ openTraceDialog: ({ trace, openedFrom, entryPoint }) => {
+ // Opening another trace over an open dialog ends the first session.
+ if (cache.session) {
+ captureClosed(cache.session, 'replaced')
+ }
+ const session: TraceDialogSession = {
+ entryPoint,
+ openedAtMs: Date.now(),
+ loadStartedAtMs: Date.now(),
+ spansSelected: 0,
+ keyboardSteps: 0,
+ tabsViewed: new Set(),
+ }
+ cache.session = session
+ posthog.capture('tracing trace dialog opened', {
+ entry_point: entryPoint,
+ has_span: !!trace.spanId,
+ has_log: !!openedFrom,
+ })
actions.loadTraceSpans(trace)
// Capture phase, and stopped there, so the page under the dialog does not also act on
// the key: with log details open, the logs list binds J and K to its own cursor.
@@ -563,10 +625,52 @@ export const traceDialogLogic = kea<traceDialogLogicType>([
return () => window.removeEventListener('keydown', onKeyDown, { capture: true })
}, 'spanKeys')
},
- closeTraceDialog: () => {
+ closeTraceDialog: ({ reason }) => {
cache.disposables.dispose('spanKeys')
+ const session: TraceDialogSession | undefined = cache.session
+ if (!session) {
+ return
+ }
+ cache.session = undefined
+ captureClosed(session, reason)
+ },
+ openInTracing: () => {
+ // Close here rather than on navigation: from /tracing itself the link only changes the query.
+ actions.closeTraceDialog('open_in_tracing')
+ },
+ loadTraceSpans: () => {
+ if (cache.session) {
+ cache.session.loadStartedAtMs = Date.now()
+ }
+ },
+ loadTraceSpansSuccess: ({ traceSpans }) => {
+ if (!cache.session || !traceSpans) {
+ return
+ }
+ posthog.capture('tracing trace dialog loaded', {
+ entry_point: cache.session.entryPoint,
+ span_count: traceSpans.spans.length,
+ truncated: traceSpans.truncated,
+ load_ms: Date.now() - cache.session.loadStartedAtMs,
+ })
+ },
+ loadTraceSpansFailure: () => {
+ if (cache.session) {
+ posthog.capture('tracing trace dialog load failed', { entry_point: cache.session.entryPoint })
+ }
+ },
+ selectSpan: () => {
+ if (cache.session) {
+ cache.session.spansSelected += 1
+ }
+ },
+ setInspectorTab: ({ tab }) => {
+ cache.session?.tabsViewed.add(tab)
},
selectNextSpan: () => {
+ if (cache.session) {
+ cache.session.keyboardSteps += 1
+ }
// A missing-parent row is selectable too, so step from it rather than from the root fallback.
const currentId = values.missingParentSpanId ?? values.selectedSpan?.span_id
const index = values.flatSpans.findIndex((node) => node.span.span_id === currentId)
@@ -576,6 +680,9 @@ export const traceDialogLogic = kea<traceDialogLogicType>([
}
},
selectPreviousSpan: () => {
+ if (cache.session) {
+ cache.session.keyboardSteps += 1
+ }
const currentId = values.missingParentSpanId ?? values.selectedSpan?.span_id
const index = values.flatSpans.findIndex((node) => node.span.span_id === currentId)
const previous = values.flatSpans[Math.max(index - 1, 0)]
@@ -615,7 +722,7 @@ export const traceDialogLogic = kea<traceDialogLogicType>([
}
cache.lastPathname = pathname
if (values.isOpen) {
- actions.closeTraceDialog()
+ actions.closeTraceDialog('navigated')
}
},
})),
diff --git a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx
index 400b834cd6a8..641aa52262ba 100644
--- a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx
+++ b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx
@@ -20,7 +20,9 @@ function DialogTraceButton(): JSX.Element | null {
<ViewTraceButton
traceId="abc123"
spanId="def456"
- onClick={(event) => openTraceDialog(event, { traceId: 'abc123', spanId: 'def456' })}
+ onClick={(event) =>
+ openTraceDialog(event, { traceId: 'abc123', spanId: 'def456' }, { entryPoint: 'log_details' })
+ }
/>
)
}
diff --git a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts
index dfedb49f7023..b455a7fb3561 100644
--- a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts
+++ b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts
@@ -3,17 +3,12 @@ import { type MouseEvent, useCallback } from 'react'
import type { TraceLinkParams } from 'lib/components/ViewTraceButton/traceUrl'
-import { type TraceDialogSource, traceDialogLogic } from './traceDialogLogic'
-
-export interface OpenTraceDialogOptions {
- /** The log the link sits on, shown in the dialog as the reason the trace was opened. */
- openedFrom?: TraceDialogSource | null
-}
+import { type OpenTraceDialogOptions, traceDialogLogic } from './traceDialogLogic'
export type OpenTraceDialogHandler = (
event: MouseEvent | null,
trace: TraceLinkParams,
- options?: OpenTraceDialogOptions
+ options: OpenTraceDialogOptions
) => boolean
/**
@@ -35,7 +30,7 @@ export function useOpenTraceDialog(): OpenTraceDialogHandler {
return false
}
event?.preventDefault()
- openTraceDialog(trace, options?.openedFrom)
+ openTraceDialog(trace, options)
return true
},
[dialogEnabled, openTraceDialog]