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(aio): clear the stale trace window when opening a different trace (#105092)

Christiaan Hendriksen273a5092bc44
diff --git a/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts b/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts
index 3119efaf0cd0..8b1a32f565d6 100644
--- a/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts
+++ b/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts
@@ -120,6 +120,32 @@ describe('aiObservabilityTraceLogic', () => {
})
})
+ const firstTraceTimestamp = '2024-01-15T12:00:00Z'
+
+ it.each([
+ ['clears the previous window when a different trace opens without a timestamp', 'other-trace-id', null],
+ ['keeps the window when the same trace reopens without a timestamp', 'test-trace-id', firstTraceTimestamp],
+ ])('%s', async (_, nextTraceId, expectedDateFrom) => {
+ router.actions.push(
+ addProjectIdIfMissing(
+ combineUrl(urls.aiObservabilityTrace('test-trace-id', { timestamp: firstTraceTimestamp })).url,
+ MOCK_TEAM_ID
+ )
+ )
+ await expectLogic(logic).toMatchValues({ dateRange: { dateFrom: firstTraceTimestamp, dateTo: null } })
+
+ router.actions.push(
+ addProjectIdIfMissing(
+ combineUrl(urls.aiObservabilityTrace(nextTraceId, { tab: 'evals' })).url,
+ MOCK_TEAM_ID
+ )
+ )
+ await expectLogic(logic).toMatchValues({
+ traceId: nextTraceId,
+ dateRange: { dateFrom: expectedDateFrom, dateTo: null },
+ })
+ })
+
it('does not write the search query back to the URL when it originates from the URL', async () => {
// Regression: setSearchQuery's listener wrote the query back to the URL, which
// re-fired urlToAction, which called setSearchQuery again. For a query that the URL
diff --git a/products/ai_observability/frontend/aiObservabilityTraceLogic.ts b/products/ai_observability/frontend/aiObservabilityTraceLogic.ts
index bdf00f7a8094..893bf241fc96 100644
--- a/products/ai_observability/frontend/aiObservabilityTraceLogic.ts
+++ b/products/ai_observability/frontend/aiObservabilityTraceLogic.ts
@@ -848,12 +848,14 @@ export const aiObservabilityTraceLogic = kea<aiObservabilityTraceLogicType>([
},
})),
- urlToAction(({ actions, cache }) => ({
+ urlToAction(({ actions, values, cache }) => ({
[`${urls.aiObservabilityTraces()}/:id`]: (
{ id },
{ event, timestamp, exception_ts, search, line, tab, msg }
) => {
- actions.setTraceId(tryDecodeURIComponent(id ?? ''))
+ const traceId = tryDecodeURIComponent(id ?? '')
+ const isNewTrace = traceId !== values.traceId
+ actions.setTraceId(traceId)
void addProductIntent({
product_type: ProductKey.AI_OBSERVABILITY,
intent_context: ProductIntentContext.LLM_ANALYTICS_TRACE_VIEWED,
@@ -873,6 +875,8 @@ export const aiObservabilityTraceLogic = kea<aiObservabilityTraceLogicType>([
parsedDate.subtract(EXCEPTION_LOOKUP_WINDOW_MINUTES, 'minutes').toISOString(),
parsedDate.add(EXCEPTION_LOOKUP_WINDOW_MINUTES, 'minutes').toISOString()
)
+ } else if (isNewTrace) {
+ actions.setDateRange(null)
}
// Set search from URL param if provided, otherwise clear it.
// Mark it as URL-driven so the listener doesn't write it straight back to the URL.