Python APIagent-framework

Core

Instrumentation

Python · Instrumentation

openinference-instrumentation-agent-framework

OpenInference span processor for Microsoft Agent Framework - transforms native OpenTelemetry spans to OpenInference format

Module
openinference.instrumentation.agent_framework
Version
0.1.17
Python
>=3.10, <3.16
Instruments
agent-framework-core >= 1.0.0, agent-framework-openai >= 1.0.0

Install

pip install openinference-instrumentation-agent-framework

openinference.instrumentation.agent_framework

OpenInference instrumentation for Microsoft Agent Framework.

This package provides a SpanProcessor that transforms Microsoft Agent Framework’s native OpenTelemetry spans (using GenAI semantic conventions) to OpenInference format for compatibility with OpenInference-compliant backends like Arize Phoenix.

Usage

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from agent_framework.observability import configure_otel_providers
from openinference.instrumentation.agent_framework import (
    AgentFrameworkToOpenInferenceProcessor
)

# Configure MS Agent Framework's native telemetry
# Set OTEL_EXPORTER_OTLP_TRACES_ENDPOINT env var for Phoenix endpoint
configure_otel_providers(enable_sensitive_data=True)

# Add OpenInference processor to transform spans
tracer_provider = trace.get_tracer_provider()
if isinstance(tracer_provider, TracerProvider):
    tracer_provider.add_span_processor(
        AgentFrameworkToOpenInferenceProcessor()
    )

# Use framework normally - spans will be transformed automatically
from agent_framework.openai import OpenAIChatClient

client = OpenAIChatClient(model="gpt-4o-mini")
agent = client.as_agent(name="Assistant")
response = await agent.run("Hello!")

AgentFrameworkToOpenInferenceProcessor

classSource ↗
class AgentFrameworkToOpenInferenceProcessor(
    debug: bool = False,
    span_filter: Optional[SpanFilter] = None,
)

Also importable from openinference.instrumentation.agent_framework.processor.

SpanProcessor that converts Microsoft Agent Framework telemetry attributes to OpenInference format for compatibility with OpenInference-compliant backends.

This processor intercepts spans on completion and transforms their attributes from the GenAI semantic conventions used by Microsoft Agent Framework to the OpenInference semantic conventions.

Usage

from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation.agent_framework import (
    AgentFrameworkToOpenInferenceProcessor
)

provider = TracerProvider()
provider.add_span_processor(
    AgentFrameworkToOpenInferenceProcessor(debug=False)
)

Attributes

NameType and value
debugdebug

on_start

methodSource ↗
def on_start(span: ReadableSpan, parent_context: Any = None) -> None

Called when a span is started. No-op for this processor.

on_end

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

Called when a span ends. Transform the span attributes from Microsoft Agent Framework GenAI format to OpenInference format.

shutdown

methodSource ↗
def shutdown() -> None

Shutdown the processor.

force_flush

methodSource ↗
def force_flush(timeout_millis: Optional[int] = None) -> bool

Force flush any pending data.

get_processor_info

methodSource ↗
def get_processor_info() -> Dict[str, Any]

Get information about this processor’s capabilities.

is_openinference_span

functionSource ↗
def is_openinference_span(span: ReadableSpan) -> bool

Also importable from openinference.instrumentation.agent_framework.utils.

Check if a span is an OpenInference span.

openinference.instrumentation.agent_framework.utils

should_export_span

functionSource ↗
def should_export_span(
    span: ReadableSpan,
    span_filter: Optional[SpanFilter] = None,
) -> bool

Determine if a span should be exported based on a filter.

openinference.instrumentation.agent_framework.semantic_conventions

Semantic conventions for Microsoft Agent Framework telemetry.

This module defines attribute constants used by Microsoft Agent Framework’s OpenTelemetry instrumentation and provides transformation functions to convert GenAI attributes to OpenInference format.

Reference: agent_framework/observability.py OtelAttr enum

safe_json_dumps

functionSource ↗
def safe_json_dumps(obj: Any) -> str

Safely serialize an object to JSON string.

Parameters

NameTypeDescription
objAny

Object to serialize

Returns

TypeDescription
str

JSON string representation

get_attributes

functionSource ↗
def get_attributes(
    attrs: Dict[str, Any],
    span_name: str,
    span_id: int,
) -> Iterator[Tuple[str, Any]]

Extract OpenInference attributes from Microsoft Agent Framework GenAI attributes.

Parameters

NameTypeDescription
attrsDict[str, Any]

Original span attributes with GenAI semantic conventions

span_namestr

The span name

span_idint

The span context ID

Returns

TypeDescription
Iterator[Tuple[str, Any]]

Iterator of (key, value) pairs for OpenInference attributes