MCPcopy Index your code
hub / github.com/google/adk-python / install_telemetry

Function install_telemetry

tests/unittests/telemetry/functional_test_helpers.py:280–322  ·  view source on GitHub ↗

Installs in-memory tracer + log exporter and patches ADK's globals. Spans and logs emitted by ADK during the test are written into the provided exporters. Both exporters MUST be passed in so each test makes the choice of exporter explicit (e.g. ``InMemoryLogRecordExporter`` vs ``WebUILogExp

(
    monkeypatch: pytest.MonkeyPatch,
    span_exporter: InMemorySpanExporter,
    log_exporter: InMemoryLogRecordExporter,
)

Source from the content-addressed store, hash-verified

278
279
280def install_telemetry(
281 monkeypatch: pytest.MonkeyPatch,
282 span_exporter: InMemorySpanExporter,
283 log_exporter: InMemoryLogRecordExporter,
284) -> None:
285 """Installs in-memory tracer + log exporter and patches ADK's globals.
286
287 Spans and logs emitted by ADK during the test are written into the
288 provided exporters. Both exporters MUST be passed in so each test makes
289 the choice of exporter explicit (e.g. ``InMemoryLogRecordExporter`` vs
290 ``WebUILogExporter``).
291 """
292 tracer_provider = TracerProvider()
293 tracer_provider.add_span_processor(SimpleSpanProcessor(span_exporter))
294 real_tracer = tracer_provider.get_tracer(__name__)
295
296 monkeypatch.setattr(
297 tracing.tracer,
298 "start_as_current_span",
299 real_tracer.start_as_current_span,
300 )
301 monkeypatch.setattr(
302 tracing.tracer,
303 "start_span",
304 real_tracer.start_span,
305 )
306 monkeypatch.setattr(
307 node_tracing.tracer,
308 "start_as_current_span",
309 real_tracer.start_as_current_span,
310 )
311 monkeypatch.setattr(
312 node_tracing.tracer,
313 "start_span",
314 real_tracer.start_span,
315 )
316
317 logger_provider = LoggerProvider()
318 logger_provider.add_log_record_processor(
319 SimpleLogRecordProcessor(log_exporter)
320 )
321 real_logger = logger_provider.get_logger(__name__)
322 monkeypatch.setattr(tracing.otel_logger, "emit", real_logger.emit)
323
324
325# ---------------------------------------------------------------------------

Calls

no outgoing calls

Tested by

no test coverage detected