Skip to content

feat(cli): traces interface - #7763

Open
kemaldotearth wants to merge 25 commits into
developfrom
kemal/debug-308-design-the-cli-interface-for-traces
Open

kemaldotearth wants to merge 25 commits into
developfrom
kemal/debug-308-design-the-cli-interface-for-traces

Conversation

@kemaldotearth

@kemaldotearth kemaldotearth commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

Adds an experimental supabase traces command that looks up a trace by id and prints its spans, using the Management API's v2-get-trace operation via the generated packages/api client. Gated behind --experimental / SUPABASE_EXPERIMENTAL=1: closed alpha, trace search doesn't exist yet, and the output may still change.

Linked issue

Closes #

  • The linked issue is open and carries the open-for-contribution label (or I'm a Supabase maintainer).

Checklist

  • The PR title follows Conventional Commits (e.g. fix(cli): …).
  • Tests added or updated for the change.
  • From the repository root, pnpm check:all passes for every workspace touched by this PR; relevant package tests pass for every touched workspace, and pnpm types:check passes for each touched TypeScript workspace.

…sign-the-cli-interface-for-traces

# Conflicts:
#	apps/cli/src/cli/root.ts
#	apps/cli/src/command-internal/colors.ts
@kemaldotearth
kemaldotearth marked this pull request as ready for review December 2, 2026 16:03
@kemaldotearth
kemaldotearth requested a review from a team as a code owner December 2, 2026 16:03
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

CLI benchmark (Lightweight Commands): no changes found

Commit c6127e1 against develop at db9167e · 10 runs each · report only, never blocks merging

Command Workload Before After Change
supabase --version version 321 ms 351 ms no real change (+9%, within normal variation)
supabase --help help 263 ms 250 ms no real change (-5%, within normal variation)
supabase init init 201 ms 171 ms no real change (-15%, within normal variation)
supabase migration new bench migration-new 221 ms 226 ms no real change
supabase config convert config-convert 245 ms 242 ms no real change
supabase config validate config-validate 258 ms 256 ms no real change
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 240 ms 241 ms no real change
supabase projects list projects-list 206 ms 213 ms no real change
supabase functions list --project-ref replayfixtureprojref functions-list 221 ms 222 ms no real change

API calls: unchanged for all 9 commands.

Binary size: 135.1 MB, up 24.0 KB from 135.1 MB.

Details: timing ranges, API calls per command, slowest phases

Timing ranges

Command Workload Before range After range Change Verdict
supabase --version version 179-526 ms 161-445 ms +30 ms (+9%) within noise
supabase --help help 196-308 ms 183-327 ms -13 ms (-5%) within noise
supabase init init 159-244 ms 148-233 ms -30 ms (-15%) within noise
supabase migration new bench migration-new 199-285 ms 199-248 ms +5 ms (+2%) within noise
supabase config convert config-convert 214-322 ms 211-350 ms -2 ms (-1%) within noise
supabase config validate config-validate 199-454 ms 208-428 ms -3 ms (-1%) within noise
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 201-309 ms 208-289 ms +1 ms (+1%) within noise
supabase projects list projects-list 177-243 ms 197-277 ms +6 ms (+3%) within noise
supabase functions list --project-ref replayfixtureprojref functions-list 208-287 ms 158-263 ms +1 ms (+0%) within noise

API calls per command

Command Workload Before After Endpoint changes
supabase --version version 0 0
supabase --help help 0 0
supabase init init 0 0
supabase migration new bench migration-new 0 0
supabase config convert config-convert 0 0
supabase config validate config-validate 0 0
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 2 2
supabase projects list projects-list 1 1
supabase functions list --project-ref replayfixtureprojref functions-list 2 2

Slowest phases

No command moved beyond noise, so there are no phase deltas.

Workflow run

Comment /bench to run the lightweight benchmark (this comment) again on the latest commit, or /bench full to also run the integration-heavy benchmark, which posts in its own comment.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

CLI reference prose guidance: snapshot supabase/supabase@4da4e91 supplied to reviewers (advisory, not a style pass).

The PR adds the experimental supabase traces command. Both independent reviews were available. Their 23 findings resolve to 20 confirmed findings after merging three overlaps. The highest-severity finding is that deep traces can fail before any output is produced. The review also confirmed unsanitized span IDs in terminal output, misleading timing and completeness information, and four generated Fumadocs files whose source files are missing. The supplied next context shows no fundamental conflict. Verification included code inspection and focused Bun checks. The full CLI suite was not run because workspace dependencies were absent.

Findings

Severity Location Category Sources Claim
🟠 MAJOR apps/cli/src/commands/traces/traces.tree.ts:40 correctness codex A sufficiently deep trace can overflow the call stack before the command produces text or structured output.
🟡 MINOR apps/cli/src/commands/traces/traces.render.ts:128 security claude+codex Returned span IDs bypass terminal sanitization in the ID column and the first-error line.
🟡 MINOR apps/cli/src/commands/traces/traces.handler.ts:83 error-handling claude A malformed --trace-id produces the generated client's schema error and is classified as an internal request-construction failure.
🟡 MINOR apps/cli/src/commands/traces/traces.handler.ts:43 timing codex The command loses submillisecond precision before it orders spans or computes durations.
🟡 MINOR apps/cli/src/commands/traces/traces.handler.ts:49 timing codex An unparseable span timestamp can make a present-day trace appear to start in 1970 and last decades.
🟡 MINOR apps/cli/src/commands/traces/traces.tree.ts:55 correctness codex Cycle recovery can detach a span from its valid parent even when the span is outside the cycle.
🟡 MINOR apps/cli/src/commands/traces/traces.tree.ts:40 correctness codex Repeated span IDs can be counted twice or silently dropped depending on their parentage.
🟡 MINOR apps/cli/src/commands/traces/traces.handler.ts:119 terminal-output codex The default text output presents duration and counts without indicating that they describe a partial trace.
🟡 MINOR apps/cli/src/commands/traces/traces.render.ts:122 terminal-output codex Long labels or deep indentation can hide the error and slowest-span markers in terminal output.
🟡 MINOR apps/cli/src/commands/traces/traces.handler.ts:123 terminal-output claude+codex Color preferences govern terminal layout, so forced color can truncate piped output while a no-color TTY can get unbounded rows.
🟡 MINOR apps/docs/.source/server.ts:2 stray-artifact claude+codex The PR adds four generated Fumadocs files for a docs app whose source configuration and content are absent.
🟡 MINOR apps/cli/src/commands/traces/SIDE_EFFECTS.md:20 documentation codex The side-effects table overstates when the handler runs its cache and telemetry finalizers and when those finalizers write files.
🟡 MINOR apps/cli/src/commands/traces/traces.tree.unit.test.ts:136 test-quality codex The error-ordering test cannot detect changes to the order of error spans.
⚪ NIT apps/cli/src/commands/traces/SIDE_EFFECTS.md:38 docs-accuracy claude The side-effects table incorrectly says SUPABASE_API_MAX_RETRIES does not apply to the trace request.
⚪ NIT apps/cli/src/commands/traces/traces.tree.unit.test.ts:102 test-quality codex The large-trace test claims to exercise rendering but measures only tree construction and flattening.
⚪ NIT apps/cli/src/commands/traces/traces.integration.test.ts:160 test-quality codex The success-with-errors test duplicates the successful invocation already covered by the plain-text integration test.
⚪ NIT apps/cli/src/commands/traces/traces.integration.test.ts:225 test-quality codex The route assertion accepts an incorrect path that contains the expected route as a substring.
⚪ NIT apps/cli/src/commands/traces/traces.render.ts:97 maintainability codex Each renderer cell carries an unused depth field.
⚪ NIT apps/cli/src/commands/traces/traces.command.ts:21 docs-style codex The flag description uses lowercase id in prose and uses time-relative wording for search availability.
⚪ NIT apps/cli/src/commands/traces/traces.command.ts:31 docs-style codex The command description uses lowercase id in prose and uses may to express an uncertain outcome.

Stats

Claude findings: 5 · Codex findings: 18 · Confirmed: 20 · Refuted: 0 · Uncertain: 0


Models: claude-opus-5-5 + gpt-6.2-sol · Trigger: auto · Workflow run

This review runs once per PR. A maintainer can request another with a /ai-review comment.

@jordienr jordienr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align the generated reference and validation errors with the command’s actual behavior, and clarify how the footer selects the first error. The 110 focused tests passed. The inline comments include the cases I reproduced.

const config = {
traceId: Flag.String("trace-id").pipe(
Flag.withDescription("The ID of the trace to look up. Trace search is unavailable."),
Flag.optional,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every successful lookup requires --trace-id, but the generated reference gives it an empty default and omits the required badge. Please keep the tailored missing-ID error and add Flag.annotate(FlagDocumentation, { required: true }), following gen bearer-jwt. Describe the 32-character lowercase hexadecimal format and add a Command.withExamples invocation with both --experimental and --trace-id so users can copy it from help or the reference.

yield* requiredExperimentalAccess.check;
return yield* tracesGet(flags).pipe(
withCommandTelemetry({ flags }),
Effect.provide(managementApiRuntimeLayer(["traces"])),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a clean CLI home, supabase traces --experimental --trace-id bad --output-format json returns AccessTokenRequiredError. This layer loads credentials before the handler validates the ID, so the user is told to log in to fix a malformed argument. Please defer credential resolution until flag validation passes and cover this case through the real command entry point.

Effect.gen(function* () {
yield* requiredExperimentalAccess.check;
return yield* tracesGet(flags).pipe(
withCommandTelemetry({ flags }),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-o csv tells users to choose from env, pretty, json, toml, and yaml. Following that advice with -o json then tells them -o is unsupported. Please pass outputFormats: GLOBAL_OUTPUT_FORMATS to the wrapper, following logs, so both values reach the handler and point users to --output-format json|stream-json.


const closingLine =
summary.errorSpanIds.length > 0
? `\nTrace has errors. First error span: ${shortenTraceId(sanitizeInlineName(summary.errorSpanIds[0]!))}\n`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a trace with errors in sibling branches at +2ms and +50ms, the footer reported the +50ms span as “First error span” because its branch appeared first in the tree. Please choose the earliest error by start time, or label this “First error shown” if the footer is meant to follow display order. A sibling-branch test would capture the distinction.

@Coly010 Coly010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey 👋 thanks for this, the span tree output is really nice to read

Requesting changes, but it's about how the command is gated, not the command itself.

Blocking:

traces uses the per-command --experimental gate (requiredExperimentalAccess). Unless im mistaken, that means it's listed in supabase --help for everyone, and with withSidebar it ends up in the generated reference docs and sidebar as well - I checked on this branch and supabase traces is in both. For something still in closed alpha I don't think we want to advertise it to users who can't use it yet.

Since warehouse (#7640), closed-alpha features use a project-level toggle instead, which keeps the command out of the tree, help, completion and the stable docs until the project opts in. Could we move traces over to that?

  • [experimental.traces] enabled = true / SUPABASE_EXPERIMENTAL_TRACES_ENABLED - a table with enabled, not a bare experimental.traces = true (that's the shape #7847 just moved stack and compute to)
  • register it in featureSchemas/featureKeys in shared/config/experimental-feature.ts and mount the command conditionally in root.ts, the same way compute is
  • add ["experimental", "traces"] to DOCUMENT_ONLY_LOCAL_PATHS in hosted-sections.ts, otherwise config diff/config pull will treat it as a hosted setting
  • move the code under src/commands/experimental/traces/, which is where apps/cli/AGENTS.md puts opt-in commands

Non-blocking:

  • Closes # in the description is empty - could you link the issue this is for?

otherwise, it looks good to me!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants