Skip to content

Promote AddHttpLatencyTelemetry to stable - #7730

Open
EasyL0ver wants to merge 3 commits into
mainfrom
users/pkudlacik/http-latency-enricher-followup
Open

EasyL0ver wants to merge 3 commits into
mainfrom
users/pkudlacik/http-latency-enricher-followup

Conversation

@EasyL0ver

@EasyL0ver EasyL0ver commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Promotes AddHttpLatencyTelemetry (incoming HTTP request latency log enricher, package Microsoft.AspNetCore.Diagnostics.Middleware) to stable public API, documents the required companion services, and fixes a delimiter-escaping bug in the enricher.

Changes

  • Remove the [Experimental(EXTEXP0013)] attribute from HttpLatencyTelemetryServiceCollectionExtensions and its AddHttpLatencyTelemetry method, plus the now-unused usings.
  • Regenerate the public API baseline via ApiChief so the type and method move to Stage: Stable.
  • Document the required latency services (AddLatencyContext, AddRequestLatencyTelemetry, AddRequestCheckpoint) in the XML remarks and the package README example.
  • Fix a bug in HttpLatencyLogEnricher: the LatencyInfo value escaped only the list-item separator / and left the section separator , and the client application name field unescaped, so a client name (or tag value) containing , or / could shift the positional layout and corrupt the value. Both , and / are now escaped to _ across every string field, including the client name, keeping the v1.0 format. Scoped to the incoming enricher; the outgoing HttpClient enricher has the same class of defect and is tracked in Outgoing HttpClient LatencyInfo enricher value has incomplete escaping #7757.

This mirrors the already-stable outgoing-request equivalent HttpClientLatencyTelemetryExtensions.AddHttpClientLatencyTelemetry.

Validation

  • Library builds with 0 warnings.
  • All 188 tests in Microsoft.AspNetCore.Diagnostics.Middleware.Tests pass, including a new test asserting the client name delimiters are escaped.

Closes #7729

Note

Draft pending API review approval of #7729.

Remove the [Experimental(EXTEXP0013)] attribute from
HttpLatencyTelemetryServiceCollectionExtensions and its AddHttpLatencyTelemetry
method, and regenerate the public API baseline so the type and method move to
Stage: Stable. This mirrors the already-stable outgoing-request equivalent
HttpClientLatencyTelemetryExtensions.AddHttpClientLatencyTelemetry.

Pending API review approval of #7729.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 544c8b44-3b80-41b2-b9be-e60561adaa97
@EasyL0ver
EasyL0ver force-pushed the users/pkudlacik/http-latency-enricher-followup branch from 73b3732 to ad6cec5 Compare September 3, 2026 12:50
Update the AddHttpLatencyTelemetry XML remarks and the package README example to include the required AddLatencyContext call (and name the UseRequestCheckpoint/UseRequestLatencyTelemetry middleware), so the documented setup actually produces an ILatencyContext instead of throwing or silently no-op'ing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 373d48a1-1c50-4f3b-b1ae-555139892620
@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.64 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.32 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 57.59 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.03 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 69.93 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 67.36 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 84
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597709&view=codecoverage-tab

The incoming latency enricher escaped only the list-item separator '/' and left
the section separator ',' and the client application name field unescaped, so a
client name (or tag value) containing ',' or '/' could shift the positional
LatencyInfo layout. Escape both ',' and '/' to '_' across every string field,
including the client name, keeping the v1.0 format. Fix is scoped to the incoming
enricher; the outgoing HttpClient enricher is tracked in #7757.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 373d48a1-1c50-4f3b-b1ae-555139892620
@EasyL0ver
EasyL0ver marked this pull request as ready for review September 15, 2026 17:57
@EasyL0ver
EasyL0ver requested a review from a team as a code owner September 15, 2026 17:57
Copilot AI lite review requested due to automatic review settings September 15, 2026 17:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Delimiter-escaping coverage and README setup corrections remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Promotes AddHttpLatencyTelemetry to stable and fixes delimiter escaping in serialized latency data.

Changes:

  • Removes experimental API annotations and updates the API baseline.
  • Documents required latency services and usage examples.
  • Escapes commas and slashes across latency string fields.
  • Adds regression coverage for delimiter escaping.
File summaries
File Summary
test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Latency/Internal/HttpLatencyLogEnricherTests.cs Adds client-name delimiter coverage; broader latency-field coverage remains requested.
src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/README.md Updates setup documentation; example corrections remain requested.
src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Microsoft.AspNetCore.Diagnostics.Middleware.json Updates the API baseline to stable.
src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Latency/Internal/HttpLatencyLogEnricher.cs Escapes delimiters across serialized string fields.
src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Latency/HttpLatencyTelemetryServiceCollectionExtensions.cs Promotes the API and documents prerequisites.
Review details

Suppressed comments (2)

src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Latency/Internal/HttpLatencyLogEnricher.cs:64

  • The new helper changes serialization for tag names/values, checkpoint names, and measure names, but the added test only puts delimiters in the client header; MockLatencyData covers / but no , in those fields. A regression in any of these new comma-escaping paths would therefore pass the suite. Add comma-containing names/values (or assert the complete nine-section output) for the latency data fields as well.
        AppendSpanEscapingDelimiters(sb, latencyData.Tags, a => a.Name);
        _ = sb.Append(',');
        AppendSpanEscapingDelimiters(sb, latencyData.Tags, a => a.Value);

test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Latency/Internal/HttpLatencyLogEnricherTests.cs:81

  • This test only puts delimiters in the client header. The updated serializer also routes tag names/values, checkpoint names, and measure names through the new escaping path, while MockLatencyData currently exercises only / in those fields. Please add comma-containing latency-data fields and assert the positional layout so a regression at any of these call sites cannot pass unnoticed.
    public void HttpLatencyLogEnricher_EscapesDelimiters_InClientName()
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLatencyContext();
@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.64 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.32 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 57.59 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.03 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 71.61 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 67.21 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 84
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597895&view=codecoverage-tab

/// Extensions for enriching incoming HTTP request logs with latency telemetry.
/// </summary>
[Experimental(diagnosticId: DiagnosticIds.Experiments.HttpLogging, UrlFormat = DiagnosticIds.UrlFormat)]
public static class HttpLatencyTelemetryServiceCollectionExtensions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please rename as approved #7729 (comment)

Suggested change
public static class HttpLatencyTelemetryServiceCollectionExtensions
public static class HttpLoggingServiceCollectionExtensions

as well as the .cs file name

/// that an <see cref="Microsoft.Extensions.Diagnostics.Latency.ILatencyContext"/> is available for each request.
/// </remarks>
[Experimental(diagnosticId: DiagnosticIds.Experiments.HttpLogging, UrlFormat = DiagnosticIds.UrlFormat)]
public static IServiceCollection AddHttpLatencyTelemetry(this IServiceCollection services)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public static IServiceCollection AddHttpLatencyTelemetry(this IServiceCollection services)
public static IServiceCollection AddHttpServerLatencyTelemetry(this IServiceCollection services)

rename as approved

/// <summary>
/// Extensions for enriching incoming HTTP request logs with latency telemetry.
/// </summary>
[Experimental(diagnosticId: DiagnosticIds.Experiments.HttpLogging, UrlFormat = DiagnosticIds.UrlFormat)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's not remove the attribute for now. Since the changes were requested at the API review and pre-approved, the right course of action is to rename stuff to the API approved shape, release it in that shape at least once, and then remove the attribute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so in 10.11.0 version we release it with approved changes but in experimental form, and then in 11.0.0 version we release it in production form.

@dotnet-policy-service dotnet-policy-service Bot added the waiting-author-feedback 📭 The author of this issue needs to respond in order for us to continue investigating this issue. label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-author-feedback 📭 The author of this issue needs to respond in order for us to continue investigating this issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: AddHttpLatencyTelemetry for incoming HTTP request logs

4 participants