Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/nurse_scheduling/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def capture_optimize_exception(job: "Job", content: bytes, error: Exception) ->
def capture_invalid_request(request: Request, status_code: int, detail: Any) -> None:
if not _should_enable_sentry():
return
if status_code == 404:
return
Comment on lines +101 to +102

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bug: The new filter in capture_invalid_request silences all 404 errors, including legitimate application errors like JobNotFoundError, not just bot-generated noise.
Severity: MEDIUM

Suggested Fix

The filtering logic should be more specific. Instead of filtering all 404s, it should distinguish between 404s from non-existent routes (e.g., from StarletteHTTPException) and application-level 404s (e.g., from JobNotFoundError). This could be done by passing more context to capture_invalid_request or by handling the filtering at the call sites in app.py.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: core/nurse_scheduling/sentry.py#L101-L102

Potential issue: The change in `sentry.py` adds a blanket filter to stop reporting any
event with a `status_code` of 404 to Sentry. While this is intended to filter out noise
from bots scanning for non-existent paths, it also unintentionally filters legitimate
application-level 404 errors. For example, when a user tries to access a deleted or
expired job, the application correctly generates a `JobNotFoundError`, which results in
a 404 status. Previously, this would be captured by Sentry, providing valuable
observability. With this change, these legitimate errors will be silently ignored,
reducing the ability to monitor and understand application behavior related to
resource-not-found scenarios.

Did we get this right? 👍 / 👎 to inform future reviews.


import sentry_sdk

Expand Down
Loading