fix(log): use 30d default period and show newest logs first#568
Conversation
The default statsPeriod of 90d exceeded log retention (30 days), causing the Explore/Events API to return stale/incomplete data. Also changes the default sort to newest-first for one-shot queries (matching typical dashboard behavior) and adds a --sort flag. - Change DEFAULT_PROJECT_PERIOD from 90d to 30d (log/list) - Change listLogs fallback from 7d to 14d (api/logs) - Default to newest-first for one-shot queries (no reverse) - Keep oldest-first (chronological) for --follow mode - Add --sort flag (newest/oldest) to log list and trace logs - Update tests for new period and ordering defaults Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Dashboard
Init
Other
Bug Fixes 🐛Dashboard
Event
Other
Internal Changes 🔧Coverage
Event
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 88.00%. Project has 1282 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.49% 95.47% -0.02%
==========================================
Files 194 194 —
Lines 28245 28279 +34
Branches 0 0 —
==========================================
+ Hits 26969 26997 +28
- Misses 1276 1282 +6
- Partials 0 0 —Generated by Codecov Action |
Update SKILL.md reference and website docs to reflect: - Default period changed from 90d to 30d (30-day log retention) - New --sort flag (newest/oldest, default: newest) - New --period flag documented in website docs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Break long function call lines into multiline format to satisfy the formatter's line length requirements. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Moves the duplicated SortDirection type, VALID_SORT_DIRECTIONS constant, and parseSort function from log/list.ts and trace/logs.ts into the shared arg-parsing module. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move sort direction to the API layer (LogSortDirection in api/logs.ts) and pass it through to both listLogs() and listTraceLogs() endpoints instead of reversing arrays client-side. Rename parseSort to parseLogSort to avoid collision with per-command parseSort functions in trace/span/issue list commands.
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.
The API-layer fallback was 14d while the CLI default was 30d — a maintenance footgun for future direct callers. Both should match the 30-day log retention period.
Follow mode streams new logs as they arrive, so oldest-first ordering is not meaningful. Throw a ValidationError early when both flags are combined instead of silently ignoring --sort.
BYK
left a comment
There was a problem hiding this comment.
LGTM. Server-side sorting, naming alignment, API default fix, and follow-mode validation all look good.

Summary
sentry log listreturning stale/incomplete data by changing the defaultstatsPeriodfrom90dto30d(log retention is 30 days — periods >30d hit a degraded API path)--sortflag (newest/oldest)--followmode-timestamp/timestampAPI param), not client-side array reversalRoot cause confirmed via API testing:
Design decisions
--sortflag maps to the APIsortparameter ("newest"→"-timestamp","oldest"→"timestamp") rather than reversing arrays client-side. This matches the pattern used bytrace listandspan list.LogSortDirectiontype in API layer: Defined and exported fromsrc/lib/api/logs.ts, following the convention ofSpanSortValueinapi/traces.ts. Re-exported viaapi-client.ts.parseLogSortnaming: The shared parser inarg-parsing.tsis namedparseLogSort(notparseSort) to avoid collisions with the three existing per-commandparseSortfunctions that operate on different sort vocabularies (date/duration,date/new/freq/user).--followstreaming always fetches newest-first and displays in arrival order. The--sortflag only affects one-shot fetch mode.Test plan
30d) and newest-first ordering--sort oldestflag — verifies API receivessort: "oldest"log/listandtrace/logssentry logs <org>/<project>shows recent logs, newest at topsentry logs <org>/<project> --sort oldestshows oldest at topsentry logs <org>/<project> -ffollow mode still chronological