mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Sentry error logging (#784)
This commit is contained in:
parent
e469ee201b
commit
82d9457647
@ -17,7 +17,8 @@ class Red(commands.Bot):
|
|||||||
packages=[],
|
packages=[],
|
||||||
coowners=[],
|
coowners=[],
|
||||||
whitelist=[],
|
whitelist=[],
|
||||||
blacklist=[]
|
blacklist=[],
|
||||||
|
enable_sentry=None
|
||||||
)
|
)
|
||||||
|
|
||||||
self.db.register_guild(
|
self.db.register_guild(
|
||||||
|
|||||||
19
core/cli.py
19
core/cli.py
@ -1,6 +1,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from core.bot import Red
|
||||||
|
|
||||||
|
|
||||||
def confirm(m=""):
|
def confirm(m=""):
|
||||||
return input(m).lower().strip() in ("y", "yes")
|
return input(m).lower().strip() in ("y", "yes")
|
||||||
@ -39,9 +41,26 @@ def interactive_config(red, token_set, prefix_set):
|
|||||||
if prefix:
|
if prefix:
|
||||||
loop.run_until_complete(red.db.set("prefix", [prefix]))
|
loop.run_until_complete(red.db.set("prefix", [prefix]))
|
||||||
|
|
||||||
|
ask_sentry(red)
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
def ask_sentry(red: Red):
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
print("\nThank you for installing Red V3 alpha! The current version\n"
|
||||||
|
" is not suited for production use and is aimed at testing\n"
|
||||||
|
" the current and upcoming featureset, that's why we will\n"
|
||||||
|
" also collect the fatal error logs to help us fix any new\n"
|
||||||
|
" found issues in a timely manner. If you wish to opt in\n"
|
||||||
|
" the process please type \"yes\":\n")
|
||||||
|
if not confirm("> "):
|
||||||
|
loop.run_until_complete(red.db.set("enable_sentry", False))
|
||||||
|
else:
|
||||||
|
loop.run_until_complete(red.db.set("enable_sentry", True))
|
||||||
|
print("\nThank you for helping us with the development process!")
|
||||||
|
|
||||||
|
|
||||||
def parse_cli_flags():
|
def parse_cli_flags():
|
||||||
parser = argparse.ArgumentParser(description="Red - Discord Bot")
|
parser = argparse.ArgumentParser(description="Red - Discord Bot")
|
||||||
parser.add_argument("--owner", help="ID of the owner. Only who hosts "
|
parser.add_argument("--owner", help="ID of the owner. Only who hosts "
|
||||||
|
|||||||
42
core/sentry_setup.py
Normal file
42
core/sentry_setup.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from raven import Client
|
||||||
|
from raven.versioning import fetch_git_sha
|
||||||
|
from raven.conf import setup_logging
|
||||||
|
from raven.handlers.logging import SentryHandler
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
client = None
|
||||||
|
|
||||||
|
|
||||||
|
def init_sentry_logging():
|
||||||
|
global client
|
||||||
|
client = Client(
|
||||||
|
dsn=("https://27f3915ba0144725a53ea5a99c9ae6f3:87913fb5d0894251821dcf06e5e9cfe6@"
|
||||||
|
"sentry.telemetry.red/19?verify_ssl=0"),
|
||||||
|
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'
|
||||||
|
),
|
||||||
|
release=fetch_git_sha(str(Path.cwd()))
|
||||||
|
)
|
||||||
|
|
||||||
|
handler = SentryHandler(client)
|
||||||
|
setup_logging(
|
||||||
|
handler,
|
||||||
|
exclude=(
|
||||||
|
"asyncio",
|
||||||
|
"discord"
|
||||||
|
)
|
||||||
|
)
|
||||||
10
main.py
10
main.py
@ -1,7 +1,8 @@
|
|||||||
from core.bot import Red, ExitCodes
|
from core.bot import Red, ExitCodes
|
||||||
from core.global_checks import init_global_checks
|
from core.global_checks import init_global_checks
|
||||||
from core.events import init_events
|
from core.events import init_events
|
||||||
from core.cli import interactive_config, confirm, parse_cli_flags
|
from core.sentry_setup import init_sentry_logging
|
||||||
|
from core.cli import interactive_config, confirm, parse_cli_flags, ask_sentry
|
||||||
from core.core_commands import Core
|
from core.core_commands import Core
|
||||||
from core.dev_commands import Dev
|
from core.dev_commands import Dev
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -59,6 +60,7 @@ if __name__ == '__main__':
|
|||||||
red = Red(cli_flags, description=description, pm_help=None)
|
red = Red(cli_flags, description=description, pm_help=None)
|
||||||
init_global_checks(red)
|
init_global_checks(red)
|
||||||
init_events(red, cli_flags)
|
init_events(red, cli_flags)
|
||||||
|
|
||||||
red.add_cog(Core())
|
red.add_cog(Core())
|
||||||
|
|
||||||
if cli_flags.dev:
|
if cli_flags.dev:
|
||||||
@ -77,6 +79,12 @@ if __name__ == '__main__':
|
|||||||
log.critical("Token and prefix must be set in order to login.")
|
log.critical("Token and prefix must be set in order to login.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if red.db.enable_sentry() is None:
|
||||||
|
ask_sentry(red)
|
||||||
|
|
||||||
|
if red.db.enable_sentry():
|
||||||
|
init_sentry_logging()
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
cleanup_tasks = True
|
cleanup_tasks = True
|
||||||
|
|
||||||
|
|||||||
@ -3,3 +3,4 @@ youtube_dl
|
|||||||
pytest
|
pytest
|
||||||
git+https://github.com/pytest-dev/pytest-asyncio
|
git+https://github.com/pytest-dev/pytest-asyncio
|
||||||
pymongo
|
pymongo
|
||||||
|
git+https://github.com/getsentry/raven-python
|
||||||
9
tests/core/test_sentry.py
Normal file
9
tests/core/test_sentry.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from core import sentry_setup
|
||||||
|
|
||||||
|
|
||||||
|
def test_sentry_capture():
|
||||||
|
sentry_setup.init_sentry_logging()
|
||||||
|
|
||||||
|
assert sentry_setup.client is not None
|
||||||
|
|
||||||
|
sentry_setup.client.captureMessage("Message from test_sentry module.")
|
||||||
Loading…
x
Reference in New Issue
Block a user