Repository navigation
fix(log): scope log queries by numeric project ID - #1318
Conversation
`sentry log list <org>/<project>` and `log view` scoped a slug target only via `project:<slug>` search syntax, which the Events API matches only when the project is actively selected in the org. For any other project this returned empty `data: []` even when logs existed. Resolve the slug to its numeric project ID and pass `project: [id]` on the Events request (mirroring the issues fix in #312), falling back to `project:<slug>` query scoping only when no ID is available. Fixes #1317
|
Codecov Results 📊✅ Patch coverage is 92.00%. Project has 5486 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.77% 81.78% +0.01%
==========================================
Files 430 430 —
Lines 30098 30116 +18
Branches 19731 19744 +13
==========================================
+ Hits 24613 24630 +17
- Misses 5485 5486 +1
- Partials 2045 2045 —Generated by Codecov Action |
|
Holding off on auto-merge — this one needs a human look:
CI is fully green (unit + e2e tests, lint, typecheck, codeql, semgrep, warden). Ready for review whenever someone has a moment. |
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.
Reviewed by Cursor Bugbot for commit 85ca065. Configure here.
BYK
left a comment
There was a problem hiding this comment.
Overall looks good. A few things before merging:
- Get the patch coverage above 80%
- Make sure we are not duplicating existing functionality with these new helpers
- Try to find ways to avoid this class of errors with better types here or upstream in @sentry/api package
- Check all sentry issues for the CLI project that are still open and refer to "event id not found" or similar regarding logs and if you think this PR would resolve them, tag them in PR body so they get resolved.
| * A 404 (project genuinely not found) still throws from {@link fetchProjectId}; | ||
| * that is a user-actionable error, not a transient failure to swallow. | ||
| */ | ||
| export async function resolveLogProjectId( |
There was a problem hiding this comment.
Should this be memoized for perf? And I'm talking about "offline" memoization like on-disk cache if we have such a thing for project/org caches.
There was a problem hiding this comment.
It already is, transparently — resolveLogProjectId delegates to fetchProjectId, which is cache-first against the on-disk SQLite project_cache table (getCachedProjectBySlug → setCachedProject, the same store listProjects and DSN resolution populate). So after the first lookup for an (org, project) pair, subsequent log commands resolve the id from disk with no API call. The numeric-slug and --json/env paths skip resolution entirely. Given that, I didn't add a second caching layer here.
resolveLogProjectId only re-threw ResolutionError, silently swallowing AuthError and HostScopeError (which fetchProjectId re-throws via withAuthGuard) and degrading to slug scoping instead of failing fast. Re-throw any CliError so auth/host-scope/404 failures surface with a clear message; only genuinely unexpected errors fall back as transient. Adds resolveLogProjectId unit tests covering the numeric-slug short-circuit, successful resolution, transient-500 fallback, and the AuthError/ResolutionError re-throw paths.
|
Thanks for the review @BYK. Addressing your points:
|
Can you file an issue for this on https://github.com/getsentry/sentry-api-schema then which powers the |
|
Good to merge after that Jared |
I meant on Sentry using the Sentry CLI |
|
Filed the typed-error-unions follow-up: getsentry/sentry-api-schema#82. On the related-issues point — got it, you meant checking Sentry itself (the product) via |

sentry log list <org>/<project>(andlog view) returned an empty result —No logs found in the last 30d— for projects that aren't actively selected in the org, even when the Events API had logs for them.The log API scoped a slug target only via
project:<slug>search syntax, which the Events endpoint matches only when that project is actively selected. This resolves the slug to its numeric project ID and passesproject: [id]on the request instead (mirroring the issues fix in #312), falling back toproject:<slug>scoping only when no ID is available. Bothlog listandlog vieware covered.The same naively-concatenated
project:<slug> <user-query>also surfaces as400 Bad Requestfrom the Events API whenever the user passes--queryagainst a slug-scoped project — root cause is identical (slug scoping in query string instead of viaproject=param). Tracking issue: #1319.Sentry issues resolved
ApiError: Failed to list logs: 400 Bad Request— 316 events (every event had the malformedquery=project:<slug> <user-query>pattern)Testing
bun run typecheck, biome lint on changed files, and the log command + log API test suites (test/commands/log/*,test/lib/api/logs.test.ts) — all green. Added tests asserting theprojectparam is used when an ID is available and that scoping falls back toproject:<slug>otherwise.Closes #1317
Closes #1319