microsoft/opentelemetry-distro-dotnet
C#
Captured source
source ↗microsoft/opentelemetry-distro-dotnet
Language: C#
License: NOASSERTION
Stars: 4
Forks: 9
Open issues: 3
Created: 2026-04-06T22:32:32Z
Pushed: 2026-10-09T18:17:53Z
Default branch: main
Fork: no
Archived: no
README:
Microsoft.OpenTelemetry
A unified OpenTelemetry distribution for .NET. One-line onboarding for ASP.NET Core apps, Microsoft Agent Framework, and Agent365 — Microsoft's managed observability backend for AI agents.
Targets: net8.0, netstandard2.0
Install
dotnet add package Microsoft.OpenTelemetry
Quick Start
ASP.NET Core / Worker Services (hosted)
using Microsoft.OpenTelemetry;
var builder = WebApplication.CreateBuilder(args);
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.AzureMonitor;
});
var app = builder.Build();
app.Run();Console / non-hosted apps
using Microsoft.OpenTelemetry;
using OpenTelemetry;
var sdk = OpenTelemetrySdk.Create(otel =>
{
otel.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.AzureMonitor;
});
});
// Your application logic here.
// The SDK must stay alive for the lifetime of the app.
// Disposing the SDK flushes pending telemetry and shuts down all providers.
sdk.Dispose();> Important: Do not dispose the SDK until your application is shutting down. Disposing it early stops all telemetry collection and export — you will lose data.
> UseMicrosoftOpenTelemetry() works on any IOpenTelemetryBuilder — both the host-integrated and OpenTelemetrySdk.Create() paths are supported.
Signals & destinations
| Signal | Azure Monitor | Agent365 | OTLP | Console | |---|:---:|:---:|:---:|:---:| | Traces | ✅ | ✅ | ✅ | ✅ | | Metrics | ✅ | — | ✅ | ✅ | | Logs | ✅ | — | ✅ | ✅ |
Exporters auto-detect when Exporters isn't set:
- Azure Monitor — enabled when
ConnectionStringis set (code, env varAPPLICATIONINSIGHTS_CONNECTION_STRING, orIConfiguration). - Agent365 — enabled when
TokenResolveris set (or when the DI token cache is registered byMicrosoft.Agents.A365.Observability.Hosting).
Set explicitly to override auto-detection: o.Exporters = ExportTarget.AzureMonitor | ExportTarget.Agent365;
Instrumentation (always active)
- ASP.NET Core incoming HTTP requests
- HTTP client outbound calls (with Azure SDK dedup filter)
- SQL client queries
- Azure SDK client calls
- Resource detection (Azure App Service, VM, Container Apps)
- Agent365 scopes (
InvokeAgentScope,InferenceScope,ExecuteToolScope,OutputScope) and baggage propagation - Microsoft Agent Framework —
Experimental.Microsoft.Agents.AIactivity sources - Semantic Kernel —
Microsoft.SemanticKernel*activity sources - OpenAI / Azure OpenAI —
Azure.AI.OpenAI*,OpenAI.*,Experimental.Microsoft.Extensions.AI - Azure SDK EventSource →
ILoggerlog forwarding - Metrics —
Microsoft.AspNetCore.Hosting,System.Net.Http
Onboarding by scenario
Pick the section that matches your workload. All can be combined in the same app.
---
1. Azure Monitor
Send traces, metrics, and logs to Application Insights / Azure Monitor.
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.AzureMonitor;
o.AzureMonitor.ConnectionString = "InstrumentationKey=...";
});Configuration sources — the connection string can be set via code, appsettings.json, or the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.
📖 Full guide: [Azure Monitor Getting Started](docs/azure-monitor-getting-started.md)
---
2. Microsoft Agent Framework
Capture activity from Agent Framework agents and export to Azure Monitor, OTLP, or both.
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.AzureMonitor | ExportTarget.Otlp;
});Agent Framework activity sources are captured automatically — no extra configuration needed.
📖 Full guide: [Agent Framework Getting Started](docs/agent-framework-getting-started.md)
---
3. Agent365
Send agent telemetry (invoke agent, inference, tool execution, output) to the Agent365 observability backend.
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.Agent365;
o.Agent365.TokenResolver = async (agentId, tenantId) =>
{
return await MyTokenService.GetTokenAsync(agentId, tenantId);
};
});📖 Full guide: [Agent365 Getting Started](docs/agent365-getting-started.md)
---
4. Microsoft Fabric / Azure Data Explorer
Send traces, metrics, and logs to Microsoft Fabric Real-Time Intelligence or Azure Data Explorer via an OpenTelemetry Collector with the Azure Data Explorer exporter.
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.Otlp;
});The app sends OTLP to a collector, which forwards to Fabric/ADX. No code changes needed — just configure the collector.
📖 Full guide: [Fabric Getting Started](docs/fabric-getting-started.md)
---
Combining destinations
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.AzureMonitor | ExportTarget.Agent365 | ExportTarget.Otlp;
o.AzureMonitor.ConnectionString = "InstrumentationKey=...";
o.Agent365.TokenResolver = async (agentId, tenantId) =>
{
return await MyTokenService.GetTokenAsync(agentId, tenantId);
};
});Options reference
Full surface of MicrosoftOpenTelemetryOptions. Everything is opt-in; values shown are defaults.
builder.UseMicrosoftOpenTelemetry(o =>
{
// --- Export targets (pick one or combine with |) ---
o.Exporters = ExportTarget.Console // Console output (dev)
| ExportTarget.Agent365 // Agent365 observability platform
| ExportTarget.AzureMonitor // Application Insights
| ExportTarget.Otlp; // OTLP (Aspire, Jaeger, Grafana)
// --- Azure Monitor settings ---
o.AzureMonitor.ConnectionString = "InstrumentationKey=...";
o.AzureMonitor.Credential = new DefaultAzureCredential(); // Optional AAD auth
o.AzureMonitor.SamplingRatio = 1.0f;
o.AzureMonitor.TracesPerSecond = 5.0; // Rate-limited sampling (default)
o.AzureMonitor.EnableLiveMetrics = true;
o.AzureMonitor.EnableStandardMetrics = true;
o.AzureMonitor.EnablePerfCounters = true;
o.AzureMonitor.EnableTraceBasedLogsSampler = true;
o.AzureMonitor.DisableOfflineStorage = false;...Excerpt shown — open the source for the full document.