-
Notifications
You must be signed in to change notification settings - Fork 570
Sync potel-base with master #4458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We are always just using the current scope anyway; it is less confusing if we eliminate the parameter Stacked on: - #4423
### PR Summary This small PR resolves the `threading` library warnings, which you can find in the [CI logs](https://github.com/getsentry/sentry-python/actions/runs/15490014338/job/43613162178#step:6:3523): ```python /home/runner/work/sentry-python/sentry-python/tests/conftest.py:608: DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead mock_server_thread.setDaemon(True) ``` Signed-off-by: Emmanuel Ferdman <[email protected]>
Hi! In the Python SDK, more specifically
`sentry_sdk/integrations/logging.py`, a couple of loggers are ignored to
avoid recursion errors.
```py
_IGNORED_LOGGERS = set(
["sentry_sdk.errors", "urllib3.connectionpool", "urllib3.connection"]
)
```
Log records from these loggers are discarded, using an exact match on
`record.name`. Unforunately, this breaks if the user modifies
`record.name`, e.g. for formatting, which is what we were doing for log
display (before becoming aware that Sentry relied on it after
investigating an infinite recursion issue).
```py
class _LengthFormatter(logging.Formatter):
def format(self, record):
"""
Format a log record's header to a constant length
"""
if len(record.name) > _MAX_LOGGER_NAME_LENGTH:
sep = "..."
cut = _MAX_LOGGER_NAME_LENGTH // 3 - len(sep)
record.name = record.name[:cut] + sep + record.name[-(_MAX_LOGGER_NAME_LENGTH - cut - len(sep)) :]
record.name = record.name.ljust(_MAX_LOGGER_NAME_LENGTH)
record.levelname = record.levelname.ljust(_MAX_LOGGER_LEVEL_NAME_LENGTH)
return super().format(record)
```
As you can see, `record.name` is right-padded with blank spaces. We have
found a workaround since, but given that it has taken us quite some time
to find the issue, I thought that maybe it could affect others. This PR
proposes matching `record.name.strip()` instead for increased
robustness.
Allow to send Loguru logs to Sentry. We can't parametrize them nicely, but this is a good first step. Also: * Move some tests around. Tests specific to the stdlib logging integration were moved from the generic sentry logs tests to the logging integration tests. * Remove `@minimum_python_37` from some tests that don't need 3.7+. * Dedupe some code by moving it to a superclass (`_LoguruBaseHandler`) Closes #4151 --------- Co-authored-by: Daniel Szoke <[email protected]>
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## potel-base #4458 +/- ##
==============================================
- Coverage 84.79% 84.77% -0.03%
==============================================
Files 144 144
Lines 14742 14788 +46
Branches 2346 2361 +15
==============================================
+ Hits 12501 12537 +36
- Misses 1525 1527 +2
- Partials 716 724 +8
|
f73ec83 to
673c34c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Testing last master -> potel-base sync