Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agentex/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies = [
"opentelemetry-api>=1.28.0",
"opentelemetry-sdk>=1.28.0",
"opentelemetry-exporter-otlp>=1.28.0",
"opentelemetry-instrumentation-fastapi>=0.49b0",
"pyyaml>=6.0,<7",
]

Expand Down
8 changes: 4 additions & 4 deletions agentex/src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from src.config.environment_variables import EnvVarKeys
from src.domain.exceptions import GenericException
from src.utils.logging import make_logger
from src.utils.otel_metrics import init_otel_metrics, shutdown_otel_metrics
from src.utils.otel_metrics import configure_app_metrics, shutdown_otel_metrics

logger = make_logger(__name__)

Expand Down Expand Up @@ -73,9 +73,6 @@ def __init__(

@asynccontextmanager
async def lifespan(_: FastAPI):
# Initialize OpenTelemetry metrics first (before dependencies register instruments)
init_otel_metrics()

await dependencies.startup_global_dependencies()
configure_statsd()

Expand Down Expand Up @@ -190,6 +187,9 @@ async def handle_unexpected(request, exc):
fastapi_app.include_router(checkpoints.router)
fastapi_app.include_router(task_retention.router)

# Instrument before the first ASGI message; lifespan startup is too late.
configure_app_metrics(fastapi_app)

# Wrap FastAPI app with health check interceptor for sub-millisecond K8s probe responses.
# This must be the outermost layer to bypass all middleware.
# Export as `app` so existing uvicorn entry points (app:app) work without changes.
Expand Down
Loading