wooden-umbrella-84098
08/26/2026, 5:55 PMimport litellm
from arize.otel import register
from openinference.instrumentation.litellm import LiteLLMInstrumentor
def enable_tracing(project_name: str):
"""Send traces to an Arize project and capture every LiteLLM call.
Safe to call more than once — each call re-points instrumentation at the
new project.
"""
tracer_provider = register(
space_id=ARIZE_SPACE_ID,
api_key=ARIZE_API_KEY,
project_name=project_name,
set_global_tracer_provider=False,
)
# Release any previous instrumentation first, so repeat calls take effect.
instrumentor = LiteLLMInstrumentor()
if instrumentor.is_instrumented_by_opentelemetry:
instrumentor.uninstrument()
instrumentor.instrument(tracer_provider=tracer_provider)
# The SDK imports LiteLLM's functions by name at import time, so point those
# references at the newly instrumented versions.
from openhands.sdk.llm import llm as openhands_llm
for attribute, function in (
("litellm_completion", "completion"),
("litellm_acompletion", "acompletion"),
("litellm_responses", "responses"),
("litellm_aresponses", "aresponses"),
):
if hasattr(openhands_llm, attribute) and hasattr(litellm, function):
setattr(openhands_llm, attribute, getattr(litellm, function))
return tracer_provider
tracer_provider = enable_tracing(f"{PROJECT_NAME}-llm-only")
print(f"\nTracing to Arize project: {PROJECT_NAME}-llm-only")limited-student-10747
08/26/2026, 7:21 PMwooden-umbrella-84098
08/26/2026, 7:59 PMlimited-student-10747
08/26/2026, 8:13 PMmelodic-furniture-87909
08/26/2026, 10:08 PM