Skip to content

Commit

Permalink
Sentry removal (#2439)
Browse files Browse the repository at this point in the history
Resolves #2430.
  • Loading branch information
Twentysix26 authored and Tobotimus committed Feb 11, 2019
1 parent dae7552 commit 889fa63
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 199 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -18,7 +18,6 @@ redbot/core/i18n.py @tekulvw
redbot/core/json_io.py @tekulvw
redbot/core/modlog.py @palmtree5
redbot/core/rpc.py @tekulvw
redbot/core/sentry_setup.py @Kowlin @tekulvw
redbot/core/utils/chat_formatting.py @tekulvw
redbot/core/utils/mod.py @palmtree5
redbot/core/utils/data_converter.py @mikeshardmind
Expand Down
28 changes: 0 additions & 28 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions redbot/__main__.py
Expand Up @@ -10,7 +10,7 @@
from redbot.core.json_io import JsonIO
from redbot.core.global_checks import init_global_checks
from redbot.core.events import init_events
from redbot.core.cli import interactive_config, confirm, parse_cli_flags, ask_sentry
from redbot.core.cli import interactive_config, confirm, parse_cli_flags
from redbot.core.core_commands import Core
from redbot.core.dev_commands import Dev
from redbot.core import __version__
Expand Down Expand Up @@ -77,11 +77,7 @@ def init_loggers(cli_flags):
logger.addHandler(fhandler)
logger.addHandler(stdout_handler)

# Sentry stuff
sentry_logger = logging.getLogger("red.sentry")
sentry_logger.setLevel(logging.WARNING)

return logger, sentry_logger
return logger


async def _get_prefix_and_token(red, indict):
Expand All @@ -92,7 +88,6 @@ async def _get_prefix_and_token(red, indict):
"""
indict["token"] = await red.db.token()
indict["prefix"] = await red.db.prefix()
indict["enable_sentry"] = await red.db.enable_sentry()


def list_instances():
Expand Down Expand Up @@ -136,7 +131,7 @@ def main():
cli_flags.instance_name = "temporary_red"
create_temp_config()
load_basic_configuration(cli_flags.instance_name)
log, sentry_log = init_loggers(cli_flags)
log = init_loggers(cli_flags)
red = Red(cli_flags=cli_flags, description=description, pm_help=None)
init_global_checks(red)
init_events(red, cli_flags)
Expand Down Expand Up @@ -166,8 +161,6 @@ def main():
if cli_flags.dry_run:
loop.run_until_complete(red.http.close())
sys.exit(0)
if tmp_data["enable_sentry"]:
red.enable_sentry()
try:
loop.run_until_complete(red.start(token, bot=True))
except discord.LoginFailure:
Expand All @@ -184,7 +177,6 @@ def main():
red._shutdown_mode = ExitCodes.SHUTDOWN
except Exception as e:
log.critical("Fatal exception", exc_info=e)
sentry_log.critical("Fatal Exception", exc_info=e)
loop.run_until_complete(red.logout())
finally:
pending = asyncio.Task.all_tasks(loop=red.loop)
Expand Down
19 changes: 0 additions & 19 deletions redbot/core/bot.py
Expand Up @@ -16,7 +16,6 @@
from .cog_manager import CogManager
from .help_formatter import Help, help as help_
from .rpc import RPCMixin
from .sentry import SentryManager
from .utils import common_filters


Expand Down Expand Up @@ -47,7 +46,6 @@ def __init__(self, *args, cli_flags=None, bot_dir: Path = Path.cwd(), **kwargs):
owner=None,
whitelist=[],
blacklist=[],
enable_sentry=None,
locale="en",
embeds=True,
color=15158332,
Expand Down Expand Up @@ -120,23 +118,8 @@ async def prefix_manager(bot, message):

self.add_command(help_)

self._sentry_mgr = None
self._permissions_hooks: List[commands.CheckPredicate] = []

def enable_sentry(self):
"""Enable Sentry logging for Red."""
if self._sentry_mgr is None:
sentry_log = logging.getLogger("red.sentry")
sentry_log.setLevel(logging.WARNING)
self._sentry_mgr = SentryManager(sentry_log)
self._sentry_mgr.enable()

def disable_sentry(self):
"""Disable Sentry logging for Red."""
if self._sentry_mgr is None:
return
self._sentry_mgr.disable()

async def _dict_abuse(self, indict):
"""
Please blame <@269933075037814786> for this.
Expand Down Expand Up @@ -516,8 +499,6 @@ class Red(RedBase, discord.AutoShardedClient):

async def logout(self):
"""Logs out of Discord and closes all connections."""
if self._sentry_mgr:
await self._sentry_mgr.close()

await super().logout()

Expand Down
19 changes: 0 additions & 19 deletions redbot/core/cli.py
@@ -1,8 +1,6 @@
import argparse
import asyncio

from redbot.core.bot import Red


def confirm(m=""):
return input(m).lower().strip() in ("y", "yes")
Expand Down Expand Up @@ -42,26 +40,9 @@ def interactive_config(red, token_set, prefix_set):
if prefix:
loop.run_until_complete(red.db.prefix.set([prefix]))

ask_sentry(red)

return token


def ask_sentry(red: Red):
loop = asyncio.get_event_loop()
print(
"\nThank you for installing Red V3! Red is constantly undergoing\n"
" improvements, and we would like to ask if you are comfortable with\n"
" the bot automatically submitting fatal error logs to the development\n"
' team. If you wish to opt into the process please type "yes":\n'
)
if not confirm("> "):
loop.run_until_complete(red.db.enable_sentry.set(False))
else:
loop.run_until_complete(red.db.enable_sentry.set(True))
print("\nThank you for helping us with the development process!")


def parse_cli_flags(args):
parser = argparse.ArgumentParser(
description="Red - Discord Bot", usage="redbot <instance_name> [arguments]"
Expand Down
17 changes: 0 additions & 17 deletions redbot/core/core_commands.py
Expand Up @@ -1015,23 +1015,6 @@ async def locale(self, ctx: commands.Context, locale_name: str):

await ctx.send(_("Locale has been set."))

@_set.command()
@checks.is_owner()
async def sentry(self, ctx: commands.Context, on_or_off: bool):
"""Enable or disable Sentry logging.
Sentry is the service Red uses to manage error reporting. This should
be disabled if you have made your own modifications to the redbot
package.
"""
await ctx.bot.db.enable_sentry.set(on_or_off)
if on_or_off:
ctx.bot.enable_sentry()
await ctx.send(_("Done. Sentry logging is now enabled."))
else:
ctx.bot.disable_sentry()
await ctx.send(_("Done. Sentry logging is now disabled."))

@_set.command()
@checks.is_owner()
async def custominfo(self, ctx: commands.Context, *, text: str = None):
Expand Down
42 changes: 4 additions & 38 deletions redbot/core/events.py
Expand Up @@ -19,34 +19,18 @@
from .utils import fuzzy_command_search, format_fuzzy_results

log = logging.getLogger("red")
sentry_log = logging.getLogger("red.sentry")
init()

INTRO = """
______ _ ______ _ _ ______ _
| ___ \ | | | _ (_) | | | ___ \ | |
| |_/ /___ __| | ______ | | | |_ ___ ___ ___ _ __ __| | | |_/ / ___ | |_
______ _ ______ _ _ ______ _
| ___ \ | | | _ (_) | | | ___ \ | |
| |_/ /___ __| | ______ | | | |_ ___ ___ ___ _ __ __| | | |_/ / ___ | |_
| // _ \/ _` | |______| | | | | / __|/ __/ _ \| '__/ _` | | ___ \/ _ \| __|
| |\ \ __/ (_| | | |/ /| \__ \ (_| (_) | | | (_| | | |_/ / (_) | |_
| |\ \ __/ (_| | | |/ /| \__ \ (_| (_) | | | (_| | | |_/ / (_) | |_
\_| \_\___|\__,_| |___/ |_|___/\___\___/|_| \__,_| \____/ \___/ \__|
"""


def should_log_sentry(exception) -> bool:
e = exception
while e.__cause__ is not None:
e = e.__cause__

tb = e.__traceback__
tb_frame = None
while tb is not None:
tb_frame = tb.tb_frame
tb = tb.tb_next

module = tb_frame.f_globals.get("__name__")
return module is not None and module.startswith("redbot")


def init_events(bot, cli_flags):
@bot.event
async def on_connect():
Expand Down Expand Up @@ -142,7 +126,6 @@ async def on_ready():
)
INFO2 = []

sentry = await bot.db.enable_sentry()
mongo_enabled = storage_type() != "JSON"
reqs_installed = {"docs": None, "test": None}
for key in reqs_installed.keys():
Expand All @@ -155,7 +138,6 @@ async def on_ready():
reqs_installed[key] = True

options = (
("Error Reporting", sentry),
("MongoDB", mongo_enabled),
("Voice", True),
("Docs", reqs_installed["docs"]),
Expand All @@ -177,10 +159,6 @@ async def on_ready():

bot.color = discord.Colour(await bot.db.color())

@bot.event
async def on_error(event_method, *args, **kwargs):
sentry_log.exception("Exception in {}".format(event_method))

@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
Expand All @@ -201,11 +179,6 @@ async def on_command_error(ctx, error):
"Exception in command '{}'".format(ctx.command.qualified_name),
exc_info=error.original,
)
if should_log_sentry(error):
sentry_log.exception(
"Exception in command '{}'".format(ctx.command.qualified_name),
exc_info=error.original,
)

message = "Error in command '{}'. Check your console or logs for details.".format(
ctx.command.qualified_name
Expand Down Expand Up @@ -245,13 +218,6 @@ async def on_command_error(ctx, error):
)
else:
log.exception(type(error).__name__, exc_info=error)
try:
sentry_error = error.original
except AttributeError:
sentry_error = error

if should_log_sentry(sentry_error):
sentry_log.exception("Unhandled command error.", exc_info=sentry_error)

@bot.event
async def on_message(message):
Expand Down
41 changes: 0 additions & 41 deletions redbot/core/sentry.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/cogs/downloader/test_downloader.py
Expand Up @@ -4,7 +4,6 @@

import pytest
from unittest.mock import MagicMock
from raven.versioning import fetch_git_sha

from redbot.pytest.downloader import *

Expand Down Expand Up @@ -60,18 +59,6 @@ async def test_current_branch(bot_repo):
assert branch not in ("WRONG", "")


@pytest.mark.asyncio
async def test_current_hash(bot_repo):
branch = await bot_repo.current_branch()
bot_repo.branch = branch

commit = await bot_repo.current_commit()

sentry_sha = fetch_git_sha(str(bot_repo.folder_path))

assert sentry_sha == commit


@pytest.mark.asyncio
async def test_existing_repo(repo_manager):
repo_manager.does_repo_exist = MagicMock(return_value=True)
Expand Down
12 changes: 0 additions & 12 deletions tests/core/test_sentry.py

This file was deleted.

0 comments on commit 889fa63

Please sign in to comment.