Skip to content

fix(log): add ID column, --fields in human mode, and swapped-arg recovery#871

Merged
BYK merged 5 commits intomainfrom
fix/log-prefix-fields-argorder
Apr 29, 2026
Merged

fix(log): add ID column, --fields in human mode, and swapped-arg recovery#871
BYK merged 5 commits intomainfrom
fix/log-prefix-fields-argorder

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 28, 2026

Summary

Fixes #858 — three improvements to sentry log commands:

  • ID column in sentry log list: Adds a new ID column showing the first 8 characters of the log entry ID (sentry.item_id). Users can copy this prefix and use it with sentry log view, which resolves it via the existing hex-id-recovery fuzzy prefix matching system.
  • --fields in human mode: When --fields email,user_id is passed, the requested fields are now sent to the ourlogs API as additional field parameters and rendered as extra columns in the human-mode table output. Works in both single-fetch and --follow modes. In trace mode, a warning is emitted since the trace-logs endpoint has a fixed field set.
  • Swapped argument auto-recovery: sentry log view <hex-id> <org/project> now auto-detects the reversed argument order (exactly 2 args), swaps them, and emits a warning. Issue short IDs like CAM-82X are checked first so they still get the correct "Did you mean: sentry issue view" suggestion.

Issue #4 from the bug report (numeric extra={} fields returning null) is a backend/ingestion issue, not fixable in the CLI.

Changes

src/lib/formatters/log.ts

  • Export LogLike type with sentry.item_id, id, and index signature for extra fields
  • Add getLogId() helper with safe typeof guards (no as string casts)
  • Add ID column to table headers and buildLogRowCells (4 cells: ID, Timestamp, Level, Message)
  • Accept optional extraFields in buildLogRowCells, formatLogRow, createLogStreamingTable, formatLogsHeader, formatLogTable
  • Extend hint rows with placeholder values for extra columns (StreamingTable width estimation)

src/lib/api/logs.ts

  • Add extraFields?: string[] to ListLogsOptions
  • Merge extra fields into the API field parameter with deduplication

src/commands/log/list.ts

  • Import canonical LogLike from formatters and extend with timestamp_precise (no duplicate type)
  • Thread flags.fields through to listLogs() as extraFields in both single-fetch and follow modes
  • Wrap first follow-mode batch in LogListResult to carry extraFields context for the renderer
  • Extract initFirstRender, isLogListResult, validateFollowFlags to reduce cognitive complexity
  • Warn when --fields is used with trace mode

src/commands/log/view.ts

  • Wire detectSwappedViewArgs for exactly 2-arg case to auto-correct reversed positional arguments
  • Check looksLikeIssueShortId before swap detection to preserve issue-view suggestions

Tests

  • Updated formatter tests for 4-column table layout
  • Added tests for getLogId, buildLogRowCells with extra fields, extra columns in formatLogTable/formatLogsHeader
  • Updated swapped-args test to verify auto-correction behavior

…very

- Add ID column to `sentry log list` showing first 8 chars of the log
  entry ID (sentry.item_id), enabling prefix lookup via `sentry log view`
- Make `--fields` request custom fields from the ourlogs API and render
  them as extra columns in human-mode table output
- Auto-detect and correct swapped arguments in `sentry log view` using
  the existing detectSwappedViewArgs helper

Closes #858
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-871/

Built to branch gh-pages at 2026-04-29 03:33 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Codecov Results 📊

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

📊 Comparison with Base Branch

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

All tests are passing successfully.

✅ Patch coverage is 80.68%. Project has 13026 uncovered lines.
❌ Project coverage is 76.02%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
src/commands/log/list.ts 81.32% ⚠️ 17 Missing
src/commands/log/view.ts 61.11% ⚠️ 14 Missing
src/lib/api/logs.ts 44.44% ⚠️ 5 Missing
src/lib/formatters/log.ts 94.37% ⚠️ 4 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    76.03%    76.02%    -0.01%
==========================================
  Files          294       294         —
  Lines        54164     54315      +151
  Branches         0         0         —
==========================================
+ Hits         41182     41289      +107
- Misses       12982     13026       +44
- Partials         0         0         —

Generated by Codecov Action

Comment thread src/commands/log/list.ts
Comment thread src/commands/log/view.ts
Comment thread src/lib/formatters/log.ts
…ority, hint-row widths

- Pass extraFields to listLogs in follow-mode fetch callback (Seer)
- Move looksLikeIssueShortId check before swap detection so issue
  short IDs like CAM-82X get the correct suggestion (BugBot)
- Extend hint rows with placeholder values for extra columns so
  StreamingTable allocates reasonable widths (BugBot)
Comment thread src/commands/log/list.ts
…lumns

In project-scoped follow mode, yieldFollowItems now wraps the first
non-empty batch in a LogListResult carrying extraFields so the
renderer creates a table with the correct extra columns. Previously
bare LogLike items were yielded, causing extraFields to stay undefined
and extra columns to be silently dropped in human output.
Copy link
Copy Markdown
Contributor

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

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 51ffec8. Configure here.

Comment thread src/commands/log/list.ts
Comment thread src/commands/log/list.ts
…on, trace --fields warning

- B1: Import canonical LogLike from formatters and extend with
  timestamp_precise in list.ts instead of duplicating the type
- B2: Replace unsafe 'as string' casts with typeof guards in getLogId
  to handle index-signature widening correctly
- B3: Limit swap detection to exactly 2 args to prevent silently
  dropping extra args in multi-arg use
- I4: Warn when --fields is used with trace mode (endpoint doesn't
  support custom fields)
- Extract validateFollowFlags to reduce func() cognitive complexity
@BYK BYK merged commit 566b87f into main Apr 29, 2026
37 of 39 checks passed
@BYK BYK deleted the fix/log-prefix-fields-argorder branch April 29, 2026 03:43
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 log: prefix lookup, attribute visibility, and argument order issues

1 participant