File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ def shutdown_otel_tracing() -> None:
108108
109109def instrument_fastapi (app ):
110110 """Instrument FastAPI app with OpenTelemetry"""
111- FastAPIInstrumentor .instrument_app (app )
111+ FastAPIInstrumentor .instrument_app (app , excluded_urls = "/health" )
112112
113113
114114def instrument_sqlalchemy (engine : AsyncEngine ) -> None :
Original file line number Diff line number Diff line change 11import asyncio
2+ import logging
23from contextlib import asynccontextmanager
34from typing import Optional , List
45from fastapi import FastAPI , Query , Path , Body
4041from acontext_core .schema .orm import Task
4142from sqlalchemy import select , func , cast , Integer
4243
44+
45+ # Filter to exclude /health endpoint from uvicorn access logs
46+ # Uses record.args directly instead of parsing formatted message for efficiency
47+ class _HealthCheckFilter (logging .Filter ):
48+ def filter (self , record : logging .LogRecord ) -> bool :
49+ """True if the record should be logged, False otherwise."""
50+ if not record .args :
51+ return True
52+ if len (record .args ) != 5 :
53+ return True
54+ endpoint : str = record .args [2 ]
55+ status_code : int = record .args [4 ]
56+ if not endpoint .startswith ("/health" ):
57+ return True
58+ if status_code != 200 :
59+ return True
60+ return False
61+
62+
63+ logging .getLogger ("uvicorn.access" ).addFilter (_HealthCheckFilter ())
64+
4365# Setup OpenTelemetry tracing before app creation
4466# This ensures tracer provider is set up before instrumentation
4567telemetry_config = TelemetryConfig .from_env ()
You can’t perform that action at this time.
0 commit comments