From 27be47d23874e8ae5eeed1bb5b777a0dab90e88a Mon Sep 17 00:00:00 2001 From: shtlrs Date: Tue, 13 Feb 2024 22:52:19 +0100 Subject: move logger to its own package This sets the place to centralize all logs configs in its own module --- arthur/log.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 arthur/log.py (limited to 'arthur/log.py') diff --git a/arthur/log.py b/arthur/log.py new file mode 100644 index 0000000..cfc6c62 --- /dev/null +++ b/arthur/log.py @@ -0,0 +1,6 @@ +from functools import partial + +import loguru + +logger = loguru.logger.opt(colors=True) +logger.opt = partial(logger.opt, colors=True) -- cgit v1.2.3 From 4adb57499383e4835848bd5f2c792088ebcf6e74 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Wed, 14 Feb 2024 00:43:06 +0100 Subject: setup the sentry integration upon bot startup --- arthur/__main__.py | 4 +++- arthur/config.py | 6 ++++++ arthur/log.py | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'arthur/log.py') diff --git a/arthur/__main__.py b/arthur/__main__.py index 6f4a68f..041399b 100644 --- a/arthur/__main__.py +++ b/arthur/__main__.py @@ -9,7 +9,7 @@ from discord.ext import commands import arthur from arthur.bot import KingArthur from arthur.config import CONFIG -from arthur.log import logger +from arthur.log import logger, setup_sentry async def main() -> None: @@ -35,5 +35,7 @@ async def main() -> None: await bot.start(CONFIG.token.get_secret_value()) +setup_sentry() + with logger.catch(): asyncio.run(main()) diff --git a/arthur/config.py b/arthur/config.py index e9f80d9..c4f7e1a 100644 --- a/arthur/config.py +++ b/arthur/config.py @@ -1,5 +1,7 @@ """Utilities for interacting with the config for King Arthur.""" +from os import environ + import pydantic from pydantic_settings import BaseSettings @@ -23,6 +25,10 @@ class Config( devops_role: int = 409416496733880320 guild_id: int = 267624335836053506 + sentry_dsn: str = "" + + +GIT_SHA = environ.get("GIT_SHA", "development") CONFIG = Config() diff --git a/arthur/log.py b/arthur/log.py index cfc6c62..c382479 100644 --- a/arthur/log.py +++ b/arthur/log.py @@ -1,6 +1,27 @@ from functools import partial import loguru +import sentry_sdk +from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration + +from arthur.config import CONFIG, GIT_SHA logger = loguru.logger.opt(colors=True) logger.opt = partial(logger.opt, colors=True) + + +def setup_sentry() -> None: + """Set up the Sentry logging integrations.""" + loguru_integration = LoguruIntegration( + level=LoggingLevels.DEBUG.value, event_level=LoggingLevels.WARNING.value + ) + + sentry_sdk.init( + dsn=CONFIG.sentry_dsn, + integrations=[ + loguru_integration, + ], + release=f"king-arthur@{GIT_SHA}", + traces_sample_rate=0.5, + profiles_sample_rate=0.5, + ) -- cgit v1.2.3