skip to content

What telemetry does ASP.NET Core 10 produce with no OpenTelemetry package installed, and what does AddAspNetCoreInstrumentation add on top?

level: middleimportance: should knowfreq 42%

answer

  1. built in since .NET 8
  2. meter Microsoft.AspNetCore.Hosting
  3. http.server.request.duration in seconds
  4. activity HttpRequestIn from source Microsoft.AspNetCore
  5. AddMeter works without the package

basics

~20 s

ASP.NET Core 10 creates a request Activity and, since .NET 8, records metrics such as http.server.request.duration on built-in meters. AddAspNetCoreInstrumentation subscribes the SDK to them, adds span attributes and filter/enrich hooks; exporting still needs the SDK.

solid answer

~40 s

Out of the box, the hosting layer starts an `Activity` named `Microsoft.AspNetCore.Hosting.HttpRequestIn` from the `Microsoft.AspNetCore` `ActivitySource` for each request; with logging on, as it is by default, it does so even when nothing listens, which is why `Activity.Current` and trace ids exist in a plain app. Since .NET 8 the framework also records metrics through `IMeterFactory` on built-in meters: `Microsoft.AspNetCore.Hosting` emits `http.server.request.duration` (a histogram in seconds) and `http.server.active_requests`, and Kestrel, routing, rate limiting, authentication and others have meters too. Nothing leaves the process until an SDK subscribes. On the metrics side `AddAspNetCoreInstrumentation()` is just `AddMeter` for the 13 built-in meter names, so `AddMeter("Microsoft.AspNetCore.Hosting")` works without the package. On the tracing side it subscribes to the request activity, adds semantic-convention attributes such as `http.route` and `url.path`, and offers `Filter`, `EnrichWithHttpRequest` and `RecordException`.

code

csharp · 12 lines
csharp
// Metrics without OpenTelemetry.Instrumentation.AspNetCore:
builder.Services.AddOpenTelemetry()
    .WithMetrics(m => m
        .AddMeter("Microsoft.AspNetCore.Hosting")
        .AddMeter("Microsoft.AspNetCore.Server.Kestrel"))
    .UseOtlpExporter();

// The same metrics, plus richer request spans, with the package:
builder.Services.AddOpenTelemetry()
    .WithMetrics(m => m.AddAspNetCoreInstrumentation())
    .WithTracing(t => t.AddAspNetCoreInstrumentation(o => o.RecordException = true))
    .UseOtlpExporter();

go deeper

for a junior

Recall that ASP.NET Core already creates a request Activity and records request metrics, and that the OpenTelemetry SDK is what exports them.

for a middle

Name the hosting meter and its two instruments with units, and explain that the metrics half of AddAspNetCoreInstrumentation is only AddMeter for built-in names.

for a senior

Explain when the hosting layer creates the request activity, what the tracing half of the package adds, and when to drop the package for bare AddMeter to trim dependencies.

for a principal

Judge whether teams should standardise on the instrumentation package or on explicit meter and source lists, given upgrade churn in a contrib package versus framework-owned names.

## What the framework does by itself ASP.NET Core 10 is instrumented with the runtime's own diagnostics types, so an app with **no OpenTelemetry package** already produces telemetry inside the process. It just does not send it anywhere. ### The request activity The hosting layer, which runs before any middleware, decides at the start of each request whether to create an `Activity`: - The activity is named **`Microsoft.AspNetCore.Hosting.HttpRequestIn`** and comes from an `ActivitySource` named **`Microsoft.AspNetCore`** that the web host registers in DI. - It is created when a listener subscribes to that source, **or** when logging is enabled, **or** when a `DiagnosticListener` subscriber asks for it. Because logging is on in every default app, a request normally has an activity even without an SDK. That is why `Activity.Current` is not null in a handler and why ASP.NET Core's ProblemDetails responses can carry a `traceId`. - If the incoming request carries trace context headers, the activity continues that trace instead of starting a new one. - In ASP.NET Core 10 the framework can also put OpenTelemetry semantic-convention tags on that activity itself. This is controlled by the AppContext switch **`Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryData`**, whose default is `true` (suppressed). OpenTelemetry.Instrumentation.AspNetCore 1.16.0 and later notices when the switch is set to `false` and skips the tagging it would otherwise repeat. ### The built-in meters Since .NET 8, ASP.NET Core records metrics through `IMeterFactory`. The hosting meter is the one every dashboard starts with: | Meter | Instrument | Type and unit | |---|---|---| | `Microsoft.AspNetCore.Hosting` | `http.server.request.duration` | `Histogram<double>`, seconds (`s`) | | `Microsoft.AspNetCore.Hosting` | `http.server.active_requests` | `UpDownCounter<long>`, `{request}` | The duration histogram is tagged with `http.request.method`, `url.scheme`, `http.response.status_code`, `http.route`, `network.protocol.version` and, on failure, `error.type`. Other built-in meters include `Microsoft.AspNetCore.Server.Kestrel`, `Microsoft.AspNetCore.Routing`, `Microsoft.AspNetCore.Diagnostics`, `Microsoft.AspNetCore.RateLimiting`, `Microsoft.AspNetCore.Authentication`, `Microsoft.AspNetCore.Authorization`, `Microsoft.AspNetCore.Identity`, `Microsoft.AspNetCore.Http.Connections`, `Microsoft.AspNetCore.MemoryPool` and three Blazor component meters. Instruments record only while some listener has enabled them, so an app nobody watches pays almost nothing. ## What the instrumentation package adds `OpenTelemetry.Instrumentation.AspNetCore` provides `AddAspNetCoreInstrumentation()` for both provider builders, and the two do very different amounts of work. ### On the meter builder On .NET 8 and later it calls `AddMeter` with the 13 built-in ASP.NET Core meter names listed above and does nothing else. Its own README points out the alternative: call `AddMeter("Microsoft.AspNetCore.Hosting", ...)` yourself and drop the package dependency for metrics. Before .NET 8 the package had to measure requests itself; that is the history behind the habit of always adding it. ### On the tracer builder Here the package does real work: 1. It subscribes the tracer provider to the `Microsoft.AspNetCore` source (and, with `EnableAspNetCoreSignalRSupport` defaulting to `true`, to SignalR's `Microsoft.AspNetCore.SignalR.Server` source). 2. It adds the semantic-convention attributes: `http.request.method`, `url.path`, `url.scheme`, `url.query` with values replaced by `Redacted`, `http.route`, `http.response.status_code`, `user_agent.original`, `server.address`, `server.port`, `network.protocol.version` and `error.type`. 3. It exposes `AspNetCoreTraceInstrumentationOptions`: `Filter` to drop requests, `EnrichWithHttpRequest`, `EnrichWithHttpResponse` and `EnrichWithException` to add your own tags, and `RecordException` to record exceptions as span events. ## What always needs the SDK Whether you use the package or bare `AddMeter`/`AddSource` calls, getting data out needs `OpenTelemetry.Extensions.Hosting` for `AddOpenTelemetry()` and an exporter such as `UseOtlpExporter()`. The framework produces; the SDK collects and ships. ## Seeing it for yourself A quick experiment makes the split concrete. Start from `dotnet new webapi`, add only `OpenTelemetry.Extensions.Hosting` and the console exporter, and register `WithMetrics(m => m.AddMeter("Microsoft.AspNetCore.Hosting").AddConsoleExporter())`. Call an endpoint a few times and the console prints `http.server.request.duration` with `http.route` and status-code tags, even though the ASP.NET Core instrumentation package is not installed. Add `WithTracing(t => t.AddSource("Microsoft.AspNetCore").AddConsoleExporter())` and you will see the request activity too, but with far fewer attributes than the package produces, because the package is what adds the semantic-convention tags (unless the ASP.NET Core 10 switch above is turned off). ## Choosing between them - Keep the package when you want full request-span attributes, the `Filter` and enrich hooks, or exception events; that is most services. - Use bare `AddMeter` names when a service only needs metrics and you prefer fewer third-party dependencies. - Either way, list your own meters and sources explicitly; neither route discovers custom names. ## Interview summary - **Native:** the request activity, trace-context continuation, and since .NET 8 the request and server metrics. - **Package, metrics:** a convenience list of `AddMeter` names. - **Package, traces:** subscription, standard attributes, filtering and enrichment hooks. - **SDK:** sampling, aggregation, resource and export.

  • Why is Activity.Current set in a handler of an app that never installed OpenTelemetry?
    The hosting layer creates the request activity when a listener subscribes, when a DiagnosticListener subscriber asks, or when logging is enabled. Logging is on by default, so the activity exists and `Activity.Current` points at it. It is just never exported, which is why log scopes and ProblemDetails responses can still carry its trace id.
  • What does the SuppressActivityOpenTelemetryData switch change in ASP.NET Core 10?
    With its default `true`, the framework does not add OpenTelemetry semantic-convention tags to the request activity, leaving that to the instrumentation package. Setting the AppContext switch `Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryData` to `false` lets the framework add them natively, and instrumentation 1.16.0+ then skips its duplicate tagging.

  • ASP.NET Core records no request metrics until OpenTelemetry.Instrumentation.AspNetCore is installed.
  • The request duration metric is reported in milliseconds.
  • AddAspNetCoreInstrumentation on the meter builder installs middleware that times requests.
  • The built-in ASP.NET Core metrics are exported to OTLP automatically on .NET 10.
  • Activity.Current is always null unless an OpenTelemetry tracer provider is registered.

Assumes ASP.NET Core 10: built-in ASP.NET Core metrics exist since .NET 8, and the SuppressActivityOpenTelemetryData switch is new in 10.