mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
With the unified logs preview on, an edge function's Logs tab renders the unified logs view scoped to that function (#50954), with its invocations and runtime output in one list. That replaces the separate Invocations and Logs tabs. - `UnifiedLogs` takes a `scope` plus view props: `hasFilterSideBar`, `offeredFilters` and `columnPreferencesKey`. The function Logs tab turns the sidebar off, which also drops the filters-toggle shortcut, and saves its columns and panel layout separately from the Logs page. - `getEdgeFunctionLogsScope` and `EDGE_FUNCTION_LOGS_VIEW` are the edge function preset: the scope's fixed filters, the filters the tab offers and its saved-columns key. It offers date, log type, level and message, so no user filter, since no function row has a user. - The Invocations tab and its shortcut are hidden. Old Invocations links redirect to Logs, converting `its`/`ite`/`log` to `date`/`id`. - `getEdgeFunctionLogsUrl` builds links into the scoped tab with the shared params serializer from #50953, and clicking a bar on the invocations chart uses it. With the preview off, both tabs work as on master. ### How to test 1. Turn on the unified logs preview and open an edge function's Logs tab. You should see only that function's invocations and runtime logs, with the filter bar limited to date, log type, level and message. 2. Filter to Edge Function runtime, then to errors, and check counts and the chart follow. 3. Open an old `/functions/<slug>/invocations?its=…&ite=…&log=…` link. It lands on Logs with the same range and log selected. 4. Click a bar on the Overview invocations chart. The Logs tab opens on that bucket. ### Validation - URL helper, offered filter and preset tests, plus the scoped query tests from #50954. - Studio typecheck, lint ratchet, Prettier and knip pass on this layer. ### Stack Merge in order: 1. #50953 — reusable logs table building blocks 2. #50954 — function-scoped unified logs queries 3. #50955 — slimmer function detail layout, header on Overview 4. #50957 — Invocations merged into a function-scoped Logs tab 5. #50958 — Overview errors in the shared logs table 6. #52281 — remove the legacy Overview --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jordi Enric <jordi.err@gmail.com>
74 lines
2.8 KiB
TypeScript
74 lines
2.8 KiB
TypeScript
import { getFunctionLogsDateRange } from './EdgeFunctionOverview/EdgeFunctionOverview.utils'
|
|
import { SEARCH_PARAMS_PARSER } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.constants'
|
|
import { parseLogsFilterUrlParams } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.filters'
|
|
import { serializeUnifiedLogsSearchParams } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.utils'
|
|
|
|
export function getFunctionLogsMigrationUrl({
|
|
projectRef,
|
|
functionSlug,
|
|
searchParams,
|
|
usesOtelLegacyLogs = false,
|
|
}: {
|
|
projectRef: string
|
|
functionSlug: string
|
|
searchParams: URLSearchParams
|
|
usesOtelLegacyLogs?: boolean
|
|
}): string | null {
|
|
const params = new URLSearchParams(searchParams)
|
|
const unifiedFilters = SEARCH_PARAMS_PARSER.filter.parse(params.get('filter') ?? '') ?? []
|
|
const validFilters = unifiedFilters.filter(
|
|
(filter) => parseLogsFilterUrlParams([filter]).length > 0
|
|
)
|
|
const filters = [...validFilters]
|
|
|
|
if (filters.length === 0) {
|
|
let legacyFilters: unknown = {}
|
|
try {
|
|
legacyFilters = JSON.parse(params.get('f') || '{}')
|
|
} catch {
|
|
return null
|
|
}
|
|
if (
|
|
typeof legacyFilters !== 'object' ||
|
|
legacyFilters === null ||
|
|
Array.isArray(legacyFilters)
|
|
) {
|
|
return null
|
|
}
|
|
const activeFilters = Object.entries(legacyFilters).filter(([, value]) => value !== false)
|
|
if (activeFilters.some(([key]) => key !== 'search_query')) return null
|
|
const legacySearch =
|
|
params.get('s') || activeFilters.find(([key]) => key === 'search_query')?.[1]
|
|
if (legacySearch !== undefined && typeof legacySearch !== 'string') return null
|
|
if (legacySearch) {
|
|
if (!usesOtelLegacyLogs) return null
|
|
if (/[\\^$.*+?()[\]{}|%_]/.test(legacySearch)) return null
|
|
filters.push(`event_message:ilike:${legacySearch}`)
|
|
}
|
|
}
|
|
|
|
const unifiedDate = SEARCH_PARAMS_PARSER.date.parse(params.get('date') ?? '')
|
|
let date: Date[] | null = null
|
|
if (unifiedDate?.length === 2 && unifiedDate.every((value) => Number.isFinite(value.getTime()))) {
|
|
date = getFunctionLogsDateRange(unifiedDate[0].toISOString(), unifiedDate[1].toISOString())
|
|
}
|
|
const start = params.get('its') || undefined
|
|
const end = params.get('ite') || undefined
|
|
const partialRange = start || end
|
|
const hasValidPartialRange =
|
|
Boolean(start) !== Boolean(end) &&
|
|
!!partialRange &&
|
|
Number.isFinite(new Date(partialRange).getTime())
|
|
if (!date && hasValidPartialRange) return null
|
|
date ??= getFunctionLogsDateRange(start, end)
|
|
const id = params.get('id') || params.get('log') || null
|
|
for (const key of ['its', 'ite', 'log', 's', 'f']) params.delete(key)
|
|
const query = params.toString()
|
|
const base = `/project/${projectRef}/functions/${functionSlug}/logs${query ? `?${query}` : ''}`
|
|
return serializeUnifiedLogsSearchParams(base, {
|
|
date,
|
|
id,
|
|
filter: filters.length ? filters : null,
|
|
})
|
|
}
|