Skip to content

Azure Monitor

The Azure Monitor exporter posts straight to the Application Insights ingestion endpoint (/v2.1/track), with no collector in between. Page views, requests, dependencies, exceptions, custom events and metrics land in their usual tables - pageViews, requests, dependencies, exceptions, customEvents, customMetrics - so the portal's Application Map, Failures, Performance and Usage blades work as they do with Microsoft's own SDKs.

Connection string

The exporter needs the resource's connection string: the instrumentation key and the regional IngestionEndpoint (records go to {IngestionEndpoint}/v2.1/track; without one, to https://dc.services.visualstudio.com), plus the LiveEndpoint for Live Metrics. Outside the browser, with options.UseEnvironmentVariables on, an unset connection string is read from APPLICATIONINSIGHTS_CONNECTION_STRING - and that variable alone adds the exporter when none is configured, which is what App Service and Container Apps set.

builder.Services.AddBitBelemetryServices(options =>
{
    options.ServiceName = "MyApp";            // ai.cloud.role
    options.ServiceNamespace = "Shop";        // ai.cloud.role = "[Shop]/MyApp"

    options.AddAzureMonitorExporter(builder.Configuration["ApplicationInsights:ConnectionString"]!);
});

The browser script exports to Application Insights too (IncludeInBrowser, on by default) - the same arrangement as Microsoft's JavaScript SDK, whose connection string is in every page it runs on. The instrumentation key identifies the resource; it does not authorize reading anything. Turn IncludeInBrowser off to keep the browser away from it, and use the Relay transport to send browser records through .NET instead.

Microsoft Entra ID

A resource with local authentication disabled only accepts telemetry with an Entra ID token. AccessTokenProvider supplies one, sent as Authorization: Bearer, for the scope https://monitor.azure.com//.default. Belemetry takes no dependency on Azure.Identity: the provider is a plain delegate, so any credential - managed identity, workload identity, a client secret - plugs in.

An exporter with a token provider is never handed to the browser script, which could not hold the token safely. On Blazor Server and Hybrid, browser records reach such a resource through the Relay transport. In WebAssembly the .NET pipeline runs in the browser too, so it is no place for a credential either: there, send telemetry to a server of yours (an OpenTelemetry Collector with the Azure Monitor exporter, for example) and let that server authenticate.

using Azure.Core;
using Azure.Identity;

var credential = new DefaultAzureCredential();

builder.Services.AddBitBelemetryServices(options =>
{
    options.AddAzureMonitorExporter(builder.Configuration["ApplicationInsights:ConnectionString"]!, azure =>
    {
        azure.AccessTokenProvider = async cancellationToken =>
            (await credential.GetTokenAsync(
                new TokenRequestContext(["https://monitor.azure.com//.default"]), cancellationToken)).Token;
    });
});

MaskIp

Application Insights derives each record's city and country from the client IP address it was sent from. With MaskIp (on by default) Belemetry sends ai.location.ip = 0.0.0.0, so no location is derived and the user's address is not part of the record. Belemetry never adds the client IP itself. Turn it off only if you need the geography and your privacy notice covers it.

Live Metrics

With EnableLiveMetrics the .NET side streams requests, dependencies, exceptions, CPU and memory to the portal's Live Metrics blade once per second while someone is watching it - following the Application Insights QuickPulse protocol, so treat it as a preview feature. It is not available in the browser, and in WebAssembly it reports the app running in that one browser, so it is most useful with the server pipeline and in Hybrid apps.

Compression, timeout and signals

Compression = BelemetryCompression.Gzip compresses the envelope array (Content-Encoding: gzip), in the browser too. Timeout bounds one request (30 s). Signals restricts what is sent, by the browser script as well - for example metrics only, while traces and logs go to an OTLP backend. Throttling (429, 439), transient failures (408, 500, 502, 503, 504) and the items of a partial success (206) are retried, and kept by the offline persistence while the network is down. Metrics are always sent as deltas, which is what customMetrics expects, whatever Metrics.Temporality says. MinimumLogLevel is the per-exporter counterpart of a logging provider's level: Application Insights gets the plain log records at or above it while an OTLP backend gets everything, from one pipeline; events (page views, custom events, web vitals, exceptions), spans and metrics always pass.

How each record becomes an envelope - the types, tags and properties - is on the Azure mapping page.

API

BelemetryAzureMonitorExporterOptions Class

Settings of the Azure Monitor (Application Insights) exporter, which posts to the ingestion endpoint (/v2.1/track) directly, so page views, requests, dependencies, exceptions and custom events land in their usual Application Insights tables without a collector in between.

Name Type and default Description
ConnectionString string The Application Insights connection string (InstrumentationKey=...;IngestionEndpoint=https://...;LiveEndpoint=https://...). Defaults to APPLICATIONINSIGHTS_CONNECTION_STRING when set (outside the browser).
AccessTokenProvider Func<CancellationToken, ValueTask<string>> Supplies a Microsoft Entra ID access token (scope https://monitor.azure.com//.default) sent as Authorization: Bearer, for resources with local authentication disabled. Belemetry takes no dependency on Azure.Identity: pass e.g. ct => credential.GetTokenAsync(...).
MaskIp bool= true Whether to send ai.location.ip = 0.0.0.0 so the ingestion service does not derive the user's location from the client IP address. Defaults to true.
Compression BelemetryCompression= BelemetryCompression.None The request-body compression. Defaults to none.
Timeout TimeSpan= 00:00:30 The maximum time one export request may take. Defaults to 30 seconds.
EnableLiveMetrics bool= false Whether to stream Live Metrics (requests, dependencies, exceptions, CPU and memory, once per second while someone watches the Live Metrics blade). Not available in the browser. Defaults to false.
IncludeInBrowser bool= true Whether the browser script exports to Application Insights too (with BelemetryBrowserTransport.Direct). Defaults to true.
Signals BelemetrySignals= BelemetrySignals.All The signals sent to Application Insights. Defaults to all three.
MinimumLogLevel LogLevel? The least severe log level this exporter receives from the .NET pipeline (its own logs and the records the browser relays); plain log records below it are left out of this exporter's batches only. Events - page views, interactions, web vitals, custom events, exceptions - are not logs to a log level and always pass, as do spans and metrics. null (the default) sends every collected record. Use it when Application Insights should get warnings and errors only while an OTLP backend gets everything, as a per-provider logging level would with two logging providers.
An unhandled error has occurred. Reload 🗙