|
1 | 1 | """OpenTelemetry setup for a Microsoft Agent Framework Agent App.""" |
2 | 2 |
|
3 | | -import logging |
4 | | - |
5 | | -from agent_framework.observability import configure_otel_providers |
6 | | -from agenticlayer.shared.otel import request_hook, response_hook |
7 | | -from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor |
| 3 | +from agent_framework.observability import enable_instrumentation |
| 4 | +from agenticlayer.shared.otel import setup_otel as _setup_otel_shared |
8 | 5 |
|
9 | 6 | __all__ = ["setup_otel"] |
10 | 7 |
|
11 | | -_logger = logging.getLogger(__name__) |
12 | | - |
13 | 8 |
|
14 | 9 | def setup_otel() -> None: |
15 | 10 | """Set up OpenTelemetry tracing, logging and metrics for a Microsoft Agent Framework agent. |
16 | 11 |
|
17 | | - Uses the built-in ``agent_framework`` OTLP provider setup (reads standard |
18 | | - ``OTEL_EXPORTER_OTLP_*`` environment variables) and enables the telemetry |
| 12 | + Calls the shared OTLP provider/exporter setup (traces, logs, metrics, HTTPX |
| 13 | + instrumentation) and then enables the built-in ``agent_framework`` telemetry |
19 | 14 | layers that emit ``gen_ai.client.token.usage`` and |
20 | 15 | ``gen_ai.client.operation.duration`` metrics. |
21 | 16 |
|
22 | | - Additionally instruments HTTPX clients so outgoing HTTP calls (to |
23 | | - sub-agents, MCP servers, LLM gateways) are traced with debug-level |
24 | | - request/response body logging. |
25 | | -
|
26 | 17 | Starlette server instrumentation is handled separately by |
27 | 18 | :func:`agenticlayer.shared.otel_starlette.instrument_starlette_app`. |
28 | 19 | """ |
29 | | - # Set log level for urllib to WARNING to reduce noise |
30 | | - logging.getLogger("urllib3").setLevel(logging.WARNING) |
31 | | - |
32 | | - configure_otel_providers() |
33 | | - |
34 | | - HTTPXClientInstrumentor().instrument( |
35 | | - request_hook=request_hook, |
36 | | - response_hook=response_hook, |
37 | | - ) |
| 20 | + _setup_otel_shared() |
| 21 | + enable_instrumentation() |
0 commit comments