mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem
The Unified Logs trace tab needs the spans for a request's trace.
Nothing in Studio fetches them yet.
Part 2 of 3. Data layer only — the tab that consumes this lands in part
3.
## Solution
Adds `unifiedLogTraceSpansQueryOptions`, fetching `GET
/v2/projects/{ref}/analytics/traces/{trace_id}`, plus the `traceSpans`
query key.
Two choices worth flagging:
**Fetched and parsed directly, not through the typed client.** The route
is live in the v2 OpenAPI spec, but it isn't in the committed
`api-types` — and `get()` is typed off the generated `paths`, so it
can't address a route that isn't there. Getting it there means
regenerating `api-types`, which currently drags in a large amount of
unrelated production drift and breaks Studio's typecheck in three
places. That's worth doing on its own, not as a side effect of this. So
the query goes through `fetchHandler` and parses the response with zod,
following the `platform-apps/platform-app-query.ts` precedent.
The parse likely stays even after a regen: the spec declares no
`additionalProperties` on a span's `attributes`, so the generated type
would describe only the seven known keys and none of the OTel attributes
the trace view actually reads (`http.route`, `url.full`, `db.*`, and
whatever else a service reports). `.passthrough()` keeps them. It also
means the parse is load-bearing — it's the only thing validating the
response shape at runtime, so a backend change surfaces as an error at
the boundary rather than a build failure.
**A temporary knip entry.** Nothing imports the query until part 3, so
knip reports it as an unused file and fails the build. Per
`apps/studio/AGENTS.md`, it's listed in `knip.jsonc` with a `used from
#NNN` comment; part 3 deletes that entry when it adds the importer.
## Review instructions
1. Check the zod schema against the live spec — it should match field
for field:
```bash
curl -s https://api.supabase.com/api/v2-json \
| jq '.components.schemas.ListSpansResponse_Output'
```
2. Confirm the knip entry in `knip.jsonc` is marked temporary and points
at part 3.
3. Run `pnpm knip --workspace apps/studio` and confirm it passes.
## Checklist
Check all before review:
- [ ] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
import { QuerySearchParamsType } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.types'
|
|
|
|
export const logsKeys = {
|
|
otelLogKeys: (projectRef: string | undefined, source: string | undefined) =>
|
|
['projects', projectRef, 'otel-log-keys', source] as const,
|
|
unifiedLogsInfinite: (
|
|
projectRef: string | undefined,
|
|
searchParams: QuerySearchParamsType | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'logs-data',
|
|
...(searchParams ? [searchParams].filter(Boolean) : []),
|
|
] as const,
|
|
unifiedLog: (
|
|
projectRef: string | undefined,
|
|
searchParams: QuerySearchParamsType,
|
|
id: string | undefined
|
|
) => ['projects', projectRef, 'unified-logs', 'single-log', searchParams, id] as const,
|
|
unifiedLogsCount: (
|
|
projectRef: string | undefined,
|
|
searchParams: QuerySearchParamsType | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'count-data',
|
|
...(searchParams ? [searchParams].filter(Boolean) : []),
|
|
] as const,
|
|
unifiedLogsChart: (
|
|
projectRef: string | undefined,
|
|
searchParams: QuerySearchParamsType | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'chart-data',
|
|
...(searchParams ? [searchParams].filter(Boolean) : []),
|
|
] as const,
|
|
unifiedLogsFacetCount: (
|
|
projectRef: string | undefined,
|
|
facet: string,
|
|
facetSearch: string | undefined,
|
|
searchParams: QuerySearchParamsType | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'count-data',
|
|
facet,
|
|
facetSearch,
|
|
...(searchParams ? [searchParams].filter(Boolean) : []),
|
|
] as const,
|
|
logAttributes: (
|
|
projectRef: string | undefined,
|
|
logId: string | undefined,
|
|
source: string | undefined,
|
|
logTimestampMs: number | null | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'log-attributes',
|
|
logId,
|
|
{ source, logTimestampMs },
|
|
] as const,
|
|
requestTimeline: (
|
|
projectRef: string | undefined,
|
|
logId: string | undefined,
|
|
source: string | undefined,
|
|
logTimestampMs: number | null | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'request-timeline',
|
|
logId,
|
|
{ source, logTimestampMs },
|
|
] as const,
|
|
serviceFlow: (
|
|
projectRef: string | undefined,
|
|
searchParams: QuerySearchParamsType | undefined,
|
|
logId: string | undefined
|
|
) =>
|
|
[
|
|
'projects',
|
|
projectRef,
|
|
'unified-logs',
|
|
'service-flow',
|
|
logId,
|
|
...(searchParams ? [searchParams].filter(Boolean) : []),
|
|
] as const,
|
|
traceSpans: (projectRef: string | undefined, traceId: string | undefined) =>
|
|
['projects', projectRef, 'unified-logs', 'trace-spans', traceId] as const,
|
|
}
|