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.2.1.tar.gz (141.3 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.2.1-py3-none-any.whl (259.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for snitchbot-1.2.1.tar.gz
Algorithm Hash digest
SHA256 18bca0ba98fd6a2fdfb6a49e44fc0d168803fe3c3aa1f9fa0153c74f071329c2
MD5 116822a5e732ddc495d8dac2985b8142
BLAKE2b-256 753a384581ea204ccc04365acfe23af871a84d0cdc625970e986206d1c328be9

See more details on using hashes here.

Provenance

The following attestation bundles were made for snitchbot-1.2.1.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.2.1-py3-none-any.whl.

File metadata

  • Download URL: snitchbot-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 259.6 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3445c208cb5d3939bdc7bec44b3dd4a0e1462000edcc3deb0ceeb63e694e253e
MD5 e0c8c6697089f0e52b04114a951b2fff
BLAKE2b-256 3008ad94dd20823275931ad5aed8e8bb59a97b0bbe7ac871006bb457cc0c7f46

See more details on using hashes here.

Provenance

The following attestation bundles were made for snitchbot-1.2.1-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