Try it free

Get started with Microsoft Agent Framework and AI Observability

  • Latest Dynatrace
  • How-to guide
  • 4-min read
  • Published Jun 17, 2026

The Microsoft Agent Framework provides built-in OpenTelemetry (OTel) support for AI agents. No additional instrumentation SDK is required. When your agent runs, the framework automatically emits traces and metrics following the GenAI semantic conventions, which AI Observability AI Observability natively understands.

This guide shows you how to run a sample agent that calls Azure OpenAI and exports traces and metrics directly to Dynatrace via OTLP HTTP.

Who is this for?

This getting started guide is for:

  • AI engineering teams building agent- and LLM-powered applications using the Microsoft Agent Framework.
  • Site Reliability Engineers responsible for monitoring AI workloads on Azure.
  • Platform engineers integrating OTel data from AI agents into Dynatrace.

What will you learn?

By following this guide, you'll learn:

  • How the Microsoft Agent Framework self-instruments using OTel natively.
  • How to configure OTLP exports to Dynatrace.
  • What GenAI attributes and spans the framework emits out-of-the-box.
  • How to view agent traces, prompts, token usage, and latency in AI Observability AI Observability.

Before you begin

Prerequisites

To get started, you need to have:

  • Python 3.10 or later.

  • An Azure OpenAI endpoint and deployment key.

  • The sample app, or your own application using the Microsoft Agent Framework.

  • Dynatrace SaaS with a Dynatrace Platform Subscription (DPS) license that has Traces powered by Grail and Metrics powered by Grail enabled.

  • OTLP ingestion enabled, see OpenTelemetry and Dynatrace.

  • A Dynatrace API token with the following scopes, see Dynatrace API - Tokens and authentication.

    • Ingest OTel traces (openTelemetryTrace.ingest)
    • Ingest metrics (metrics.ingest)

Prior knowledge

It's helpful to have some basic knowledge of:

  • Python.
  • OTel concepts like spans, exporters, and OTLP.
  • Dynatrace permissions and data ingestion.

About the Microsoft Agent Framework and AI observability

The Microsoft Agent Framework instruments itself via OTel natively. Calling Agent.run() produces two nested spans that AI Observability AI Observability understands without any additional configuration:

  • invoke_agent is emitted by AgentTelemetryLayer, and carries gen_ai.agent.name and gen_ai.conversation.id.
  • chat is emitted by ChatTelemetryLayer, and carries token counts, model name, and prompt and completion content.

The following table lists the signals that the Microsoft Agent Framework exports, their endpoints, and their key attributes.

SignalEndpointKey attributes

Traces

/api/v2/otlp/v1/traces

  • gen_ai.agent.name
  • gen_ai.input.messages
  • gen_ai.output.messages
  • token counts

Metrics

/api/v2/otlp/v1/metrics

These populate the latency and cost dashboard views in Dynatrace.

  • gen_ai.client.operation.duration
  • gen_ai.client.token.usage

Metrics are exported with OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta, which Dynatrace requires. For more information, see Aggregation temporality.

Get started with Microsoft Agent Framework and Dynatrace

This example runs an agent that calls Azure OpenAI to write a haiku about observability. The agent exports traces and metrics directly to Dynatrace, with no additional instrumentation code required.

1. Configure your environment

Copy .env.sample to .env in the microsoft-agent-framework/opentelemetry directory and fill in your values.

OPENAI_API_KEY=...
OPENAI_API_BASE=https://<resource>.openai.azure.com/openai/deployments/<deployment> # full deployment URL; the app strips the path to derive the Azure base endpoint
OPENAI_API_VERSION=2025-04-01-preview
MODEL=<deployment>
TEMPERATURE=0.7
DT_ENDPOINT=https://<YOUR_ENV>.live.dynatrace.com
DT_API_TOKEN=dt0c01....
OTEL_SERVICE_NAME=microsoft-agent-framework
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf # required by Dynatrace OTLP ingest
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta # Dynatrace requires delta; the SDK default (cumulative) returns HTTP 400

2. Install dependencies

Create a virtual environment and install the required packages.

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

The required packages are:

  • agent-framework
  • agent-framework-openai
  • opentelemetry-sdk
  • opentelemetry-exporter-otlp-proto-http
  • python-dotenv

3. Save the sample as a Python file

The code block below shows the sample application It configures OTLP exports to Dynatrace, creates an agent, and runs the agent with a single prompt. Copy the contents and save them to a local file, app.py.

import asyncio
import os
import uuid
from agent_framework import Agent
from agent_framework.observability import configure_otel_providers
from agent_framework.openai import OpenAIChatCompletionClient
from dotenv import load_dotenv
from opentelemetry import metrics as otel_metrics
from opentelemetry import trace as otel_trace
def _derive_azure_endpoint(base_url: str) -> str:
marker = "/openai/"
if marker in base_url:
return base_url.split(marker, 1)[0]
return base_url.rstrip("/")
def _configure_dynatrace_otlp() -> None:
dt_endpoint = os.environ["DT_ENDPOINT"].rstrip("/")
dt_api_token = os.environ["DT_API_TOKEN"]
auth_header = f"Authorization=Api-Token {dt_api_token}"
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = f"{dt_endpoint}/api/v2/otlp/v1/traces"
os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = auth_header
os.environ["OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"] = f"{dt_endpoint}/api/v2/otlp/v1/metrics"
os.environ["OTEL_EXPORTER_OTLP_METRICS_HEADERS"] = auth_header
async def main() -> None:
load_dotenv()
_configure_dynatrace_otlp()
configure_otel_providers(enable_sensitive_data=True)
client = OpenAIChatCompletionClient(
model=os.getenv("MODEL", "gpt-4o-mini"),
azure_endpoint=_derive_azure_endpoint(os.environ["OPENAI_API_BASE"]),
api_key=os.environ["OPENAI_API_KEY"],
api_version=os.getenv("OPENAI_API_VERSION", "2025-04-01-preview"),
)
agent = Agent(
client=client,
name="observability-haiku-agent",
description="Writes concise haikus about software observability.",
instructions="You write concise haikus about software observability.",
default_options={
"temperature": float(os.getenv("TEMPERATURE", "0.7")),
"conversation_id": str(uuid.uuid4()),
},
)
result = await agent.run("Write a haiku about observability.")
print(result.text)
for provider in (otel_trace.get_tracer_provider(), otel_metrics.get_meter_provider()):
if hasattr(provider, "force_flush"):
provider.force_flush()
if hasattr(provider, "shutdown"):
provider.shutdown()
if __name__ == "__main__":
asyncio.run(main())

4. Run the sample

Run the sample with the following command.

python path/to/app.py

The agent then calls Azure OpenAI, writes a haiku about observability, and exports traces and metrics to your Dynatrace environment—all in a single prompt.

5. Observe in Dynatrace

Once your agent has run, open AI Observability AI Observability to see the data.

  1. Select Ctrl+K and search for AI Observability.
  2. Your agent appears under the Agent filter as observability-haiku-agent.
  3. Open a trace to inspect the invoke_agent and chat spans and their gen_ai.* attributes.

Use the following views to explore the data further, or you can also view spans in Distributed Tracing Distributed Tracing.

ViewWhat to look for

Overview → Response time per model

p99 and mean latency per model (requires metrics endpoint)

Cost dashboard

Input and output token cost split by model (requires metrics endpoint)

Prompts

Prompt and completion text, conversation grouping by gen_ai.conversation.id

Prompt and completion content (gen_ai.input.messages / gen_ai.output.messages) are captured as span attributes when enable_sensitive_data=True. They travel with traces and don't require a separate logs endpoint.

Congratulations!

Now that you've set up your AI agent to send observability data directly to Dynatrace, you can:

  • Explore Distributed Tracing Distributed Tracing and AI Observability AI Observability to visualize your AI workloads.
  • Check out the full sample for more details and a troubleshooting guide.
  • Point the OTLP endpoint to your Collector or any ActiveGate endpoint.
Related tags
AI Observability