
Skill
microsoft-opentelemetry-setup
set up Microsoft OpenTelemetry in .NET
Description
Set up Microsoft.OpenTelemetry distro in a new .NET application. Use when adding observability to an agent, ASP.NET Core app, console app, or Agent Framework project. Covers package installation, exporter configuration, token resolver setup, baggage context, and instrumentation options.
SKILL.md
Microsoft OpenTelemetry Distro — Greenfield Setup
When to Use
- User asks to "add observability" or "add telemetry" to a .NET app
- User wants to set up Agent 365, Azure Monitor, or OTLP export
- User is starting a new agent project and needs tracing
- User asks about
Microsoft.OpenTelemetrypackage
Procedure
1. Detect App Type
Scan the project to determine the app type:
- ASP.NET Core — has
WebApplication.CreateBuilder()orIHostApplicationBuilder→ use hosted pattern - Console / Background Service — no web host, uses
OpenTelemetrySdk.Create()→ use console pattern - Agent Framework — references
Microsoft.Agents.BuilderorMicrosoft.Agents.AI→ use Agent Framework pattern
2. Install Package
Add to the project's .csproj:
<PackageReference Include="Microsoft.OpenTelemetry" Version="<latest>" />
Remove any individual OpenTelemetry packages the distro replaces:
OpenTelemetry.Extensions.HostingOpenTelemetry.Instrumentation.AspNetCoreOpenTelemetry.Instrumentation.HttpOpenTelemetry.Instrumentation.SqlClientOpenTelemetry.Exporter.ConsoleOpenTelemetry.Exporter.OpenTelemetryProtocol
3. Configure Exporters
See export targets reference for all options.
Minimal setup in Program.cs:
using Microsoft.OpenTelemetry;
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.Console | ExportTarget.Agent365;
});
4. Set Up Authentication
- Agent Framework apps: No code needed — DI token cache auto-registers
- Custom apps: Set
o.Agent365.TokenResolver
5. Add Baggage Context
See baggage setup.
Baggage propagates tenant/agent identity to all child spans.
6. Tune Instrumentation (optional)
7. Verify
- Build the project
- Run with
ExportTarget.Consoleto see spans in stdout - Verify
gen_ai.agent.idandmicrosoft.tenant.idappear on spans - See troubleshooting if spans are missing
More skills from the opentelemetry-distro-dotnet repository
View all 2 skillsMore from Microsoft
View publisherrushstack-best-practices
manage Rush monorepos with best practices
rushstack
Apr 6EngineeringLocal DevelopmentMicrosoftProject Management +1azure-ai-agents-persistent-dotnet
build AI agents with Azure .NET SDK
skills
Jul 3.NETAgentsAzureLLMazure-ai-anomalydetector-java
build anomaly detection applications with Java
skills
May 13AnalyticsAzureData AnalysisJava +2azure-ai-contentsafety-java
build content moderation applications with Azure AI
skills
Jul 7AI InfrastructureAzureJavaSecurityazure-ai-contentsafety-py
detect harmful content with Azure AI Content Safety
skills
Jul 18AzureComplianceLLMMicrosoft +2azure-ai-language-conversations-py
implement conversational language understanding with Python
skills
Jul 18AnalyticsAzureLLMPython