You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(log): use 30d default period and show newest logs first (#568)
## Summary
- Fix `sentry log list` returning stale/incomplete data by changing the
default `statsPeriod` from `90d` to `30d` (log retention is 30 days —
periods >30d hit a degraded API path)
- Change default sort order to newest-first for one-shot queries, add
`--sort` flag (`newest`/`oldest`)
- Keep chronological (oldest-first) ordering for `--follow` mode
- Sort is server-side (`-timestamp` / `timestamp` API param), not
client-side array reversal
**Root cause confirmed via API testing:**
| Period | Count | Newest | Status |
|--------|-------|--------|--------|
| 14d | 19 | 16:42:23 | correct |
| 30d | 82 | 16:42:23 | correct |
| 60d | 13 | 15:21:42 | **stale** |
| 90d | 13 | 15:21:42 | **stale** |
## Design decisions
- **Server-side sorting**: The `--sort` flag maps to the API `sort`
parameter (`"newest"` → `"-timestamp"`, `"oldest"` → `"timestamp"`)
rather than reversing arrays client-side. This matches the pattern used
by `trace list` and `span list`.
- **`LogSortDirection` type in API layer**: Defined and exported from
`src/lib/api/logs.ts`, following the convention of `SpanSortValue` in
`api/traces.ts`. Re-exported via `api-client.ts`.
- **`parseLogSort` naming**: The shared parser in `arg-parsing.ts` is
named `parseLogSort` (not `parseSort`) to avoid collisions with the
three existing per-command `parseSort` functions that operate on
different sort vocabularies (`date`/`duration`,
`date`/`new`/`freq`/`user`).
- **Follow mode unaffected**: `--follow` streaming always fetches
newest-first and displays in arrival order. The `--sort` flag only
affects one-shot fetch mode.
## Test plan
- [x] Updated unit tests for new default period (`30d`) and newest-first
ordering
- [x] Added test for `--sort oldest` flag — verifies API receives `sort:
"oldest"`
- [x] Tests verify sort param is passed through to API (not just output
order)
- [x] All 65 unit tests pass across `log/list` and `trace/logs`
- [ ] Manual: `sentry logs <org>/<project>` shows recent logs, newest at
top
- [ ] Manual: `sentry logs <org>/<project> --sort oldest` shows oldest
at top
- [ ] Manual: `sentry logs <org>/<project> -f` follow mode still
chronological
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Burak Yigit Kaya <byk@sentry.io>
0 commit comments