feat: add the FastApiInstrumentator to the API
This commit is contained in:
parent
8b0989a566
commit
40af152a2a
1 changed files with 3 additions and 6 deletions
|
|
@ -14,16 +14,14 @@ from opentelemetry.sdk.trace.export import (
|
|||
)
|
||||
from prometheus_client import start_http_server
|
||||
|
||||
|
||||
_observability_initialized = False
|
||||
|
||||
|
||||
def setup_observability(app: FastAPI) -> None:
|
||||
global _observability_initialized
|
||||
if _observability_initialized:
|
||||
return
|
||||
|
||||
|
||||
|
||||
service_name = os.getenv("OTEL_SERVICE_NAME", "language-learning-api")
|
||||
metrics_host = os.getenv("OTEL_EXPORTER_PROMETHEUS_HOST", "0.0.0.0")
|
||||
metrics_port = int(os.getenv("OTEL_EXPORTER_PROMETHEUS_PORT", "9464"))
|
||||
|
|
@ -40,10 +38,9 @@ def setup_observability(app: FastAPI) -> None:
|
|||
metrics.set_meter_provider(meter_provider)
|
||||
|
||||
LoggingInstrumentor().instrument(set_logging_format=True)
|
||||
FastAPIInstrumentor.instrument_app(app)
|
||||
|
||||
# Expose OTel metrics for Prometheus scraping on the standard endpoint.
|
||||
start_http_server(port=metrics_port, addr=metrics_host)
|
||||
|
||||
|
||||
|
||||
_observability_initialized = True
|
||||
_observability_initialized = True
|
||||
|
|
|
|||
Loading…
Reference in a new issue