# openinference-instrumentation-agent-framework

**Python · Instrumentation**

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

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

[PyPI](https://pypi.org/project/openinference-instrumentation-agent-framework/) · [README](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/README.md) · [Source](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-agent-framework)

## Install

```sh
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**

```python
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`

_class_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/processor.py#L27-L141)

```python
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**

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

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

**Attributes**

| Name | Type and value |
| - | - |
| [`debug`](https://openinf.dev/python/openinference-instrumentation-agent-framework.html.md#openinference.instrumentation.agent_framework.AgentFrameworkToOpenInferenceProcessor.debug) | `debug` |

#### `on_start`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/processor.py#L62-L64)

```python
def on_start(span: ReadableSpan, parent_context: Any = None) -> None
```

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

#### `on_end`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/processor.py#L66-L108)

```python
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`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/processor.py#L110-L112)

```python
def shutdown() -> None
```

Shutdown the processor.

#### `force_flush`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/processor.py#L114-L116)

```python
def force_flush(timeout_millis: Optional[int] = None) -> bool
```

Force flush any pending data.

#### `get_processor_info`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/processor.py#L118-L141)

```python
def get_processor_info() -> Dict[str, Any]
```

Get information about this processor’s capabilities.

### `is_openinference_span`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/utils.py#L11-L15)

```python
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`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/utils.py#L18-L23)

```python
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`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/semantic_conventions.py#L75-L87)

```python
def safe_json_dumps(obj: Any) -> str
```

Safely serialize an object to JSON string.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `obj` | `Any` | Object to serialize |

**Returns**

| Type | Description |
| - | - |
| `str` | JSON string representation |

### `get_attributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-agent-framework/src/openinference/instrumentation/agent_framework/semantic_conventions.py#L90-L133)

```python
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**

| Name | Type | Description |
| - | - | - |
| `attrs` | `Dict[str, Any]` | Original span attributes with GenAI semantic conventions |
| `span_name` | `str` | The span name |
| `span_id` | `int` | The span context ID |

**Returns**

| Type | Description |
| - | - |
| `Iterator[Tuple[str, Any]]` | Iterator of (key, value) pairs for OpenInference attributes |
