working with Arize on a workshop today. This is ho...
# proj-agent
w
working with Arize on a workshop today. This is how they injected their tracing into OpenHands SDK Seems like we could make this easier
Copy code
import 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")
l
Do they support OTEL? If so then we can just point openhands at their OTEL provider with an env var
w
ah interesting, yeah they are definitely OTEL compatible
l
Probably this page works, although I’m not 100% sure: laminar.sh/docs/tracing/otel#…
m
Yeah, we export to any OTEL-compatible backend. I can try and export to Arize later, check all the format compatibility, and report back later. Happy to make required changes too. Please keep me in the loop if there are any updates or requirements from the Arize side