diff --git a/apps/studio/components/interfaces/UserJourneys/UserJourneySheet.tsx b/apps/studio/components/interfaces/UserJourneys/UserJourneySheet.tsx index e7b731a1d24..1a8f38eb586 100644 --- a/apps/studio/components/interfaces/UserJourneys/UserJourneySheet.tsx +++ b/apps/studio/components/interfaces/UserJourneys/UserJourneySheet.tsx @@ -1,4 +1,4 @@ -import { useParams } from 'common' +import { useFlag, useParams } from 'common' import { AlertTriangle, Info, RefreshCw } from 'lucide-react' import { useCallback, useEffect, useState } from 'react' import { @@ -41,6 +41,7 @@ export const UserJourneySheet = ({ identifier, onOpenChange }: UserJourneySheetP const { data: project } = useSelectedProjectQuery() const { getEntitlementNumericValue } = useCheckEntitlements('log.retention_days') const retentionDays = getEntitlementNumericValue() || 1 + const useOtel = useFlag('otelUnifiedLogs') const [isLoading, setIsLoading] = useState(true) const [isRefreshing, setIsRefreshing] = useState(false) @@ -71,8 +72,20 @@ export const UserJourneySheet = ({ identifier, onOpenChange }: UserJourneySheetP const authRows = await ( isId - ? fetchAuthLogsByActorId(projectRef, identifier, start.toISOString(), end.toISOString()) - : fetchAuthLogsByEmail(projectRef, identifier, start.toISOString(), end.toISOString()) + ? fetchAuthLogsByActorId( + projectRef, + identifier, + start.toISOString(), + end.toISOString(), + useOtel + ) + : fetchAuthLogsByEmail( + projectRef, + identifier, + start.toISOString(), + end.toISOString(), + useOtel + ) ).catch(() => { errors.push('Auth') return [] @@ -95,7 +108,8 @@ export const UserJourneySheet = ({ identifier, onOpenChange }: UserJourneySheetP projectRef, userId, start.toISOString(), - end.toISOString() + end.toISOString(), + useOtel ).catch(() => { errors.push('Postgres') return [] @@ -110,7 +124,7 @@ export const UserJourneySheet = ({ identifier, onOpenChange }: UserJourneySheetP setTruncated(didTruncate) setSourcesUsed(Array.from(new Set(allEvents.map((e) => e.source)))) setSourceErrors(errors) - }, [projectRef, identifier, isId, project?.connectionString, retentionDays]) + }, [projectRef, identifier, isId, project?.connectionString, retentionDays, useOtel]) useEffect(() => { if (!identifier) return diff --git a/apps/studio/components/interfaces/UserJourneys/UserJourneys.queries.ts b/apps/studio/components/interfaces/UserJourneys/UserJourneys.queries.ts index 238cf8e1f11..1dcfd69ae05 100644 --- a/apps/studio/components/interfaces/UserJourneys/UserJourneys.queries.ts +++ b/apps/studio/components/interfaces/UserJourneys/UserJourneys.queries.ts @@ -6,9 +6,12 @@ import { logsAllEndpointUrl } from '@/data/logs/logs-endpoint' import { analyticsLiteral, safeSql } from '@/data/logs/safe-analytics-sql' import { executeSql } from '@/data/sql/execute-sql-mutation' -// This feature only targets the OTEL (ClickHouse) logs path — see phase 1 findings, -// the legacy BigQuery path has no auth_event.* / user-correlation fields ported to it. -const otelEndpoint = logsAllEndpointUrl(true) +// The SQL below is OTEL/ClickHouse-only — the legacy BigQuery path has no +// auth_event.* / user-correlation fields (phase 1 finding). The endpoint is no +// longer hardcoded: callers pass `useOtel` (from `useFlag('otelUnifiedLogs')`, +// the same flag the Unified Logs hooks read) so the two backends never get +// crossed. When the flag is off there is no BigQuery equivalent to run, which is +// acceptable while this timeline is parked pending the auth_logs pipeline fix. export interface LogRow { id: string @@ -72,6 +75,7 @@ export async function fetchAuthLogsByActorId( userId: string, isoStart: string, isoEnd: string, + useOtel: boolean, signal?: AbortSignal ): Promise { const idLit = analyticsLiteral(userId) @@ -86,7 +90,7 @@ export async function fetchAuthLogsByActorId( ` const data = await executeAnalyticsSql({ projectRef, - endpoint: otelEndpoint, + endpoint: logsAllEndpointUrl(useOtel), sql, iso_timestamp_start: isoStart, iso_timestamp_end: isoEnd, @@ -105,6 +109,7 @@ export async function fetchAuthLogsByEmail( email: string, isoStart: string, isoEnd: string, + useOtel: boolean, signal?: AbortSignal ): Promise { const emailLit = analyticsLiteral(email) @@ -121,7 +126,7 @@ export async function fetchAuthLogsByEmail( ` const data = await executeAnalyticsSql({ projectRef, - endpoint: otelEndpoint, + endpoint: logsAllEndpointUrl(useOtel), sql, iso_timestamp_start: isoStart, iso_timestamp_end: isoEnd, @@ -143,6 +148,7 @@ export async function fetchPostgresErrorsForUser( userId: string, isoStart: string, isoEnd: string, + useOtel: boolean, signal?: AbortSignal ): Promise { const idPattern = analyticsLiteral(`%${userId}%`) @@ -158,7 +164,7 @@ export async function fetchPostgresErrorsForUser( ` const data = await executeAnalyticsSql({ projectRef, - endpoint: otelEndpoint, + endpoint: logsAllEndpointUrl(useOtel), sql, iso_timestamp_start: isoStart, iso_timestamp_end: isoEnd,