Observability for Microsoft Agent Framework (Python) with Opik

Microsoft Agent Framework is a comprehensive multi-language framework for building, orchestrating, and deploying AI agents and multi-agent workflows with support for both Python and .NET implementations.

The framework provides everything from simple chat agents to complex multi-agent workflows with graph-based orchestration, built-in OpenTelemetry integration for distributed tracing and monitoring, and a flexible middleware system for request/response processing.

Account Setup

Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.

You can also run the Opik platform locally, see the installation guide for more information.

Microsoft Agent Framework tracing

Getting started

To use the Microsoft Agent Framework integration with Opik, you will need to have the Agent Framework and the required OpenTelemetry packages installed:

$pip install --pre agent-framework opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp

In addition, you will need to set the following environment variables to configure OpenTelemetry to send data to Opik:

If you are using Opik Cloud, you will need to set the following environment variables:

$export OTEL_EXPORTER_OTLP_ENDPOINT=https://www.comet.com/opik/api/v1/private/otel
>export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default'

To log the traces to a specific project, you can add the projectName parameter to the OTEL_EXPORTER_OTLP_HEADERS environment variable:

$export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default,projectName=<your-project-name>'

You can also update the Comet-Workspace parameter to a different value if you would like to log the data to a different workspace.

Using Opik with Microsoft Agent Framework

The Microsoft Agent Framework has built-in OpenTelemetry instrumentation. Once you’ve configured the environment variables above, you can start creating agents and their traces will automatically be sent to Opik:

1import asyncio
2import os
3
4os.environ["ENABLE_OTEL"] = "True"
5os.environ["ENABLE_SENSITIVE_DATA"] = "True"
6
7from agent_framework.openai import OpenAIChatClient
8from opentelemetry import trace
9from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
10from opentelemetry.sdk.resources import Resource
11from opentelemetry.sdk.trace import TracerProvider
12from opentelemetry.sdk.trace.export import BatchSpanProcessor
13
14
15def setup_telemetry():
16 """Configure OpenTelemetry with HTTP exporter"""
17 # Create a resource with service name and other metadata
18 resource = Resource.create(
19 {
20 "service.name": "agent-framework-demo",
21 "service.version": "1.0.0",
22 "deployment.environment": "development",
23 }
24 )
25
26 # Create TracerProvider with the resource
27 provider = TracerProvider(resource=resource)
28
29 # Create BatchSpanProcessor with OTLPSpanExporter
30 processor = BatchSpanProcessor(OTLPSpanExporter())
31 provider.add_span_processor(processor)
32
33 # Set the TracerProvider
34 trace.set_tracer_provider(provider)
35
36 tracer = trace.get_tracer(__name__)
37
38 return tracer, provider
39
40
41setup_telemetry()
42
43
44async def main():
45 # Initialize a chat agent with Azure OpenAI Responses
46 agent = OpenAIChatClient(model_id="gpt-4.1").create_agent(
47 name="HaikuBot",
48 instructions="You are an upbeat assistant that writes beautifully.",
49 )
50
51 # This will automatically create a trace in Opik
52 result = await agent.run("Write a haiku about Microsoft Agent Framework.")
53 print(result)
54
55
56asyncio.run(main())

The framework will automatically:

  • Create traces for agent executions
  • Log input prompts and outputs
  • Track token usage and performance metrics
  • Capture any errors or exceptions

Further improvements

If you would like to see us improve this integration, simply open a new feature request on Github.