Add role-based filtering and imporve code

This commit is contained in:
Urtzi Alfaro
2025-10-15 16:12:49 +02:00
parent 96ad5c6692
commit 8f9e9a7edc
158 changed files with 11033 additions and 1544 deletions

View File

@@ -23,6 +23,7 @@ from fastapi.routing import APIRouter
from shared.monitoring import setup_logging
from shared.monitoring.metrics import setup_metrics_early
from shared.monitoring.health_checks import setup_fastapi_health_checks
from shared.monitoring.tracing import setup_tracing
from shared.database.base import DatabaseManager
if TYPE_CHECKING:
@@ -51,6 +52,7 @@ class BaseFastAPIService:
enable_cors: bool = True,
enable_exception_handlers: bool = True,
enable_messaging: bool = False,
enable_tracing: bool = True,
custom_metrics: Optional[Dict[str, Dict[str, Any]]] = None,
alert_service_class: Optional[type] = None
):
@@ -69,6 +71,7 @@ class BaseFastAPIService:
self.enable_cors = enable_cors
self.enable_exception_handlers = enable_exception_handlers
self.enable_messaging = enable_messaging
self.enable_tracing = enable_tracing
self.custom_metrics = custom_metrics or {}
self.alert_service_class = alert_service_class
@@ -106,6 +109,18 @@ class BaseFastAPIService:
if self.enable_metrics:
self.metrics_collector = setup_metrics_early(self.app, self.service_name)
# Setup distributed tracing
if self.enable_tracing:
try:
jaeger_endpoint = os.getenv(
"JAEGER_COLLECTOR_ENDPOINT",
"http://jaeger-collector.monitoring:4317"
)
setup_tracing(self.app, self.service_name, self.version, jaeger_endpoint)
self.logger.info(f"Distributed tracing enabled for {self.service_name}")
except Exception as e:
self.logger.warning(f"Failed to setup tracing, continuing without it: {e}")
# Setup lifespan
self.app.router.lifespan_context = self._create_lifespan()