Skip to content

Commit

Permalink
Added sentry error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
shehroze37 committed Feb 18, 2024
1 parent fe0923b commit 0f8107d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
44 changes: 36 additions & 8 deletions autogpts/autogpt/autogpt/logs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import TYPE_CHECKING, Optional

from auto_gpt_plugin_template import AutoGPTPluginTemplate
from openai._base_client import log as openai_logger
from openai.util import logger as openai_logger

if TYPE_CHECKING:
from autogpt.config import Config
Expand All @@ -21,6 +21,9 @@
from .formatters import AutoGptFormatter, StructuredLoggingFormatter
from .handlers import TTSHandler, TypingConsoleHandler

import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration

LOG_DIR = Path(__file__).parent.parent.parent / "logs"
LOG_FILE = "activity.log"
DEBUG_LOG_FILE = "debug.log"
Expand Down Expand Up @@ -76,12 +79,12 @@ class LoggingConfig(SystemConfiguration):


def configure_logging(
level: int = logging.INFO,
log_dir: Path = LOG_DIR,
log_format: Optional[LogFormatName] = None,
log_file_format: Optional[LogFormatName] = None,
plain_console_output: bool = False,
tts_config: Optional[TTSConfig] = None,
level: int = logging.INFO,
log_dir: Path = LOG_DIR,
log_format: Optional[LogFormatName] = None,
log_file_format: Optional[LogFormatName] = None,
plain_console_output: bool = False,
tts_config: Optional[TTSConfig] = None,
) -> None:
"""Configure the native logging module.
Expand Down Expand Up @@ -129,6 +132,9 @@ def configure_logging(
typing_console_handler.setLevel(logging.INFO)
typing_console_handler.setFormatter(console_formatter)

# Initialize sentry logging
initialize_sentry()

# User friendly output logger (text + speech)
user_friendly_output_logger = logging.getLogger(USER_FRIENDLY_OUTPUT_LOGGER)
user_friendly_output_logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -184,7 +190,7 @@ def configure_logging(
json_logger.propagate = False

# Disable debug logging from OpenAI library
openai_logger.setLevel(logging.WARNING)
openai_logger.setLevel(logging.INFO)


def configure_chat_plugins(config: Config) -> None:
Expand All @@ -201,3 +207,25 @@ def configure_chat_plugins(config: Config) -> None:
if hasattr(plugin, "can_handle_report") and plugin.can_handle_report():
logger.debug(f"Loaded plugin into logger: {plugin.__class__.__name__}")
_chat_plugins.append(plugin)


def initialize_sentry(self):
"""
Initialize sentry logging
Args:
self:
Returns:
"""
sentry_logging = LoggingIntegration(
level=logging.WARN, # Capture warn as breadcrumbs
event_level=logging.ERROR, # Send errors as events
)
sentry_sdk.init(
# dsn="Will be taken from environment variable SENTRY_DSN",
integrations=[
sentry_logging,
],
traces_sample_rate=1.0, # TODO: Tweak this
)
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mkdocs
mkdocs-material
mkdocs-table-reader-plugin
pymdown-extensions
sentry-sdk
pymdown-extensions

0 comments on commit 0f8107d

Please sign in to comment.