Skip to content

Commit 68df119

Browse files
committed
Add asyncio integration to Sentry
1 parent 2f04c75 commit 68df119

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
This is a simple Discord bot used to trigger WATO's infrastructure provisioning pipeline when a user joins the Discord server.
44

5-
## Usage
5+
## Development
66

77
```bash
88
docker build . -t discord-provisioner-bot
9-
docker run --rm -it -e DISCORD_TOKEN=<DISCORD_TOKEN> -e GITHUB_TOKEN=<GITHUB_TOKEN> -e SENTRY_DSN=<SENTRY_DSN> discord-provisioner-bot
9+
docker run --rm -it -v $(pwd):/app -e DISCORD_TOKEN=<DISCORD_TOKEN> -e GITHUB_TOKEN=<GITHUB_TOKEN> -e SENTRY_DSN=<SENTRY_DSN> discord-provisioner-bot
1010
```
1111

1212
## Deployment
1313

14-
This bot is deployed to WATO's Kubernetes cluster. The deployment is managed in the internal [infra-config](https://github.com/watonomous/infra-config) repo.
14+
This bot is deployed via in the internal [infra-config](https://github.com/watonomous/infra-config) repo.

main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sentry_sdk
77
from aiohttp import web
88
from discord.ext import tasks
9+
from sentry_sdk.integrations.asyncio import AsyncioIntegration
910
from sentry_sdk.integrations.logging import LoggingIntegration
1011
from sentry_sdk.crons import monitor
1112
from time import perf_counter, sleep
@@ -51,7 +52,7 @@ def sentry_traces_sampler(sampling_context):
5152

5253
sentry_sdk.init(
5354
**sentry_config,
54-
integrations=[sentry_logging],
55+
integrations=[sentry_logging, AsyncioIntegration()],
5556

5657
# Set traces_sample_rate to 1.0 to capture 100%
5758
# of transactions for performance monitoring.
@@ -118,12 +119,14 @@ async def health_endpoint(_request):
118119
async def healthcheck_loop():
119120
logger.info(f'Healthcheck loop running. {client.is_closed()=}')
120121
start = perf_counter()
121-
monitor_once()
122+
await monitor_once()
122123
stop = perf_counter()
123124
logger.info(f"Healthcheck loop completed in {stop-start:.2f} seconds")
124125

125126
@monitor(monitor_slug='discord-provisioner-bot')
126-
def monitor_once():
127-
sleep(0.5) # space out the begin and end API calls
127+
async def monitor_once():
128+
res = await health_endpoint(None)
129+
if res.status != 200:
130+
raise Exception(f"Healthcheck failed with status {res.status}")
128131

129132
client.run(os.environ['DISCORD_TOKEN'])

0 commit comments

Comments
 (0)