Skip to content

feat(log-list): add --trace flag to filter logs by trace ID#329

Merged
BYK merged 6 commits intomainfrom
feat/317-trace-id-filter
Mar 4, 2026
Merged

feat(log-list): add --trace flag to filter logs by trace ID#329
BYK merged 6 commits intomainfrom
feat/317-trace-id-filter

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Mar 4, 2026

Add --trace flag to sentry log list that scopes the query to a specific trace ID.

When --trace is 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

  • --trace flag with 32-char hex validation on sentry log list
  • Works in both single-fetch and --follow streaming modes
  • Trace follow mode polls the trace-logs endpoint and deduplicates by timestamp_precise
  • Refactored writeLogs() to accept both SentryLog and TraceLog via shared LogLike type
  • Trace-logs mock route + 5 E2E tests

Usage

sentry log list --trace abc123def456abc123def456abc123de
sentry log list myorg --trace abc123def456abc123def456abc123de
sentry log list myorg --trace abc123def456abc123def456abc123de -f
sentry log list myorg --trace abc123def456abc123def456abc123de --json

Closes #317

@github-actions
Copy link
Copy Markdown
Contributor

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

Trace

Other

  • (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
  • (log-list) Add --trace flag to filter logs by trace ID by BYK in #329
  • (project) Add project create command by betegon in #237
  • (upgrade) Add binary delta patching via TRDIFF10/bsdiff by BYK in #327

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

Setup

  • Suppress agent skills and welcome messages on upgrade by BYK in #328
  • Suppress shell completion messages on upgrade by BYK in #326

Other

  • (ci) Generate JUnit XML to silence codecov-action warnings by BYK in #300
  • (install) Fix nightly digest extraction on macOS by BYK in #331
  • (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
  • (trace-logs) Timestamp_precise is a number, not a string by BYK in #323

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

Other

  • (craft) Add sentry-release-registry target by BYK in #325

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Codecov Results 📊

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

📊 Comparison with Base Branch

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

All tests are passing successfully.

✅ Patch coverage is 96.71%. Project has 3126 uncovered lines.
✅ Project coverage is 82.42%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
list.ts 94.16% ⚠️ 18 Missing
log.ts 96.61% ⚠️ 6 Missing
logs.ts 97.74% ⚠️ 3 Missing
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

BYK added a commit that referenced this pull request Mar 4, 2026
- 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
BYK and others added 2 commits March 4, 2026 10:05
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
BYK added a commit that referenced this pull request Mar 4, 2026
- 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
@BYK BYK force-pushed the feat/317-trace-id-filter branch from 8279838 to eed7237 Compare March 4, 2026 10:14
BYK added a commit that referenced this pull request Mar 4, 2026
- 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
@BYK BYK force-pushed the feat/317-trace-id-filter branch from eed7237 to e703ed5 Compare March 4, 2026 12:06
@BYK BYK marked this pull request as ready for review March 4, 2026 12:29
- 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
@BYK BYK force-pushed the feat/317-trace-id-filter branch from e703ed5 to 816fdc1 Compare March 4, 2026 12:39
@BYK
Copy link
Copy Markdown
Member Author

BYK commented Mar 4, 2026

Addressed Cursor Bugbot's review: added a stopped guard flag to executeFollowMode that prevents orphaned poll loops when SIGINT fires during an in-flight fetchInitial() or fetchPoll(). The flag is checked in scheduleNextPoll() and poll() before any work is done. Added a regression test that verifies SIGINT during initial fetch does not start a poll loop (mock resolves the fetch after SIGINT, confirms no poll calls).

- 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
BYK added 2 commits March 4, 2026 13:29
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.
Copy link
Copy Markdown

@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.

@BYK BYK merged commit f7933f0 into main Mar 4, 2026
20 checks passed
@BYK BYK deleted the feat/317-trace-id-filter branch March 4, 2026 14:15
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.

sentry logs: add --trace / --trace-id filter flag

1 participant