feat(shard): 🔊 Set up sentry (GlitchTip).

This commit is contained in:
2025-03-16 02:18:52 -03:00
parent 1d2b065111
commit ac53c42452
4 changed files with 90 additions and 9 deletions
+23
View File
@@ -2,6 +2,8 @@ from typing import Literal
from datetime import datetime, timezone from datetime import datetime, timezone
import sys
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import errors from discord.ext.commands import errors
@@ -10,6 +12,8 @@ from tortoise import expressions
import redis.asyncio as redis import redis.asyncio as redis
import sentry_sdk
from payphone.db import setup, models from payphone.db import setup, models
from payphone.core import constants, logging, exceptions, formatting, help_command from payphone.core import constants, logging, exceptions, formatting, help_command
@@ -57,6 +61,8 @@ class Payphone(commands.AutoShardedBot):
self.log.info("Ready! Logged in as %s.", self.user.display_name) self.log.info("Ready! Logged in as %s.", self.user.display_name)
raise Exception("HEYYY")
async def set_presence(self, shard_id: int) -> None: async def set_presence(self, shard_id: int) -> None:
"""Sets the presence of the bot back to online. """Sets the presence of the bot back to online.
@@ -380,8 +386,12 @@ class Payphone(commands.AutoShardedBot):
return return
else: else:
sentry_sdk.capture_exception(exception)
return await super().on_command_error(context, exception) return await super().on_command_error(context, exception)
async def on_error(self, *args, **kwargs):
sentry_sdk.capture_exception(sys.exc_info())
@property @property
def embed_author(self) -> discord.EmbedAuthor: def embed_author(self) -> discord.EmbedAuthor:
"""The author of the embeds.""" """The author of the embeds."""
@@ -440,6 +450,19 @@ class Payphone(commands.AutoShardedBot):
def run(): def run():
"""Runs the bot.""" """Runs the bot."""
sentry_sdk.init(
constants.SENTRY_DSN,
environment="development" if constants.IS_DEBUG else "production",
debug=constants.IS_DEBUG,
server_name=f"Shard #{constants.SHARD_ID + 1}",
attach_stacktrace=True,
send_default_pii=True,
enable_tracing=True,
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
release=constants.VERSION,
)
bot = Payphone() bot = Payphone()
try: try:
+13 -1
View File
@@ -1,5 +1,7 @@
import os import os
import toml
try: try:
import dotenv import dotenv
@@ -23,7 +25,7 @@ SHARD_COUNT = int(os.getenv("SHARD_COUNT", "1"))
REDIS_HOST = os.getenv("REDIS_HOST", "localhost") REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
REDIS_PORT = int(os.getenv("REDIS_PORT", "6379")) REDIS_PORT = int(os.getenv("REDIS_PORT", "6379"))
INVISIBLE_CHARACTER = "\u200B" INVISIBLE_CHARACTER = "\u200b"
BRAILE_CHARACTER = "\u2800" BRAILE_CHARACTER = "\u2800"
PRIMARY_COLOR = 0xE2D9D0 PRIMARY_COLOR = 0xE2D9D0
@@ -32,3 +34,13 @@ MODERATOR_COLOR = 0xFF8787
MASK_COLOR = 0xFFC868 MASK_COLOR = 0xFFC868
DISCORD_SERVER_INVITE = "https://discord.gg/fKuZty23pm" DISCORD_SERVER_INVITE = "https://discord.gg/fKuZty23pm"
SENTRY_DSN = os.getenv(
"SENTRY_DSN", "https://[email protected]/67"
)
VERSION = None
with open("pyproject.toml", "r", encoding="UTF-8") as f:
data = toml.load(f)
VERSION = "v" + data["project"]["version"].split(".")[1]
+16 -2
View File
@@ -4,10 +4,24 @@ version = "0.47.0"
description = "Add your description here" description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"
dependencies = [ "aerich>=0.8.2", "aiohttp>=3.10.10", "orjson>=3.10.11", "py-cord>=2.6.1", "redis[hiredis]>=5.2.0", "rich>=13.9.4", "tortoise-orm[accel,asyncpg]>=0.21.7", "typer>=0.13.0",] dependencies = [
"aerich>=0.8.2",
"aiohttp>=3.10.10",
"orjson>=3.10.11",
"py-cord>=2.6.1",
"redis[hiredis]>=5.2.0",
"rich>=13.9.4",
"sentry-sdk>=2.22.0",
"toml>=0.10.2",
"tortoise-orm[accel,asyncpg]>=0.21.7",
"typer>=0.13.0",
]
[dependency-groups] [dependency-groups]
dev = [ "python-dotenv>=1.0.1", "pyyaml>=6.0.2", "toml>=0.10.2",] dev = [
"python-dotenv>=1.0.1",
"pyyaml>=6.0.2",
]
[tool.aerich] [tool.aerich]
tortoise_orm = "payphone.db.setup.CONFIG" tortoise_orm = "payphone.db.setup.CONFIG"
Generated
+38 -6
View File
@@ -1,5 +1,4 @@
version = 1 version = 1
revision = 1
requires-python = ">=3.12" requires-python = ">=3.12"
[[package]] [[package]]
@@ -128,7 +127,7 @@ version = "8.1.8"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple" }
dependencies = [ dependencies = [
{ name = "anyio" }, { name = "anyio" },
{ name = "colorama", marker = "sys_platform == 'win32'" }, { name = "colorama", marker = "platform_system == 'Windows'" },
] ]
sdist = { url = "https://files.pythonhosted.org/packages/cb/b5/e1e5fdf1c1bb7e6e614987c120a98d9324bf8edfaa5f5cd16a6235c9d91b/asyncclick-8.1.8.tar.gz", hash = "sha256:0f0eb0f280e04919d67cf71b9fcdfb4db2d9ff7203669c40284485c149578e4c", size = 232900 } sdist = { url = "https://files.pythonhosted.org/packages/cb/b5/e1e5fdf1c1bb7e6e614987c120a98d9324bf8edfaa5f5cd16a6235c9d91b/asyncclick-8.1.8.tar.gz", hash = "sha256:0f0eb0f280e04919d67cf71b9fcdfb4db2d9ff7203669c40284485c149578e4c", size = 232900 }
wheels = [ wheels = [
@@ -169,6 +168,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", size = 63815 }, { url = "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", size = 63815 },
] ]
[[package]]
name = "certifi"
version = "2025.1.31"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/1c/ab/c9f1e32b7b1bf505bf26f0ef697775960db7932abeb7b516de930ba2705f/certifi-2025.1.31.tar.gz", hash = "sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651", size = 167577 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/38/fc/bce832fd4fd99766c04d1ee0eead6b0ec6486fb100ae5e74c1d91292b982/certifi-2025.1.31-py3-none-any.whl", hash = "sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe", size = 166393 },
]
[[package]] [[package]]
name = "ciso8601" name = "ciso8601"
version = "2.3.2" version = "2.3.2"
@@ -189,7 +197,7 @@ name = "click"
version = "8.1.8" version = "8.1.8"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple" }
dependencies = [ dependencies = [
{ name = "colorama", marker = "sys_platform == 'win32'" }, { name = "colorama", marker = "platform_system == 'Windows'" },
] ]
sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 } sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 }
wheels = [ wheels = [
@@ -405,7 +413,7 @@ wheels = [
[[package]] [[package]]
name = "payphone" name = "payphone"
version = "0.46.0" version = "0.47.0"
source = { virtual = "." } source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "aerich" }, { name = "aerich" },
@@ -414,6 +422,8 @@ dependencies = [
{ name = "py-cord" }, { name = "py-cord" },
{ name = "redis", extra = ["hiredis"] }, { name = "redis", extra = ["hiredis"] },
{ name = "rich" }, { name = "rich" },
{ name = "sentry-sdk" },
{ name = "toml" },
{ name = "tortoise-orm", extra = ["accel", "asyncpg"] }, { name = "tortoise-orm", extra = ["accel", "asyncpg"] },
{ name = "typer" }, { name = "typer" },
] ]
@@ -422,7 +432,6 @@ dependencies = [
dev = [ dev = [
{ name = "python-dotenv" }, { name = "python-dotenv" },
{ name = "pyyaml" }, { name = "pyyaml" },
{ name = "toml" },
] ]
[package.metadata] [package.metadata]
@@ -433,6 +442,8 @@ requires-dist = [
{ name = "py-cord", specifier = ">=2.6.1" }, { name = "py-cord", specifier = ">=2.6.1" },
{ name = "redis", extras = ["hiredis"], specifier = ">=5.2.0" }, { name = "redis", extras = ["hiredis"], specifier = ">=5.2.0" },
{ name = "rich", specifier = ">=13.9.4" }, { name = "rich", specifier = ">=13.9.4" },
{ name = "sentry-sdk", specifier = ">=2.22.0" },
{ name = "toml", specifier = ">=0.10.2" },
{ name = "tortoise-orm", extras = ["accel", "asyncpg"], specifier = ">=0.21.7" }, { name = "tortoise-orm", extras = ["accel", "asyncpg"], specifier = ">=0.21.7" },
{ name = "typer", specifier = ">=0.13.0" }, { name = "typer", specifier = ">=0.13.0" },
] ]
@@ -441,7 +452,6 @@ requires-dist = [
dev = [ dev = [
{ name = "python-dotenv", specifier = ">=1.0.1" }, { name = "python-dotenv", specifier = ">=1.0.1" },
{ name = "pyyaml", specifier = ">=6.0.2" }, { name = "pyyaml", specifier = ">=6.0.2" },
{ name = "toml", specifier = ">=0.10.2" },
] ]
[[package]] [[package]]
@@ -655,6 +665,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/19/71/39c7c0d87f8d4e6c020a393182060eaefeeae6c01dab6a84ec346f2567df/rich-13.9.4-py3-none-any.whl", hash = "sha256:6049d5e6ec054bf2779ab3358186963bac2ea89175919d699e378b99738c2a90", size = 242424 }, { url = "https://files.pythonhosted.org/packages/19/71/39c7c0d87f8d4e6c020a393182060eaefeeae6c01dab6a84ec346f2567df/rich-13.9.4-py3-none-any.whl", hash = "sha256:6049d5e6ec054bf2779ab3358186963bac2ea89175919d699e378b99738c2a90", size = 242424 },
] ]
[[package]]
name = "sentry-sdk"
version = "2.22.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "certifi" },
{ name = "urllib3" },
]
sdist = { url = "https://files.pythonhosted.org/packages/81/b6/662988ecd2345bf6c3a5c306a9a3590852742eff91d0a78a143398b816f3/sentry_sdk-2.22.0.tar.gz", hash = "sha256:b4bf43bb38f547c84b2eadcefbe389b36ef75f3f38253d7a74d6b928c07ae944", size = 303539 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/12/7f/0e4459173e9671ba5f75a48dda2442bcc48a12c79e54e5789381c8c6a9bc/sentry_sdk-2.22.0-py2.py3-none-any.whl", hash = "sha256:3d791d631a6c97aad4da7074081a57073126c69487560c6f8bffcf586461de66", size = 325815 },
]
[[package]] [[package]]
name = "shellingham" name = "shellingham"
version = "1.5.4" version = "1.5.4"
@@ -731,6 +754,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", size = 37438 }, { url = "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", size = 37438 },
] ]
[[package]]
name = "urllib3"
version = "2.3.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/aa/63/e53da845320b757bf29ef6a9062f5c669fe997973f966045cb019c3f4b66/urllib3-2.3.0.tar.gz", hash = "sha256:f8c5449b3cf0861679ce7e0503c7b44b5ec981bec0d1d3795a07f1ba96f0204d", size = 307268 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/c8/19/4ec628951a74043532ca2cf5d97b7b14863931476d117c471e8e2b1eb39f/urllib3-2.3.0-py3-none-any.whl", hash = "sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df", size = 128369 },
]
[[package]] [[package]]
name = "uvloop" name = "uvloop"
version = "0.21.0" version = "0.21.0"