Skip to content

Commit 72c997c

Browse files
committed
chore(core): remove 200 health access log
1 parent 06dd35e commit 72c997c

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/server/core/acontext_core/telemetry/otel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def shutdown_otel_tracing() -> None:
108108

109109
def instrument_fastapi(app):
110110
"""Instrument FastAPI app with OpenTelemetry"""
111-
FastAPIInstrumentor.instrument_app(app)
111+
FastAPIInstrumentor.instrument_app(app, excluded_urls="/health")
112112

113113

114114
def instrument_sqlalchemy(engine: AsyncEngine) -> None:

src/server/core/api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import logging
23
from contextlib import asynccontextmanager
34
from typing import Optional, List
45
from fastapi import FastAPI, Query, Path, Body
@@ -40,6 +41,27 @@
4041
from acontext_core.schema.orm import Task
4142
from 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
4567
telemetry_config = TelemetryConfig.from_env()

0 commit comments

Comments
 (0)