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): keep trace filters intact when switching tabs (#87663)

posthog[bot]a7068f778ba2
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsx
index e75336d9ace9..a10c299a718c 100644
--- a/frontend/src/products.tsx
+++ b/frontend/src/products.tsx
@@ -1053,6 +1053,7 @@ export const productUrls = {
search?: string
tab?: string
msg?: string
+ [key: string]: string | undefined
}
): string => {
const encodePathSegment = (value: string): string => {
@@ -1065,7 +1066,13 @@ export const productUrls = {
(character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`
)
}
- const queryParams = new URLSearchParams(params)
+ const definedParams: Record<string, string> = {}
+ for (const [key, value] of Object.entries(params ?? {})) {
+ if (value !== undefined) {
+ definedParams[key] = value
+ }
+ }
+ const queryParams = new URLSearchParams(definedParams)
const stringifiedParams = queryParams.toString()
return `/ai-observability/traces/${encodePathSegment(id)}${stringifiedParams ? `?${stringifiedParams}` : ''}`
},
diff --git a/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts b/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts
index 3bf7147f63fa..3119efaf0cd0 100644
--- a/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts
+++ b/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts
@@ -65,6 +65,20 @@ describe('aiObservabilityTraceLogic', () => {
)
})
+ it('keeps object-valued search params intact when the view mode changes', async () => {
+ const traceId = 'trace-with-filters'
+ const filters = [{ key: '$ai_model', value: 'gpt-4', operator: 'exact', type: 'event' }]
+ const traceUrl = combineUrl(urls.aiObservabilityTrace(traceId), { filters, tab: 'conversation' })
+
+ router.actions.push(addProjectIdIfMissing(traceUrl.url, MOCK_TEAM_ID))
+ await expectLogic(logic).toFinishAllListeners()
+
+ logic.actions.setViewMode(TraceViewMode.Raw)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(router.values.searchParams.filters).toEqual(filters)
+ })
+
it('handles trace ID with event and timestamp parameters', async () => {
const traceIdWithColon = 'session-summary:group:16-16:81008d53ff0a708b:da6c0390-409f-485c-aab3-5e910bcf8b33'
const eventId = 'event123'
diff --git a/products/ai_observability/frontend/aiObservabilityTraceLogic.ts b/products/ai_observability/frontend/aiObservabilityTraceLogic.ts
index 35328744b800..bdf00f7a8094 100644
--- a/products/ai_observability/frontend/aiObservabilityTraceLogic.ts
+++ b/products/ai_observability/frontend/aiObservabilityTraceLogic.ts
@@ -907,7 +907,8 @@ export const aiObservabilityTraceLogic = kea<aiObservabilityTraceLogicType>([
}
// Always include tab parameter
params.tab = values.viewMode
- return urls.aiObservabilityTrace(values.traceId, params)
+ // combineUrl JSON encodes object values (e.g. the filters array), so they survive the round trip.
+ return combineUrl(urls.aiObservabilityTrace(values.traceId), params).url
}
return {
diff --git a/products/ai_observability/manifest.tsx b/products/ai_observability/manifest.tsx
index 3441eccff9c6..189eeaaf27a5 100644
--- a/products/ai_observability/manifest.tsx
+++ b/products/ai_observability/manifest.tsx
@@ -317,6 +317,9 @@ export const manifest: ProductManifest = {
search?: string
tab?: string
msg?: string
+ // Only string values are valid query params. An object (e.g. the filters array)
+ // would stringify to "[object Object]" and corrupt the URL, so reject it at compile time.
+ [key: string]: string | undefined
}
): string => {
const encodePathSegment = (value: string): string => {
@@ -330,7 +333,13 @@ export const manifest: ProductManifest = {
(character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`
)
}
- const queryParams = new URLSearchParams(params)
+ const definedParams: Record<string, string> = {}
+ for (const [key, value] of Object.entries(params ?? {})) {
+ if (value !== undefined) {
+ definedParams[key] = value
+ }
+ }
+ const queryParams = new URLSearchParams(definedParams)
const stringifiedParams = queryParams.toString()
return `/ai-observability/traces/${encodePathSegment(id)}${stringifiedParams ? `?${stringifiedParams}` : ''}`
},