Instrument with OpenInference helpers

As part of the OpenInference library, Arize AX provides helpful abstractions to make manual instrumentation easier.

OpenInference OTEL Tracing

OpenInference OTEL Tracing enables detailed observability of your LLM or agent workflows by automatically capturing inputs, outputs, and execution details as OpenTelemetry spans viewable in Arize AX.

It provides decorators and helper methods for instrumenting functions, chains, agents, and tools — simplifying setup and reducing the need for manual tracing code.

Installation

Ensure you have OpenInference and OpenTelemetry installed:

pip install openinference opentelemetry-api opentelemetry-sdk

Setting Up Tracing

You can configure tracing in two ways:

  • Option 1: Using TracerProvider (OpenInference)

  • Option 2: Using arize.otel.register

You can configure the tracer using either TracerProvider from openinference.instrumentation or using arize.otel.register.

import opentelemetry
from arize.otel import register

# Setup OTel via our convenience function
tracer_provider = register(
    space_id = "your-space-id", # in app space settings page
    api_key = "your-api-key", # in app space settings page
    project_name = "your-project-name", # name this to whatever you would like
)

tracer = tracer_provider.get_tracer(__name__)

Using your Tracer

Your tracer object can be used in two ways:

As a Decorator (trace an entire function)

@tracer.chain
def my_func(input: str) -> str:
    return "output"

This function appears as a Span in Arize AX. Input, output, and status attributes are set automatically, based on my_func's parameters and return.

As a Context Manager (trace a specific block)

with tracer.start_as_current_span(
    "my-span-name",
    openinference_span_kind="chain",
) as span:
    span.set_input("input")
    span.set_output("output")
    span.set_status(Status(StatusCode.OK))

Use this when you need only a portion of a method to be captured as a Span. Here the input, output, and status must be set manually.


Spans

For more information about all the different spans kinds you can trace & how to, you can check out our complete guide for spans.


Additional Tracing Features

These utilities help you control or enrich your tracing:

  • Suppress tracing to skip certain spans (useful for non-critical or noisy code).

  • Context attributes to add metadata (like session_id or user_id) to all spans in a block — making your traces searchable and contextual in Arize AX.

Use these to keep your traces clean and meaningful while maintaining full observability of your application.

Suppress Tracing

with suppress_tracing():
    with tracer.start_as_current_span(
        "THIS-SPAN-SHOULD-NOT-BE-TRACED",
        openinference_span_kind="chain",
    ) as span:
        span.set_input("input")
        span.set_output("output")
        span.set_status(Status(StatusCode.OK))

Using Context Attributes

with using_attributes(session_id="123"):
    with tracer.start_as_current_span(
        "chain-span-with-context-attributes",
        openinference_span_kind="chain",
    ) as span:
        span.set_input("input")
        span.set_output("output")
        span.set_status(Status(StatusCode.OK))

OpenInference OTEL Tracing makes it easy to instrument your LLM or agent workflows, visualize performance, and debug behavior directly inside Arize AX.

For advanced configuration and supported frameworks, see the OpenInference Repo.

Last updated

Was this helpful?