Add OTEL semantic conventions tags to HTTP server activity#64851
Add OTEL semantic conventions tags to HTTP server activity#64851
Conversation
There was a problem hiding this comment.
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.SuppressActivityOpenTelemetryDatafrom 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, anderror.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 |
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
|
There might be an issue with forwarded headers handling in the current implementation. The attributes The specification recommends setting these attributes based on the processed forwarded headers:
Should these attributes also be set when the activity stops? |
|
Do you plan to add specific support for activity enrichment based on the |
No plans for special events. |
I don't know. I looked at what OpenTelemetry.Instrumentation.AspNetCore does and it doesn't appear to have any special logic. Those tags are set at the same of the request. The guiding principal of this improvement is to match OpenTelemetry.Instrumentation.AspNetCore tag output. |
There is an open issue in OTel repo because of this behavior: open-telemetry/opentelemetry-dotnet-contrib#2231 |
|
@BrennanConroy @halter73 Please review when you have some time. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
62ef656 to
ca09352
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
7067ce8 to
53b8993
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
This PR adds OTEL telemetry tags to the HTTP activity:
Microsoft.AspNetCore.Hosting.SuppressActivityOpenTelemetryDatanow defaults to false. Telemetry is added to activity by default in .NET 11.The goal is to match the metadata set on the activity by OpenTelemetry.Instrumentation.AspNetCore.
Fixes #52439