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.

chore(taxonomic-filter): drop dead timing writes, log search latency (#64300)

Paul D'Ambra466bae4d617a
diff --git a/frontend/src/lib/components/PropertiesTimeline/propertiesTimelineLogic.ts b/frontend/src/lib/components/PropertiesTimeline/propertiesTimelineLogic.ts
index 962c69d77ceb..e9ee86d08209 100644
--- a/frontend/src/lib/components/PropertiesTimeline/propertiesTimelineLogic.ts
+++ b/frontend/src/lib/components/PropertiesTimeline/propertiesTimelineLogic.ts
@@ -2,9 +2,8 @@ import { actions, afterMount, connect, kea, key, path, props, reducers, selector
import { loaders } from 'kea-loaders'
import posthog from 'posthog-js'
+import api from 'lib/api'
import { Dayjs, dayjsUtcToTimezone } from 'lib/dayjs'
-import { apiGetWithTimeToSeeDataTracking } from 'lib/internalMetrics'
-import { uuid } from 'lib/utils/dom'
import { toParams } from 'lib/utils/url'
import { teamLogic } from 'scenes/teamLogic'
@@ -66,21 +65,10 @@ export const propertiesTimelineLogic = kea<propertiesTimelineLogicType>([
{
loadResult: async () => {
if (props.actor.type === 'person') {
- const queryId = uuid()
- const response = await apiGetWithTimeToSeeDataTracking<RawPropertiesTimelineResult>(
+ const response = await api.get<RawPropertiesTimelineResult>(
`api/environments/${values.currentTeamId}/persons/${
props.actor.id
- }/properties_timeline/?${toParams(props.filter)}`,
- values.currentTeamId,
- {
- type: 'properties_timeline_load',
- context: 'actors_modal',
- primary_interaction_id: queryId,
- query_id: queryId,
- insights_fetched: 1,
- insights_fetched_cached: 0, // TODO: Cache properties timeline requests eventually
- is_primary_interaction: true,
- }
+ }/properties_timeline/?${toParams(props.filter)}`
)
if (response.points.length === 0) {
// It should not be possible for a properties timeline to have zero points, as all actors
diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts
index 3c28aff4c6ef..593d0e7eaa36 100644
--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts
@@ -16,7 +16,8 @@
*
* Open follow-ups (not implemented in v1):
* - DataWarehouse pinned-row detail-pane state
- * - performance instrumentation (`captureTimeToSeeData`)
+ * - search-latency telemetry (legacy emits `taxonomic filter search latency`
+ * from the list-results handler; the rebuild emits its own menu events)
* - the GroupNamesPrefix clickhouse fast path (still goes through generic
* endpoint fetcher; behaviour identical, just slower for large groups)
*/
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
index 4d4b3d8737d1..ce9c875620db 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
@@ -128,6 +128,14 @@ describe('infiniteListLogic', () => {
})
})
+ it('stamps the remote load duration so callers can report search latency', async () => {
+ await expectLogic(logic)
+ .toDispatchActions(['loadRemoteItemsSuccess'])
+ .toMatchValues({
+ remoteItems: partial({ loadDurationMs: expect.any(Number) }),
+ })
+ })
+
it('can set the index', async () => {
await expectLogic(logic).toDispatchActions(['loadRemoteItemsSuccess']) // wait for data
expectLogic(logic).toMatchValues({ index: 0, remoteItems: partial({ count: 156 }) })
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
index 8c999dbe483b..29a323ba731e 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
@@ -44,7 +44,6 @@ import { getCoreFilterDefinition } from '~/taxonomy/helpers'
import { CohortType, EventDefinition, GroupTypeIndex, PropertyType } from '~/types'
import { teamLogic } from '../../../scenes/teamLogic'
-import { captureTimeToSeeData } from '../../internalMetrics'
import { getItemGroup } from './InfiniteList'
import type { infiniteListLogicType } from './infiniteListLogicType'
@@ -325,21 +324,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
breakpoint()
const queryChanged = values.remoteItems.searchQuery !== searchQuery
-
- // Cache before the second await — the logic may unmount during captureTimeToSeeData,
- // and kea's no-arg breakpoint() does not protect against unmount (only new invocations).
- const currentTeamId = values.currentTeamId
const existingResults = values.remoteItems.results
-
- await captureTimeToSeeData(currentTeamId, {
- type: 'properties_load',
- context: 'filters',
- action: listGroupType,
- primary_interaction_id: '',
- status: 'success',
- time_to_see_data_ms: Math.floor(performance.now() - start),
- api_response_bytes: 0,
- })
cache.abortController = null
return {
@@ -350,6 +335,9 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
),
searchQuery,
queryChanged,
+ // Only the initial page times the search; "load more" (offset > 0)
+ // would otherwise overwrite it with pagination latency.
+ loadDurationMs: offset === 0 ? Math.floor(performance.now() - start) : undefined,
count:
response.count ||
(Array.isArray(response) ? response.length : 0) ||
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
index d32f9c90c943..053adeed1a61 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
@@ -1,6 +1,7 @@
import { MOCK_TEAM_ID } from 'lib/api.mock'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import {
isSkeletonItem,
@@ -188,6 +189,29 @@ describe('taxonomicFilterLogic', () => {
})
})
+ it('emits search latency for the active remote tab when its results land', async () => {
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ const eventsListLogic = infiniteListLogic({
+ ...logic.props,
+ listGroupType: TaxonomicFilterGroupType.Events,
+ })
+
+ await expectLogic(eventsListLogic, () => logic.actions.setSearchQuery('event')).toDispatchActions([
+ 'loadRemoteItemsSuccess',
+ ])
+ await expectLogic(logic).toDispatchActions(['infiniteListResultsReceived']).delay(1)
+
+ const latencyCall = captureSpy.mock.calls.find(([event]) => event === 'taxonomic filter search latency')
+ expect(latencyCall).toBeTruthy()
+ expect(latencyCall?.[1]).toMatchObject({
+ groupType: TaxonomicFilterGroupType.Events,
+ searchQuery: 'event',
+ time_to_see_data_ms: expect.any(Number),
+ })
+
+ captureSpy.mockRestore()
+ })
+
it('tabs skip groups with no results', async () => {
await expectLogic(logic).toDispatchActions(['infiniteListResultsReceived']).delay(1).clearHistory()
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index 67c5f313bde7..f64e10baa22e 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -2025,6 +2025,28 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
},
infiniteListResultsReceived: async ({ groupType, results }, breakpoint) => {
+ // Search-latency telemetry: one event per settled remote search on the
+ // active tab. `loadDurationMs` is set only for the offset-0 page (see
+ // infiniteListLogic), so pagination and local-only groups don't fire,
+ // and the value is the real fetch wall-clock — this runs when the
+ // results actually land, so there's no debounce race to wait out.
+ if (
+ groupType === values.activeTab &&
+ values.searchQuery &&
+ typeof results?.loadDurationMs === 'number' &&
+ results.searchQuery === values.searchQuery
+ ) {
+ posthog.capture('taxonomic filter search latency', {
+ surface: legacyTaxonomicSurface(
+ values.featureFlags[FEATURE_FLAGS.TAXONOMIC_FILTER_CATEGORY_DROPDOWN]
+ ),
+ groupType,
+ searchQuery: values.searchQuery,
+ time_to_see_data_ms: results.loadDurationMs,
+ resultCount: results.count,
+ })
+ }
+
if (groupType && !values.metaGroupTypes.has(groupType)) {
const subLogic = values.infiniteListLogics[groupType]
if (subLogic?.isMounted()) {
diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.ts
index e31e8c9bb518..40795c2a2085 100644
--- a/frontend/src/lib/components/TaxonomicFilter/types.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/types.ts
@@ -377,6 +377,9 @@ export interface ListStorage {
expandedCount?: number
queryChanged?: boolean
first?: boolean
+ // Wall-clock duration of the remote fetch that produced this page, in ms.
+ // Only set for server-backed loads; absent for local/empty storage.
+ loadDurationMs?: number
}
export interface LoaderOptions {
diff --git a/frontend/src/lib/internalMetrics.ts b/frontend/src/lib/internalMetrics.ts
index dac88886338b..b92eea88948e 100644
--- a/frontend/src/lib/internalMetrics.ts
+++ b/frontend/src/lib/internalMetrics.ts
@@ -1,10 +1,5 @@
import posthog from 'posthog-js'
-import api, { getJSONOrNull } from 'lib/api'
-import { getResponseBytes } from 'scenes/insights/utils'
-
-import { getCurrentExporterData } from '~/exporter/exporterViewLogic'
-
export interface TimeToSeeDataPayload {
team_id?: number | null
type: 'dashboard_load' | 'insight_load' | 'properties_timeline_load' | 'property_values_load' | 'properties_load'
@@ -29,59 +24,3 @@ export function currentSessionId(): string | undefined {
const sessionDetails = posthog.sessionManager?.checkAndGetSessionAndWindowId?.(true)
return sessionDetails?.sessionId
}
-
-export async function captureTimeToSeeData(teamId: number | null, payload: TimeToSeeDataPayload): Promise<void> {
- if (window.JS_CAPTURE_TIME_TO_SEE_DATA && teamId) {
- if (getCurrentExporterData()) {
- // This is likely we are in a "sharing" context so we are essentially unauthenticated
- return
- }
-
- try {
- await api.create(`api/projects/${teamId}/insights/timing`, {
- session_id: currentSessionId(),
- current_url: window.location.href,
- ...payload,
- })
- } catch (e) {
- // NOTE: As this is only telemetry, we don't want to block the user if it fails
- console.warn('Failed to capture time to see data', e)
- posthog.captureException(e)
- }
- }
-}
-
-/** api.get() wrapped in captureTimeToSeeData() tracking for simple cases of fetching insights or dashboards.
- * This is not in api.ts to avoid circular dependencies, but the principle is the same.
- */
-export async function apiGetWithTimeToSeeDataTracking<T>(
- url: string,
- teamId: number | null,
- timeToSeeDataPayload: Omit<
- TimeToSeeDataPayload,
- 'api_url' | 'time_to_see_data_ms' | 'status' | 'api_response_bytes'
- >
-): Promise<T> {
- let response: Response | undefined
- let responseData: T | undefined
- let error: any
- const requestStartMs = performance.now()
- try {
- response = await api.getResponse(url)
- responseData = await getJSONOrNull(response)
- } catch (e) {
- error = e
- }
- const requestDurationMs = performance.now() - requestStartMs
- void captureTimeToSeeData(teamId, {
- ...timeToSeeDataPayload,
- api_url: url,
- status: error ? 'failure' : 'success',
- api_response_bytes: response && getResponseBytes(response),
- time_to_see_data_ms: requestDurationMs,
- })
- if (!responseData) {
- throw error // If there's no response data, there must have been an error - rethrow it
- }
- return responseData
-}
diff --git a/frontend/src/models/propertyDefinitionsModel.ts b/frontend/src/models/propertyDefinitionsModel.ts
index ea760d58684a..fd4f1403b76a 100644
--- a/frontend/src/models/propertyDefinitionsModel.ts
+++ b/frontend/src/models/propertyDefinitionsModel.ts
@@ -3,7 +3,6 @@ import { actions, connect, kea, listeners, path, reducers, selectors } from 'kea
import api, { ApiMethodOptions, CountedPaginatedResponse } from 'lib/api'
import { TaxonomicFilterValue } from 'lib/components/TaxonomicFilter/types'
import { dayjs } from 'lib/dayjs'
-import { captureTimeToSeeData } from 'lib/internalMetrics'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { colonDelimitedDuration } from 'lib/utils/durations'
import { isKeyOf } from 'lib/utils/guards'
@@ -431,8 +430,6 @@ export const propertyDefinitionsModel = kea<propertyDefinitionsModelType>([
return
}
- const start = performance.now()
-
await breakpoint(300)
actions.setOptionsLoading(propertyKey)
actions.abortAnyRunningQuery()
@@ -487,16 +484,6 @@ export const propertyDefinitionsModel = kea<propertyDefinitionsModelType>([
clearTimeout(cache.pollingTimeouts[propertyKey])
delete cache.pollingTimeouts[propertyKey]
}
-
- await captureTimeToSeeData(teamLogic.values.currentTeamId, {
- type: 'property_values_load',
- context: 'filters',
- action: type,
- primary_interaction_id: '',
- status: 'success',
- time_to_see_data_ms: Math.floor(performance.now() - start),
- api_response_bytes: 0,
- })
} catch (e) {
// Bail if a newer listener invocation has superseded this one
breakpoint()