Skip to main content

RSE standard logging with correlation id, Vault-backed Telegram alerts, and FastAPI middleware.

Project description

rse-logging

RSE standard logging package for Python APIs.

Features:

  • colored console logs
  • request correlation id with ContextVar
  • FastAPI middleware for X-Correlation-ID
  • helper functions: log_info, log_warning, log_error
  • Telegram alerts for ERROR logs in stg and prd
  • Telegram credentials loaded from HashiCorp Vault

Usage

from fastapi import FastAPI
from rse_logging import CorrelationIdMiddleware, log_error, setup_logger

setup_logger("my-api")

app = FastAPI()
app.add_middleware(CorrelationIdMiddleware)

log_error("startup", "Example error")

Diagnostics

To debug Telegram/Vault configuration without printing tokens:

from rse_logging import diagnose_telegram, setup_logger

setup_logger("my-api")
print(diagnose_telegram(send_test_message=True))

Set RSE_LOGGING_DEBUG=true to print skipped Telegram alert reasons to stderr.

Vault

Telegram alerts are enabled only when RSE_ENV is stg or prd.

The package reads Vault using:

  • RSE_ENV as the KV v2 mount point
  • RSE_VAULT_HOST as the Vault URL
  • RSE_VAULT_TOKEN as the Vault token
  • shared as the default secret path

Expected keys:

telegram_bot_token
telegram_chat_id

Examples:

stg/shared.telegram_bot_token
stg/shared.telegram_chat_id
prd/shared.telegram_bot_token
prd/shared.telegram_chat_id

Set RSE_LOGGING_TELEGRAM_ENABLED=false to disable Telegram alerts.

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

rse_logging-0.1.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

rse_logging-0.1.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file rse_logging-0.1.2.tar.gz.

File metadata

  • Download URL: rse_logging-0.1.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.0 Windows/10

File hashes

Hashes for rse_logging-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a167fe2d0ba6523240da1abbabfbf2d55dbfdd5451e9f33dadf7c03a701a099c
MD5 b3ae00ea4e20df693d1e2bedd9ee21fa
BLAKE2b-256 1e1f71f483083fb7b13184ed7db43ee26e5fb58be18f195af1a27e130b1a410c

See more details on using hashes here.

File details

Details for the file rse_logging-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: rse_logging-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.0 Windows/10

File hashes

Hashes for rse_logging-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94d9735ca34e4a3420452295703c64e9a73049e054b8b702ee435a08138d01c3
MD5 a5baf6ad6818df37ee684b661d1fb06d
BLAKE2b-256 c7dca4ce92b2d8771cd1394c2f9c43b2179268cbd81fd9c423f6c4a2d5b43d93

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