Skip to main content

Telegram telemetry: crash reports, slow calls, watchdog and anomaly alerts for Python services

Project description

snitchbot

PyPI version Python versions License: MIT Docs CI

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 notificationsnotify("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 logging handler + structlog processor

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snitchbot-1.1.0.tar.gz (141.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snitchbot-1.1.0-py3-none-any.whl (259.3 kB view details)

Uploaded Python 3

File details

Details for the file snitchbot-1.1.0.tar.gz.

File metadata

  • Download URL: snitchbot-1.1.0.tar.gz
  • Upload date:
  • Size: 141.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for snitchbot-1.1.0.tar.gz
Algorithm Hash digest
SHA256 beb27c737301f31027b90dcf65bdf3dcf90f8d092364d900bc3d235950394aa2
MD5 47e18eabcfe3d8197b1d31b028c4c3a9
BLAKE2b-256 eb35d7f3ba43dffe2e5f5cfff9be5f41070762fbf170cb6d92c0153a86cc2f46

See more details on using hashes here.

Provenance

The following attestation bundles were made for snitchbot-1.1.0.tar.gz:

Publisher: publish.yml on Sense1Tapo4ek/snitchbot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snitchbot-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: snitchbot-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 259.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for snitchbot-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af243a2c9403ef3219514e606ee29bb6dc779ceb9ac6dd091c865118716f60e5
MD5 b737731f135f4a5485dfd94fb0fa37f2
BLAKE2b-256 e6e1823b248afb77383941c74f0dca4717dfb96dc930d6fd50dc9b94255b7a08

See more details on using hashes here.

Provenance

The following attestation bundles were made for snitchbot-1.1.0-py3-none-any.whl:

Publisher: publish.yml on Sense1Tapo4ek/snitchbot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page