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
ERRORlogs instgandprd - 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_ENVas the KV v2 mount pointRSE_VAULT_HOSTas the Vault URLRSE_VAULT_TOKENas the Vault tokensharedas 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rse_logging-0.1.6.tar.gz.
File metadata
- Download URL: rse_logging-0.1.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36b379106231f424a8eea67e544c0456cc94baac7e3d526540a6e02e37173557
|
|
| MD5 |
d4238a443442122779f95f37e214a22b
|
|
| BLAKE2b-256 |
95e96386d025e6c8581df845bc20caa46ede9b7ca4fee20647972c0ee2c3758f
|
File details
Details for the file rse_logging-0.1.6-py3-none-any.whl.
File metadata
- Download URL: rse_logging-0.1.6-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2152affdaabdbdb72318d5109d565e864ea2f6f52a23ddcd27a505ed1ac2795
|
|
| MD5 |
7c19fff185d44dd5eadeb10f822ff407
|
|
| BLAKE2b-256 |
a9a615fd500fba34843280f4da7e011a27d4664ea03a59f89bb54c431d243616
|