Python APIagentspec

Core

Instrumentation

Python · Instrumentation

openinference-instrumentation-agentspec

OpenInference Open Agent Spec Instrumentation

Module
openinference.instrumentation.agentspec
Version
0.1.22
Python
>=3.10, <3.15
Instruments
opentelemetry-sdk, pyagentspec >= 26.1.0

Install

pip install openinference-instrumentation-agentspec

Usage

Instrument once, at startup, before the library is used. The AgentSpecInstrumentor reference below lists the options.

from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation.agentspec import AgentSpecInstrumentor

tracer_provider = TracerProvider()
# ...add a span processor that exports to Phoenix or any OTLP backend.

AgentSpecInstrumentor().instrument(tracer_provider=tracer_provider)

openinference.instrumentation.agentspec

AgentSpecInstrumentor

classSource ↗
class AgentSpecInstrumentor(BaseInstrumentor)

An instrumentor for Agent Spec Tracing

instrument

method
def instrument(
    *,
    tracer_provider: Optional[TracerProvider] = None,
    skip_dep_check: bool = False,
) -> None

Start tracing opentelemetry-sdk, pyagentspec: patch it so its calls make OpenInference spans. Calling it again does nothing. Inherited from OpenTelemetry’s BaseInstrumentor.

Parameters

NameDescription
tracer_provider

The tracer provider the spans are made with. Defaults to the global one, opentelemetry.trace.get_tracer_provider().

skip_dep_check

Instrument even if the installed version of opentelemetry-sdk, pyagentspec is outside the supported range.

uninstrument

method
def uninstrument() -> None

Stop tracing: undo the patches instrument() made. Inherited from OpenTelemetry’s BaseInstrumentor.

instrumentation_dependencies

methodSource ↗
def instrumentation_dependencies() -> Collection[str]

instrument_context

methodSource ↗
def instrument_context(**kwargs: Any = {}) -> Generator[None, Any, None]

Context manager to instrument and uninstrument the library

OpenInferenceSpanProcessor

classSource ↗
class OpenInferenceSpanProcessor(
    resource: Optional[OtelSdkResource] = None,
    otel_span_processor: Optional[OtelSdkSpanProcessor] = None,
    span_exporter: Optional[OtelSdkSpanExporter] = None,
    use_batch_span_processor: bool = True,
    mask_sensitive_information: bool = True,
)

Attributes

NameType and value
span_exporterspan_exporter
resourceresource
span_model_dump_funcspan_model_dump_func
span_processorotel_span_processor
use_batch_span_processoruse_batch_span_processor

on_start

methodSource ↗
def on_start(span: AgentSpecSpan) -> None

Method called at the start of a Span.

Parameters span: The AgentSpec span that is starting

on_end

methodSource ↗
def on_end(span: AgentSpecSpan) -> None

Method called at the end of a Span.

Parameters span: The AgentSpec span that is ending

on_event

methodSource ↗
def on_event(event: AgentSpecEvent, span: AgentSpecSpan) -> None

startup

methodSource ↗
def startup() -> None

shutdown

methodSource ↗
def shutdown() -> None

on_start_async

methodSource ↗
async def on_start_async(span: AgentSpecSpan) -> None

on_end_async

methodSource ↗
async def on_end_async(span: AgentSpecSpan) -> None

on_event_async

methodSource ↗
async def on_event_async(
    event: AgentSpecEvent,
    span: AgentSpecSpan,
) -> None

startup_async

methodSource ↗
async def startup_async() -> None

shutdown_async

methodSource ↗
async def shutdown_async() -> None

force_flush

methodSource ↗
def force_flush(timeout_millis: int = 30000) -> bool

Export all ended spans to the configured Exporter that have not yet been exported.

Forwards the call to the internal OpenTelemetry span processor.