Skip to content

feat(traces): add --fields projection flag to traces get and export#58

Open
dark-sorceror wants to merge 3 commits into
mainfrom
feat/traces-fields-flag
Open

feat(traces): add --fields projection flag to traces get and export#58
dark-sorceror wants to merge 3 commits into
mainfrom
feat/traces-fields-flag

Conversation

@dark-sorceror

@dark-sorceror dark-sorceror commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #51

traceroot traces get never sent the fields query parameter, so every span came back from the server's default skeleton projection with input: null, output: null, metadata: null — silently, with no error. That's the exact payload someone debugging a trace needs. Meanwhile traces export bundles already contained full I/O (the export endpoint defaults to full server-side), so get and export disagreed about the same trace with nothing in --help or the README explaining why. This PR wires the fields projection parameter (already documented in the vendored openapi.json) through both commands so callers can ask for full or a specific group like io,metadata, and documents the default in --help and the README.

How it works

traces get/export --fields <groups>
  → parsed as a plain string option (onceOption guards against repeats)
    → threaded into ApiClient.getTrace/exportTrace as { fields }
      → appended as ?fields=<groups> on the request URL, omitted entirely when not passed
        → server validates the group list; an unknown group surfaces as a normal CliError from its 400

traces get keeps the server's skeleton default (no per-span input/output/metadata) since it's the fast, common-case view. traces export keeps the server's full default since a bundle written to disk is expected to be complete. --fields overrides either default without changing anything else about the request.

What's included

API client

  • src/api/client.ts — new TraceFieldsParams type; getTrace/exportTrace now take an optional params and append ?fields=... to the request URL only when a value is provided

Commands

  • src/commands/traces/get.ts--fields <groups> option (reuses onceOption from traces/list.ts), threaded from RunGetDeps into client.getTrace
  • src/commands/traces/export.ts--fields <groups> option, threaded from ExportDeps into client.exportTrace

Docs

  • README.md — documents that traces get defaults to the lightweight skeleton projection and traces export defaults to full, with a --fields full example

Test plan

  • 597/597 vitest tests pass; typecheck and lint/format clean
  • New unit tests pin that fields appears in the outgoing URL for getTrace/exportTrace, and is absent when omitted (tests/api/client.test.ts)
  • New unit tests confirm --fields threads from runGet/runExport through to the client call, and that omitting it passes fields: undefined (tests/commands/traces-get.test.ts, tests/commands/traces.export.test.ts)
  • Live e2e against app.traceroot.ai on a 123-span trace:
    • traces get --json with no flag → 0/123 spans with input (confirms the bug and the documented default)
    • --fields full → 120/123 spans with input
    • --fields io,metadata → same result as full
    • --fields bogus → clean CLI error listing the valid groups (no stack trace)
    • traces export --fields skeletonspans.json written without I/O
    • traces export with no flag (default) → spans.json written with I/O
  • --help output for both traces get and traces export documents the default projection and how to override it

Summary by cubic

Adds a --fields projection flag to traces get and traces export, wiring it through the API client so you can request full or specific groups like io,metadata. This also fixes missing span I/O in traces get and makes get/export consistent.

  • New Features

    • --fields <groups> for traces get and traces export; forwarded to the server as ?fields=....
    • API: getTrace(traceId, { fields }) and exportTrace(traceId, { fields }); only send the query when provided.
    • Defaults: traces get keeps skeleton; traces export keeps full. The flag overrides either.
    • Help text and README updated with examples.
  • Bug Fixes

    • traces get now sends fields when requested, fixing silent input/output/metadata: null responses and aligning with export.
    • Tests cover URL query handling and flag threading for both commands.

Written for commit 199ce67. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 7 files

Re-trigger cubic

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.

traces get never requests span I/O — every span's input/output is silently null

1 participant