Initial commit
Some checks failed
CI/CD Pipeline / Code Quality & Linting (push) Has been cancelled
CI/CD Pipeline / Policy Validation (push) Has been cancelled
CI/CD Pipeline / Test Suite (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-coverage) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-extract) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-firm-connectors) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-forms) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-hmrc) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-ingestion) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-kg) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-normalize-map) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-ocr) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-rag-indexer) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-rag-retriever) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-reason) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-rpa) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (ui-review) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-coverage) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-extract) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-kg) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-rag-retriever) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (ui-review) (push) Has been cancelled
CI/CD Pipeline / Generate SBOM (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Notifications (push) Has been cancelled
Some checks failed
CI/CD Pipeline / Code Quality & Linting (push) Has been cancelled
CI/CD Pipeline / Policy Validation (push) Has been cancelled
CI/CD Pipeline / Test Suite (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-coverage) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-extract) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-firm-connectors) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-forms) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-hmrc) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-ingestion) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-kg) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-normalize-map) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-ocr) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-rag-indexer) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-rag-retriever) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-reason) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (svc-rpa) (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (ui-review) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-coverage) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-extract) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-kg) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (svc-rag-retriever) (push) Has been cancelled
CI/CD Pipeline / Security Scanning (ui-review) (push) Has been cancelled
CI/CD Pipeline / Generate SBOM (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Notifications (push) Has been cancelled
This commit is contained in:
64
libs/observability/setup.py
Normal file
64
libs/observability/setup.py
Normal file
@@ -0,0 +1,64 @@
|
||||
"""Complete observability setup orchestration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .logging import configure_logging
|
||||
from .opentelemetry_setup import init_opentelemetry
|
||||
from .prometheus import get_business_metrics, init_prometheus_metrics
|
||||
|
||||
|
||||
def setup_observability(
|
||||
settings_or_app: Any,
|
||||
service_name: str | None = None,
|
||||
service_version: str = "1.0.0",
|
||||
log_level: str = "INFO",
|
||||
otlp_endpoint: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Setup complete observability stack for a service"""
|
||||
|
||||
# Handle both settings object and individual parameters
|
||||
if hasattr(settings_or_app, "service_name"):
|
||||
# Called with settings object
|
||||
settings = settings_or_app
|
||||
service_name = settings.service_name
|
||||
service_version = getattr(settings, "service_version", "1.0.0")
|
||||
log_level = getattr(settings, "log_level", "INFO")
|
||||
otlp_endpoint = getattr(settings, "otel_exporter_endpoint", None)
|
||||
app = None
|
||||
else:
|
||||
# Called with app object
|
||||
app = settings_or_app
|
||||
if not service_name:
|
||||
raise ValueError("service_name is required when passing app object")
|
||||
|
||||
# Configure logging
|
||||
configure_logging(service_name or "unknown", log_level)
|
||||
|
||||
# Initialize OpenTelemetry
|
||||
tracer, meter = init_opentelemetry(
|
||||
service_name or "unknown", service_version, otlp_endpoint
|
||||
)
|
||||
|
||||
# Get business metrics
|
||||
business_metrics = get_business_metrics(service_name or "unknown")
|
||||
|
||||
# If app is provided, set up Prometheus and add to app state
|
||||
if app:
|
||||
# Initialize Prometheus metrics
|
||||
instrumentator = init_prometheus_metrics(app, service_name or "unknown")
|
||||
|
||||
# Add to app state
|
||||
app.state.tracer = tracer
|
||||
app.state.meter = meter
|
||||
app.state.metrics = business_metrics
|
||||
app.state.instrumentator = instrumentator
|
||||
|
||||
return {
|
||||
"tracer": tracer,
|
||||
"meter": meter,
|
||||
"metrics": business_metrics,
|
||||
"instrumentator": instrumentator,
|
||||
}
|
||||
|
||||
# Just return the observability components
|
||||
return {"tracer": tracer, "meter": meter, "metrics": business_metrics}
|
||||
Reference in New Issue
Block a user