mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Unified Logs can show the logs correlated with a request, but not the trace behind it. Where time actually went across services isn't visible anywhere in Studio. Part 3 of 3, and the one that ships the feature. Builds on the `Trace` primitives from part 1 and the spans query from part 2. ## Solution Adds a **Trace** tab to the log detail panel, composed entirely from the shared `Trace` primitives — header, summary strip, waterfall, inspector — and ships it as a feature preview. **Resolving the trace id.** The selected log's own trace id wins. A related log's id is used only as a fallback, and only when there's exactly one candidate — picking between several would be a guess. The ids come from the correlated logs the Timeline tab already fetches, so the two tabs share a cache entry instead of each making a request. **Mapping spans.** `RequestTrace.utils.ts` turns the endpoint's spans into `Trace`'s `Span`/`TraceData` shape. Three things worth noting: - Span names come from OTel attributes where the raw name isn't useful on its own — a span named `GET` becomes `GET /rest/v1/orders` from `http.route`, falling back to the path from `url.full` for outbound fetches that have no server-matched route. - `Date.parse` only resolves whole milliseconds, so two spans less than a millisecond apart would round to the same instant and render stacked. The fractional part of the ISO string is added back. - Spans with a missing or invalid start time are counted and reported rather than dropped silently. **States.** The tab is always present when the Timeline is, so a request with no trace shows an empty state rather than a tab that appears and disappears as the trace resolves. Separate states cover: no trace id, a trace with no spans, spans that exist but can't be placed, and a failed fetch. `meta.partial` surfaces as a badge, since a trace can be incomplete while spans are still being collected. **Feature preview.** Listed under Observability as "Request traces", following the same pattern as the Explorer and Storage versioning previews. Two gates gives the kill switch and the opt-in independently: - `enableTracesWaterfall` (ConfigCat) controls whether the preview is listed at all - The user's opt-in controls the tab, stored in local storage and preserved across sign-out It's not default opt-in, so nobody gets the tab without choosing it — the endpoint is still alpha. Also removes the temporary `knip.jsonc` entry added in part 2, now that the query has an importer. ## Review instructions 1. Open the feature preview modal and confirm **Request traces** is listed under Observability, with a panel describing the feature. Enable it. 2. Open **Logs** and select a request log that has a trace id. 3. Confirm the **Trace** tab appears beside Timeline, with the header, the summary strip (trace start, duration, services, depth, span count) and the waterfall. 4. Select a span and confirm the inspector opens with its attributes and events. 5. Select a request with no trace id and confirm the tab is still there, showing an empty state. 6. Turn the preview off and confirm the tab disappears while Timeline is unaffected. 7. `pnpm --filter studio test components/interfaces/UnifiedLogs/components/RequestTrace.utils.test.ts components/interfaces/UnifiedLogs/components/RequestTimeline.platform.test.tsx` Note the traces endpoint is in alpha: a request only has a trace when its logs carry a trace ID, so landing on the empty state in step 2 isn't necessarily this PR misbehaving. The component tests cover every state against mocked responses.
211 lines
7.4 KiB
TypeScript
211 lines
7.4 KiB
TypeScript
import { LOCAL_STORAGE_KEYS, useFlag } from 'common'
|
|
import { useMemo } from 'react'
|
|
|
|
import { type BannerId } from '@/components/ui/BannerStack/BannerStackProvider'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
|
|
export type FeaturePreview = {
|
|
key: string
|
|
name: string
|
|
discussionsUrl?: string
|
|
isNew: boolean
|
|
/** If feature flag is only relevant for the hosted platform */
|
|
isPlatformOnly: boolean
|
|
/** If feature flag should be enabled by default for users, if not yet toggled before */
|
|
isDefaultOptIn: boolean
|
|
/** Visibility in the feature preview modal (For feature flagging a feature preview) */
|
|
enabled: boolean
|
|
/**
|
|
* Forces the preview on for this user, whatever they previously chose — for a
|
|
* preview that has become the default behavior. Overrides both `isDefaultOptIn`
|
|
* and a stored opt-out, and takes away the ability to turn the preview back off.
|
|
*/
|
|
isForced?: boolean
|
|
/** Optional category that the feature preview falls under, defaults to "Others" in the UI otherwise */
|
|
category?: 'observability' | 'database' | 'editors' | 'storage'
|
|
/**
|
|
* Where to send the user after enabling, to try the feature out. Omit if the
|
|
* feature has no single destination (e.g. a global layout change).
|
|
*/
|
|
getRoute?: (ref?: string) => string
|
|
/**
|
|
* Set when nested routes under `getRoute` also surface the feature, so being
|
|
* on one of them counts as already being at the destination. Otherwise only
|
|
* an exact match of `getRoute` does.
|
|
*/
|
|
matchesSubroutes?: boolean
|
|
bannerId?: BannerId
|
|
}
|
|
|
|
export const useFeaturePreviews = (): FeaturePreview[] => {
|
|
const isPipelineCreationWizardAvailable = useFlag('pipelineCreationWizard')
|
|
const isPlatformWebhooksEnabled = useFlag('platformWebhooks')
|
|
const jitDbAccessEnabled = useFlag('jitDbAccess')
|
|
const isExplorerEnabled = useFlag('explorer')
|
|
const isStorageVersioningEnabled = useFlag('storageVersioningPrivateAlpha')
|
|
const isTracesEnabled = useFlag('enableTracesWaterfall')
|
|
|
|
const isSqlEditorManualSaveForced = useFlag('sqlEditorManualSaveForced')
|
|
|
|
return useMemo(() => {
|
|
const previews: FeaturePreview[] = [
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_PIPELINE_CREATION,
|
|
name: 'Pipeline creation wizard',
|
|
category: 'database',
|
|
enabled: isPipelineCreationWizardAvailable,
|
|
isNew: true,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_EXPLORER,
|
|
name: 'Explorer & Notebooks',
|
|
category: 'editors',
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/49916',
|
|
enabled: isExplorerEnabled,
|
|
isNew: true,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
getRoute: (ref?: string) => `/project/${ref}/explorer`,
|
|
matchesSubroutes: true,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS,
|
|
name: 'Updated Logs interface',
|
|
category: 'observability',
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/37234',
|
|
enabled: true,
|
|
isNew: false,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: true,
|
|
getRoute: (ref?: string) => `/project/${ref}/logs`,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_ADVISOR_RULES,
|
|
name: 'Disable Advisor rules',
|
|
discussionsUrl: undefined,
|
|
enabled: true,
|
|
isNew: false,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
getRoute: (ref?: string) => `/project/${ref}/advisors/rules/security`,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_PG_DELTA_DIFF,
|
|
name: 'PG Delta diff',
|
|
discussionsUrl: undefined,
|
|
isNew: false,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: true,
|
|
enabled: true,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_PLATFORM_WEBHOOKS,
|
|
name: 'Platform webhooks',
|
|
discussionsUrl: undefined,
|
|
isNew: false,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
enabled: isPlatformWebhooksEnabled,
|
|
getRoute: (ref?: string) => `/project/${ref}/settings/webhooks`,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_JIT_DB_ACCESS,
|
|
name: 'Database token access',
|
|
category: 'database',
|
|
discussionsUrl: undefined,
|
|
isNew: false,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
enabled: jitDbAccessEnabled,
|
|
getRoute: (ref?: string) => `/project/${ref}/database/settings`,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,
|
|
name: 'Column-level privileges',
|
|
category: 'database',
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/20295',
|
|
enabled: true,
|
|
isNew: false,
|
|
isPlatformOnly: false,
|
|
isDefaultOptIn: false,
|
|
getRoute: (ref?: string) => `/project/${ref}/database/column-privileges`,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE,
|
|
category: 'editors',
|
|
name: 'Disable snippet auto-saving',
|
|
discussionsUrl: undefined,
|
|
isNew: false,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
enabled: true,
|
|
// Manual saving is becoming the default for the SQL Editor. The preview
|
|
// stays listed so users who lose their local storage can opt back in
|
|
// before the rollout reaches them.
|
|
isForced: isSqlEditorManualSaveForced,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_STORAGE_VERSIONING,
|
|
name: 'Storage object versioning',
|
|
category: 'storage',
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/54551',
|
|
isNew: true,
|
|
isPlatformOnly: false,
|
|
isDefaultOptIn: true,
|
|
enabled: isStorageVersioningEnabled,
|
|
getRoute: (ref?: string) => `/project/${ref}/storage/files`,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_TRACES,
|
|
name: 'Request traces',
|
|
category: 'observability',
|
|
discussionsUrl: undefined,
|
|
isNew: true,
|
|
isPlatformOnly: true,
|
|
isDefaultOptIn: false,
|
|
enabled: isTracesEnabled,
|
|
getRoute: (ref?: string) => `/project/${ref}/logs`,
|
|
},
|
|
]
|
|
|
|
return previews.sort((a, b) => Number(b.isNew) - Number(a.isNew))
|
|
}, [
|
|
isPipelineCreationWizardAvailable,
|
|
isSqlEditorManualSaveForced,
|
|
isPlatformWebhooksEnabled,
|
|
jitDbAccessEnabled,
|
|
isExplorerEnabled,
|
|
isStorageVersioningEnabled,
|
|
isTracesEnabled,
|
|
])
|
|
}
|
|
|
|
export type FeaturePreviewCategoryGroup = {
|
|
category: FeaturePreview['category']
|
|
previews: FeaturePreview[]
|
|
}
|
|
|
|
/**
|
|
* The visible feature previews (respecting platform-only/enabled gating),
|
|
* grouped by category in first-seen order, uncategorized previews last as a
|
|
* final `category: undefined` group. Shared by the feature preview modal and
|
|
* the Cmd+K "Feature previews" page so both list the exact same previews.
|
|
*/
|
|
export const useVisibleFeaturePreviewsByCategory = (): FeaturePreviewCategoryGroup[] => {
|
|
const featurePreviews = useFeaturePreviews()
|
|
|
|
return useMemo(() => {
|
|
const previews = (
|
|
IS_PLATFORM ? featurePreviews : featurePreviews.filter((preview) => !preview.isPlatformOnly)
|
|
).filter((preview) => preview.enabled)
|
|
const categories = [...new Set(previews.map((preview) => preview.category).filter(Boolean))]
|
|
|
|
return categories.concat(undefined).map((category) => ({
|
|
category,
|
|
previews: previews.filter((preview) => preview.category === category),
|
|
}))
|
|
}, [featurePreviews])
|
|
}
|