feat(log-list): add --trace flag to filter logs by trace ID#329
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Trace
Other
Bug Fixes 🐛Api
Formatters
Setup
Other
Internal Changes 🔧Api
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 2628 passed | Total: 2628 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 96.71%. Project has 3126 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.46% 82.42% +0.96%
==========================================
Files 125 126 +1
Lines 17700 17782 +82
Branches 0 0 —
==========================================
+ Hits 14418 14656 +238
- Misses 3282 3126 -156
- Partials 0 0 —Generated by Codecov Action |
- Create src/lib/trace-id.ts with shared TRACE_ID_RE and validateTraceId() - Update trace/logs.ts and log/list.ts to use shared module - Remove duplicated regex, validation function, and ValidationError import - Add test/lib/trace-id.test.ts with property-based and unit tests (20 tests) - Add test/commands/log/list.test.ts covering standard and trace modes (20 tests) - Generic error message (no command-specific example) in shared validator
Add --trace flag to `sentry log list` that filters logs by a specific trace ID. When provided, the command uses the dedicated trace-logs endpoint (org-scoped) instead of the project-scoped events endpoint, since the Explore/Events logs API does not support trace ID filtering in query syntax. Key changes: - Add --trace flag with 32-char hex validation to log list command - When --trace is given, only org resolution is needed (not org/project) - Support --trace in both single-fetch and --follow streaming modes - Trace follow mode filters by timestamp_precise for deduplication - Refactor writeLogs to accept LogLike type (works with both SentryLog and TraceLog) and includeTrace option - Add trace-logs mock route for e2e testing - Add 5 e2e tests covering: basic trace filter, JSON output, validation, empty state, and help output Closes #317
- Create src/lib/trace-id.ts with shared TRACE_ID_RE and validateTraceId() - Update trace/logs.ts and log/list.ts to use shared module - Remove duplicated regex, validation function, and ValidationError import - Add test/lib/trace-id.test.ts with property-based and unit tests (20 tests) - Add test/commands/log/list.test.ts covering standard and trace modes (20 tests) - Generic error message (no command-specific example) in shared validator
8279838 to
eed7237
Compare
- Create src/lib/trace-id.ts with shared TRACE_ID_RE and validateTraceId() - Update trace/logs.ts and log/list.ts to use shared module - Remove duplicated regex, validation function, and ValidationError import - Add test/lib/trace-id.test.ts with property-based and unit tests (20 tests) - Add test/commands/log/list.test.ts covering standard and trace modes (20 tests) - Generic error message (no command-specific example) in shared validator
eed7237 to
e703ed5
Compare
- Create src/lib/trace-id.ts with shared TRACE_ID_RE and validateTraceId() - Update trace/logs.ts and log/list.ts to use shared module - Remove duplicated regex, validation function, and ValidationError import - Add test/lib/trace-id.test.ts with property-based and unit tests (20 tests) - Add test/commands/log/list.test.ts covering standard and trace modes (20 tests) - Generic error message (no command-specific example) in shared validator
e703ed5 to
816fdc1
Compare
|
Addressed Cursor Bugbot's review: added a |
- Add comment explaining ms → ns conversion (timestamp_precise) - Replace .then()/.catch() with async/await IIFE in executeFollowMode - DRY fetchInitial/fetchPoll into single fetch(statsPeriod, afterTimestamp?) callback
Reverts the async IIFE wrapping back to .then()/.catch() and adds a comment explaining why: we cannot await inside the Promise constructor because resolve must remain callable by the SIGINT handler at any time.
Extract duplicated trace-log display logic into a shared displayTraceLogs() function in src/lib/formatters/log.ts. Both 'sentry log list --trace' and 'sentry trace logs' now use the same helper for JSON output, empty state, and table formatting. This also normalizes JSON output for trace/logs.ts to use chronological order (oldest-first), consistent with all other JSON outputs in the CLI.
There was a problem hiding this comment.
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.
Add
--traceflag tosentry log listthat scopes the query to a specific trace ID.When
--traceis given, the command uses the dedicated trace-logs endpoint (/organizations/{org}/trace-logs/) instead of the project-scoped events endpoint, since the Explore/Events logs API does not support trace ID filtering in query syntax. This means only org resolution is needed — the positional target is treated as an org slug, not an org/project pair.Changes
--traceflag with 32-char hex validation onsentry log list--followstreaming modestimestamp_precisewriteLogs()to accept bothSentryLogandTraceLogvia sharedLogLiketypeUsage
Closes #317