Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The HTTP server Activity created by Microsoft.AspNetCore.Hosting now emits the OpenTelemetry HTTP server-span semantic-convention tags by default, and its http.route tag uses the resolved values of conventional-route default parameters. StatusDescription is no longer set when an unhandled exception occurs. Together, these changes bring the built-in Microsoft.AspNetCore.Hosting activity into line with the metadata produced by OpenTelemetry.Instrumentation.AspNetCore.
Version introduced
.NET 11
Previous behavior
Previously:
- The
Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryDataAppContextswitch defaulted totrue, so the framework's HTTP serverActivitydidn't carry OpenTelemetry HTTP server-span tags. Apps that wanted those tags usedOpenTelemetry.Instrumentation.AspNetCoreto add them, or set the switch tofalseexplicitly. - The
http.routetag on the activity used the raw route template. For conventional routes such as{controller=Home}/{action=Index}/{id?}, every endpoint that resolved through the conventional pipeline reported the samehttp.routevalue. - When an unhandled exception escaped the request pipeline, the framework set
Activity.StatustoErrorand also setActivity.StatusDescriptionto the exception message.
New behavior
Starting in ASP.NET Core 11:
Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryDatadefaults tofalse. The framework's HTTP serverActivitynow carries the OpenTelemetry HTTP server-span tags out of the box. The added tags includehttp.request.method,http.response.status_code,http.route,network.protocol.version,url.path,url.scheme,server.address,server.port, anduser_agent.original. See the OpenTelemetry HTTP server span spec for the full set of attributes.- The HTTP request duration metric (
http.server.request.duration) carries an additionalerror.typedimension for5xxresponses. - For conventional routes, the
http.routetag has the{controller},{action},{area}, and{page}parameters replaced by their resolved values. For example, a request toStore/Checkoutmatched by the conventional route{controller=Home}/{action=Index}/{id?}now reportshttp.route = "Store/Checkout/{id?}"instead of"{controller=Home}/{action=Index}/{id?}". - When an unhandled exception escapes the request pipeline, the framework sets
Activity.StatustoErrorbut does not setActivity.StatusDescription. The exception is still recorded as anActivityevent with the standardexception.type,exception.message, andexception.stacktracetags, and the exception type is reflected in theerror.typemetric dimension.
Type of breaking change
This is a behavioral change.
Reason for change
Aligning the built-in hosting activity with the OpenTelemetry HTTP server-span specification lets apps observe their HTTP behavior without taking an extra dependency on OpenTelemetry.Instrumentation.AspNetCore. Using resolved route values in http.route matches the OpenTelemetry guidance for that tag and produces more useful aggregations in dashboards. Not setting Activity.StatusDescription on exceptions aligns with OpenTelemetry.Instrumentation.AspNetCore (which already left it unset) and avoids putting potentially sensitive exception messages in places that aren't designed to receive them.
For more information, see dotnet/aspnetcore#64851, dotnet/aspnetcore#64854, and dotnet/aspnetcore#65825.
Recommended action
Most apps don't need to do anything—the new defaults match what OpenTelemetry.Instrumentation.AspNetCore already produced.
If you observe duplicate tags because both the framework and OpenTelemetry.Instrumentation.AspNetCore add the same set, upgrade the instrumentation package to the latest version, which detects the built-in tags and skips adding them.
If you have a custom span enricher or exporter that depended on the absence of these tags, on the previous http.route format, or on Activity.StatusDescription being populated, update it. The error.type metric dimension also grows the cardinality of the duration metric for 5xx responses; review your metrics backend's cardinality budget if you previously aggregated by status code only.
To restore the pre-11 behavior (no OpenTelemetry semantic-convention tags from the framework), set the AppContext switch back to true early in app startup:
AppContext.SetSwitch(
"Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryData", true);
The switch only controls the OpenTelemetry tags. The http.route value-substitution change and the Activity.StatusDescription change can't be reverted independently.
Affected APIs
Microsoft.AspNetCore.Hosting.HostingHostBuilderExtensions- System.Diagnostics.Activity.StatusDescription
- The OpenTelemetry HTTP server span semantic conventions.
ASP.NET Core