Files
supabase/packages/common/constants/local-storage.ts
kemal.earth b7d8b2d311 feat(studio): traces tab in unified logs (#54393)
## 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.
2026-12-04 11:24:48 +00:00

214 lines
9.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { safeLocalStorage } from '../safe-storage'
const ONBOARDING_SURVEY_FOLLOW_UP_PREFIX = 'supabase-onboarding-survey-follow-up-'
export const LOCAL_STORAGE_KEYS = {
/**
* STUDIO
*/
LOG_PRICING_ANNOUNCEMENT_DISMISSED: 'log-pricing-announcement-dismissed',
AI_ASSISTANT_STATE: (projectRef: string | undefined) =>
`supabase-ai-assistant-state-${projectRef}`,
SIDEBAR_BEHAVIOR: 'supabase-sidebar-behavior',
EXPLORER_PREFERENCES: 'supabase-explorer-preferences',
PROJECTS_VIEW: 'projects-view',
PROJECTS_FILTER: 'projects-filter',
PROJECTS_SORT: 'projects-sort',
FEEDBACK_WIDGET_CONTENT: 'feedback-widget-content',
FEEDBACK_WIDGET_SCREENSHOT: 'feedback-widget-screenshot',
STATUS_BANNER_DISMISSED_KEYS: 'status-banner-dismissed-keys',
DASHBOARD_PREFERENCES: (ref: string) => `dashboard-preferences-${ref}`,
HOME_CHART_INTERVAL: (ref: string) => `home-chart-interval-${ref}`,
UNIFIED_LOGS_DOCK: 'unified-logs-dock',
UI_TIMEZONE: 'supabase-ui-timezone',
UI_THEME_OVERRIDES: 'supabase-ui-theme-overrides',
UI_PREVIEW_CLS: 'supabase-ui-cls',
UI_PREVIEW_INLINE_EDITOR: 'supabase-ui-preview-inline-editor',
UI_PREVIEW_UNIFIED_LOGS: 'supabase-ui-preview-unified-logs',
UI_PREVIEW_ADVISOR_RULES: 'supabase-ui-advisor-rules',
UI_PREVIEW_QUEUE_OPERATIONS: 'supabase-ui-queue-operations',
UI_PREVIEW_PG_DELTA_DIFF: 'supabase-ui-pg-delta-diff',
UI_PREVIEW_PLATFORM_WEBHOOKS: 'supabase-ui-platform-webhooks',
UI_PREVIEW_JIT_DB_ACCESS: 'supabase-ui-jit-db-access',
UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE: 'supabase-ui-sql-editor-manual-save',
UI_PREVIEW_EXPLORER: 'preview-explorer',
UI_PREVIEW_PIPELINE_CREATION: 'supabase-ui-pipeline-creation',
UI_PREVIEW_STORAGE_VERSIONING: 'supabase-ui-storage-versioning',
UI_PREVIEW_TRACES: 'supabase-ui-traces',
AI_ASSISTANT_MCP_OPT_IN: 'ai-assistant-mcp-opt-in',
DASHBOARD_HISTORY: (ref: string) => `dashboard-history-${ref}`,
STORAGE_PREFERENCE: (ref: string) => `storage-explorer-${ref}`,
AUTH_USERS_FILTER: (ref: string) => `auth-users-filter-${ref}`,
AUTH_USERS_SORT_BY_VALUE: (ref: string) => `auth-users-sort-by-value-${ref}`,
AUTH_USERS_COLUMNS_CONFIGURATION: (ref: string) => `supabase-auth-users-columns-${ref}`,
AUTH_USERS_IMPROVED_SEARCH_DISMISSED: (ref: string) =>
`auth-users-improved-search-dismissed-${ref}`,
SQL_EDITOR_INTELLISENSE: 'supabase_sql-editor-intellisense-enabled',
SQL_EDITOR_SPLIT_SIZE: 'supabase_sql-editor-split-size',
// Key to track which schemas are ok to be sent to AI. The project ref is intentionally put at the end for easier search in the browser console.
SQL_EDITOR_AI_SCHEMA: (ref: string) => `supabase_sql-editor-ai-schema-enabled-${ref}`,
SQL_EDITOR_AI_OPEN: 'supabase_sql-editor-ai-open',
SQL_EDITOR_LAST_SELECTED_DB: (ref: string) => `sql-editor-last-selected-db-${ref}`,
SQL_EDITOR_SQL_BLOCK_ACKNOWLEDGED: (ref: string) => `sql-editor-sql-block-acknowledged-${ref}`,
SQL_EDITOR_SECTION_STATE: (ref: string) => `sql-editor-section-state-${ref}`,
SQL_EDITOR_SORT: (ref: string) => `sql-editor-sort-${ref}`,
SQL_EDITOR_MANUAL_SAVE_NOTICE_DISMISSED: 'sql-editor-manual-save-notice-dismissed',
SQL_EDITOR_CONFIRM_UNSAVED_CHANGES: 'sql-editor-confirm-unsaved-changes',
EXPLORER_QUERY_DRAFTS: (ref: string) => `explorer-query-drafts-${ref}`,
NOTEBOOK_DRAFTS: (ref: string) => `notebook-drafts-${ref}`,
LOG_EXPLORER_SPLIT_SIZE: 'supabase_log-explorer-split-size',
GRAPHQL_INTROSPECTION_NOTICE_COLLAPSED: (ref: string) =>
`graphql-introspection-notice-collapsed-${ref}`,
CLS_DIFF_WARNING: 'cls-diff-warning-dismissed',
CLS_SELECT_STAR_WARNING: 'cls-select-star-warning-dismissed',
QUERY_PERF_SHOW_BOTTOM_SECTION: 'supabase-query-perf-show-bottom-section',
LINTER_SHOW_FOOTER: 'supabase-linter-show-footer',
// Key to track account deletion requests
ACCOUNT_DELETION_REQUEST: 'supabase-account-deletion-request',
// Used for storing the last sign in method used by the user
LAST_SIGN_IN_METHOD: 'supabase-last-sign-in-method',
// Key to track the last selected schema. The project ref is intentionally put at the end for easier search in the browser console.
LAST_SELECTED_SCHEMA: (ref: string) => `last-selected-schema-${ref}`,
// Track position of nodes for schema visualizer
SCHEMA_VISUALIZER_POSITIONS: (ref: string, schemaId: number) =>
`schema-visualizer-positions-${ref}-${schemaId}`,
// Used for allowing the main nav panel to expand on hover
EXPAND_NAVIGATION_PANEL: 'supabase-expand-navigation-panel',
GITHUB_AUTHORIZATION_STATE: 'supabase-github-authorization-state',
// Notice banner keys
API_KEYS_FEEDBACK_DISMISSED: (ref: string) => `supabase-api-keys-feedback-dismissed-${ref}`,
SUPAVISOR_MAINTENANCE: (ref: string) => `supavisor-maintenance-2026-06-09-${ref}`,
REPORT_DATERANGE: 'supabase-report-daterange',
PROJECT_PAUSING_STARTED_AT: (ref: string) => `supabase-project-pausing-started-at-${ref}`,
PROJECT_RESTORING_STARTED_AT: (ref: string) => `supabase-project-restoring-started-at-${ref}`,
// api keys view switcher for new and legacy api keys
API_KEYS_VIEW: (ref: string) => `supabase-api-keys-view-${ref}`,
// Connect sheet: remember last-used tab/framework/method etc. across opens
CONNECT_SHEET_PREFS: 'supabase-connect-sheet-prefs',
// Shortcut preferences
SHORTCUT_STORAGE_KEY: 'supabase-shortcut-preferences',
LAST_VISITED_ORGANIZATION: (uid?: number) => `last-visited-organization-${uid}`,
// user impersonation selector previous searches
USER_IMPERSONATION_SELECTOR_PREVIOUS_SEARCHES: (ref: string) =>
`user-impersonation-selector-previous-searches-${ref}`,
LAST_OPENED_SIDE_BAR: (ref: string) => `last-opened-sidebar-${ref}`,
// Index Advisor notice dismissed
INDEX_ADVISOR_NOTICE_DISMISSED: (ref: string) => `index-advisor-notice-dismissed-${ref}`,
// RLS event trigger banner dismissed
RLS_EVENT_TRIGGER_BANNER_DISMISSED: (ref: string) => `rls-event-trigger-banner-dismissed-${ref}`,
PROJECT_SECURITY_DISMISSED_AT: (ref: string) => `project-security-dismissed-at-${ref}`,
ORGANIZATION_MARKETPLACE_BANNER_DISMISSED: (orgSlug: string, managedBy: string) =>
`organization-marketplace-banner-dismissed-${orgSlug}-${managedBy}`,
PROJECT_INTEGRATION_BANNER_DISMISSED: (ref: string, integrationSource: string) =>
`project-integration-banner-dismissed-${ref}-${integrationSource}`,
EXPLORER_BANNER_DISMISSED: `explorer-banner-dismissed`,
EXPLORER_BANNER_EXPOSED_AT: `explorer-banner-exposed-at`,
STORAGE_VERSIONING_PREVIEW_BANNER_DISMISSED: (ref: string) =>
`storage-versioning-preview-banner-dismissed-${ref}`,
TABLE_EDITOR_QUEUE_OPERATIONS_BANNER_DISMISSED: (ref: string) =>
`table-editor-queue-operations-banner-dismissed-${ref}`,
FREE_MICRO_UPGRADE_BANNER_DISMISSED_AT: (ref: string) =>
`free-micro-upgrade-banner-dismissed-at-${ref}`,
PROJECT_UPGRADE_FAILED_BANNER_DISMISSED_AT: (ref: string) =>
`project-upgrade-failed-banner-dismissed-at-${ref}`,
UNIFIED_LOGS_SIDEBAR_BANNER_DISMISSED: 'unified-logs-sidebar-banner-dismissed',
SCOPED_TOKENS_MIGRATION_ADMONITION_DISMISSED: 'scoped-tokens-migration-admonition-dismissed',
STORAGE_PUBLIC_BUCKET_SELECT_POLICY_WARNING_DISMISSED: (ref: string, bucketId: string) =>
`storage-public-bucket-select-policy-warning-dismissed-${ref}-${bucketId}`,
ONBOARDING_SURVEY_FOLLOW_UP: (profileId: string, orgSlug: string) =>
`${ONBOARDING_SURVEY_FOLLOW_UP_PREFIX}${profileId}-${orgSlug}`,
/**
* COMMON
*/
/** @deprecated – we're using usercentrics instead to handle telemetry consent */
TELEMETRY_CONSENT: 'supabase-consent-ph',
/**
* DOCS
*/
SAVED_ORG: 'docs.ui.user.selected.org',
SAVED_PROJECT: 'docs.ui.user.selected.project',
SAVED_BRANCH: 'docs.ui.user.selected.branch',
IA_NAV_FLAG: 'docs-ia-mvp-v1',
DOCS_PAGE_ACTION: 'docs.ui.page-action',
DOCS_LAYOUT_CHOICE: 'docs.ui.layout-choice',
/**
* WWW
*/
BLOG_VIEW: 'supabase-blog-view',
} as const
export type LocalStorageKey = (typeof LOCAL_STORAGE_KEYS)[keyof typeof LOCAL_STORAGE_KEYS]
const LOCAL_STORAGE_KEYS_ALLOWLIST = [
'graphiql:theme',
'theme',
'supabaseDarkMode',
'supabase.dashboard.auth.debug',
'supabase.dashboard.auth.navigatorLock.disabled',
LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT,
LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
LOCAL_STORAGE_KEYS.UI_PREVIEW_QUEUE_OPERATIONS,
LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,
LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS,
LOCAL_STORAGE_KEYS.UI_PREVIEW_PLATFORM_WEBHOOKS,
LOCAL_STORAGE_KEYS.UI_PREVIEW_JIT_DB_ACCESS,
LOCAL_STORAGE_KEYS.UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE,
LOCAL_STORAGE_KEYS.SQL_EDITOR_MANUAL_SAVE_NOTICE_DISMISSED,
LOCAL_STORAGE_KEYS.UI_PREVIEW_PIPELINE_CREATION,
LOCAL_STORAGE_KEYS.UI_PREVIEW_STORAGE_VERSIONING,
LOCAL_STORAGE_KEYS.UI_PREVIEW_TRACES,
LOCAL_STORAGE_KEYS.LAST_SIGN_IN_METHOD,
LOCAL_STORAGE_KEYS.BLOG_VIEW,
LOCAL_STORAGE_KEYS.DOCS_PAGE_ACTION,
LOCAL_STORAGE_KEYS.DOCS_LAYOUT_CHOICE,
LOCAL_STORAGE_KEYS.AI_ASSISTANT_MCP_OPT_IN,
LOCAL_STORAGE_KEYS.LINTER_SHOW_FOOTER,
LOCAL_STORAGE_KEYS.SIDEBAR_BEHAVIOR,
LOCAL_STORAGE_KEYS.EXPLORER_PREFERENCES,
LOCAL_STORAGE_KEYS.UI_TIMEZONE,
LOCAL_STORAGE_KEYS.UI_THEME_OVERRIDES,
]
export function clearLocalStorage() {
for (const key of safeLocalStorage.keys()) {
const isRecoveryReminder = key.startsWith('account-recovery-reminder:')
// Per-profile, and holds the new org's type and size until the follow-up saves them
const isOnboardingSurveyFollowUp = key.startsWith(ONBOARDING_SURVEY_FOLLOW_UP_PREFIX)
// Consent belongs to the browser, so an opt-out has to survive sign-out
const isConsentRecord =
key.startsWith('uc_') ||
key === 'ucData' ||
key === 'ucString' ||
key.startsWith('__ph_opt_in_out_')
if (
!LOCAL_STORAGE_KEYS_ALLOWLIST.includes(key) &&
!isRecoveryReminder &&
!isOnboardingSurveyFollowUp &&
!isConsentRecord
) {
safeLocalStorage.removeItem(key)
}
}
}