Skip to content

feat(logging): Separate ignore lists for events/breadcrumbs and sentry logs#5698

Merged
sl0thentr0py merged 1 commit intomasterfrom
neel/separate-logging-ignores
Mar 18, 2026
Merged

feat(logging): Separate ignore lists for events/breadcrumbs and sentry logs#5698
sl0thentr0py merged 1 commit intomasterfrom
neel/separate-logging-ignores

Conversation

@sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Mar 18, 2026

Description

Split _IGNORED_LOGGERS into two independent sets so that framework loggers silenced for events/breadcrumbs (e.g. django.server) can still be captured as Sentry Logs.

  • _IGNORED_LOGGERS controls EventHandler and BreadcrumbHandler
  • _IGNORED_LOGGERS_SENTRY_LOGS controls SentryLogsHandler
  • Add ignore_logger_for_sentry_logs() and unignore_logger*() helpers
  • Move _can_record into each handler class with its own ignore set
  • Split _handle_record into separate event and sentry-logs paths

Issues

@sl0thentr0py sl0thentr0py requested a review from a team as a code owner March 18, 2026 13:49
@linear-code
Copy link

linear-code bot commented Mar 18, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

Semver Impact of This PR

🟡 Minor (new features)

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

  • (logging) Separate ignore lists for events/breadcrumbs and sentry logs by sl0thentr0py in #5698

Bug Fixes 🐛

  • (anthropic) Patch Stream.close() and MessageStream.close() to finish spans by alexander-alderman-webb in #5674

Internal Changes 🔧

  • Add client report tests for span streaming by sentrivana in #5677

Other

  • Update CHANGELOG.md by sentrivana in #5685

🤖 This preview updates automatically when you update the PR.

…y Logs

Split _IGNORED_LOGGERS into two independent sets so that framework
loggers silenced for events/breadcrumbs (e.g. django.server) can still
be captured as Sentry Logs.

- _IGNORED_LOGGERS controls EventHandler and BreadcrumbHandler
- _IGNORED_LOGGERS_SENTRY_LOGS controls SentryLogsHandler
- Add ignore_logger_for_sentry_logs() and unignore_logger*() helpers
- Move _can_record into each handler class with its own ignore set
- Split _handle_record into separate event and sentry-logs paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sl0thentr0py sl0thentr0py force-pushed the neel/separate-logging-ignores branch from 9a6ec82 to d384b59 Compare March 18, 2026 13:50
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 20.72s

All tests are passing successfully.

❌ Patch coverage is 25.00%. Project has 13681 uncovered lines.

Files with missing lines (1)
File Patch % Lines
logging.py 32.58% ⚠️ 120 Missing and 3 partials

Generated by Codecov Action

Copy link

@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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Identical _can_record duplicated across two handler classes
    • Moved duplicate _can_record method to _BaseHandler, eliminating duplication while preserving SentryLogsHandler's override for different ignore list.

Create PR

Or push these changes by commenting:

@cursor push 538bf4d0a5
Preview (538bf4d0a5)
diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py
--- a/sentry_sdk/integrations/logging.py
+++ b/sentry_sdk/integrations/logging.py
@@ -226,6 +226,13 @@
         )
     )
 
+    def _can_record(self, record: "LogRecord") -> bool:
+        """Prevents ignored loggers from recording"""
+        for logger in _IGNORED_LOGGERS:
+            if fnmatch(record.name.strip(), logger):
+                return False
+        return True
+
     def _logging_to_event_level(self, record: "LogRecord") -> str:
         return LOGGING_TO_EVENT_LEVEL.get(
             record.levelno, record.levelname.lower() if record.levelname else ""
@@ -247,13 +254,6 @@
     Note that you do not have to use this class if the logging integration is enabled, which it is by default.
     """
 
-    def _can_record(self, record: "LogRecord") -> bool:
-        """Prevents ignored loggers from recording"""
-        for logger in _IGNORED_LOGGERS:
-            if fnmatch(record.name.strip(), logger):
-                return False
-        return True
-
     def emit(self, record: "LogRecord") -> "Any":
         with capture_internal_exceptions():
             self.format(record)
@@ -346,13 +346,6 @@
     Note that you do not have to use this class if the logging integration is enabled, which it is by default.
     """
 
-    def _can_record(self, record: "LogRecord") -> bool:
-        """Prevents ignored loggers from recording"""
-        for logger in _IGNORED_LOGGERS:
-            if fnmatch(record.name.strip(), logger):
-                return False
-        return True
-
     def emit(self, record: "LogRecord") -> "Any":
         with capture_internal_exceptions():
             self.format(record)

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@sl0thentr0py sl0thentr0py merged commit 238cadf into master Mar 18, 2026
159 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/separate-logging-ignores branch March 18, 2026 14:23
sl0thentr0py added a commit that referenced this pull request Mar 18, 2026
…y logs (#5698)

Split `_IGNORED_LOGGERS` into two independent sets so that framework
loggers silenced for events/breadcrumbs (e.g. `django.server`) can still
be captured as Sentry Logs.

- `_IGNORED_LOGGERS` controls `EventHandler` and `BreadcrumbHandler`
- `_IGNORED_LOGGERS_SENTRY_LOGS` controls `SentryLogsHandler`
- Add `ignore_logger_for_sentry_logs()` and `unignore_logger*()` helpers
- Move `_can_record` into each handler class with its own ignore set
- Split `_handle_record` into separate event and sentry-logs paths

* resolves: #5689
* resolves: PY-2146

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Celery logs filtered out

2 participants