Skip to content

feat(trace): add trace list and view commands#218

Merged
betegon merged 9 commits intomainfrom
feat/trace-command
Feb 10, 2026
Merged

feat(trace): add trace list and view commands#218
betegon merged 9 commits intomainfrom
feat/trace-command

Conversation

@betegon
Copy link
Member

@betegon betegon commented Feb 9, 2026

Summary

Adds sentry trace list and sentry trace view commands for exploring distributed traces. Follows the same patterns as the existing log and issue commands — auto-detect from DSN, explicit org/project target, project search across orgs.

Features

  • trace list — Recent transactions with trace ID, name, duration, and relative time
    • --sort date|duration, --query, --limit 1-1000, --json
    • traces shortcut registered at top level (like issues, logs)
  • trace view <trace-id> — Trace summary + span tree
    • Shows root transaction, duration, span count, projects involved, start time
    • --spans depth limit (default 3), --web to open in Sentry UI, --json
    • Root span breadth cap at 50 to prevent terminal flooding on flat traces

Usage Examples

# List recent traces (auto-detect project from DSN)
$ sentry trace list
Recent traces in sentry/mcp-server:

TRACE ID                          TRANSACTION                    DURATION    WHEN
────────────────────────────────────────────────────────────────────────────────────────────────
c3e999db2762427f98c49eda60e2691f  POST /mcp                            5m 7s  5h ago
f9dbcf6ddfcf4528b97d8effa636714d  POST /mcp                            5m 6s  3h ago

# Sort by slowest
$ sentry trace list --sort duration --limit 20

# View a trace
$ sentry trace view c3e999db2762427f98c49eda60e2691f
Trace c3e999db2762427f98c49eda60e2691f
══════════════════════════════════════

Root:        [http.server] POST /mcp
Duration:    15m 3s
Span Count:  2761
Projects:    mcp-server, sentry, snuba
Started:     2026-02-09 13:11:01

─── Span Tree ───
Trace — c3e999db2762427f98c49eda60e2691f
└─ http.server — POST /mcp
   └─ mcp.server — tools/call analyze_issue_with_seer
      ├─ http.client — GET .../autofix/
      ├─ http.client — POST .../autofix/
      └─ http.client — GET .../autofix/

Implementation Notes

  • API types: TransactionListItemSchema / TransactionsResponseSchema (Zod)
  • API client: listTransactions() using dataset=transactions on the events endpoint
  • Handles the Sentry trace API returning end_timestamp instead of timestamp on spans
  • Timestamp guards in computeTraceSummary() handle spans with zero/missing timestamps gracefully (renders "—" instead of NaN)
  • Limit validation (1-1000) matching the log list pattern
  • 48 tests: 22 unit + 26 property-based (fast-check)

Add sentry trace list and sentry trace view commands for exploring
distributed traces from Sentry projects.

trace list: shows recent transactions with trace ID, name, duration,
and relative time. Supports --sort (date/duration), --query, --limit,
and --json flags. Auto-detects project from DSN or accepts explicit
org/project target.

trace view: displays trace summary (root transaction, duration, span
count, projects involved) and a span tree. Supports --spans depth
limit, --web to open in browser, and --json output.

Also includes:
- TransactionListItem/TransactionsResponse Zod schemas and types
- listTransactions() API client function
- Trace-specific formatters (duration, header, row, summary)
- Root span breadth cap (50) to prevent terminal flooding
- Handle API returning end_timestamp instead of timestamp on spans
- Limit validation (1-1000) matching log list pattern
22 unit tests covering formatTraceDuration, formatTracesHeader,
formatTraceRow, computeTraceSummary, and formatTraceSummary including
edge cases like NaN/zero timestamps.

26 property-based tests using fast-check verifying invariants:
determinism, trace ID preservation, non-negative durations,
project deduplication, and correct duration format units.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 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 ✨

Cli

  • Add setup command for shell integration by BYK in #213
  • Add plural command aliases for list commands by betegon in #209

Other

  • (formatters) Display span duration in span tree by betegon in #219
  • (log) Add view command to display log entry details by betegon in #212
  • (setup) Auto-install Claude Code agent skill during setup by BYK in #216
  • (trace) Add trace list and view commands by betegon in #218

Bug Fixes 🐛

Upgrade

  • Handle EPERM in isProcessRunning for cross-user locks by BYK in #211
  • Replace curl pipe with direct binary download by BYK in #208

Documentation 📚

  • (log) Add documentation for sentry log view command by betegon in #214
  • Add documentation for log command by betegon in #210

Internal Changes 🔧

  • (ci) Remove merge-artifacts job with Craft 2.21.1 by BYK in #215
  • (setup) Unify binary placement via setup --install by BYK in #217
  • Enable minify for standalone binaries by BYK in #220

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

Codecov Results 📊

✅ Patch coverage is 91.55%. Project has 3986 uncovered lines.
✅ Project coverage is 68.47%. Comparing base (base) to head (head).

Files with missing lines (66)
File Patch % Lines
human.ts 56.16% ⚠️ 395 Missing
resolve-target.ts 15.28% ⚠️ 366 Missing
list.ts 14.39% ⚠️ 345 Missing
api-client.ts 66.91% ⚠️ 224 Missing
list.ts 23.47% ⚠️ 212 Missing
oauth.ts 25.10% ⚠️ 194 Missing
list.ts 21.96% ⚠️ 167 Missing
view.ts 22.07% ⚠️ 166 Missing
plan.ts 19.37% ⚠️ 154 Missing
help.ts 19.85% ⚠️ 109 Missing
upgrade.ts 57.71% ⚠️ 107 Missing
interactive-login.ts 9.17% ⚠️ 99 Missing
view.ts 25.81% ⚠️ 92 Missing
view.ts 47.70% ⚠️ 91 Missing
clipboard.ts 4.49% ⚠️ 85 Missing
status.ts 24.07% ⚠️ 82 Missing
view.ts 49.07% ⚠️ 82 Missing
migration.ts 47.44% ⚠️ 82 Missing
list.ts 27.18% ⚠️ 75 Missing
browser.ts 4.11% ⚠️ 70 Missing
login.ts 33.33% ⚠️ 64 Missing
span-tree.ts 5.00% ⚠️ 57 Missing
explain.ts 33.33% ⚠️ 56 Missing
telemetry.ts 79.86% ⚠️ 56 Missing
api.ts 89.80% ⚠️ 47 Missing
upgrade.ts 66.91% ⚠️ 46 Missing
seer.ts 75.54% ⚠️ 45 Missing
schema.ts 89.56% ⚠️ 40 Missing
refresh.ts 40.63% ⚠️ 38 Missing
seer.ts 79.87% ⚠️ 30 Missing
preload.ts 53.23% ⚠️ 29 Missing
utils.ts 88.94% ⚠️ 25 Missing
view.ts 61.54% ⚠️ 25 Missing
detector.ts 90.10% ⚠️ 20 Missing
binary.ts 88.67% ⚠️ 17 Missing
code-scanner.ts 95.00% ⚠️ 16 Missing
help.ts 57.14% ⚠️ 15 Missing
output.ts 28.57% ⚠️ 15 Missing
arg-parsing.ts 90.00% ⚠️ 12 Missing
dsn-cache.ts 94.62% ⚠️ 12 Missing
logout.ts 56.00% ⚠️ 11 Missing
token.ts 52.17% ⚠️ 11 Missing
fix.ts 83.61% ⚠️ 10 Missing
qrcode.ts 33.33% ⚠️ 10 Missing
fs-utils.ts 57.14% ⚠️ 9 Missing
view.ts 95.36% ⚠️ 7 Missing
project-root.ts 97.73% ⚠️ 7 Missing
version-check.ts 91.76% ⚠️ 7 Missing
feedback.ts 84.21% ⚠️ 6 Missing
auth.ts 95.52% ⚠️ 6 Missing
shell.ts 96.23% ⚠️ 6 Missing
app.ts 93.24% ⚠️ 5 Missing
resolver.ts 94.57% ⚠️ 5 Missing
setup.ts 97.84% ⚠️ 4 Missing
list.ts 97.33% ⚠️ 4 Missing
index.ts 95.96% ⚠️ 4 Missing
project-aliases.ts 97.40% ⚠️ 2 Missing
project-root-cache.ts 96.92% ⚠️ 2 Missing
alias.ts 99.42% ⚠️ 1 Missing
completions.ts 99.37% ⚠️ 1 Missing
env-file.ts 99.19% ⚠️ 1 Missing
parser.ts 98.63% ⚠️ 1 Missing
colors.ts 97.96% ⚠️ 1 Missing
trace.ts 99.16% ⚠️ 1 Missing
helpers.ts 94.74% ⚠️ 1 Missing
helpers.ts 94.74% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    67.47%    68.47%       +1%
==========================================
  Files           99       103        +4
  Lines        12133     12640      +507
  Branches         0         0         —
==========================================
+ Hits          8186      8654      +468
- Misses        3947      3986       +39
- Partials         0         0         —

Generated by Codecov Action

Export internal helpers (validateLimit, parseSort, resolveTraceTarget,
writeHumanOutput) and add direct unit tests for the command func() bodies
using spyOn to mock api-client and resolve-target. This covers the code
paths that e2e tests exercise but can't contribute to coverage since they
run as subprocesses.
@betegon betegon marked this pull request as ready for review February 9, 2026 20:00
@betegon betegon force-pushed the feat/trace-command branch from b3bb520 to d258f5c Compare February 9, 2026 20:28
…llback

- Fix formatTraceDuration producing 'Xm 60s' when seconds round up to 60
  by computing total seconds first then splitting into mins/secs
- Remove unused buildTracesUrl function (dead code)
- Use || instead of ?? for end_timestamp fallback so 0 falls through
  to the valid timestamp field
@betegon betegon force-pushed the feat/trace-command branch from d258f5c to 81b4725 Compare February 9, 2026 21:13
…uman.ts

Same fix as trace.ts — end_timestamp: 0 is invalid and should fall
through to timestamp field.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@betegon betegon merged commit 8aa1a82 into main Feb 10, 2026
23 checks passed
@betegon betegon deleted the feat/trace-command branch February 10, 2026 19:44
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.

1 participant