Instrument: Python
As part of the OpenInference library, Phoenix provides helpful abstractions to make manual instrumentation easier.
OpenInference OTEL Tracing
This documentation provides a guide on using OpenInference OTEL tracing decorators and methods for instrumenting functions, chains, agents, and tools using OpenTelemetry.
These tools can be combined with, or used in place of, OpenTelemetry instrumentation code. They are designed to simplify the instrumentation process.
If you'd prefer to use pure OTEL instead, see Instrument: Python using Base OTEL
Installation
Ensure you have OpenInference and OpenTelemetry installed:
Setting Up Tracing
You can configure the tracer using either TracerProvider
from openinference.instrumentation
or using phoenix.otel.register
.
Using TracerProvider
TracerProvider
Using phoenix.otel.register
phoenix.otel.register
Using your Tracer
Your tracer object can now be used in two primary ways:
1. As a decorator to trace entire functions
This entire function will appear as a Span in Phoenix. Input and output attributes in Phoenix will be set automatically based on my_func
's parameters and return. The status attribute will also be set automatically.
2. As a with clause to trace specific code blocks
The code within this clause will be captured as a Span in Phoenix. Here the input, output, and status must be set manually.
This approach is useful when you need only a portion of a method to be captured as a Span.
OpenInference Span Kinds
OpenInference Span Kinds denote the possible types of spans you might capture, and will be rendered different in the Phoenix UI.
The possible values are:
CHAIN
General logic operations, functions, or code blocks
LLM
Making LLM calls
TOOL
Completing tool calls
RETRIEVER
Retrieving documents
EMBEDDING
Generating embeddings
AGENT
Agent invokations - typically a top level or near top level span
RERANKER
Reranking retrieved context
UNKNOWN
Unknown
GUARDRAIL
Guardrail checks
EVALUATOR
Evaluators - typically only use by Phoenix when automatically tracing evaluation and experiment calls
Chains
Using Context Managers
Using Decorators
Using JSON Output
Overriding Span Name
Agents
Using Context Managers
Using Decorators
Tools
Using Context Managers
Using Decorators
Overriding Tool Name
Additional Features
Suppress Tracing
Using Context Attributes
This documentation provides an overview of how to use OpenInference OTEL tracing decorators with chains, agents, and tools. For more details, refer to the OpenInference official documentation.
Last updated
Was this helpful?