[V3 Sentry] Fix sentry logging (#1169)

This commit is contained in:
Will 2017-12-12 22:34:34 -05:00 committed by GitHub
parent b34a58e521
commit be591d7c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 30 deletions

View File

@ -8,7 +8,6 @@ from pkg_resources import DistributionNotFound
import discord
from .sentry_setup import should_log
from discord.ext import commands
from . import __version__
@ -134,6 +133,10 @@ def init_events(bot, cli_flags):
if bot.rpc_enabled:
await initialize(bot)
@bot.event
async def on_error(event_method, *args, **kwargs):
sentry_log.exception("Exception in on_{}".format(event_method))
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
@ -166,12 +169,6 @@ def init_events(bot, cli_flags):
error, error.__traceback__))
bot._last_exception = exception_log
await ctx.send(inline(message))
module = ctx.command.module
if should_log(module):
sentry_log.exception("Exception in command '{}'"
"".format(ctx.command.qualified_name),
exc_info=error.original)
elif isinstance(error, commands.CommandNotFound):
pass
elif isinstance(error, commands.CheckFailure):
@ -185,6 +182,10 @@ def init_events(bot, cli_flags):
else:
log.exception(type(error).__name__, exc_info=error)
sentry_log.exception("Exception in command '{}'"
"".format(ctx.command.qualified_name),
exc_info=error.original)
@bot.event
async def on_message(message):
bot.counter["messages_read"] += 1

View File

@ -1,25 +1,13 @@
from raven import Client, breadcrumbs
from raven import Client
from raven.handlers.logging import SentryHandler
from redbot.core import __version__
__all__ = ("init_sentry_logging", "should_log")
__all__ = ("init_sentry_logging",)
include_paths = (
'core',
'cogs.alias',
'cogs.audio',
'cogs.downloader',
'cogs.economy',
'cogs.general',
'cogs.image',
'cogs.streams',
'cogs.trivia',
'cogs.utils',
'tests.core.test_sentry',
'main',
'launcher'
'redbot',
)
client = None
@ -30,14 +18,9 @@ def init_sentry_logging(logger):
client = Client(
dsn=("https://62402161d4cd4ef18f83b16f3e22a020:9310ef55a502442598203205a84da2bb@"
"sentry.io/253983"),
release=__version__
release=__version__,
include_paths=['redbot'],
enable_breadcrumbs=False
)
breadcrumbs.ignore_logger("websockets")
breadcrumbs.ignore_logger("websockets.protocol")
handler = SentryHandler(client)
logger.addHandler(handler)
def should_log(module_name: str) -> bool:
return any(module_name.startswith(path) for path in include_paths)