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")

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.0.tar.gz (4.0 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.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rse_logging-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 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.0.tar.gz
Algorithm Hash digest
SHA256 e8a2d4898121903e7371a11e81e7766e4b0e8f69b76e0be29b86c58be9080ed1
MD5 6f6a2c2909aa5aac3174e3f648884c92
BLAKE2b-256 3be2ee59d56a0d60ac86ded8f676861954c5ffa43d99e01819ccae256d506f21

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rse_logging-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c774c32507c7568bf6349b2baffd14b744d5ac5ddda9af0704554ab11ddf82c
MD5 50eaa57461f4ce977de30b05eeb99d45
BLAKE2b-256 34c349fa46f1da12173f3d8e26d23cedb88e7aa9a139feda4828533701012aa7

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