Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix: Update the auth user field in the Logs page (#48237)

Ivan Vasilov810852868289
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts
index 15f713a3474..a9b62e271bd 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts
@@ -282,14 +282,18 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
})
describe('user filter', () => {
- it('restricts to auth_logs/postgres_logs and skips the default postgres+edge restriction', () => {
+ it('restricts to auth_logs/edge_logs and skips the default postgres+edge restriction', () => {
const sql = getUnifiedLogsQuery(withUser('user-123'))
const where = sql.split(/\bWHERE\b/)[1] ?? ''
- expect(where).toContain(`log_attributes['auth_event.actor_id'] = 'user-123'`)
- expect(where).toContain(`source = 'postgres_logs'`)
- // The unfiltered default (postgres_logs OR edge_logs) would incorrectly exclude
+ expect(where).toContain(
+ `(source = 'auth_logs' AND log_attributes['auth_event.actor_id'] = 'user-123')`
+ )
+ expect(where).toContain(
+ `(source = 'edge_logs' AND log_attributes['request.sb.jwt.authorization.payload.subject'] = 'user-123')`
+ )
+ // The unfiltered default (edge_logs OR postgres_logs) would incorrectly exclude
// auth_logs, the primary attributable source, so it must not appear here.
- expect(where).not.toContain(`(source = 'postgres_logs') OR (source = 'edge_logs')`)
+ expect(where).not.toContain(`(source = 'edge_logs') OR (source = 'postgres_logs')`)
})
it('does not restrict sources when the user filter is inactive', () => {
@@ -321,8 +325,8 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
expect(isUserFilterUnreachable(withUser('user-123', 'log_type:eq:auth'))).toBe(false)
})
- it('is false when the explicit log_type filter includes an attributable source (postgres)', () => {
- expect(isUserFilterUnreachable(withUser('user-123', 'log_type:eq:postgres'))).toBe(false)
+ it('is false when the explicit log_type filter includes an attributable source (edge)', () => {
+ expect(isUserFilterUnreachable(withUser('user-123', 'log_type:eq:edge'))).toBe(false)
})
it('is false when at least one of several selected log types is attributable', () => {
@@ -332,12 +336,12 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
})
it('is true when the explicit log_type filter restricts to a single non-attributable source', () => {
- expect(isUserFilterUnreachable(withUser('user-123', 'log_type:eq:edge'))).toBe(true)
+ expect(isUserFilterUnreachable(withUser('user-123', 'log_type:eq:storage'))).toBe(true)
})
it('is true when every selected log type is non-attributable', () => {
expect(
- isUserFilterUnreachable(withUser('user-123', 'log_type:eq:edge', 'log_type:eq:storage'))
+ isUserFilterUnreachable(withUser('user-123', 'log_type:eq:realtime', 'log_type:eq:storage'))
).toBe(true)
})
@@ -347,7 +351,7 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
it('(neq) is true only when both attributable sources are excluded', () => {
expect(
- isUserFilterUnreachable(withUser('user-123', 'log_type:neq:auth', 'log_type:neq:postgres'))
+ isUserFilterUnreachable(withUser('user-123', 'log_type:neq:auth', 'log_type:neq:edge'))
).toBe(true)
})
})
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
index 1b56bae859e..619fd33ceef 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
@@ -104,6 +104,13 @@ const LEVEL_EXPR: SafeLogSqlFragment = safeSql`CASE
ELSE 'success'
END`
+// The `auth_user` column is derived from the source-specific fields that can be attributed to a user.
+const AUTH_USER_EXPR: SafeLogSqlFragment = safeSql`nullIf(CASE
+ WHEN source = 'auth_logs' THEN log_attributes['auth_event.actor_id']
+ WHEN source = 'edge_logs' THEN log_attributes['request.sb.jwt.authorization.payload.subject']
+ ELSE null
+ END, '')`
+
const logTypeWhereCondition = (logTypes: string[]): SafeLogSqlFragment => {
const effective = logTypes.filter((t) => t in LOG_TYPE_CONDITION)
const types = effective.length ? effective : [...DEFAULT_LOG_TYPES]
@@ -248,7 +255,7 @@ const truncationFunction = (level: 'MINUTE' | 'HOUR' | 'DAY'): SafeLogSqlFragmen
* inlined so the result can be referenced (or filtered) at the same query
* level — the OTEL endpoint rejects subqueries.
*/
-const rowProjection = (): SafeLogSqlFragment => safeSql`
+const ROW_PROJECTION: SafeLogSqlFragment = safeSql`
id,
null AS source_id,
timestamp,
@@ -258,6 +265,7 @@ const rowProjection = (): SafeLogSqlFragment => safeSql`
${ATTR.path} AS pathname,
event_message,
${ATTR.method} AS method,
+ ${AUTH_USER_EXPR} AS auth_user,
null AS log_count,
null AS logs
`
@@ -335,17 +343,14 @@ const userAttributionCondition = (search: QuerySearchParamsType): SafeLogSqlFrag
const value = userFilterValue(search)
if (!value) return null
const exact = lit(value)
- const contains = lit('%' + value + '%')
return safeSql`(
- (source = 'auth_logs' AND (
- log_attributes['auth_event.actor_id'] = ${exact}
- OR event_message ILIKE ${contains}
- ))
- OR (source = 'postgres_logs' AND event_message ILIKE ${contains})
+ (source = 'auth_logs' AND log_attributes['auth_event.actor_id'] = ${exact})
+ OR
+ (source = 'edge_logs' AND log_attributes['request.sb.jwt.authorization.payload.subject'] = ${exact})
)`
}
-const USER_ATTRIBUTABLE_SOURCES = new Set([LOG_TYPE_TO_SOURCE.auth, LOG_TYPE_TO_SOURCE.postgres])
+const USER_ATTRIBUTABLE_SOURCES = new Set([LOG_TYPE_TO_SOURCE.auth, LOG_TYPE_TO_SOURCE.edge])
/**
* True when the user filter is active but an explicit log_type filter restricts the
@@ -411,7 +416,7 @@ const applySearchParamsFilter = (search: QuerySearchParamsType): SafeLogSqlFragm
export const getUnifiedLogsQuery = (search: QuerySearchParamsType): SafeLogSqlFragment => {
const conditions = buildBaseWhere(search)
return safeSql`-- unified logs: row list
-SELECT ${rowProjection()}
+SELECT ${ROW_PROJECTION}
FROM logs
${whereClause(conditions)}
`