Skip to content

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Dec 23, 2025

This PR adds OTEL telemetry tags to the HTTP activity:

  • Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryData now defaults to false. Telemetry is added to activity by default in .NET 11.
  • All required attributes are added to telemetry from HTTP server span spec.
  • Fixed HTTP request duration metric to include error.type attribute for 500+ response status codes

Fixes #52439

@JamesNK JamesNK added the area-hosting Includes Hosting label Dec 23, 2025
@JamesNK JamesNK requested a review from halter73 as a code owner December 23, 2025 02:16
Copilot AI review requested due to automatic review settings December 23, 2025 02:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds OpenTelemetry semantic convention tags to HTTP server activities and metrics in ASP.NET Core, aligning with OTEL specifications. The key change is that telemetry is now enabled by default in .NET 11.

  • Changes the default value of Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryData from true to false, enabling OTEL data by default
  • Adds required OTEL semantic convention attributes to HTTP activities including http.response.status_code, network.protocol.version, http.route, and error.type
  • Implements error.type attribute for HTTP server metrics with 5xx status codes, following OTEL specifications

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Shared/Diagnostics/RouteDiagnosticsHelpers.cs Updates comment to reference "telemetry attributes" instead of just "metrics"
src/Hosting/Hosting/src/Internal/HostingTelemetryHelpers.cs Adds new attribute constants for OTEL semantic conventions and implements IsErrorStatusCode helper method
src/Hosting/Hosting/src/Internal/HostingMetrics.cs Updates metrics to use attribute constants and adds error.type tag for 5xx status codes
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs Changes default to enable OTEL data, adds end tags to activities including error handling logic
src/Hosting/Hosting/test/HostingMetricsTests.cs Adds comprehensive tests for error.type behavior in metrics with various status codes
src/Hosting/Hosting/test/HostingApplicationDiagnosticsTests.cs Adds extensive tests for activity tags, error handling, and sampling scenarios

JamesNK and others added 2 commits December 23, 2025 10:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@joegoldman2
Copy link
Contributor

There might be an issue with forwarded headers handling in the current implementation. The attributes server.address, server.port, and url.scheme are currently set at the start of the activity, before the middleware pipeline is executed and the forwarded headers have been processed. This results in incorrect values for these attributes.

The specification recommends setting these attributes based on the processed forwarded headers:

HTTP server instrumentations SHOULD do the best effort when populating server.address and server.port attributes and SHOULD determine them by using the first of the following that applies:

  • The original host which may be passed by the reverse proxy in the Forwarded#host, X-Forwarded-Host, or a similar header.
  • The :authority pseudo-header in case of HTTP/2 or HTTP/3
  • The Host header.

Should these attributes also be set when the activity stops?

@joegoldman2
Copy link
Contributor

Do you plan to add specific support for activity enrichment based on the HttpRequest and HttpResponse , similar to what is available in OpenTelemetry.Instrumentation.AspNetCore? https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/c938a14321ebf64e3ef4f10a679bc3c3d71690e6/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs#L68-L86
Or is the current recommendation to use a middleware (or similar) to enrich the activity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-hosting Includes Hosting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Trace Instrumentation Support for ASP.NET Core as per OTel specification

3 participants