Telegram telemetry: crash reports, slow calls, watchdog and anomaly alerts for Python services
Project description
snitchbot
Telegram telemetry for Python services. Crash reports, slow-call alerts, watchdog events, custom notifications, and anomaly detection — delivered to your Telegram chat.
Docs: https://sense1tapo4ek.github.io/snitchbot/
Features
- Crash reporting — uncaught exceptions in sync, threading, and asyncio
- Slow-call monitoring —
@watch_slow(threshold_ms=1000)decorator - Watchdog — event loop block detection with severity escalation
- Custom notifications —
notify("deploy complete", severity="warning") - Request context — trace IDs and tags propagated across async boundaries
- Anomaly detection — RSS spikes, CPU sustained, FD leaks, thread growth
- Interactive Telegram — /status, /last, /test, /mute, /unmute commands
- Live dashboard — auto-updating message with service vitals
- Secret scrubbing — API keys, tokens, passwords never reach Telegram
- Logging bridges — stdlib
logginghandler +structlogprocessor
Architecture
Thin host client + detached sidecar process. The client never blocks your app — events are sent via AF_UNIX SOCK_DGRAM to the sidecar, which handles dedup, rate limiting, and Telegram delivery.
Installation
uv add snitchbot
With example frameworks (FastAPI, Litestar, Flask):
uv add snitchbot[examples]
Quick Start
1. Get a Telegram bot token
Talk to @BotFather, create a bot, copy the token.
2. Get your chat ID
Add the bot to a group or start a DM, then use @userinfobot or the Telegram API to find the chat ID.
3. Configure
cp .env.example .env
# Edit .env — set SNITCHBOT_TOKEN and SNITCHBOT_CHAT_ID
4. Add to your app
import snitchbot
# Reads SNITCHBOT_TOKEN and SNITCHBOT_CHAT_ID from env / .env file
snitchbot.init("my-service")
# Or pass explicitly:
# snitchbot.init("my-service", token="...", chat_id="...")
# That's it. Crashes are now reported automatically.
# Optional: custom notifications
snitchbot.notify("Deploy complete", severity="warning")
# Optional: slow-call monitoring
@snitchbot.watch_slow(threshold_ms=1000)
async def process_order(order_id: str):
...
# Optional: request context
with snitchbot.request_context(trace_id="req-abc", user_id="42"):
snitchbot.notify("Processing started")
Running Examples
Prerequisites
# Clone and install
git clone https://github.com/Sense1Tapo4ek/snitchbot.git
cd snitchbot
uv sync --extra dev --extra examples
# Configure
cp .env.example .env
# Edit .env with your bot token and chat ID
FastAPI
uv run uvicorn examples.fastapi_app:app --reload
Then visit:
- http://localhost:8000/ — health check
- http://localhost:8000/notify — sends a custom notification
- http://localhost:8000/slow — triggers slow-call alert (200ms > 100ms threshold)
- http://localhost:8000/crash — triggers crash report
- http://localhost:8000/context — demonstrates request context
Litestar
uv run litestar run --app examples.litestar_app:app --reload
Flask
uv run flask --app examples.flask_app run --reload
Testing
# Run all tests (no Telegram token required)
uv run pytest
# Run only unit tests
uv run pytest tests/shared/unit tests/client/unit tests/sidecar/unit
# Run framework integration tests
uv run pytest tests/e2e/test_framework_integration.py -v
Python Support
- Python >= 3.10
- Linux (primary), macOS (supported)
- Works with: FastAPI, Litestar, Flask, Django, Celery, Gunicorn, uvicorn, uvloop
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snitchbot-1.0.0.tar.gz.
File metadata
- Download URL: snitchbot-1.0.0.tar.gz
- Upload date:
- Size: 139.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea6e1daeb3c846a444a32d878de3b72b94c9bd2d252016ac0af60b137b984583
|
|
| MD5 |
c61d7095f72237fdb1086c58116e3f20
|
|
| BLAKE2b-256 |
4f0446a0dff436fe2b0654f64662671fb5c9d31d6d859bfaeeadcd4214367a2f
|
File details
Details for the file snitchbot-1.0.0-py3-none-any.whl.
File metadata
- Download URL: snitchbot-1.0.0-py3-none-any.whl
- Upload date:
- Size: 258.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad0c5ae4790a94eb0ab0ceaa4c6c1dc317d5f1afc8db542895fa8768817ff2fe
|
|
| MD5 |
bcf0b3cdc3cc7190caeaec40d124dc2e
|
|
| BLAKE2b-256 |
db264955c8fb0770fb5151e338d8aca93468b1595248322d87d454c4476ab105
|