Skip to content

fix: Filter 404 invalid requests from Sentry - #53

Open
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/sentry-404-noise
Open

fix: Filter 404 invalid requests from Sentry#53
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/sentry-404-noise

Conversation

@sentry

@sentry sentry Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issue NURSE-SCHEDULING-49, where Sentry was receiving excessive 'Invalid API request' warnings due to bot vulnerability scanners probing nonexistent paths, resulting in 404 Not Found errors.

The capture_invalid_request function in core/nurse_scheduling/sentry.py was logging all 4xx HTTP errors, including 404s, to Sentry. To reduce this noise, an early return has been added to capture_invalid_request to ignore requests with a status_code of 404. This ensures that only relevant invalid requests (e.g., 422 validation errors) are reported to Sentry, while common bot-generated 404s are filtered out.

Fixes NURSE-SCHEDULING-49

Comment on lines +101 to +102
if status_code == 404:
return

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.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.64%. Comparing base (1c60cc8) to head (70d69e6).

Files with missing lines Patch % Lines
core/nurse_scheduling/sentry.py 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #53      +/-   ##
==========================================
- Coverage   92.65%   92.64%   -0.02%     
==========================================
  Files         100      100              
  Lines        8250     8252       +2     
  Branches      705      705              
==========================================
+ Hits         7644     7645       +1     
- Misses        460      461       +1     
  Partials      146      146              
Flag Coverage Δ
core 94.14% <50.00%> (-0.02%) ⬇️
core-macos 94.17% <50.00%> (+<0.01%) ⬆️
core-windows 94.14% <50.00%> (-0.02%) ⬇️
web-frontend 88.84% <ø> (ø)
web-frontend-macos 88.84% <ø> (ø)
web-frontend-windows 88.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
core/nurse_scheduling/sentry.py 93.33% <50.00%> (-2.02%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

0 participants