Skip to main content

Lightweight FastAPI middleware for centralized API monitoring

Project description

tigzig-api-monitor

Lightweight FastAPI middleware for centralized API monitoring. Automatically captures request/response metrics and sends them to a central monitoring service.

Installation

pip install tigzig-api-monitor

Quick Start

from fastapi import FastAPI
from tigzig_api_monitor import APIMonitorMiddleware

app = FastAPI()

# Add the monitoring middleware
app.add_middleware(
    APIMonitorMiddleware,
    app_name="YOUR_APP_NAME",  # Required: identifies your app in logs
)

Configuration

Set these environment variables:

Variable Required Description
API_MONITOR_URL Yes URL of the monitoring service (e.g., https://logger.tigzig.com/log)
API_MONITOR_KEY Yes API key for authentication

Features

  • Non-blocking: Logs are sent asynchronously, never slowing down your API
  • Automatic capture: Request method, endpoint, status code, response time
  • Privacy-safe: IP addresses are hashed, not stored
  • Lightweight: Minimal dependencies (just httpx and starlette)
  • Fire-and-forget: Logging failures don't affect your API
  • Noise filtering: Automatically skips health checks, bots, and vulnerability scanners

What Gets Logged

Each request automatically captures:

  • App name (configured)
  • Endpoint path (no query params for privacy)
  • HTTP method (GET, POST, etc.)
  • Response status code
  • Response time in milliseconds
  • Client IP (sent to service, hashed before storage)
  • User-Agent header
  • Origin header
  • Referer path (no query params)

Example

import os
from fastapi import FastAPI
from tigzig_api_monitor import APIMonitorMiddleware

# Set environment variables (or use .env file)
os.environ["API_MONITOR_URL"] = "https://logger.tigzig.com/log"
os.environ["API_MONITOR_KEY"] = "your-api-key"

app = FastAPI()

# Add monitoring - that's it!
app.add_middleware(APIMonitorMiddleware, app_name="MY_BACKEND")

@app.get("/")
def read_root():
    return {"message": "Hello World"}

# Every request to this API will now be monitored automatically

Noise Filtering (v1.1.0+)

By default, the middleware automatically skips logging for:

  • Health check endpoints (/, /health, /healthz, /ready)
  • Static files (/favicon.ico, /robots.txt, /sitemap.xml)
  • Vulnerability scanner probes (/.env, /wp-admin, /vendor/phpunit/..., etc.)
  • Common bot paths (/_next/, /js/, /css/, etc.)

Customize Filtering

# Add additional paths to exclude
app.add_middleware(
    APIMonitorMiddleware,
    app_name="MY_BACKEND",
    exclude_paths={"/internal", "/metrics", "/debug"},
    exclude_prefixes=("/admin/", "/private/"),
)

# Log everything (disable noise filtering)
app.add_middleware(
    APIMonitorMiddleware,
    app_name="MY_BACKEND",
    include_noise=True,
)

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

tigzig_api_monitor-1.2.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

tigzig_api_monitor-1.2.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tigzig_api_monitor-1.2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for tigzig_api_monitor-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a28d270643bcd38deee78c9823944c47d50f0f0a3572eab0d06b2600d7e485c4
MD5 40067bb6ee99af071c5ae20a682a981a
BLAKE2b-256 00b640fc714a378fe05c601ac9e8adb6e95e45870c15ee832d6a613f1f911975

See more details on using hashes here.

File details

Details for the file tigzig_api_monitor-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tigzig_api_monitor-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1e773620e7e1dc399bec21fbc2c1cbe94ef9fea27ce7c16033f72fb8d6c75b7
MD5 f3ce49ca6a384bb0fad6bc69b84f9a4e
BLAKE2b-256 ea75f64e9f7568de8a6263687ccaa86f7dead77e5b44a3d5662bcbe869fd87fa

See more details on using hashes here.

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