: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
perf(tracing): load the trace dialog logic only when the dialog opens (#126311)
Paul D'Ambra8f68c442bb5a
diff --git a/frontend/src/layout/GlobalModals.tsx b/frontend/src/layout/GlobalModals.tsxindex 276afb3eeb35..08c4a37a6592 100644--- a/frontend/src/layout/GlobalModals.tsx+++ b/frontend/src/layout/GlobalModals.tsx@@ -26,7 +26,7 @@ import { MaybeWelcomeDialog } from 'scenes/welcome/WelcomeDialog'import { composeTicketLogic } from 'products/conversations/frontend/components/ComposeTicket/composeTicketLogic'import { logsViewerModalLogic } from 'products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic'-import { traceDialogLogic } from 'products/tracing/frontend/components/TraceDialog/traceDialogLogic'+import { traceDialogOpenLogic } from 'products/tracing/frontend/components/TraceDialog/traceDialogOpenLogic'import { globalModalsLogic } from './globalModalsLogic'@@ -66,7 +66,7 @@ export function GlobalModals(): JSX.Element {// Grace-extended so the modals' exit animations finish before the lazy subtree unmounts.const shouldRenderSessionPlayerModal = useKeepMountedWhileOpen(!!activeSessionRecording)const shouldRenderLogsViewerModal = useKeepMountedWhileOpen(isLogsViewerModalOpen)- const { isOpen: isTraceDialogOpen } = useValues(traceDialogLogic)+ const { isOpen: isTraceDialogOpen } = useValues(traceDialogOpenLogic)const shouldRenderTraceDialog = useKeepMountedWhileOpen(isTraceDialogOpen)const { isOpen: isComposeTicketModalOpen } = useValues(composeTicketLogic)const shouldRenderComposeTicketModal = useKeepMountedWhileOpen(isComposeTicketModalOpen)diff --git a/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx b/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsxindex 6143d41705a9..1e56daa3da76 100644--- a/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx+++ b/products/logs/frontend/components/LogsViewer/LogContextLinks/LogContextLinks.tsx@@ -16,7 +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 type { TraceDialogEntryPoint } from 'products/tracing/frontend/components/TraceDialog/traceDialogOpenLogic'import { useOpenTraceDialog } from 'products/tracing/frontend/components/TraceDialog/useOpenTraceDialog'import { type ErrorScope } from 'products/tracing/frontend/errorCorrelation'diff --git a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx b/products/logs/frontend/components/LogsViewer/LogsViewer.tsxindex 5f01a085c4f6..e18d13ea9388 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx+++ b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx@@ -22,7 +22,7 @@ import { logsExportLogic } from 'products/logs/frontend/components/LogsViewer/loimport { QueryFailedOverlay } from 'products/logs/frontend/components/QueryFailedOverlay'import { VirtualizedLogsList } from 'products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList'import { virtualizedLogsListLogic } from 'products/logs/frontend/components/VirtualizedLogsList/virtualizedLogsListLogic'-import { traceDialogLogic } from 'products/tracing/frontend/components/TraceDialog/traceDialogLogic'+import { traceDialogOpenLogic } from 'products/tracing/frontend/components/TraceDialog/traceDialogOpenLogic'import { LogDetailsModal } from './LogDetailsModal'import { logDetailsModalLogic } from './LogDetailsModal/logDetailsModalLogic'@@ -144,7 +144,7 @@ function LogsViewerContent({togglePrettifyLog,} = useActions(logsViewerLogic)const { orderBy, sparklineCollapsed, facetRailCollapsed, viewMode } = useValues(logsViewerConfigLogic)- const { isOpen: isTraceDialogOpen } = useValues(traceDialogLogic)+ const { isOpen: isTraceDialogOpen } = useValues(traceDialogOpenLogic)const { setOrderBy, toggleSparklineCollapsed } = useActions(logsViewerConfigLogic)const {logsLoading,diff --git a/products/tracing/frontend/components/TraceDialog/TraceDialogSpanRow.tsx b/products/tracing/frontend/components/TraceDialog/TraceDialogSpanRow.tsxindex c6b3ff8bf0de..4bfa6a1615ff 100644--- a/products/tracing/frontend/components/TraceDialog/TraceDialogSpanRow.tsx+++ b/products/tracing/frontend/components/TraceDialog/TraceDialogSpanRow.tsx@@ -11,8 +11,8 @@ import { parseTimestampUs } from 'products/tracing/frontend/spanTree'import { formatDuration } from 'products/tracing/frontend/TraceWaterfallView'import type { TraceRunToggleMethod, TraceViewTimeline } from '../TraceView/traceViewLogic'-import type { TraceDialogSource } from './traceDialogLogic'import { LOG_MARK_TAG_TYPE, TraceDialogLogMark } from './TraceDialogLogMark'+import type { TraceDialogSource } from './traceDialogOpenLogic'import { summarizeRun, type TraceDialogRow } from './traceDialogRows'import { indentPx, MAX_VISUAL_DEPTH, TraceDialogTreeLines } from './TraceDialogTreeLines'diff --git a/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.tsx b/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.tsxindex 17fa9567c78d..7a07f117bafb 100644--- a/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.tsx+++ b/products/tracing/frontend/components/TraceDialog/TraceDialogSpanTree.tsx@@ -15,8 +15,8 @@ import {type TraceViewSurface,type TraceViewTimeline,} from '../TraceView/traceViewLogic'-import type { TraceDialogSource } from './traceDialogLogic'import { TraceDialogMoreSpansRow } from './TraceDialogMoreSpansRow'+import type { TraceDialogSource } from './traceDialogOpenLogic'import { rowSpanNode, type TraceDialogRow } from './traceDialogRows'import { TraceDialogSpanRow } from './TraceDialogSpanRow'diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.tsindex 731df8a67f10..03b55e8b622b 100644--- a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts+++ b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts@@ -16,6 +16,7 @@ import type { Span } from 'products/tracing/frontend/types'import { traceViewLogic } from '../TraceView/traceViewLogic'import { TRACE_DIALOG_VIEW_ID, traceDialogLogic } from './traceDialogLogic'+import { traceDialogOpenLogic } from './traceDialogOpenLogic'type TracePage = Awaited<ReturnType<typeof api.tracing.getTrace>>@@ -96,16 +97,30 @@ describe('traceDialogLogic', () => {})it.each([- ['an id in the API case', 'B1'],+ ['an id in the API case', 'B1', false],// Logs carry lowercase hex, and the trace API returns uppercase.- ['a lowercase hex id from a log', 'b1'],- ])('selects the span the dialog was opened from, given %s', async (_name, openedSpanId) => {+ ['a lowercase hex id from a log', 'b1', false],+ // The lazy dialog mounts this logic only after a caller has opened it.+ ['a dialog that mounts after the open', 'b1', true],+ ])('selects the span the dialog was opened from, given %s', async (_name, openedSpanId, mountsAfterOpen) => {getTraceSpy.mockResolvedValueOnce({ results: [span('A1'), span('B1')], hasMore: false, nextOffset: null })+ if (mountsAfterOpen) {+ traceDialogOpenLogic.mount()+ logic.unmount()+ logic = traceDialogLogic()+ }await expectLogic(logic, () => {- logic.actions.openTraceDialog({ traceId: 'abc123', spanId: openedSpanId }, { entryPoint: 'log_details' })+ traceDialogOpenLogic.actions.openTraceDialog(+ { traceId: 'abc123', spanId: openedSpanId },+ { entryPoint: 'log_details' }+ )+ if (mountsAfterOpen) {+ logic.mount()+ }}).toDispatchActions(['loadTraceSpansSuccess'])+ expect(getTraceSpy).toHaveBeenCalledWith('abc123', expect.anything())expect(view.values.selectedSpan?.span_id).toBe('B1')})diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.tsindex 07590a466df0..014fdf79d6f5 100644--- a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts+++ b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.ts@@ -1,28 +1,11 @@import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'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'-import { usableId } from 'lib/components/ViewTraceButton/usableId'-import { FEATURE_FLAGS } from 'lib/constants'import { dayjs } from 'lib/dayjs'-import { type FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'-import {- type SessionPlayerModalContext,- sessionPlayerModalLogic,-} from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'--import type { LogSeverityLevel } from '~/queries/schema/schema-general'-import type { SessionRecordingType, UniversalFiltersGroup } from '~/types'-import type { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'-import {- type OpenLogsViewerModalOptions,- logsViewerModalLogic,-} from 'products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic'import { parseTimestampUs } from 'products/tracing/frontend/spanTree'import {EMPTY_TRACE_IDENTITY,@@ -36,6 +19,12 @@ import { tracingCorrelationConfigLogic } from 'products/tracing/frontend/tracingimport type { Span, SpanInspectorTab, TraceViewMode } from 'products/tracing/frontend/types'import { traceViewLogic } from '../TraceView/traceViewLogic'+import {+ type TraceDialogCloseReason,+ type TraceDialogEntryPoint,+ type TraceDialogSource,+ traceDialogOpenLogic,+} from './traceDialogOpenLogic'// The trace endpoint pages at 2,000 spans, so this caps the dialog at 10,000. Bigger traces open in// Tracing, which pages in on scroll.@@ -47,42 +36,11 @@ const TRACE_DIALOG_SELECTOR = `[data-attr="${TRACE_DIALOG_DATA_ATTR}"]`export const TRACE_DIALOG_VIEW_ID = 'trace-dialog'-// The trace API returns hex span ids in uppercase, and logs and metrics carry them in lowercase. The-// dialog matches the opened span against the loaded spans exactly, so it keeps the API's case.-function inApiCase(spanId: string | null | undefined): string | null {- if (!spanId) {- return null- }- return usableId(spanId) ? spanId.toUpperCase() : spanId-}-export interface TraceDialogSpans {spans: Span[]truncated: boolean}-/** The log the dialog was opened from, shown above the tree so the reason for the trace stays in view. */-export interface TraceDialogSource {- body: string- 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: TraceDialogEntryPointopenedAtMs: number@@ -107,19 +65,18 @@ function captureClosed(session: TraceDialogSession, reason: TraceDialogCloseReas// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface traceDialogLogicValues {- featureFlags: FeatureFlagsSet // featureFlagLogic+ entryPoint: TraceDialogEntryPoint | null // traceDialogOpenLogic+ isOpen: boolean // traceDialogOpenLogic+ openedFrom: TraceDialogSource | null // traceDialogOpenLogic+ trace: TraceLinkParams | null // traceDialogOpenLogictraceViewMode: TraceViewMode // tracingConfigLogicconfiguredDistinctIdKeys: string[] | undefined // tracingCorrelationConfigLogicconfiguredSessionIdKeys: string[] | undefined // tracingCorrelationConfigLogiccorrelationLinksEnabled: boolean // tracingCorrelationConfigLogicsessionErrorBadgesEnabled: boolean // tracingCorrelationConfigLogic- dialogEnabled: booleaninspectorOpen: booleanisFullscreen: boolean- isOpen: booleanopenedAtUs: number | null- openedFrom: TraceDialogSource | null- trace: TraceLinkParams | nulltraceIdentity: TraceIdentitytraceSessionId: string | nulltraceSpans: TraceDialogSpans | null@@ -129,47 +86,21 @@ export interface traceDialogLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface traceDialogLogicActions {- openLogsViewerModal: (options?: OpenLogsViewerModalOptions | undefined) => {- 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- } // logsViewerModalLogic- locationChanged: ({- method,- pathname,- search,- searchParams,- hash,- hashParams,- initial,- url,- routerState,- }: LocationChangedPayload) => {- hash: string- hashParams: Record<string, any>- initial: boolean- method: 'POP' | 'PUSH' | 'REPLACE'- pathname: string- routerState: Record<string, any>- search: string- searchParams: Record<string, any>- url: string- } // router- openSessionPlayer: (- sessionRecording: Pick<SessionRecordingType, 'id' | 'matching_events'>,- initialTimestamp?: number | null | undefined,- modalContext?: SessionPlayerModalContext | undefined+ closeTraceDialog: (reason?: TraceDialogCloseReason | undefined) => {+ reason: TraceDialogCloseReason+ } // traceDialogOpenLogic+ openTraceDialog: (+ trace: TraceLinkParams,+ options: import('./traceDialogOpenLogic').OpenTraceDialogOptions) => {- initialTimestamp: number | null- modalContext: SessionPlayerModalContext- sessionRecording: Pick<SessionRecordingType, 'id' | 'matching_events'>- } // sessionPlayerModalLogic+ entryPoint: TraceDialogEntryPoint+ openedFrom: TraceDialogSource | null+ trace: {+ spanId: string | null+ traceId: string+ ts?: string | null | undefined+ }+ } // traceDialogOpenLogiccollapseSelectedSpan: (surface: import('../TraceView/traceViewLogic').TraceViewSurface) => {surface: import('../TraceView/traceViewLogic').TraceViewSurface} // traceViewLogic@@ -230,9 +161,6 @@ export interface traceDialogLogicActions {toggleSpanCollapsed: (spanId: string) => {spanId: string} // traceViewLogic- closeTraceDialog: (reason?: TraceDialogCloseReason) => {- reason: TraceDialogCloseReason- }loadTraceSpans: (trace: TraceLinkParams) => TraceLinkParamsloadTraceSpansFailure: (error: string,@@ -251,17 +179,8 @@ export interface traceDialogLogicActions {openInTracing: () => {value: true}- openTraceDialog: (- trace: TraceLinkParams,- options: OpenTraceDialogOptions- ) => {- entryPoint: TraceDialogEntryPoint- openedFrom: TraceDialogSource | null- trace: {- spanId: string | null- traceId: string- ts?: string | null | undefined- }+ startSession: () => {+ value: true}toggleFullscreen: () => {value: true@@ -274,7 +193,6 @@ export interface traceDialogLogicActions {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface traceDialogLogicMeta {__keaTypeGenInternalSelectorTypes: {- dialogEnabled: (featureFlags: FeatureFlagsSet) => booleantraceIdentity: (traceSpans: TraceDialogSpans | null,configuredDistinctIdKeys: string[] | undefined,@@ -301,12 +219,8 @@ export const traceDialogLogic = kea<traceDialogLogicType>([path(['products', 'tracing', 'frontend', 'components', 'TraceDialog', 'traceDialogLogic']),connect(() => ({actions: [- router,- ['locationChanged'],- sessionPlayerModalLogic,- ['openSessionPlayer'],- logsViewerModalLogic,- ['openLogsViewerModal'],+ traceDialogOpenLogic,+ ['openTraceDialog', 'closeTraceDialog'],traceViewLogic({ id: TRACE_DIALOG_VIEW_ID }),['showTrace',@@ -326,6 +240,8 @@ export const traceDialogLogic = kea<traceDialogLogicType>([],],values: [+ traceDialogOpenLogic,+ ['isOpen', 'trace', 'openedFrom', 'entryPoint'],tracingCorrelationConfigLogic,['configuredDistinctIdKeys',@@ -333,20 +249,13 @@ export const traceDialogLogic = kea<traceDialogLogicType>(['correlationLinksEnabled','sessionErrorBadgesEnabled',],- featureFlagLogic,- ['featureFlags'],tracingConfigLogic,['traceViewMode'],],})),actions({- openTraceDialog: (trace: TraceLinkParams, options: OpenTraceDialogOptions) => ({- trace: { ...trace, spanId: inApiCase(trace.spanId) },- openedFrom: options.openedFrom ?? null,- entryPoint: options.entryPoint,- }),+ startSession: true,openInTracing: true,- closeTraceDialog: (reason: TraceDialogCloseReason = 'dismissed') => ({ reason }),toggleInspector: true,toggleFullscreen: true,}),@@ -386,30 +295,9 @@ export const traceDialogLogic = kea<traceDialogLogicType>([],})),reducers({- isOpen: [- false,- {- openTraceDialog: () => true,- closeTraceDialog: () => false,- },- ],- // Survives close: useKeepMountedWhileOpen keeps the dialog rendered through its exit- // animation, and clearing the trace then would flash an empty dialog.- trace: [- null as TraceLinkParams | null,- {- openTraceDialog: (_, { trace }) => trace,- },- ],traceSpans: {openTraceDialog: () => null,},- openedFrom: [- null as TraceDialogSource | null,- {- openTraceDialog: (_, { openedFrom }) => openedFrom,- },- ],traceSpansFailed: [false,{@@ -433,12 +321,6 @@ export const traceDialogLogic = kea<traceDialogLogicType>([],}),selectors({- // Every entry point checks this one place, so the flag cannot open the dialog from some- // links and not others.- dialogEnabled: [- (s) => [s.featureFlags],- (featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.TRACING_TRACE_DIALOG],- ],// A truncated trace may hold a second, conflicting person on a page the dialog never// loaded, so it names no one rather than risk naming the wrong one.traceIdentity: [@@ -477,7 +359,14 @@ export const traceDialogLogic = kea<traceDialogLogicType>([}),// pinned: analytics event names and properties. Renaming one breaks the dashboards built on it.listeners(({ values, actions, cache }) => ({- openTraceDialog: ({ trace, openedFrom, entryPoint }) => {+ openTraceDialog: () => {+ actions.startSession()+ },+ startSession: () => {+ const { trace, openedFrom, entryPoint } = values+ if (!trace || !entryPoint) {+ return+ }// Opening another trace over an open dialog ends the first session.if (cache.session) {captureClosed(cache.session, 'replaced')@@ -500,7 +389,7 @@ export const traceDialogLogic = kea<traceDialogLogicType>([// as a call tree.view: values.traceViewMode,})- actions.showTrace(trace.spanId, null)+ actions.showTrace(trace.spanId ?? null, null)actions.loadTraceSpans(trace)actions.enableSpanKeys(TRACE_DIALOG_SELECTOR, 'trace_dialog')},@@ -567,30 +456,12 @@ export const traceDialogLogic = kea<traceDialogLogicType>([cache.session.collapseToggles += 1}},- // The player and the full-screen logs viewer are global modals that can sit below this one,- // so opening either from the inspector would put it behind the dialog.- openSessionPlayer: () => {- if (values.isOpen) {- actions.closeTraceDialog()- }- },- openLogsViewerModal: () => {- if (values.isOpen) {- actions.closeTraceDialog()- }- },- locationChanged: ({ pathname }) => {- // Query and hash changes fire locationChanged too, so only a new pathname closes the dialog.- if (pathname === cache.lastPathname) {- return- }- cache.lastPathname = pathname- if (values.isOpen) {- actions.closeTraceDialog('navigated')- }- },})),- afterMount(({ cache }) => {- cache.lastPathname = router.values.location.pathname+ afterMount(({ values, actions }) => {+ // The dialog mounts this logic after traceDialogOpenLogic opens it, so the open action has+ // already gone by and the session starts here.+ if (values.isOpen) {+ actions.startSession()+ }}),])diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogOpenLogic.ts b/products/tracing/frontend/components/TraceDialog/traceDialogOpenLogic.tsnew file mode 100644index 000000000000..47c0a436f939--- /dev/null+++ b/products/tracing/frontend/components/TraceDialog/traceDialogOpenLogic.ts@@ -0,0 +1,227 @@+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { router } from 'kea-router'+import type { LocationChangedPayload } from 'kea-router/lib/types'++import type { TraceLinkParams } from 'lib/components/ViewTraceButton/traceUrl'+import { usableId } from 'lib/components/ViewTraceButton/usableId'+import { FEATURE_FLAGS } from 'lib/constants'+import { type FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'++import type { LogSeverityLevel } from '~/queries/schema/schema-general'++import { logsViewerModalLogic } from 'products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic'++/** The log the dialog was opened from, shown above the tree so the reason for the trace stays in view. */+export interface TraceDialogSource {+ body: string+ 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+}++// The trace API returns hex span ids in uppercase, and logs and metrics carry them in lowercase. The+// dialog matches the opened span against the loaded spans exactly, so it keeps the API's case.+function inApiCase(spanId: string | null | undefined): string | null {+ if (!spanId) {+ return null+ }+ return usableId(spanId) ? spanId.toUpperCase() : spanId+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface traceDialogOpenLogicValues {+ featureFlags: FeatureFlagsSet // featureFlagLogic+ dialogEnabled: boolean+ entryPoint: TraceDialogEntryPoint | null+ isOpen: boolean+ openedFrom: TraceDialogSource | null+ trace: TraceLinkParams | null+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface traceDialogOpenLogicActions {+ openLogsViewerModal: (+ options?:+ | import('products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic').OpenLogsViewerModalOptions+ | undefined+ ) => {+ fullScreen: boolean+ id: string+ 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+ } // logsViewerModalLogic+ locationChanged: ({+ method,+ pathname,+ search,+ searchParams,+ hash,+ hashParams,+ initial,+ url,+ routerState,+ }: LocationChangedPayload) => {+ hash: string+ hashParams: Record<string, any>+ initial: boolean+ method: 'POP' | 'PUSH' | 'REPLACE'+ pathname: string+ routerState: Record<string, any>+ search: string+ searchParams: Record<string, any>+ url: string+ } // router+ openSessionPlayer: (+ sessionRecording: Pick<import('~/types').SessionRecordingType, 'id' | 'matching_events'>,+ initialTimestamp?: number | null | undefined,+ modalContext?:+ | import('scenes/session-recordings/player/modal/sessionPlayerModalLogic').SessionPlayerModalContext+ | undefined+ ) => {+ initialTimestamp: number | null+ modalContext: import('scenes/session-recordings/player/modal/sessionPlayerModalLogic').SessionPlayerModalContext+ sessionRecording: Pick<import('~/types').SessionRecordingType, 'id' | 'matching_events'>+ } // sessionPlayerModalLogic+ closeTraceDialog: (reason?: TraceDialogCloseReason) => {+ reason: TraceDialogCloseReason+ }+ openTraceDialog: (+ trace: TraceLinkParams,+ options: OpenTraceDialogOptions+ ) => {+ entryPoint: TraceDialogEntryPoint+ openedFrom: TraceDialogSource | null+ trace: {+ spanId: string | null+ traceId: string+ ts?: string | null | undefined+ }+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface traceDialogOpenLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ dialogEnabled: (featureFlags: FeatureFlagsSet) => boolean+ }+}++export type traceDialogOpenLogicType = MakeLogicType<+ traceDialogOpenLogicValues,+ traceDialogOpenLogicActions,+ Record<string, any>,+ traceDialogOpenLogicMeta+>++/**+ * Whether the trace dialog is open, and which trace it shows. Every logged-in page mounts this logic,+ * so it must not import the trace view. traceDialogLogic loads the trace when the dialog mounts.+ */+export const traceDialogOpenLogic = kea<traceDialogOpenLogicType>([+ path(['products', 'tracing', 'frontend', 'components', 'TraceDialog', 'traceDialogOpenLogic']),+ connect(() => ({+ actions: [+ router,+ ['locationChanged'],+ sessionPlayerModalLogic,+ ['openSessionPlayer'],+ logsViewerModalLogic,+ ['openLogsViewerModal'],+ ],+ values: [featureFlagLogic, ['featureFlags']],+ })),+ actions({+ openTraceDialog: (trace: TraceLinkParams, options: OpenTraceDialogOptions) => ({+ trace: { ...trace, spanId: inApiCase(trace.spanId) },+ openedFrom: options.openedFrom ?? null,+ entryPoint: options.entryPoint,+ }),+ closeTraceDialog: (reason: TraceDialogCloseReason = 'dismissed') => ({ reason }),+ }),+ reducers({+ isOpen: [+ false,+ {+ openTraceDialog: () => true,+ closeTraceDialog: () => false,+ },+ ],+ // Survives close: useKeepMountedWhileOpen keeps the dialog rendered through its exit+ // animation, and clearing the trace then would flash an empty dialog.+ trace: [+ null as TraceLinkParams | null,+ {+ openTraceDialog: (_, { trace }) => trace,+ },+ ],+ openedFrom: [+ null as TraceDialogSource | null,+ {+ openTraceDialog: (_, { openedFrom }) => openedFrom,+ },+ ],+ entryPoint: [+ null as TraceDialogEntryPoint | null,+ {+ openTraceDialog: (_, { entryPoint }) => entryPoint,+ },+ ],+ }),+ selectors({+ // Every entry point checks this one place, so the flag cannot open the dialog from some+ // links and not others.+ dialogEnabled: [+ (s) => [s.featureFlags],+ (featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.TRACING_TRACE_DIALOG],+ ],+ }),+ listeners(({ values, actions, cache }) => ({+ // The player and the full-screen logs viewer are global modals that can sit below this one,+ // so opening either from the inspector would put it behind the dialog.+ openSessionPlayer: () => {+ if (values.isOpen) {+ actions.closeTraceDialog()+ }+ },+ openLogsViewerModal: () => {+ if (values.isOpen) {+ actions.closeTraceDialog()+ }+ },+ locationChanged: ({ pathname }) => {+ // Query and hash changes fire locationChanged too, so only a new pathname closes the dialog.+ if (pathname === cache.lastPathname) {+ return+ }+ cache.lastPathname = pathname+ if (values.isOpen) {+ actions.closeTraceDialog('navigated')+ }+ },+ })),+ afterMount(({ cache }) => {+ cache.lastPathname = router.values.location.pathname+ }),+])diff --git a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsxindex 641aa52262ba..ddda07c80594 100644--- a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx+++ b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.test.tsx@@ -11,7 +11,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { initKeaTests } from '~/test/init'import { AccessControlLevel, AccessControlResourceType, AppContext } from '~/types'-import { traceDialogLogic } from './traceDialogLogic'+import { traceDialogOpenLogic } from './traceDialogOpenLogic'import { useOpenTraceDialog } from './useOpenTraceDialog'function DialogTraceButton(): JSX.Element | null {@@ -51,7 +51,7 @@ describe('useOpenTraceDialog', () => {])('%s opens the dialog: %s', (_name, flagOn, modifiers, expectDialog) => {featureFlagLogic.mount()featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.TRACING_TRACE_DIALOG]: flagOn })- traceDialogLogic.mount()+ traceDialogOpenLogic.mount()router.actions.push('/logs')const pathnameBeforeClick = router.values.location.pathname@@ -62,9 +62,9 @@ describe('useOpenTraceDialog', () => {)fireEvent.click(screen.getByText('View trace'), modifiers)- expect(traceDialogLogic.values.isOpen).toBe(expectDialog)+ expect(traceDialogOpenLogic.values.isOpen).toBe(expectDialog)if (expectDialog) {- expect(traceDialogLogic.values.trace).toMatchObject({ traceId: 'abc123', spanId: 'DEF456' })+ expect(traceDialogOpenLogic.values.trace).toMatchObject({ traceId: 'abc123', spanId: 'DEF456' })// A dialog click must not also follow the link.expect(router.values.location.pathname).toBe(pathnameBeforeClick)}diff --git a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.tsindex b455a7fb3561..afc80675ed11 100644--- a/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts+++ b/products/tracing/frontend/components/TraceDialog/useOpenTraceDialog.ts@@ -3,7 +3,7 @@ import { type MouseEvent, useCallback } from 'react'import type { TraceLinkParams } from 'lib/components/ViewTraceButton/traceUrl'-import { type OpenTraceDialogOptions, traceDialogLogic } from './traceDialogLogic'+import { type OpenTraceDialogOptions, traceDialogOpenLogic } from './traceDialogOpenLogic'export type OpenTraceDialogHandler = (event: MouseEvent | null,@@ -17,8 +17,8 @@ export type OpenTraceDialogHandler = (* non-primary clicks. Cmd and ctrl then open Tracing in a new tab, and shift opens it in place.*/export function useOpenTraceDialog(): OpenTraceDialogHandler {- const { dialogEnabled } = useValues(traceDialogLogic)- const { openTraceDialog } = useActions(traceDialogLogic)+ const { dialogEnabled } = useValues(traceDialogOpenLogic)+ const { openTraceDialog } = useActions(traceDialogOpenLogic)// Stable while the flag holds, so callers can list it in a memo's dependencies.return useCallback(diff --git a/products/tracing/frontend/components/TraceView/TraceView.tsx b/products/tracing/frontend/components/TraceView/TraceView.tsxindex 4bc354c48fc4..3fb666a94a3d 100644--- a/products/tracing/frontend/components/TraceView/TraceView.tsx+++ b/products/tracing/frontend/components/TraceView/TraceView.tsx@@ -14,7 +14,7 @@ import type { ErrorScope } from 'products/tracing/frontend/errorCorrelation'import { TraceCompareFlame } from 'products/tracing/frontend/TraceCompareFlame'import type { SpanInspectorTab, TraceViewMode } from 'products/tracing/frontend/types'-import type { TraceDialogSource } from '../TraceDialog/traceDialogLogic'+import type { TraceDialogSource } from '../TraceDialog/traceDialogOpenLogic'import { TraceDialogSpanTree } from '../TraceDialog/TraceDialogSpanTree'import { TraceLoadMoreFooter } from './TraceLoadMoreFooter'import { type TraceOperationsScope, traceViewLogic, type TraceViewSurface } from './traceViewLogic'