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.0.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.0-py3-none-any.whl (259.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snitchbot-1.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4ab23720a3260c513ce7da03cfa47976d7ae449ce0aa348cbe9698d19f361fc6
MD5 9054757fc7a885d278ad1dfda75cf95b
BLAKE2b-256 2c75d80e866402dbf32141d446dc1ed75092305e5175f74c8f623a613bd1cd34

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: snitchbot-1.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b61d8481161e850c2c0488ba6b9dcc9d4dd6247fa982c0911c90aeced59bc63
MD5 13417f3e3e9dc0596137f71d48a8939d
BLAKE2b-256 789d639e7197780b15599c1185679b2649d319b35c3bbcc3150babb9342fb148

See more details on using hashes here.

Provenance

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