A component of ASP.NET Core for creating RESTful web services that support HTTP-based communication between clients and servers.
Azure Monitor’s OpenTelemetry distro already creates and flows correlation identifiers (trace/activity IDs) for requests, dependencies, and logs. The goal is to align logging with those built‑in IDs instead of maintaining a separate custom correlation ID system.
For ASP.NET Core with Azure.Monitor.OpenTelemetry.AspNetCore:
- Configure OpenTelemetry and Azure Monitor
Use the Azure Monitor distro so that traces, metrics, and logs are all correlated and exported to Application Insights:
<ItemGroup>
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.3.0-beta.1" />
</ItemGroup>
In Program.cs (before builder.Build()):
builder.Services.AddOpenTelemetry(otel =>
{
// configure tracing, metrics, logging, etc.
if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
{
otel.UseAzureMonitor();
}
});
builder.Logging.AddOpenTelemetry(); // route logs through OTel
UseAzureMonitor() wires up the exporters and common instrumentation for ASP.NET Core and .NET so that logs, metrics, and traces share the same trace/activity identifiers and are sent to Application Insights.
- Getting the correlation ID into console/log stream output
The correlation identifier in OpenTelemetry is the current Activity’s trace ID and span ID. When builder.Logging.AddOpenTelemetry is used, log records are correlated with the current Activity automatically. To see those IDs in console output:
- Configure the console sink (Serilog or built‑in logging) to include the
TraceIdandSpanIdthat OpenTelemetry attaches to log scopes. - Because all logging is routed through OpenTelemetry, the same IDs that appear in Application Insights will be present in the log record metadata and can be rendered in the console/file format string.
This way, the “correlation ID” seen in Azure (trace ID) is the same value visible in console/log stream when needed.
- Generally accepted configuration for local development
For local development where console/file logging is primary:
- Keep the same OpenTelemetry setup (
AddOpenTelemetry+UseAzureMonitor) but:- Use an Application Insights connection string from a dev resource via
APPLICATIONINSIGHTS_CONNECTION_STRINGinappsettings.Development.jsonor environment variables, as shown:"AzureMonitor": { "ConnectionString": "InstrumentationKey=12345678-abcd-abcd-abcd-12345678..." } - Or omit the connection string to disable export to Azure while still using OpenTelemetry locally.
- Use an Application Insights connection string from a dev resource via
- Route all logging through OpenTelemetry (
builder.Logging.AddOpenTelemetry) and configure console/file providers to include the trace/activity identifiers in the log format.
This matches the Modern Web App guidance: use the Azure Monitor OpenTelemetry distro, route all logging through OpenTelemetry, and rely on the built‑in trace/activity identifiers for end‑to‑end correlation across HTTP, Service Bus, and other boundaries.
References: