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 parent span missing for root spans (#113468)

Frank Hamand95cc306f5d98
diff --git a/products/tracing/frontend/TraceWaterfallView.test.tsx b/products/tracing/frontend/TraceWaterfallView.test.tsx
index 3c5046f9db5c..90fc837df9d0 100644
--- a/products/tracing/frontend/TraceWaterfallView.test.tsx
+++ b/products/tracing/frontend/TraceWaterfallView.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, within } from '@testing-library/react'
+import { fireEvent, render, screen, within } from '@testing-library/react'
import { TraceWaterfallView } from './TraceWaterfallView'
import type { Span } from './types'
@@ -105,7 +105,15 @@ describe('TraceWaterfallView', () => {
expect(within(container).queryByLabelText('Collapse all spans')).toBeNull()
})
- it('puts spans whose parent is not loaded under one parent span missing row, which selects the missing id', () => {
+ it('does not show a parent span missing row for a root span with the all-zero parent id', () => {
+ const zeroParentRoot = { ...root, parent_span_id: '0000000000000000' }
+ const { container } = render(<TraceWaterfallView spans={[zeroParentRoot, child]} />)
+
+ expect(container.querySelectorAll('[data-row-key^="missing-parent-"]')).toHaveLength(0)
+ expect(within(container).queryByText('<parent span missing>')).toBeNull()
+ })
+
+ it('puts spans whose parent is not loaded under one parent span missing row, which selects the missing id', async () => {
const onSpanSelect = jest.fn()
const sibling = makeSpan({
uuid: 'uuid-sibling',
@@ -116,6 +124,12 @@ describe('TraceWaterfallView', () => {
const { container } = render(<TraceWaterfallView spans={[child, sibling]} onSpanSelect={onSpanSelect} />)
expect(container.querySelectorAll('[data-row-key^="missing-parent-"]')).toHaveLength(1)
+ const missingLabel = within(container).getAllByText('<parent span missing>')[0]
+ fireEvent.pointerEnter(missingLabel, { pointerType: 'mouse' })
+ fireEvent.mouseEnter(missingLabel)
+ fireEvent.mouseMove(missingLabel)
+ expect(await screen.findByText('span span-root not found', undefined, { timeout: 2000 })).toBeTruthy()
+
clickSpanRow(container, '<parent span missing>')
expect(onSpanSelect).toHaveBeenCalledWith('span-root')
diff --git a/products/tracing/frontend/TraceWaterfallView.tsx b/products/tracing/frontend/TraceWaterfallView.tsx
index 84d441a38c10..34d35956406b 100644
--- a/products/tracing/frontend/TraceWaterfallView.tsx
+++ b/products/tracing/frontend/TraceWaterfallView.tsx
@@ -63,6 +63,14 @@ function missingParentNode(parentSpanId: string, child: Span): SpanNode {
}
}
+// A root span has the all-zero OTel parent id, which the API returns as hex ("0000000000000000"), not "".
+function parentSpanIdOf(span: Span): string | null {
+ if (span.is_root_span || !span.parent_span_id || /^0+$/.test(span.parent_span_id)) {
+ return null
+ }
+ return span.parent_span_id
+}
+
function buildSpanTree(spans: Span[]): SpanNode[] {
const byId = new Map<string, SpanNode>()
const missingParents = new Map<string, SpanNode>()
@@ -73,7 +81,7 @@ function buildSpanTree(spans: Span[]): SpanNode[] {
}
for (const node of byId.values()) {
- const parentSpanId = node.span.parent_span_id
+ const parentSpanId = parentSpanIdOf(node.span)
if (parentSpanId && byId.has(parentSpanId)) {
const parent = byId.get(parentSpanId)!
parent.children.push(node)
@@ -430,7 +438,7 @@ function WaterfallRow({
<IconWarning className="text-danger shrink-0 mr-1" fontSize={14} />
</Tooltip>
)}
- <Tooltip title={span.name}>
+ <Tooltip title={isMissingParent ? `span ${span.span_id} not found` : span.name}>
<span
className={`text-xs truncate ${isError || isMissingParent ? 'text-danger' : ''} ${
isSelected || isError ? 'font-semibold' : 'font-medium'