: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
fix(aio): validate url timestamp before trace query (#115805)
posthog[bot]7f5fffc7d725
diff --git a/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts b/products/ai_observability/frontend/aiObservabilityTraceLogic.test.tsindex 8b1a32f565d6..6f069637692b 100644--- a/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts+++ b/products/ai_observability/frontend/aiObservabilityTraceLogic.test.ts@@ -107,6 +107,30 @@ describe('aiObservabilityTraceLogic', () => {})})+ it.each([+ [+ 'restores a `+` offset that the URL decoded to a space',+ { timestamp: '2026-10-12T10:20:30.310693 00:00' },+ '2026-10-12T10:20:30.310693+00:00',+ ],+ [+ 'keeps a valid timestamp that ends in a space-separated time',+ { timestamp: '2026-10-12 10:20' },+ '2026-10-12 10:20',+ ],+ ['ignores a timestamp that is not a date', { timestamp: 'not-a-date' }, null],+ ['ignores an exception_ts that is not a date', { exception_ts: 'not-a-date' }, null],+ ])('%s', async (_, params, expectedDateFrom) => {+ const traceUrl = combineUrl(urls.aiObservabilityTrace('broken-date-trace', params))++ router.actions.push(addProjectIdIfMissing(traceUrl.url, MOCK_TEAM_ID))+ await expectLogic(logic).toMatchValues({+ traceId: 'broken-date-trace',+ dateRange: { dateFrom: expectedDateFrom, dateTo: null },+ })+ expect(() => logic.values.query).not.toThrow()+ })+it('preserves timestamp when both timestamp and tab parameters are present', async () => {const traceId = 'test-trace-id'const timestamp = '2024-01-15T12:00:00Z'diff --git a/products/ai_observability/frontend/aiObservabilityTraceLogic.ts b/products/ai_observability/frontend/aiObservabilityTraceLogic.tsindex 893bf241fc96..6108dd27bbec 100644--- a/products/ai_observability/frontend/aiObservabilityTraceLogic.ts+++ b/products/ai_observability/frontend/aiObservabilityTraceLogic.ts@@ -61,6 +61,16 @@ export interface AIObservabilityTraceDataNodeLogicParams {const EXCEPTION_LOOKUP_WINDOW_MINUTES = 20+// An unencoded `+` in a URL query decodes to a space, so `+00:00` arrives as ` 00:00`.+function parseUrlDate(value: string): string | null {+ const raw = String(value).trim()+ if (dayjs(raw).isValid()) {+ return raw+ }+ const repaired = raw.replace(/ (\d{2}:?\d{2})$/, '+$1')+ return dayjs(repaired).isValid() ? repaired : null+}+export function getDataNodeLogicProps({traceId,query,@@ -682,16 +692,18 @@ export const aiObservabilityTraceLogic = kea<aiObservabilityTraceLogicType>([kind: NodeKind.TraceQuery,traceId,includeSentiment: true,- dateRange: dateRange?.dateFrom- ? // dateFrom is a minimum timestamp of an event for a trace.- {- date_from: dateRange.dateFrom,- date_to: dateRange?.dateTo || dayjs(dateRange.dateFrom).add(10, 'minutes').toISOString(),- }- : // By default will look for traces from the beginning.- {- date_from: dayjs.utc(new Date(2025, 0, 10)).toISOString(),- },+ dateRange:+ dateRange?.dateFrom && dayjs(dateRange.dateFrom).isValid()+ ? // dateFrom is a minimum timestamp of an event for a trace.+ {+ date_from: dateRange.dateFrom,+ date_to:+ dateRange?.dateTo || dayjs(dateRange.dateFrom).add(10, 'minutes').toISOString(),+ }+ : // By default will look for traces from the beginning.+ {+ date_from: dayjs.utc(new Date(2025, 0, 10)).toISOString(),+ },}return {@@ -866,11 +878,13 @@ export const aiObservabilityTraceLogic = kea<aiObservabilityTraceLogicType>([const parsedLine = line ? parseInt(line, 10) : NaNactions.setLineNumber(!isNaN(parsedLine) ? parsedLine : null)actions.setInitialTab(tab || null)- if (timestamp) {- actions.setDateRange(timestamp || null)- } else if (exception_ts) {+ const dateFrom = timestamp ? parseUrlDate(timestamp) : null+ const exceptionDate = exception_ts ? parseUrlDate(exception_ts) : null+ if (dateFrom) {+ actions.setDateRange(dateFrom)+ } else if (exceptionDate) {// Increase the lookup window to 20 minutes before and after the exception timestamp, which gives in total 60 minutes.- const parsedDate = dayjs(exception_ts)+ const parsedDate = dayjs(exceptionDate)actions.setDateRange(parsedDate.subtract(EXCEPTION_LOOKUP_WINDOW_MINUTES, 'minutes').toISOString(),parsedDate.add(EXCEPTION_LOOKUP_WINDOW_MINUTES, 'minutes').toISOString()