: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): enhance user action reporting in tracing views (#61052)
Jon McCallum70891956567a
diff --git a/products/tracing/backend/presentation/views.py b/products/tracing/backend/presentation/views.pyindex f71dedd80839..d4a3f6a6d291 100644--- a/products/tracing/backend/presentation/views.py+++ b/products/tracing/backend/presentation/views.py@@ -36,6 +36,7 @@ from posthog.api.documentation import _FallbackSerializerfrom posthog.api.mixins import PydanticModelMixinfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.clickhouse.query_tagging import Feature, tag_queries+from posthog.event_usage import report_user_actionfrom posthog.hogql_queries.query_runner import ExecutionModefrom ..logic import (@@ -362,6 +363,23 @@ class SpansViewSet(TeamAndOrgViewSetMixin, PydanticModelMixin, viewsets.ViewSet)json.dumps({"timestamp": boundary_ts.isoformat(), "trace_id": boundary_trace_id}).encode("utf-8")).decode("utf-8")+ report_user_action(+ request.user,+ "tracing query executed",+ {+ "traces_count": len(kept_trace_ids),+ "spans_count": len(results),+ "has_more": has_more,+ "has_filter_group": bool(query_data.get("filterGroup")),+ "service_names_count": len(query_data.get("serviceNames") or []),+ "status_codes_count": len(query_data.get("statusCodes") or []),+ "order_by": order_by,+ "is_paginated": bool(after_cursor),+ },+ team=self.team,+ request=request,+ )+return Response({"results": results,diff --git a/products/tracing/frontend/tracingDataLogic.ts b/products/tracing/frontend/tracingDataLogic.tsindex 16f6e0bab4e3..92f6e2c03ddf 100644--- a/products/tracing/frontend/tracingDataLogic.ts+++ b/products/tracing/frontend/tracingDataLogic.ts@@ -1,5 +1,6 @@import { actions, connect, events, kea, key, listeners, path, props, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'+import posthog from 'posthog-js'import { lemonToast } from '@posthog/lemon-ui'@@ -498,9 +499,18 @@ 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 })+ }+ },fetchSpansFailure: ({ error }) => {if (!isUserInitiatedError(error)) {lemonToast.error(`Failed to load traces: ${error}`)+ posthog.capture('tracing query failed', { query_type: 'spans', error_message: String(error) })}},fetchSparklineFailure: ({ error }) => {diff --git a/products/tracing/frontend/tracingSceneLogic.ts b/products/tracing/frontend/tracingSceneLogic.tsindex a7210555d053..6fb8d9d86674 100644--- a/products/tracing/frontend/tracingSceneLogic.ts+++ b/products/tracing/frontend/tracingSceneLogic.ts@@ -1,6 +1,7 @@import equal from 'fast-deep-equal'import { actions, connect, kea, listeners, path, props, reducers, selectors } from 'kea'import { router } from 'kea-router'+import posthog from 'posthog-js'import { DEFAULT_UNIVERSAL_GROUP_FILTER } from 'lib/components/UniversalFilters/universalFiltersLogic'import { tabAwareActionToUrl } from 'lib/logic/scenes/tabAwareActionToUrl'@@ -70,6 +71,7 @@ export const tracingSceneLogic = kea<tracingSceneLogicType>([openCompareFlame: (spanName: string, serviceName: string) => ({ spanName, serviceName }),closeCompareFlame: true,syncUrlAndRunQuery: true,+ handleFilterChange: (filterType: string, extraProps?: Record<string, unknown>) => ({ filterType, extraProps }),}),reducers({@@ -129,6 +131,7 @@ export const tracingSceneLogic = kea<tracingSceneLogicType>([listeners(({ actions, values }) => ({openTraceModal: ({ traceId }) => {+ posthog.capture('tracing trace opened')const prefetchedSpans = values.spans.filter((s: Span) => s.trace_id === traceId)if (prefetchedSpans.length >= PREFETCH_SPANS) {actions.loadTraceSpans(traceId)@@ -137,21 +140,15 @@ export const tracingSceneLogic = kea<tracingSceneLogicType>([openCompareFlame: ({ spanName, serviceName }) => {actions.fetchSpanTree({ spanName, serviceName })},- setDateRange: () => {- actions.syncUrlAndRunQuery()- },- setServiceNames: () => {- actions.syncUrlAndRunQuery()- },- setFilterGroup: () => {- actions.syncUrlAndRunQuery()- },- setOrderBy: () => {- actions.syncUrlAndRunQuery()- },- setCompareMode: () => {+ handleFilterChange: ({ filterType, extraProps }) => {+ posthog.capture('tracing filter changed', { filter_type: filterType, ...extraProps })actions.syncUrlAndRunQuery()},+ setDateRange: () => actions.handleFilterChange('date_range'),+ setServiceNames: () => actions.handleFilterChange('service_names'),+ setFilterGroup: () => actions.handleFilterChange('filter_group'),+ setOrderBy: () => actions.handleFilterChange('order_by'),+ setCompareMode: ({ compareMode }) => actions.handleFilterChange('compare_mode', { enabled: compareMode }),setOverlayWindows: () => {// Overlay drags only refetch the aggregation — the sparkline canvas range// stays fixed while the user moves windows around within it. If the compare-flame