Skip to content
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

Capture warnings and report to sentry #5697

Merged
merged 1 commit into from
Feb 28, 2025
Merged
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
10 changes: 10 additions & 0 deletions supervisor/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import logging
import os
import signal
import warnings

from colorlog import ColoredFormatter
from sentry_sdk import capture_exception

from .addons.manager import AddonManager
from .api import RestAPI
Expand Down Expand Up @@ -222,6 +224,13 @@ def initialize_system(coresys: CoreSys) -> None:
config.path_addon_configs.mkdir()


def warning_handler(message, category, filename, lineno, file=None, line=None):
"""Warning handler which logs warnings using the logging module."""
_LOGGER.warning("%s:%s: %s: %s", filename, lineno, category.__name__, message)
if isinstance(message, Exception):
capture_exception(message)


def initialize_logging() -> None:
"""Initialize the logging."""
logging.basicConfig(level=logging.INFO)
Expand All @@ -248,6 +257,7 @@ def initialize_logging() -> None:
},
)
)
warnings.showwarning = warning_handler


def check_environment() -> None:
Expand Down