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-agentspecUsage
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
methoddef instrument(
*,
tracer_provider: Optional[TracerProvider] = None,
skip_dep_check: bool = False,
) -> NoneStart tracing opentelemetry-sdk, pyagentspec: patch it so its calls make OpenInference spans. Calling it again does nothing. Inherited from OpenTelemetry’s BaseInstrumentor.
Parameters
| Name | Description |
|---|---|
tracer_provider | The tracer provider the spans are made with. Defaults to the global one, |
skip_dep_check | Instrument even if the installed version of |
uninstrument
methoddef uninstrument() -> NoneStop 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
| Name | Type and value |
|---|---|
span_exporter | span_exporter |
resource | resource |
span_model_dump_func | span_model_dump_func |
span_processor | otel_span_processor |
use_batch_span_processor | use_batch_span_processor |
on_start
methodSource ↗def on_start(span: AgentSpecSpan) -> NoneMethod called at the start of a Span.
Parameters span: The AgentSpec span that is starting
on_end
methodSource ↗def on_end(span: AgentSpecSpan) -> NoneMethod 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) -> Nonestartup
methodSource ↗def startup() -> Noneshutdown
methodSource ↗def shutdown() -> Noneon_start_async
methodSource ↗async def on_start_async(span: AgentSpecSpan) -> Noneon_end_async
methodSource ↗async def on_end_async(span: AgentSpecSpan) -> Noneon_event_async
methodSource ↗async def on_event_async(
event: AgentSpecEvent,
span: AgentSpecSpan,
) -> Nonestartup_async
methodSource ↗async def startup_async() -> Noneshutdown_async
methodSource ↗async def shutdown_async() -> Noneforce_flush
methodSource ↗def force_flush(timeout_millis: int = 30000) -> boolExport all ended spans to the configured Exporter that have not yet been exported.
Forwards the call to the internal OpenTelemetry span processor.