: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(tracing): make spans the default view mode (#124933)
Frank Hamand8b2e5334aa57
diff --git a/products/tracing/frontend/TracingDisplayBar.tsx b/products/tracing/frontend/TracingDisplayBar.tsxindex c6955f123a69..49ae57d6e36b 100644--- a/products/tracing/frontend/TracingDisplayBar.tsx+++ b/products/tracing/frontend/TracingDisplayBar.tsx@@ -37,13 +37,6 @@ export function TracingDisplayBar(): JSX.Element {// data-attrs keep the names from the two controls this one replaced, for analytics continuity.const displayModeOptions: LemonSegmentedButtonOption<TracingDisplayMode>[] = [- {- value: 'traces',- label: 'Traces',- icon: <IconListTree />,- tooltip: 'Group matching spans by trace, one row per trace (its root span)',- 'data-attr': 'tracing-view-mode-traces',- },{value: 'spans',label: 'Spans',@@ -53,6 +46,13 @@ export function TracingDisplayBar(): JSX.Element {disabledReason: compareActive ? 'Not available while comparing' : undefined,'data-attr': 'tracing-view-mode-spans',},+ {+ value: 'traces',+ label: 'Traces',+ icon: <IconListTree />,+ tooltip: 'Group matching spans by trace, one row per trace (its root span)',+ 'data-attr': 'tracing-view-mode-traces',+ },...(operationsViewEnabled? [{diff --git a/products/tracing/frontend/tracingAgentContext.ts b/products/tracing/frontend/tracingAgentContext.tsindex 95ebd618e35a..8671b13caabf 100644--- a/products/tracing/frontend/tracingAgentContext.ts+++ b/products/tracing/frontend/tracingAgentContext.ts@@ -13,7 +13,6 @@ import {DEFAULT_DATE_RANGE,DEFAULT_ORDER_BY,DEFAULT_ORDER_DIRECTION,- DEFAULT_VIEW_MODE,TracingFilters,TracingOrderBy,TracingOrderDirection,@@ -213,7 +212,7 @@ export function apmSpansQueryToViewerFilters(input: Record<string, unknown>): PafilterGroup,orderBy,orderDirection,- viewMode: query.flatSpans === true ? 'spans' : DEFAULT_VIEW_MODE,+ viewMode: query.flatSpans === true ? 'spans' : 'traces',}}diff --git a/products/tracing/frontend/tracingDataLogic.test.ts b/products/tracing/frontend/tracingDataLogic.test.tsindex f1c3d69ccc69..6f046e1da1ac 100644--- a/products/tracing/frontend/tracingDataLogic.test.ts+++ b/products/tracing/frontend/tracingDataLogic.test.ts@@ -136,6 +136,7 @@ describe('tracingDataLogic', () => {},createMockSpan('root-2', '2024-01-01T01:00:00Z'),]+ tracingFiltersLogic().actions.setViewMode('traces')logic.actions.fetchSpansSuccess(withChild)// listRows = [root-1, root-2] in traces mode; index 1 is root-2, never the child at 05:00.logic.actions.setVisibleRowRange(0, 1)@@ -238,9 +239,10 @@ describe('tracingDataLogic', () => {createMockSpan('root-2', '2024-01-01T01:00:00Z'),]- it('lists only root spans in traces mode (default)', () => {- logic = mountWithSpans(withChildSpans)- expect(logic.values.filters.viewMode).toBe('traces')+ it('lists only root spans in traces mode', () => {+ logic = mountWithSpans([])+ tracingFiltersLogic().actions.setViewMode('traces')+ logic.actions.fetchSpansSuccess(withChildSpans)expect(logic.values.listRows.map((s) => s.uuid)).toEqual(['root-1', 'root-2'])})@@ -265,8 +267,9 @@ describe('tracingDataLogic', () => {it('requests grouped traces from the API in traces mode', async () => {const listSpansSpy = jest.spyOn(api.tracing, 'listSpans').mockResolvedValue({ results: [], hasMore: false })logic = mountWithSpans([])+ tracingFiltersLogic().actions.setViewMode('traces')await logic.asyncActions.fetchSpans()- expect(listSpansSpy).toHaveBeenCalledWith(+ expect(listSpansSpy).toHaveBeenLastCalledWith(expect.objectContaining({ flatSpans: false, rootSpans: false }),expect.anything())@@ -275,6 +278,7 @@ describe('tracingDataLogic', () => {it('totalMatchingFilters reports trace count in traces mode and span count in spans mode', () => {logic = mountWithSpans([])+ tracingFiltersLogic().actions.setViewMode('traces')logic.actions.fetchMatchingCountsSuccess({ count: 5000, traceCount: 100 })expect(logic.values.totalMatchingFilters).toBe(100)tracingFiltersLogic().actions.setViewMode('spans')@@ -284,8 +288,12 @@ describe('tracingDataLogic', () => {it('sparkline counts root spans in traces mode and all spans in spans mode', async () => {const sparklineSpy = jest.spyOn(api.tracing, 'sparkline').mockResolvedValue({ results: [] })logic = mountWithSpans([])+ tracingFiltersLogic().actions.setViewMode('traces')await logic.asyncActions.fetchSparkline()- expect(sparklineSpy).toHaveBeenCalledWith(expect.objectContaining({ rootSpans: true }), expect.anything())+ expect(sparklineSpy).toHaveBeenLastCalledWith(+ expect.objectContaining({ rootSpans: true }),+ expect.anything()+ )tracingFiltersLogic().actions.setViewMode('spans')await logic.asyncActions.fetchSparkline()expect(sparklineSpy).toHaveBeenLastCalledWith(@@ -340,7 +348,7 @@ describe('tracingDataLogic', () => {// The sparkline counts root spans in 'traces' mode and all spans in 'spans' mode, so a// view-mode toggle changes its scope and the auto re-query must re-fetch it.await expectLogic(logic, () => {- tracingFiltersLogic().actions.setViewMode('spans')+ tracingFiltersLogic().actions.setViewMode('traces')}).toDispatchActions(['fetchSparklineSuccess'])expect(sparklineSpy).toHaveBeenCalledTimes(2)sparklineSpy.mockRestore()diff --git a/products/tracing/frontend/tracingFiltersLogic.test.ts b/products/tracing/frontend/tracingFiltersLogic.test.tsindex 3bf71eab4536..eec1cf2fbdf2 100644--- a/products/tracing/frontend/tracingFiltersLogic.test.ts+++ b/products/tracing/frontend/tracingFiltersLogic.test.ts@@ -36,21 +36,21 @@ describe('tracingFiltersLogic', () => {})describe('view mode', () => {- it('defaults to traces', () => {- expect(logic.values.viewMode).toBe('traces')- expect(logic.values.filters.viewMode).toBe('traces')- })-- it('switches to spans', () => {- logic.actions.setViewMode('spans')+ it('defaults to spans', () => {expect(logic.values.viewMode).toBe('spans')expect(logic.values.filters.viewMode).toBe('spans')})- it('switches back to traces', () => {- logic.actions.setViewMode('spans')+ it('switches to traces', () => {logic.actions.setViewMode('traces')expect(logic.values.viewMode).toBe('traces')+ expect(logic.values.filters.viewMode).toBe('traces')+ })++ it('switches back to spans', () => {+ logic.actions.setViewMode('traces')+ logic.actions.setViewMode('spans')+ expect(logic.values.viewMode).toBe('spans')})})@@ -124,12 +124,12 @@ describe('tracingFiltersLogic', () => {a.mount()b.mount()try {- a.actions.setViewMode('spans')+ a.actions.setViewMode('traces')a.actions.setServiceNames(['svc-a'])- expect(a.values.viewMode).toBe('spans')+ expect(a.values.viewMode).toBe('traces')expect(a.values.filters.serviceNames).toEqual(['svc-a'])- expect(b.values.viewMode).toBe('traces')+ expect(b.values.viewMode).toBe('spans')expect(b.values.filters.serviceNames).toEqual([])} finally {a.unmount()diff --git a/products/tracing/frontend/tracingFiltersLogic.ts b/products/tracing/frontend/tracingFiltersLogic.tsindex 90b4d0a6b276..777201ee810f 100644--- a/products/tracing/frontend/tracingFiltersLogic.ts+++ b/products/tracing/frontend/tracingFiltersLogic.ts@@ -35,7 +35,7 @@ export const DEFAULT_TIMEZONE: string = 'UTC'export const DEFAULT_SERVICE_NAMES: string[] = []export const DEFAULT_ORDER_BY = 'timestamp' as constexport const DEFAULT_ORDER_DIRECTION = 'DESC' as const-export const DEFAULT_VIEW_MODE = 'traces' as const+export const DEFAULT_VIEW_MODE = 'spans' as constexport const DEFAULT_CHART_TYPE = 'activity' as const// Column the list is ordered by, and its direction. timestamp+DESC is "latest" (keyset paginated viadiff --git a/products/tracing/frontend/tracingSceneLogic.test.ts b/products/tracing/frontend/tracingSceneLogic.test.tsindex 3ddb1798e6a4..38a22a373a16 100644--- a/products/tracing/frontend/tracingSceneLogic.test.ts+++ b/products/tracing/frontend/tracingSceneLogic.test.ts@@ -152,7 +152,16 @@ describe('tracingSceneLogic', () => {it('ignores ?view=operations when the operations view flag is off', () => {const filtersLogic = mountAt({ view: 'operations' })expect(logic.values.activeTracingTab).toBe('traces')+ expect(filtersLogic.values.viewMode).toBe('spans')+ })++ it('round-trips the non-default traces view mode through the URL', () => {+ const filtersLogic = mountAt({ view: 'traces' })expect(filtersLogic.values.viewMode).toBe('traces')+ expect(router.values.searchParams.view).toBe('traces')++ logic.actions.setDisplayMode('spans')+ expect(router.values.searchParams).not.toHaveProperty('view')})it('reconciles the operations tab when the flag resolves after a ?view=operations deep link', () => {@@ -193,7 +202,7 @@ describe('tracingSceneLogic', () => {featureFlagLogic.actions.setFeatureFlags([], {})expect(logic.values.activeTracingTab).toBe('traces')- expect(logic.values.displayMode).toBe('traces')+ expect(logic.values.displayMode).toBe('spans')expect(router.values.searchParams).not.toHaveProperty('view')})@@ -210,7 +219,7 @@ describe('tracingSceneLogic', () => {logic.actions.setDisplayMode('spans')expect(logic.values.activeTracingTab).toBe('traces')- expect(router.values.searchParams.view).toBe('spans')+ expect(router.values.searchParams).not.toHaveProperty('view')// Back/forward to a non-operations URL while on the operations tab resets the tab.logic.actions.setDisplayMode('operations')diff --git a/products/tracing/frontend/tracingSceneLogic.ts b/products/tracing/frontend/tracingSceneLogic.tsindex 0fba9ee6520e..b3d869a673b8 100644--- a/products/tracing/frontend/tracingSceneLogic.ts+++ b/products/tracing/frontend/tracingSceneLogic.ts@@ -693,7 +693,7 @@ export const tracingSceneLogic = kea<tracingSceneLogicType>([hasChanges = true}- // `view` spans two states: 'operations' round-trips the scene tab, 'spans'/absent+ // `view` spans two states: 'operations' round-trips the scene tab, 'spans'/'traces'/absent// round-trips the viewMode filter. While the URL says operations the viewMode filter// is left untouched — it has no effect on that view and shouldn't be reset under it.// The whole operations leg is flag-gated on BOTH the read side (here) and the write@@ -705,7 +705,10 @@ export const tracingSceneLogic = kea<tracingSceneLogicType>([actions.setActiveTracingTab(operationsFromUrl ? 'operations' : 'traces')}if (!operationsFromUrl) {- const viewModeFromUrl = searchParams.view === 'spans' ? 'spans' : DEFAULT_VIEW_MODE+ const viewModeFromUrl: TracingViewMode =+ searchParams.view === 'spans' || searchParams.view === 'traces'+ ? searchParams.view+ : DEFAULT_VIEW_MODEif (viewModeFromUrl !== values.filters.viewMode) {filtersFromUrl.viewMode = viewModeFromUrlhasChanges = true