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-sdkSetting 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__)from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from openinference.instrumentation import TracerProvider
from openinference.semconv.resource import ResourceAttributes
endpoint = "https://otlp.arize.com/v1"
resource = Resource(attributes={ResourceAttributes.PROJECT_NAME: "openinference-tracer"})
tracer_provider = TracerProvider(resource=resource)
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
tracer = tracer_provider.get_tracer(__name__)Using your Tracer
Your tracer object can be used in two ways:
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_idoruser_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?

