---
title: Microsoft Agent Framework
description: Instrument Microsoft Agent Framework applications and send traces to OpenObserve via OpenTelemetry.
---

# **Microsoft Agent Framework → OpenObserve**

Capture agent run latency, input metadata, output size, and error details for every Microsoft Agent Framework invocation. Microsoft Agent Framework is a Python SDK for building multi-agent AI workflows with support for multiple LLM providers. Instrumentation wraps each `agent.run()` call in an OpenTelemetry span exported to OpenObserve.

## **Prerequisites**

* Python 3.10+
* An [OpenObserve](https://openobserve.ai/) account (cloud or self-hosted)
* Your OpenObserve **organisation ID** and **Base64-encoded auth token**
* An OpenAI API key

## **Installation**

```shell
pip install openobserve-telemetry-sdk agent-framework agent-framework-openai python-dotenv
```

## **Configuration**

Create a `.env` file in your project root:

```
OPENOBSERVE_URL=https://api.openobserve.ai/
OPENOBSERVE_ORG=your_org_id
OPENOBSERVE_AUTH_TOKEN=Basic <your_base64_token>
OPENAI_API_KEY=your-openai-api-key
```

## **Instrumentation**

Call `openobserve_init()` to set up the tracer provider, then wrap each `agent.run()` call in a manual span to capture input and output attributes.

```python
from dotenv import load_dotenv
load_dotenv()

from openobserve import openobserve_init
openobserve_init(resource_attributes={"service.name": "microsoft-agent-framework"})

from opentelemetry import trace
import asyncio
import os
from agent_framework import Agent
from agent_framework_openai import OpenAIChatClient

tracer = trace.get_tracer(__name__)

client = OpenAIChatClient(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4o-mini")
agent = Agent(client=client)

async def main():
    with tracer.start_as_current_span("agent_framework.run") as span:
        span.set_attribute("agent.input", "What is distributed tracing?")
        result = await agent.run("What is distributed tracing?")
        output = result.text if hasattr(result, "text") else str(result)
        span.set_attribute("agent.output_length", len(output))
        span.set_attribute("span_status", "OK")
    print(output)

asyncio.run(main())
```

## **What Gets Captured**

| Attribute | Example Value |
| ----- | ----- |
| `operation_name` | `agent_framework.run` |
| `agent_input` | `What is distributed tracing?` |
| `agent_output_length` | `2391` |
| `span_kind` | `Internal` |
| `span_status` | `OK` on success, `ERROR` on failure |
| `error_message` | Full error string on failed calls |
| `service_name` | `microsoft-agent-framework` |
| `duration` | End-to-end agent run latency in microseconds |

## **Viewing Traces**

1. Log in to OpenObserve and navigate to **Traces**
2. Filter by `service_name = microsoft-agent-framework` to see all agent runs
3. Click any span to inspect `agent_input`, `agent_output_length`, and `duration`
4. Filter by `span_status = ERROR` to find failed invocations and read `error_message`
5. Sort by `duration` descending to identify the slowest agent calls

![Microsoft Agent Framework traces in OpenObserve](../../../images/integration/ai/microsoft-agent-framework.png)

## **Next Steps**

With Microsoft Agent Framework instrumented, every agent run is recorded in OpenObserve. From here you can track latency per prompt type, monitor error rates, and set alerts when agent calls fail in production.

## **Read More**

- [LLM Observability Overview](../llm-applications.md)
- [Traces Ingestion with Python](../../../ingestion/traces/python.md)
- [Exploring Traces in OpenObserve](../../../user-guide/data-exploration/traces/index.md)
- [Building Dashboards](../../../user-guide/analytics/dashboards/index.md)
