Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Protectai Llm guard Configure otel

From Leeroopedia
Knowledge Sources
Domains Observability, DevOps, Monitoring
Last Updated 2026-02-14 12:00 GMT

Overview

Concrete tool for configuring OpenTelemetry tracing and metrics providers for the LLM Guard API server.

Description

The configure_otel function sets up global OpenTelemetry TracerProvider and MeterProvider with the appropriate exporters based on configuration. The instrument_app function attaches FastAPI automatic instrumentation. Supports OTLP HTTP, Prometheus, console, and AWS X-Ray exporters.

Usage

Called internally by create_app during server initialization. Not typically imported by end users.

Code Reference

Source Location

  • Repository: llm-guard
  • File: llm_guard_api/app/otel.py
  • Lines: L65-85

Signature

def configure_otel(
    app_name: str,
    tracing_config: TracingConfig,
    metrics_config: MetricsConfig,
) -> None:
    """Configure global OpenTelemetry tracing and metrics providers."""

def instrument_app(app: FastAPI) -> None:
    """Attach FastAPI automatic instrumentation, excluding health/metrics endpoints."""

Import

from llm_guard_api.app.otel import configure_otel, instrument_app

I/O Contract

Inputs

Name Type Required Description
app_name str Yes Service name for OTel resource
tracing_config TracingConfig Yes Tracing exporter config (otel_http, console, xray)
metrics_config MetricsConfig Yes Metrics exporter config (otel_http, prometheus, console)
app FastAPI Yes (instrument_app) FastAPI app to instrument

Outputs

Name Type Description
(side effect) None Global TracerProvider and MeterProvider configured
(side effect) None FastAPI app instrumented with automatic span creation

Usage Examples

YAML Configuration

tracing:
  exporter: otel_http
  endpoint: "http://collector:4318/v1/traces"

metrics:
  exporter: prometheus

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment