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.

fix(tracing): stop showing the root span as a missing parent for span-less logs (#122056)

Jon McCallumd733b63950c2
diff --git a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts
index a46b873df02e..4901b65a4e1c 100644
--- a/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts
+++ b/products/tracing/frontend/components/TraceDialog/traceDialogLogic.test.ts
@@ -219,11 +219,15 @@ describe('traceDialogLogic', () => {
expect(view.values.activeInspectorTab).toBe('errors')
})
- it('treats a missing parent row as its own selection, not the root span', async () => {
+ it('opens a span-less log on the root span, and treats a missing parent row as its own selection', async () => {
+ const root = { ...span('a'), parent_span_id: '0000000000000000' }
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' }, { entryPoint: 'log_details' })
+ getTraceSpy.mockResolvedValueOnce({ results: [root, orphan], hasMore: false, nextOffset: null })
+ // The root's parent id is the same all-zero id a span-less log carries.
+ logic.actions.openTraceDialog({ traceId: 'abc123', spanId: '0000000000000000' }, { entryPoint: 'log_details' })
await expectLogic(logic).toDispatchActions(['loadTraceSpansSuccess'])
+ expect(view.values.missingParentSpanId).toBeNull()
+ expect(view.values.selectedSpan?.span_id).toBe('a')
logic.actions.selectSpan('GONE')
expect(view.values.missingParentSpanId).toBe('GONE')
diff --git a/products/tracing/frontend/components/TraceView/traceViewLogic.ts b/products/tracing/frontend/components/TraceView/traceViewLogic.ts
index aff640684575..c0616a59f82c 100644
--- a/products/tracing/frontend/components/TraceView/traceViewLogic.ts
+++ b/products/tracing/frontend/components/TraceView/traceViewLogic.ts
@@ -147,7 +147,7 @@ export interface traceViewLogicMeta {
opened: Set<string>
}
selectedSpan: (spans: Span[], selectedSpanId: string | null, summary: TraceViewSummary) => Span | null
- missingParentSpanId: (spans: Span[], selectedSpanId: string | null) => string | null
+ missingParentSpanId: (spanTree: TraceViewTree, selectedSpanId: string | null) => string | null
pinnedSpan: (spans: Span[], pinnedSpanId: string | null) => Span | null
activeInspectorTab: (
chosenInspectorTab: SpanInspectorTab | null,
@@ -318,13 +318,9 @@ export const traceViewLogic: LogicWrapper<traceViewLogicType> = kea<traceViewLog
],
// The tree's "<parent span missing>" row selects an id that only appears as a parent id.
missingParentSpanId: [
- (s) => [s.spans, s.selectedSpanId],
- (spans: Span[], selectedSpanId: string | null): string | null =>
- selectedSpanId &&
- !spans.some((span) => span.span_id === selectedSpanId) &&
- spans.some((span) => span.parent_span_id === selectedSpanId)
- ? selectedSpanId
- : null,
+ (s) => [s.spanTree, s.selectedSpanId],
+ (spanTree: TraceViewTree, selectedSpanId: string | null): string | null =>
+ selectedSpanId && spanTree.nodesById.get(selectedSpanId)?.isMissingParent ? selectedSpanId : null,
],
pinnedSpan: [
(s) => [s.spans, s.pinnedSpanId],