feat(proxy): enable agent tracing from general_settings.tracing

This commit is contained in:
Ishaan Jaff 2026-09-30 00:40:10 -07:00
parent bdc634a2d2
commit 29b6723b01
No known key found for this signature in database

View file

@ -713,6 +713,7 @@ try:
except ImportError:
build_billing_metrics_recorder = None
shutdown_billing_metrics_recorder = None
from litellm.proxy import tracing_endpoints
from litellm.proxy.middleware.admission_control_middleware import (
AdmissionControlMiddleware,
admission_control_state,
@ -844,6 +845,7 @@ from litellm.secret_managers.main import (
secret_manager_would_be_consulted,
str_to_bool,
)
from litellm.tracing import TraceReceiver
from litellm.types.integrations.slack_alerting import AlertType, SlackAlertingArgs
from litellm.types.llms.anthropic import (
AnthropicMessagesRequest,
@ -1124,6 +1126,9 @@ async def proxy_shutdown_event(worker_heartbeat: ProxyWorkerHeartbeat | None = N
await jwt_handler.close()
if tracing_endpoints.receiver is not None:
await tracing_endpoints.receiver.flush()
if db_writer_client is not None:
await db_writer_client.close()
@ -1520,6 +1525,9 @@ async def proxy_startup_event(app: FastAPI) -> AsyncGenerator[None, None]:
_tagged.strategy._state_loaded = True
asyncio.create_task(_adaptive_router_flusher_loop())
## [Optional] Initialize agent tracing
await ProxyStartupEvent._init_tracing(general_settings)
## [Optional] Initialize dd tracer
ProxyStartupEvent._init_dd_tracer()
@ -11309,6 +11317,23 @@ class ProxyStartupEvent:
)
return connected_client
@classmethod
async def _init_tracing(cls, general_settings: dict) -> None:
"""
Enable agent tracing (`POST/GET /v1/traces`) when configured:
general_settings:
tracing:
store: clickhouse # CLICKHOUSE_URL / _USER / _PASSWORD / _DATABASE
"""
settings = general_settings.get("tracing") or {}
if settings.get("store") != "clickhouse":
return
tracing = TraceReceiver.from_env()
await tracing.start()
tracing_endpoints.receiver = tracing
verbose_proxy_logger.info("Agent tracing enabled (store=clickhouse)")
@classmethod
def _init_dd_tracer(cls):
"""
@ -19860,6 +19885,7 @@ app.include_router(rag_router)
app.include_router(video_router)
app.include_router(container_router)
app.include_router(search_router)
app.include_router(tracing_endpoints.router)
app.include_router(image_router)
app.include_router(fine_tuning_router)
app.include_router(credential_router)