Skip to content

Commit

Permalink
Cherry-pick: Reconfigure Sentry logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Apr 18, 2024
1 parent 53893f7 commit 54939b7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/tribler/core/sentry_reporter/sentry_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Any, Dict, List, Optional

import sentry_sdk
import sentry_sdk.utils
from faker import Faker
from sentry_sdk.integrations.logging import LoggingIntegration, ignore_logger
from sentry_sdk.integrations.threading import ThreadingIntegration
Expand All @@ -22,6 +23,25 @@
parse_stacktrace,
)


def fix_sentry_logger(sentry_logger):
# Sentry log requires reconfiguration to be useful. By default, Sentry does not show even error-level log records
# until the debug option for Sentry is enabled. That means that unsuccessful attempts to send report are ignored.
# Enabling debug for Sentry is not recommended in production, and it sends the debug messages to stderr via
# a separate handler that is not in line with how Tribler handles logs. As a solution, Sentry developers recommend
# manual logger reconfiguration: https://github.com/getsentry/sentry-python/issues/1191#issuecomment-1023721841

for f in list(sentry_logger.filters):
sentry_logger.removeFilter(f)

for h in list(sentry_logger.handlers):
sentry_logger.removeHandler(h)

sentry_logger.setLevel(logging.WARNING)


fix_sentry_logger(sentry_sdk.utils.logger)

VALUE = 'value'
TYPE = 'type'
LAST_CORE_OUTPUT = 'last_core_output'
Expand Down

0 comments on commit 54939b7

Please sign in to comment.