Skip to content

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

Merged
BYK merged 5 commits intomainfrom
feat/trace-logs
Mar 3, 2026
Merged

feat(trace): add sentry trace logs subcommand (#247)#311
BYK merged 5 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 ✨

  • (api) Add --data/-d flag and auto-detect JSON body in fields by BYK in #320
  • (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 numeric project ID to avoid "not actively selected" error by betegon in #312
  • 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

Formatters

  • Expand streaming table to fill terminal width by betegon in #314
  • Fix HTML entities and escaped underscores in table output by betegon in #313

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
  • (region) Resolve DSN org prefix at resolution layer by BYK in #316
  • (test) Handle 0/-0 in getComparator anti-symmetry property test by BYK in #308

Internal Changes 🔧

Api

  • Upgrade @sentry/api to 0.21.0, remove raw HTTP pagination workarounds by BYK in #321
  • 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 📊

2408 passed | Total: 2408 | 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 87.19%. Project has 3192 uncovered lines.
✅ Project coverage is 80.84%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
api-client.ts 71.40% ⚠️ 256 Missing
log.ts 96.23% ⚠️ 6 Missing
logs.ts 97.93% ⚠️ 3 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    80.45%    80.84%    +0.39%
==========================================
  Files          120       121        +1
  Lines        16474     16662      +188
  Branches         0         0         —
==========================================
+ Hits         13254     13470      +216
- Misses        3220      3192       -28
- Partials         0         0         —

Generated by Codecov Action

Replace the 4 trace-log-specific formatter functions with a shared LogLike
interface and an includeTrace param on buildLogRowCells. The only real
difference was suppressing the trace-ID suffix — both SentryLog and TraceLog
carry the same timestamp/severity/message shape.

Net: -80 lines, no new abstractions.
@BYK BYK marked this pull request as ready for review March 2, 2026 16:06
@BYK BYK merged commit ea590fd into main Mar 3, 2026
20 checks passed
@BYK BYK deleted the feat/trace-logs branch March 3, 2026 00:55
BYK added a commit that referenced this pull request Mar 3, 2026
Fixes a runtime Zod validation error when running `sentry trace logs`.
The trace-logs API returns `timestamp_precise` as a nanosecond integer
(same as Explore/Events logs), not an ISO string as originally assumed.

**Changes:**
- `TraceLogSchema.timestamp_precise`: `z.string()` → `z.number()`
- Updated JSDoc and test fixtures to match

Follow-up to #311.
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