![]() |
VOOZH | about |
dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore --version 1.5.0
NuGet\Install-Package Azure.Monitor.OpenTelemetry.AspNetCore -Version 1.5.0
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.5.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.5.0" />Directory.Packages.props
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" />Project file
paket add Azure.Monitor.OpenTelemetry.AspNetCore --version 1.5.0
#r "nuget: Azure.Monitor.OpenTelemetry.AspNetCore, 1.5.0"
#:package Azure.Monitor.OpenTelemetry.AspNetCore@1.5.0
#addin nuget:?package=Azure.Monitor.OpenTelemetry.AspNetCore&version=1.5.0Install as a Cake Addin
#tool nuget:?package=Azure.Monitor.OpenTelemetry.AspNetCore&version=1.5.0Install as a Cake Tool
The Azure Monitor Distro is a client library that sends telemetry data to Azure Monitor following the OpenTelemetry Specification. This library can be used to instrument your ASP.NET Core applications to collect and send telemetry data to Azure Monitor for analysis and monitoring, powering experiences in Application Insights.
The Azure Monitor Distro is a distribution of the .NET OpenTelemetry SDK with instrumentation libraries, including:
Traces
Metrics
Microsoft.AspNetCore.Hosting and System.Net.Http from .NET.
For a detailed list of metrics produced, refer to the Microsoft.AspNetCore.Hosting
and System.Net.Http metrics documentation.Microsoft.Extensions.Logging. See Logging in .NET Core and ASP.NET Core for more details on how to create and configure logging.Microsoft.Extensions.LoggingResource Detectors
Note: The detectors are part of the OpenTelemetry.ResourceDetectors.Azure package. While this package is currently in its beta phase, we have chosen to vendor in the code for these detectors to include them in our Distro. Please be aware that resource attributes are only used to set the cloud role and role instance. All other resource attributes are ignored.
Azure Monitor Exporter allows sending traces, metrics, and logs data to Azure Monitor.
If you are currently using the Application Insights SDK and want to migrate to OpenTelemetry, please follow our migration guide.
If you are currently using OpenTelemetry and want to send telemetry data to Azure Monitor, please follow our getting started guide.
Install the Azure Monitor Distro for .NET from NuGet:
dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore
Nightly builds are available from this repo's dev feed. These are provided without support and are not intended for production workloads.
The following examples demonstrate how to integrate the Azure Monitor Distro into your application.
To enable Azure Monitor Distro, add UseAzureMonitor() to your Program.cs file and set the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable to the connection string from your Application Insights resource.
// This method gets called by the runtime. Use this method to add services to the container.
var builder = WebApplication.CreateBuilder(args);
// The following line enables Azure Monitor Distro.
builder.Services.AddOpenTelemetry().UseAzureMonitor();
// This code adds other services for your application.
builder.Services.AddMvc();
var app = builder.Build();
To enable Azure Monitor Distro with a hard-coded connection string, add UseAzureMonitor() to your Program.cs with the AzureMonitorOptions containing the connection string.
// This method gets called by the runtime. Use this method to add services to the container.
var builder = WebApplication.CreateBuilder(args);
// The following line enables Azure Monitor Distro with hard-coded connection string.
builder.Services.AddOpenTelemetry().UseAzureMonitor(o => o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");
// This code adds other services for your application.
builder.Services.AddMvc();
var app = builder.Build();
Note that in the examples above, UseAzureMonitor is added to the IServiceCollection in the Program.cs file. You can also add it in the ConfigureServices method of your Startup.cs file.
Note Multiple calls to
AddOpenTelemetry.UseAzureMonitor()will NOT result in multiple providers and will throwSystem.NotSupportedException. Only a singleTracerProvider,MeterProviderandLoggerProvidercan be created in the targetIServiceCollection. To establish multiple providers use theSdk.CreateTracerProviderBuilder()and/orSdk.CreateMeterProviderBuilder()and/orLoggerFactory.CreateLoggermethods with the Azure Monitor Exporter instead of using Azure Monitor Distro.
Azure Active Directory (AAD) authentication is an optional feature that can be used with Azure Monitor Distro. To enable AAD authentication, set the Credential property in AzureMonitorOptions. This is made easy with the Azure Identity library, which provides support for authenticating Azure SDK clients with their corresponding Azure services.
// Call UseAzureMonitor and set Credential to authenticate through Active Directory.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
options.Credential = new DefaultAzureCredential();
});
With this configuration, the Azure Monitor Distro will use the credentials of the currently logged-in user or of the service principal to authenticate and send telemetry data to Azure Monitor.
Note that the Credential property is optional. If it is not set, Azure Monitor Distro will use the Instrumentation Key from the Connection String to send data to Azure Monitor.
The Azure Monitor Distro uses rate-limited sampling by default, collecting up to 5.0 traces per second. This provides cost-effective telemetry collection for most applications while maintaining observability.
To customize the sampling behavior:
Option 1: Set the rate limited sampler to use a configured traces per second
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
options.TracesPerSecond = 10.0; // Collect up to 10 traces per second
});
Option 2: Switch to percentage-based sampling
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
options.SamplingRatio = 0.5F; // Sample 50% of traces
options.TracesPerSecond = null; // Disable rate-limited sampling
});
Option 3: Use environment variables For rate-limited sampling:
OTEL_TRACES_SAMPLER=microsoft.rate_limited
OTEL_TRACES_SAMPLER_ARG=10
For percentage-based sampling:
OTEL_TRACES_SAMPLER=microsoft.fixed_percentage
OTEL_TRACES_SAMPLER_ARG=0.5
Note: When both TracesPerSecond and SamplingRatio are configured, TracesPerSecond takes precedence.
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.AddSource("MyCompany.MyProduct.MyLibrary"));
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.ConfigureOpenTelemetryMeterProvider((sp, builder) => builder.AddMeter("MyCompany.MyProduct.MyLibrary"));
If you need to instrument a library or framework that isn't included in the Azure Monitor Distro, you can add additional instrumentation using the OpenTelemetry Instrumentation packages. For example, to add instrumentation for gRPC clients, you can add the OpenTelemetry.Instrumentation.GrpcNetClient package and use the following code:
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.AddGrpcClientInstrumentation());
Azure SDK instrumentation is supported under the experimental feature flag which can be enabled using one of the following ways:
Set the AZURE_EXPERIMENTAL_ENABLE_ACTIVITY_SOURCE environment variable to true.
Set the Azure.Experimental.EnableActivitySource context switch to true in your app’s code:
AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);
Add the RuntimeHostConfigurationOption setting to your project file:
<ItemGroup>
<RuntimeHostConfigurationOption Include="Azure.Experimental.EnableActivitySource" Value="true" />
</ItemGroup>
Azure Monitor Distro uses the Azure Monitor exporter to send data to Application Insights. However, if you need to send data to other services, including Application Insights, you can add another exporter. For example, to add the Console exporter, you can install the OpenTelemetry.Exporter.Console package and use the following code:
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.ConfigureOpenTelemetryMeterProvider((sp, builder) => builder.AddConsoleExporter());
To modify the resource, use the following code.
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.ConfigureResource(resourceBuilder => resourceBuilder.AddService("service-name")));
It is also possible to configure the Resource by using following
environmental variables:
| Environment variable | Description |
|---|---|
OTEL_RESOURCE_ATTRIBUTES |
Key-value pairs to be used as resource attributes. See the Resource SDK specification for more details. |
OTEL_SERVICE_NAME |
Sets the value of the service.name resource attribute. If service.name is also provided in OTEL_RESOURCE_ATTRIBUTES, then OTEL_SERVICE_NAME takes precedence. |
The Azure Monitor Distro includes .NET OpenTelemetry instrumentation for ASP.NET Core, HttpClient, and SQLClient. You can customize these included instrumentations or manually add additional instrumentation on your own using the OpenTelemetry API.
Here are some examples of how to customize the instrumentation:
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.Configure<AspNetCoreTraceInstrumentationOptions>(options =>
{
options.RecordException = true;
options.Filter = (httpContext) =>
{
// only collect telemetry about HTTP GET requests
return HttpMethods.IsGet(httpContext.Request.Method);
};
});
builder.Services.AddOpenTelemetry().UseAzureMonitor();
builder.Services.Configure<HttpClientTraceInstrumentationOptions>(options =>
{
options.RecordException = true;
options.FilterHttpRequestMessage = (httpRequestMessage) =>
{
// only collect telemetry about HTTP GET requests
return HttpMethods.IsGet(httpRequestMessage.Method.Method);
};
});
While the SQLClient instrumentation is still in beta, we have vendored it within our package. Once it reaches a stable release, it will be included as a standard package reference. Until then, for customization of the SQLClient instrumentation, manually add the OpenTelemetry.Instrumentation.SqlClient package reference to your project and utilize its public API.
dotnet add package --prerelease OpenTelemetry.Instrumentation.SqlClient
builder.Services.AddOpenTelemetry().UseAzureMonitor().WithTracing(tracing =>
{
tracing.AddSqlClientInstrumentation(options =>
{
options.SetDbStatementForStoredProcedure = false;
});
});
By default, the Live Metrics feature is enabled in the Azure Monitor Distro. This feature allows for real-time monitoring of application performance, providing immediate insights into your application's operations. However, there may be scenarios where you prefer to disable this feature, such as to optimize resource usage or in environments where real-time monitoring is not a requirement.
To disable Live Metrics, you can set the EnableLiveMetrics property to false in the AzureMonitorOptions. Here's an example of how to disable Live Metrics:
// Disable Live Metrics by setting EnableLiveMetrics to false in the UseAzureMonitor configuration.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
options.EnableLiveMetrics = false;
});
The Azure Monitor Distro enables metric collection and collects several metrics by default. If you want to exclude specific instruments from being collected in your application's telemetry use the following code snippet:
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics =>
metrics.AddView(instrumentName: "http.server.active_requests", MetricStreamConfiguration.Drop)
);
Refer to Drop an instrument for more examples.
The Azure Monitor Distro is a distribution package that facilitates users in sending telemetry data to Azure Monitor. It encompasses the .NET OpenTelemetry SDK and instrumentation libraries for ASP.NET Core, HttpClient, and SQLClient, ensuring seamless integration and data collection.
Refer to Program.cs for a complete demo.
Log scopes allow you to add additional properties to the logs generated by your application. Although the Azure Monitor Distro does support scopes, this feature is off by default in OpenTelemetry. To leverage log scopes, you must explicitly enable them.
To include the scope with your logs, set OpenTelemetryLoggerOptions.IncludeScopes to true in your application's configuration:
builder.Services.Configure<OpenTelemetryLoggerOptions>((loggingOptions) =>
{
loggingOptions.IncludeScopes = true;
});
When using ILogger scopes, use a List<KeyValuePair<string, object?>> or IReadOnlyList<KeyValue<string, object?>> as the state for best performance.
All logs written within the context of the scope will include the specified information.
Azure Monitor will add these scope values to the Log's CustomProperties.
List<KeyValuePair<string, object?>> scope =
[
new("scopeKey", "scopeValue")
];
using (logger.BeginScope(scope))
{
logger.LogInformation("Example message.");
}
In scenarios involving multiple scopes or a single scope with multiple key-value pairs, if duplicate keys are present, only the first occurrence of the key-value pair from the outermost scope will be recorded. However, when the same key is utilized both within a logging scope and directly in the log statement, the value specified in the log message template will take precedence.
Azure Monitor relies on OpenTelemetry's Log Signal to create CustomEvents.
For .NET, users will use ILogger and place an attribute named "microsoft.custom_event.name" in the message template.
Severity and CategoryName are not recorded in the CustomEvent.
To send a CustomEvent via ILogger, include the "microsoft.custom_event.name" attribute in the message template.
Note: This example shows LogInformation, but any Log method can be used.
Severity is not recorded, but depending on your configuration it may be filtered out.
Users should take care to select a severity for CustomEvents that is not filtered out by their configuration.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry().UseAzureMonitor();
var app = builder.Build();
app.Logger.LogInformation("{microsoft.custom_event.name} {key1} {key2}", "MyCustomEventName", "value1", "value2");
This example generates a CustomEvent structured like this:
{
"name": "Event",
"data": {
"baseType": "EventData",
"baseData": {
"name": "MyCustomEventName",
"properties": {
"key1": "value1",
"key2": "value2"
}
}
}
}
The Azure Monitor Distro uses EventSource for its own internal logging. The logs are available to any EventListener by opting into the source named "OpenTelemetry-AzureMonitor-Exporter".
OpenTelemetry also provides it's own self-diagnostics feature to collect internal logs. An example of this is available in our demo project here.
Missing Request Telemetry
If an app has a reference to the OpenTelemetry.Instrumentation.AspNetCore package, it could be missing request telemetry. To resolve this issue:
OpenTelemetry.Instrumentation.AspNetCore package (or)AddAspNetCoreInstrumentation to the OpenTelemetry TracerProvider configuration as per the OpenTelemetry documentation.Few or all Dependency Telemetries are missing
If an app references the OpenTelemetry.Instrumentation.Http or OpenTelemetry.Instrumentation.SqlClient packages, it might be missing dependency telemetry. To resolve:
AddHttpClientInstrumentation or AddSqlClientInstrumentation to the TracerProvider configuration. Detailed guidance can be found in the OpenTelemetry documentation for HTTP and SQL Client.Note: If all telemetries are missing or if the above troubleshooting steps do not help, please collect self-diagnostics logs.
For more information on Azure SDK, please refer to this website
See CONTRIBUTING.md for details on contribution process.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Azure.Monitor.OpenTelemetry.AspNetCore:
| Package | Downloads |
|---|---|
|
FoundationaLLM.Common
FoundationaLLM.Common is a .NET library that the FoundationaLLM.Client.Core and FoundationaLLM.Client.Management client libraries share as a common dependency. |
|
|
Soenneker.ApplicationInsights.Correlator.Jwt
A telemetry initializer that adds a request's authorization header |
|
|
devdeer.Libraries.AspNetCore.RestApi
Initialization and configuration including useful base types for ASP.NET Core APIs. |
|
|
Soenneker.ApplicationInsights.Processor.SignalR
A telemetry processor connecting SignalR hub traffic and Application Insights |
|
|
Altinn.Authorization.ServiceDefaults
Package Description |
Showing the top 19 popular GitHub repositories that depend on Azure.Monitor.OpenTelemetry.AspNetCore:
| Repository | Stars |
|---|---|
|
microsoft/mcp
Catalog of official Microsoft MCP (Model Context Protocol) server implementations for AI-powered data access and tool integration
|
|
|
collinbarrett/FilterLists
:shield: The independent, comprehensive directory of filter and host lists for advertisements, trackers, malware, and annoyances.
|
|
|
GZTimeWalker/GZCTF
The GZ::CTF project, an open source CTF platform.
|
|
|
bitfoundation/bitplatform
Build all of your apps using what you already know and love ❤️
|
|
|
grandnode/grandnode2
E-commerce platform built with ASP.NET Core using MongoDB for NoSQL storage
|
|
|
Azure/azure-mcp
The Azure MCP Server, bringing the power of Azure to your agents.
|
|
|
mehdihadeli/food-delivery-microservices
🍔 A practical and cloud-native food delivery microservices, built with .Net Aspire, .Net 9, MassTransit, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
|
|
|
microsoft/copilot-camp
Hands-on labs for extending Microsoft 365 Copilot and building custom engine agents
|
|
|
havit/Havit.Blazor
Free Bootstrap 5 components for ASP.NET Blazor + optional enterprise-level stack for Blazor development (gRPC code-first, layered architecture, localization, auth, ...)
|
|
|
Azure/apiops
APIOps applies the concepts of GitOps and DevOps to API deployment. By using practices from these two methodologies, APIOps can enable everyone involved in the lifecycle of API design, development, and deployment with self-service and automated tools to ensure the quality of the specifications and APIs that they’re building.
|
|
|
platformplatform/PlatformPlatform
A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
|
|
|
Azure-Samples/eShopOnAzure
A variant of https://github.com/dotnet/eShop that uses Azure services
|
|
|
maraf/Money
Personal Expense Manager -- UWP (+ Blazor) and CQRS+ES.
|
|
|
bitbound/ControlR
Open-source, self-hostable remote control and remote access.
|
|
|
Azure-Samples/eShopLite
eShopLite is a set of reference .NET applications implementing an eCommerce site with features like Semantic Search, MCP, Reasoning models and more.
|
|
|
Azure/modern-web-app-pattern-dotnet
The Modern Web App Pattern is a set of objectives to help you apply an iterative change to modernize a cloud deployed monolith. This content builds on the Reliable Web App. This repo contains a reference implementation of a Modern Web App for .NET.
|
|
|
Avanade/Beef
The Business Entity Execution Framework (Beef) framework, and the underlying code generation, has been primarily created to support the industrialization of API development.
|
|
|
Keboo/DotnetTemplates
A repository for my dotnet templates
|
|
|
PacktPublishing/Pragmatic-Microservices-with-CSharp-and-Azure
Pragmatic Microservices with C# and Azure, published by Packt
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.5.0 | 1,428,689 | 5/1/2026 | |
| 1.4.0 | 7,782,809 | 11/15/2025 | |
| 1.4.0-beta.1 | 21,194 | 10/22/2025 | |
| 1.3.0 | 9,030,114 | 5/9/2025 | |
| 1.3.0-beta.3 | 68,980 | 4/2/2025 | |
| 1.3.0-beta.2 | 472,510 | 10/15/2024 | |
| 1.3.0-beta.1 | 191,849 | 7/16/2024 | |
| 1.2.0 | 12,585,260 | 6/11/2024 | |
| 1.2.0-beta.4 | 58,633 | 5/20/2024 | |
| 1.2.0-beta.3 | 41,407 | 4/19/2024 | |
| 1.2.0-beta.2 | 153,015 | 3/13/2024 | |
| 1.2.0-beta.1 | 16,331 | 2/10/2024 | |
| 1.1.1 | 633,237 | 4/26/2024 | |
| 1.1.0 | 1,438,773 | 1/29/2024 | |
| 1.0.0 | 555,291 | 11/29/2023 | |
| 1.0.0-beta.8 | 211,327 | 10/6/2023 | 1.0.0-beta.8 is deprecated because it is no longer maintained. |
| 1.0.0-beta.7 | 80,065 | 9/20/2023 | 1.0.0-beta.7 is deprecated because it is no longer maintained. |
| 1.0.0-beta.6 | 103,650 | 8/9/2023 | 1.0.0-beta.6 is deprecated because it is no longer maintained. |
| 1.0.0-beta.5 | 28,160 | 7/14/2023 | 1.0.0-beta.5 is deprecated because it is no longer maintained. |
| 1.0.0-beta.4 | 121,978 | 5/10/2023 | 1.0.0-beta.4 is deprecated because it is no longer maintained. |