Skip to content

fix(log): use 30d default period and show newest logs first#568

Merged
BYK merged 10 commits intomainfrom
fix/log-list-period-and-sort
Mar 26, 2026
Merged

fix(log): use 30d default period and show newest logs first#568
BYK merged 10 commits intomainfrom
fix/log-list-period-and-sort

Conversation

@sergical
Copy link
Copy Markdown
Member

@sergical sergical commented Mar 26, 2026

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

  • Updated unit tests for new default period (30d) and newest-first ordering
  • Added test for --sort oldest flag — verifies API receives sort: "oldest"
  • Tests verify sort param is passed through to API (not just output order)
  • 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

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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 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 ✨

Dashboard

  • Add pagination and glob filtering to dashboard list by BYK in #560
  • Add a full chart rendering engine for sentry dashboard view that transforms widget data into rich terminal visualizations. by BYK in #555

Init

  • Propagate sentry-trace headers to wizard API calls by betegon in #567
  • Treat bare slug as new project name when not found by BYK in #554

Other

  • (formatters) Colorize SQL in DB span descriptions by BYK in #546
  • (output) Add Zod schema registration to OutputConfig for self-documenting JSON fields by BYK in #582
  • (telemetry) Report unknown commands to Sentry by BYK in #563
  • Bidirectional cursor pagination (-c next / -c prev) by BYK in #564
  • Add sentry sourcemap inject and sentry sourcemap upload commands by BYK in #547
  • Native debug ID injection and sourcemap upload by BYK in #543

Bug Fixes 🐛

Dashboard

  • Validate display types against all datasets by betegon in #577
  • Auto-clamp widget limit instead of erroring by BYK in #573
  • Default issue dataset table columns to ["issue"] by betegon in #570
  • Scale timeseries bar width to fill chart area by BYK in #562
  • Resolve dashboard by ID/slug in addition to title by BYK in #559

Event

  • Detect SHORT-ID/EVENT-ID format in event view by BYK in #574
  • Auto-fallback to org-wide search when event 404s in project by BYK in #575

Other

  • (api) Show meaningful message for network errors instead of '0 Unknown' by BYK in #572
  • (event-view) Auto-redirect issue short IDs in two-arg form (CLI-MP) by BYK in #558
  • (help) Show help when user passes help as positional arg by BYK in #561
  • (issue) Auto-redirect bare org slug to org-all mode in issue list by BYK in #576
  • (log) Use 30d default period and show newest logs first by sergical in #568
  • Reject @-selectors in parseOrgProjectArg with helpful redirect by BYK in #557

Internal Changes 🔧

Coverage

  • Use informational-patch input instead of sed hack by BYK in #544
  • Make checks informational on release branches by BYK in #541

Event

  • Replace "latest" magic string with @latest sentinel constant by BYK in #583
  • Deduplicate span tree building into shared helper by BYK in #581

Other

  • (api) Collapse stats on issue detail endpoints to save 100-300ms by BYK in #551
  • (ci) Upgrade GitHub Actions to Node 24 runtime by BYK in #542
  • (db) DRY up database layer with shared helpers and lint enforcement by BYK in #550
  • (docs) Polish sidebar, header, focus, and code block UX by sergical in #580
  • (issue-list) Use collapse parameter to skip unused Snuba queries by BYK in #545
  • Bump Bun from 1.3.9 to 1.3.11 by BYK in #552
  • Regenerate skill files by github-actions[bot] in ec1ffe28

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Codecov Results 📊

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

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 88.00%. Project has 1282 uncovered lines.
❌ Project coverage is 95.47%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
arg-parsing.ts 45.45% ⚠️ 6 Missing
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

sergical and others added 2 commits March 26, 2026 10:58
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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

PR Preview Action v1.8.1

QR code for preview link

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

Built to branch gh-pages at 2026-03-26 22:59 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

sergical and others added 2 commits March 26, 2026 11:01
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>
@sergical sergical marked this pull request as ready for review March 26, 2026 15:19
sergical and others added 2 commits March 26, 2026 17:08
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.
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.

Fix All in Cursor

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

BYK added 2 commits March 26, 2026 22:17
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.
Copy link
Copy Markdown
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Server-side sorting, naming alignment, API default fix, and follow-mode validation all look good.

@BYK BYK merged commit c466a19 into main Mar 26, 2026
23 checks passed
@BYK BYK deleted the fix/log-list-period-and-sort branch March 26, 2026 23:07
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.

2 participants