Skip to content

datarobot_genai.llama_index.telemetry

telemetry

Idempotent LlamaIndex auto-instrumentation for agent telemetry.

opentelemetry-instrumentation-llamaindex spans every workflow step (AgentWorkflow is itself a Workflow) but never attaches an agent identity to them - :class:_AgentNameSpanHandler fills that gap by reacting to the same span-enter notifications LlamaIndex's own instrumentation uses, without needing to re-implement span creation.

instrument

instrument() -> None

Idempotently enable the LlamaIndex OpenTelemetry instrumentor.

Source code in datarobot_genai/llama_index/telemetry.py
def instrument() -> None:
    """Idempotently enable the LlamaIndex OpenTelemetry instrumentor."""
    if _INSTRUMENTED["llamaindex"]:
        logger.info("LlamaIndex instrumentation already enabled")
        return
    try:
        LlamaIndexInstrumentor().instrument()
        get_dispatcher().add_span_handler(_AgentNameSpanHandler())
        _INSTRUMENTED["llamaindex"] = True
    except Exception as e:
        logger.info(f"LlamaIndex instrumentation failed: {e}")