This demo showcases the integration of OpenTelemetry with the Microsoft Agent Framework using Azure OpenAI and .NET Aspire Dashboard for telemetry visualization.
The demo consists of three main components:
- Aspire Dashboard - Provides a web-based interface to visualize OpenTelemetry data
- Console Application - An interactive console application that demonstrates agent interactions with proper OpenTelemetry instrumentation
- [Optional] Application Insights - When the agent is deployed to a production environment, Application Insights can be used to monitor the agent performance.
graph TD
A["Console App<br/>(Interactive)"] --> B["Agent Framework<br/>with OpenTel<br/>Instrumentation"]
B --> C["Azure OpenAI<br/>Service"]
A --> D["Aspire Dashboard<br/>(OpenTelemetry Visualization)"]
B --> D
- .NET 10 SDK or later
- Azure OpenAI service endpoint and deployment configured
- Azure CLI installed and authenticated (for Azure credential authentication)
- Docker installed (for running Aspire Dashboard)
- [Optional] Application Insights and Grafana
Set the following environment variables:
$env:AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini" # Optional, defaults to gpt-4o-miniNote: This demo uses Azure CLI credentials for authentication. Make sure you're logged in with az login and have access to the Azure OpenAI resource.
Set the following environment variables:
$env:APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=XXXX;IngestionEndpoint=https://XXXX.applicationinsights.azure.com/;LiveEndpoint=https://XXXXX.livediagnostics.monitor.azure.com/;ApplicationId=XXXXX"The easiest way to run the demo is using the provided PowerShell script:
.\start-demo.ps1This script will automatically:
- ✅ Check prerequisites (Docker, Azure OpenAI configuration)
- 🔨 Build the console application
- 🐳 Start the Aspire Dashboard via Docker (with anonymous access)
- ⏳ Wait for dashboard to be ready (polls port until listening)
- 🌐 Open your browser with the dashboard
- 📊 Configure telemetry endpoints (http://localhost:4317)
- 🎯 Start the interactive console application
If you prefer to run the components manually:
docker run -d --name aspire-dashboard -p 4318:18888 -p 4317:18889 -e DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS=true mcr.microsoft.com/dotnet/aspire-dashboard:latestOpen your browser to: http://localhost:4318
cd dotnet/demos/AgentOpenTelemetry
$env:OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317"
dotnet runYou should see a welcome message like:
=== OpenTelemetry Aspire Demo ===
This demo shows OpenTelemetry integration with the Agent Framework.
You can view the telemetry data in the Aspire Dashboard.
Type your message and press Enter. Type 'exit' or empty message to quit.
You:
- Type your message and press Enter to interact with the AI agent
- The agent will respond, and you can continue the conversation
- Type
exitto stop the application
Note: Make sure the Aspire Dashboard is running before starting the console application, as the telemetry data will be sent to the dashboard.
- Start the Aspire Dashboard (if not already running)
- Run the Console Application in a separate terminal
- Send a test message like "Hello, how are you?"
- Check the Aspire Dashboard - you should see:
- New traces appearing in the Traces tab
- Each trace showing the complete agent interaction flow
- Metrics in the Metrics tab showing token usage and duration
- Logs in the Structured Logs tab with detailed information
- In the Aspire Dashboard, navigate to the Traces tab
- You'll see traces for each agent interaction
- Each trace contains:
- An outer span for the entire agent interaction
- Inner spans from the Agent Framework's OpenTelemetry instrumentation
- Spans from HTTP calls to Azure OpenAI
- Navigate to the Metrics tab
- View metrics related to:
- Agent execution duration
- Token usage (input/output tokens)
- Request counts
- Navigate to the Structured Logs tab
- Filter by the console application to see detailed logs
- Logs include information about user inputs, agent responses, and any errors
Besides the Aspire Dashboard and the Application Insights native UI, you can also use Grafana to visualize the telemetry data in Application Insights. There are two tailored dashboards for you to get started quickly:
Open dashboard in Azure portal: https://aka.ms/amg/dash/af-agent

Open dashboard in Azure portal: https://aka.ms/amg/dash/af-workflow

- Automatic instrumentation of Agent Framework operations
- Custom spans for user interactions
- Proper span lifecycle management (create → execute → close)
- Telemetry correlation across the entire request flow
- ChatClientAgent with Azure OpenAI integration
- OpenTelemetry wrapper using
.WithOpenTelemetry() - Conversation threading for multi-turn conversations
- Error handling with telemetry correlation
- Real-time telemetry visualization
- Distributed tracing across services
- Metrics and logging integration
- Resource management and monitoring
The demo includes a PowerShell script to make running the demo easy:
Complete demo startup script that handles everything automatically.
Usage:
.\start-demo.ps1 # Start the complete demoFeatures:
- Automatic configuration detection - Checks for Azure OpenAI configuration
- Project building - Automatically builds projects before running
- Error handling - Provides clear error messages if something goes wrong
- Multi-window support - Opens dashboard in separate window for better experience
- Browser auto-launch - Automatically opens the Aspire Dashboard in your browser
- Docker integration - Uses Docker to run the Aspire Dashboard
Docker Endpoints:
- Aspire Dashboard:
http://localhost:4318 - OTLP Telemetry:
http://localhost:4317
If you encounter port binding errors, try:
- Stop any existing Docker containers using the same ports (
docker stop aspire-dashboard) - Or kill any processes using the conflicting ports
- Ensure your Azure OpenAI endpoint is correctly configured
- Check that the environment variables are set in the correct terminal session
- Verify you're logged in with Azure CLI (
az login) and have access to the Azure OpenAI resource - Ensure the Azure OpenAI deployment name matches your actual deployment
- Ensure you're using .NET 10.0 SDK
- Run
dotnet restoreif you encounter package restore issues - Check that all project references are correctly resolved
AgentOpenTelemetry/
├── AgentOpenTelemetry.csproj # Project file with dependencies
├── Program.cs # Main application with Azure OpenAI agent integration
├── start-demo.ps1 # PowerShell script to start the demo
└── README.md # This file
- Experiment with different prompts to see various telemetry patterns
- Explore the Aspire Dashboard's filtering and search capabilities
- Try modifying the OpenTelemetry configuration to add custom metrics or spans
- Integrate additional services to see distributed tracing in action