Skip to content

feat: add sentry span list and sentry span view commands#393

Draft
betegon wants to merge 7 commits intomainfrom
feat/span-commands
Draft

feat: add sentry span list and sentry span view commands#393
betegon wants to merge 7 commits intomainfrom
feat/span-commands

Conversation

@betegon
Copy link
Member

@betegon betegon commented Mar 11, 2026

Summary

Adds sentry span list and sentry span view so AI agents can filter/drill-into individual spans within a trace, instead of dealing with the full nested tree dump from sentry trace view --json.

Workflow this enables:

sentry span list <trace-id> --json -q "op:db duration:>100ms" --sort duration
sentry span view <span-id> --trace <trace-id> --json

Changes

Shared utilities (src/lib/formatters/trace.ts):

  • Extracted computeSpanDurationMs from human.ts into trace.ts for reuse
  • flattenSpanTree — converts nested span tree to flat array with depth/child_count
  • findSpanById — searches tree returning span + ancestor chain
  • parseSpanQuery / applySpanFilter — parse and apply -q "op:db duration:>100ms project:backend" filters
  • writeSpanTable / formatSpanDetails — table and detail formatters

sentry span list (src/commands/span/list.ts):

  • Positional: [<org>/<project>] <trace-id> (same pattern as trace view)
  • --query / -q: filter by op, project, description, duration thresholds
  • --sort: time (default, depth-first order) or duration (slowest first)
  • --limit / -n: cap output (default 25, max 1000)
  • JSON mode includes totalSpans and matchedSpans in envelope

sentry span view (src/commands/span/view.ts):

  • Positional: [<org>/<project>] <span-id> [<span-id>...] (multi-ID like log view)
  • --trace / -t: required trace ID
  • --spans: child tree depth (default 3)
  • Shows metadata KV table, ancestor chain, and child span tree
  • JSON mode includes ancestors and children arrays

Route wiring (src/app.ts):

  • sentry span {list, view} route
  • sentry spans plural alias → span list

Test Plan

  • bun run typecheck passes
  • bun run lint passes (0 errors)
  • bun run test:unit — all 3370 passing tests still pass (43 pre-existing failures unrelated)
  • Manual: sentry span list <trace-id> --json --limit 5
  • Manual: sentry span list <trace-id> -q "op:db" --sort duration
  • Manual: sentry span view <span-id> --trace <trace-id> --json
  • Manual: sentry span view <span-id> <span-id> --trace <trace-id>

Closes #391

betegon and others added 2 commits March 11, 2026 14:38
Move computeSpanDurationMs from human.ts to trace.ts and add shared
utilities for the upcoming span commands: flattenSpanTree, findSpanById,
parseSpanQuery, applySpanFilter, writeSpanTable, and formatSpanDetails.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add span as a first-class command group for AI-agent trace debugging.

- span list: flatten and filter spans in a trace with -q "op:db
  duration:>100ms", --sort time|duration, --limit
- span view: drill into specific spans by ID with --trace, shows
  metadata, ancestor chain, and child tree
- spans: plural alias routes to span list

Closes #391

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Init

  • Enforce canonical feature display order by betegon in #388
  • Accept multiple delimiter formats for --features flag by betegon in #386
  • Add git safety checks before wizard modifies files by betegon in #379
  • Add experimental warning before wizard runs by betegon in #378
  • Add init command for guided Sentry project setup by betegon in #283

Issue List

  • Auto-compact when table exceeds terminal height by BYK in #395
  • Redesign table to match Sentry web UI by BYK in #372

Other

  • Add sentry span list and sentry span view commands by betegon in #393
  • Add --dry-run flag to mutating commands by BYK in #387
  • Return-based output with OutputConfig on buildCommand by BYK in #380
  • Add --fields flag for context-window-friendly JSON output by BYK in #373
  • Magic @ selectors (@latest, @most_frequent) for issue commands by BYK in #371
  • Input hardening against agent hallucinations by BYK in #370
  • Add response caching for read-only API calls by BYK in #330

Bug Fixes 🐛

Init

  • Remove implementation detail from help text by betegon in #385
  • Truncate uncommitted file list to first 5 entries by MathurAditya724 in #381

Other

  • (api) Convert --data to query params for GET requests by BYK in #383
  • (docs) Remove double borders and fix column alignment on landing page tables by betegon in #369
  • Add trace ID validation to trace view + UUID dash-stripping by BYK in #375

Internal Changes 🔧

Init

  • Remove --force flag by betegon in #377
  • Remove dead determine-pm step label by betegon in #374

Other

  • Migrate non-streaming commands to CommandOutput with markdown rendering by BYK in #398
  • Convert Tier 2-3 commands to return-based output and consola by BYK in #394
  • Convert remaining Tier 1 commands to return-based output by BYK in #382
  • Converge Tier 1 commands to writeOutput helper by BYK in #376

Other

  • Minify JSON on read and pretty-print on write in init local ops by MathurAditya724 in #396

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Codecov Results 📊

104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 57.40%. Project has 1083 uncovered lines.
❌ Project coverage is 94.77%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
api-client.ts 74.19% ⚠️ 263 Missing
trace.ts 55.99% ⚠️ 136 Missing
human.ts 96.37% ⚠️ 44 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.50%    94.77%    -0.73%
==========================================
  Files          142       145        +3
  Lines        20343     20697      +354
  Branches         0         0         —
==========================================
+ Hits         19427     19614      +187
- Misses         916      1083      +167
- Partials         0         0         —

Generated by Codecov Action

betegon and others added 4 commits March 11, 2026 15:40
The UUID dash-stripping is already handled silently by validateHexId.
Remove the validateAndWarn wrappers, mergeWarnings helper, and all
related warning assertions from tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Duration filter `>` vs `>=` was wrong — `duration:>100ms` included 100ms
instead of excluding it. Added exclusive/inclusive tracking to SpanFilter
and extracted duration comparison helpers. Also made `span view --json`
always return an array for consistent output shape.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ce view

Use the server-side spans search endpoint (dataset=spans) for `span list`
instead of fetching the full trace tree and filtering client-side. Add
`translateSpanQuery` to rewrite CLI shorthand keys (op→span.op,
duration→span.duration) for the API.

Also fix trace view showing `undefined` for span IDs — the trace detail
API returns `event_id` instead of `span_id`, so normalize in
`getDetailedTrace`. Append span IDs (dimmed) to each tree line.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

feat: add sentry span command group for AI-agent trace debugging

1 participant