diff options
author | 2020-03-28 15:59:40 +0100 | |
---|---|---|
committer | 2020-03-28 15:59:40 +0100 | |
commit | adeacd6beeca90968dfc5cbce007034b7f54bf66 (patch) | |
tree | d4598667d9799f3bc97fa9e2660d4bd9b00d22e3 /bot | |
parent | Deseasonify: make `get_extensions` an iterator (diff) | |
parent | Merge pull request #383 from python-discord/setup-sentry (diff) |
Merge master: sentry sdk, updated contributing docs
Diffstat (limited to 'bot')
-rw-r--r-- | bot/__main__.py | 13 | ||||
-rw-r--r-- | bot/constants.py | 1 | ||||
-rw-r--r-- | bot/exts/evergreen/error_handler.py | 21 |
3 files changed, 34 insertions, 1 deletions
diff --git a/bot/__main__.py b/bot/__main__.py index 8b6ee782..0ffd6143 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -1,10 +1,23 @@ import logging +import sentry_sdk +from sentry_sdk.integrations.logging import LoggingIntegration + from bot.bot import bot from bot.constants import Client, STAFF_ROLES, WHITELISTED_CHANNELS from bot.exts import walk_extensions from bot.utils.decorators import in_channel_check +sentry_logging = LoggingIntegration( + level=logging.DEBUG, + event_level=logging.WARNING +) + +sentry_sdk.init( + dsn=Client.sentry_dsn, + integrations=[sentry_logging] +) + log = logging.getLogger(__name__) bot.add_check(in_channel_check(*WHITELISTED_CHANNELS, bypass_roles=STAFF_ROLES)) diff --git a/bot/constants.py b/bot/constants.py index 68e2b33f..1a2763f0 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -80,6 +80,7 @@ class Client(NamedTuple): guild = int(environ.get("SEASONALBOT_GUILD", 267624335836053506)) prefix = environ.get("PREFIX", ".") token = environ.get("SEASONALBOT_TOKEN") + sentry_dsn = environ.get("SEASONALBOT_SENTRY_DSN") debug = environ.get("SEASONALBOT_DEBUG", "").lower() == "true" diff --git a/bot/exts/evergreen/error_handler.py b/bot/exts/evergreen/error_handler.py index d268dab1..f756c321 100644 --- a/bot/exts/evergreen/error_handler.py +++ b/bot/exts/evergreen/error_handler.py @@ -5,6 +5,7 @@ from typing import Iterable, Union from discord import Embed, Message from discord.ext import commands +from sentry_sdk import push_scope from bot.constants import Colours, ERROR_REPLIES, NEGATIVE_REPLIES from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure @@ -102,7 +103,25 @@ class CommandErrorHandler(commands.Cog): await ctx.send(embed=self.error_embed("You are not authorized to use this command.", NEGATIVE_REPLIES)) return - log.exception(f"Unhandled command error: {str(error)}", exc_info=error) + with push_scope() as scope: + scope.user = { + "id": ctx.author.id, + "username": str(ctx.author) + } + + scope.set_tag("command", ctx.command.qualified_name) + scope.set_tag("message_id", ctx.message.id) + scope.set_tag("channel_id", ctx.channel.id) + + scope.set_extra("full_message", ctx.message.content) + + if ctx.guild is not None: + scope.set_extra( + "jump_to", + f"https://discordapp.com/channels/{ctx.guild.id}/{ctx.channel.id}/{ctx.message.id}" + ) + + log.exception(f"Unhandled command error: {str(error)}", exc_info=error) def setup(bot: commands.Bot) -> None: |