All checks were successful
Run linters on applied template / Python 3.13 lint and build (push) Successful in 1m40s
Changes: - put ObservabilityMiddleware before ExceptionHandlerMiddleware to avoid repetative code - add application startup and last metrics update metrics along with CPU usage metric and threads count - move host and port to new uvicorn section at config along with new reload and forwarded_allow_ips - add request_id and remove trace_id/span_id generation if tracing is disabled - move logging logic from utils to observability - pass trace_id/span_id in HEX form
50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
"""Observability config is defined here."""
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Literal
|
|
|
|
LoggingLevel = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
|
|
|
|
@dataclass
|
|
class ExporterConfig:
|
|
endpoint: str
|
|
level: LoggingLevel = "INFO"
|
|
tls_insecure: bool = False
|
|
|
|
|
|
@dataclass
|
|
class FileLogger:
|
|
filename: str
|
|
level: LoggingLevel
|
|
|
|
|
|
@dataclass
|
|
class LoggingConfig:
|
|
root_logger_level: LoggingLevel = "INFO"
|
|
stderr_level: LoggingLevel | None = None
|
|
exporter: ExporterConfig | None = None
|
|
files: list[FileLogger] = field(default_factory=list)
|
|
|
|
def __post_init__(self):
|
|
if len(self.files) > 0 and isinstance(self.files[0], dict):
|
|
self.files = [FileLogger(**f) for f in self.files]
|
|
|
|
|
|
@dataclass
|
|
class PrometheusConfig:
|
|
host: str
|
|
port: int
|
|
|
|
|
|
@dataclass
|
|
class JaegerConfig:
|
|
endpoint: str
|
|
|
|
|
|
@dataclass
|
|
class ObservabilityConfig:
|
|
logging: LoggingConfig
|
|
prometheus: PrometheusConfig | None = None
|
|
jaeger: JaegerConfig | None = None
|