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): capture results events in compare mode (#61056)

Jon McCallume21a0e0548a4
diff --git a/products/tracing/frontend/tracingDataLogic.test.ts b/products/tracing/frontend/tracingDataLogic.test.ts
index c96a27f6f821..720210a3a080 100644
--- a/products/tracing/frontend/tracingDataLogic.test.ts
+++ b/products/tracing/frontend/tracingDataLogic.test.ts
@@ -1,9 +1,23 @@
+import posthog from 'posthog-js'
+
+import { AggregatedSpanRow } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { tracingDataLogic } from './tracingDataLogic'
import { tracingFiltersLogic } from './tracingFiltersLogic'
import type { Span } from './types'
+const createMockAggregatedRow = (name: string): AggregatedSpanRow => ({
+ service_name: 'svc',
+ name,
+ count: 1,
+ total_duration_nano: 1000,
+ avg_duration_nano: 1000,
+ p50_duration_nano: 1000,
+ p95_duration_nano: 1000,
+ error_count: 0,
+})
+
const TEST_TAB = 'test-tab'
const createMockSpan = (uuid: string, timestamp: string): Span => ({
@@ -124,4 +138,51 @@ describe('tracingDataLogic', () => {
expect(logic.values.visibleRowDateRange).toBeNull()
})
})
+
+ describe('results tracking', () => {
+ let captureSpy: jest.SpyInstance
+
+ beforeEach(() => {
+ logic = mountWithSpans([])
+ captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)
+ })
+
+ afterEach(() => {
+ captureSpy.mockRestore()
+ })
+
+ it.each([
+ {
+ name: 'spans with a count',
+ dispatch: (l: typeof logic) => l.actions.fetchSpansSuccess(mockSpans),
+ event: 'tracing results returned',
+ properties: { count: mockSpans.length, query_type: 'spans' },
+ },
+ {
+ name: 'empty spans',
+ dispatch: (l: typeof logic) => l.actions.fetchSpansSuccess([]),
+ event: 'tracing no results returned',
+ properties: { query_type: 'spans' },
+ },
+ {
+ name: 'aggregation with a count',
+ dispatch: (l: typeof logic) =>
+ l.actions.fetchAggregationSuccess({
+ current: [createMockAggregatedRow('op-1'), createMockAggregatedRow('op-2')],
+ previous: null,
+ }),
+ event: 'tracing results returned',
+ properties: { count: 2, query_type: 'aggregation' },
+ },
+ {
+ name: 'empty aggregation',
+ dispatch: (l: typeof logic) => l.actions.fetchAggregationSuccess({ current: [], previous: null }),
+ event: 'tracing no results returned',
+ properties: { query_type: 'aggregation' },
+ },
+ ])('captures the right event for $name', ({ dispatch, event, properties }) => {
+ dispatch(logic)
+ expect(captureSpy).toHaveBeenCalledWith(event, properties)
+ })
+ })
})
diff --git a/products/tracing/frontend/tracingDataLogic.ts b/products/tracing/frontend/tracingDataLogic.ts
index 92f6e2c03ddf..aa9ccb4f1600 100644
--- a/products/tracing/frontend/tracingDataLogic.ts
+++ b/products/tracing/frontend/tracingDataLogic.ts
@@ -47,6 +47,14 @@ function isUserInitiatedError(error: unknown): boolean {
return error === NEW_QUERY_STARTED_ERROR_MESSAGE || errorStr.includes('abort')
}
+function captureTracingResults(count: number, queryType: 'spans' | 'aggregation'): void {
+ if (count === 0) {
+ posthog.capture('tracing no results returned', { query_type: queryType })
+ } else {
+ posthog.capture('tracing results returned', { count, query_type: queryType })
+ }
+}
+
export interface TracingDataLogicProps {
tabId?: string
}
@@ -500,12 +508,10 @@ export const tracingDataLogic = kea<tracingDataLogicType>([
actions.setSpanTreeAbortController(controller)
},
fetchSpansSuccess: () => {
- const tracesCount = values.rootSpans.length
- if (tracesCount === 0) {
- posthog.capture('tracing no results returned')
- } else {
- posthog.capture('tracing results returned', { count: tracesCount })
- }
+ captureTracingResults(values.rootSpans.length, 'spans')
+ },
+ fetchAggregationSuccess: ({ aggregation }) => {
+ captureTracingResults(aggregation.current.length, 'aggregation')
},
fetchSpansFailure: ({ error }) => {
if (!isUserInitiatedError(error)) {