Skip to content

feat(trace): add sentry trace logs subcommand (#247)#311

Draft
BYK wants to merge 2 commits intomainfrom
feat/trace-logs
Draft

feat(trace): add sentry trace logs subcommand (#247)#311
BYK wants to merge 2 commits intomainfrom
feat/trace-logs

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 1, 2026

Closes #247

Summary

Adds sentry trace logs <trace-id> — a dedicated subcommand to view logs associated with a distributed trace.

Uses the /organizations/{org}/trace-logs/ endpoint (org-scoped, queries all projects automatically), which is separate from the Explore/Events logs API and specifically designed for trace-correlated log retrieval.

Usage

sentry trace logs <trace-id>              # auto-detect org from project context
sentry trace logs <org> <trace-id>        # explicit org
sentry trace logs <org>/<trace-id>        # slash-separated

# Flags
-t / --period  14d    Time period to search (default: 14d, required by API)
-n / --limit   100    Max log entries (1–1000)
-q / --query          Additional Sentry filter query
-w / --web            Open trace in browser instead
     --json           Machine-readable JSON output

Implementation notes

  • Org-only resolution — no project context needed; the endpoint always queries all org projects
  • statsPeriod required — the API returns empty results without it; defaults to 14d
  • Chronological display — API returns newest-first; output is reversed for readability
  • Markdown-first formatting — uses the renderTextTable / plain markdown dual-mode pattern from feat(formatters): render all terminal output as markdown #297
  • 33 new tests; 2394 total passing

Implements the `sentry trace logs` subcommand to view logs associated
with a distributed trace via the dedicated `/organizations/{org}/trace-logs/`
endpoint (org-scoped, queries all projects automatically).

- Adds TraceLog/TraceLogsResponse Zod schemas and types
- Adds `listTraceLogs()` to api-client using region-aware routing
- Adds trace-log formatters to log.ts (batch table + plain markdown)
- New command with flags: --json, --period/-t, --limit/-n, --query/-q, --web/-w
- Positional: `<trace-id>`, `<org> <trace-id>`, or `<org>/<trace-id>`
- 33 tests; 2394 passing total, 0 failures
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 ✨

  • (formatters) Render all terminal output as markdown by BYK in #297
  • (issue-list) Global limit with fair distribution, compound cursor, and richer progress by BYK in #306

Bug Fixes 🐛

Api

  • Use limit param for issues endpoint page size by BYK in #309
  • Auto-correct ':' to '=' in --field values with a warning by BYK in #302

Other

  • (ci) Generate JUnit XML to silence codecov-action warnings by BYK in #300
  • (nightly) Push to GHCR from artifacts dir so layer titles are bare filenames by BYK in #301
  • (test) Handle 0/-0 in getComparator anti-symmetry property test by BYK in #308

Internal Changes 🔧

  • (api) Wire listIssuesPaginated through @sentry/api SDK for type safety by BYK in #310

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

Codecov Results 📊

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

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +33
Passed Tests 📈 +33
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 85.39%. Project has 3213 uncovered lines.
✅ Project coverage is 80.44%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
api-client.ts 70.97% ⚠️ 265 Missing
log.ts 93.41% ⚠️ 12 Missing
logs.ts 97.93% ⚠️ 3 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    80.05%    80.44%    +0.39%
==========================================
  Files          120       121        +1
  Lines        16218     16429      +211
  Branches         0         0         —
==========================================
+ Hits         12983     13216      +233
- Misses        3235      3213       -22
- Partials         0         0         —

Generated by Codecov Action

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.

Add CLI support for fetching logs associated with a trace

1 participant