From 06443177c2a8e790323fb56d15d8001a21199753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 5 Sep 2025 10:33:51 +0200 Subject: [PATCH 1/3] [Instrumentation.AspNet] Rename Enrich metrics options --- .../.publicApi/PublicAPI.Unshipped.txt | 8 ++++---- .../AspNetMetricsInstrumentationOptions.cs | 4 ++-- .../Implementation/HttpInListener.cs | 4 ++-- .../HttpInMetricsListenerTests.cs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/PublicAPI.Unshipped.txt index d0da244864..0efadbf575 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/PublicAPI.Unshipped.txt @@ -1,8 +1,8 @@ OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.AspNetMetricsInstrumentationOptions() -> void -OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.Enrich.get -> OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichFunc? -OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.Enrich.set -> void -OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichFunc +OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichWithHttpContext.get -> OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichWithHttpContextAction? +OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichWithHttpContext.set -> void +OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichWithHttpContextAction OpenTelemetry.Instrumentation.AspNet.AspNetTraceInstrumentationOptions OpenTelemetry.Instrumentation.AspNet.AspNetTraceInstrumentationOptions.AspNetTraceInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AspNet.AspNetTraceInstrumentationOptions.EnrichWithException.get -> System.Action? @@ -21,4 +21,4 @@ static OpenTelemetry.Metrics.AspNetInstrumentationMeterProviderBuilderExtensions static OpenTelemetry.Metrics.AspNetInstrumentationMeterProviderBuilderExtensions.AddAspNetInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, System.Action? configure) -> OpenTelemetry.Metrics.MeterProviderBuilder! static OpenTelemetry.Trace.AspNetInstrumentationTracerProviderBuilderExtensions.AddAspNetInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.AspNetInstrumentationTracerProviderBuilderExtensions.AddAspNetInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action? configure) -> OpenTelemetry.Trace.TracerProviderBuilder! -virtual OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichFunc.Invoke(System.Web.HttpContext! context, ref System.Diagnostics.TagList tags) -> void +virtual OpenTelemetry.Instrumentation.AspNet.AspNetMetricsInstrumentationOptions.EnrichWithHttpContextAction.Invoke(System.Web.HttpContext! context, ref System.Diagnostics.TagList tags) -> void diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs index ee3e4e6780..bf70146435 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs @@ -16,12 +16,12 @@ public sealed class AspNetMetricsInstrumentationOptions /// /// : the HttpContext object. Both Request and Response are available. /// : List of current tags. You can add additional tags to this list. - public delegate void EnrichFunc(HttpContext context, ref TagList tags); + public delegate void EnrichWithHttpContextAction(HttpContext context, ref TagList tags); /// /// Gets or sets a function to enrich a recorded metric with additional custom tags. /// - public EnrichFunc? Enrich { get; set; } + public EnrichWithHttpContextAction? EnrichWithHttpContext { get; set; } /// /// Gets or sets a value indicating whether emit `server.address` and `server.port` attributes. diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs index 7716c295ed..5b37de5365 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs @@ -94,11 +94,11 @@ private void RecordDuration(Activity? activity, HttpContext context, Exception? tags.Add(SemanticConventions.AttributeHttpRoute, template); } - if (options.Enrich is not null) + if (options.EnrichWithHttpContext is not null) { try { - options.Enrich(context, ref tags); + options.EnrichWithHttpContext(context, ref tags); } catch (Exception ex) { diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInMetricsListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInMetricsListenerTests.cs index 60fa935c45..f2a52c2351 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInMetricsListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInMetricsListenerTests.cs @@ -48,7 +48,7 @@ public void AspNetMetricTagsAreCollectedSuccessfully( { options.EnableServerAttributesForRequestDuration = enableServerAttributesForRequestDuration; - options.Enrich += (HttpContext context, ref TagList tags) => + options.EnrichWithHttpContext += (HttpContext context, ref TagList tags) => { if (enrichMode == "throw") { From b83413bb4d1a906bc63a494f1a35e350b912d0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 5 Sep 2025 10:35:55 +0200 Subject: [PATCH 2/3] CHANGELOG --- src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md index c27b301b68..9438dead62 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md @@ -7,11 +7,19 @@ `AspNetInstrumentationMeterProviderBuilderExtensions` and `AspNetInstrumentationTracerProviderBuilderExtensions` respectively. ([#2910](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2910)) + * **Breaking Change**: Made metrics generation independent from traces. Tracing must no longer be enabled to calculate metrics. A compatible version of `OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule` is required. ([#2970](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2970)) +* **Breaking Change**: Metrics related option renamed: + * delegate `AspNetMetricsInstrumentationOptions.EnrichFunc` to + `AspNetMetricsInstrumentationOptions.EnrichWithHttpContextAction`, + * property `AspNetMetricsInstrumentationOptions.Enrich` to + `AspNetMetricsInstrumentationOptions.EnrichWithHttpContext`. + ([#3070](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3070)) + ## 1.12.0-beta.1 Released 2025-May-05 From 66b59ecab853a084ad1263838a68ed92095046f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 5 Sep 2025 10:41:37 +0200 Subject: [PATCH 3/3] fix docs comment Co-authored-by: Martin Costello --- .../AspNetMetricsInstrumentationOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs index bf70146435..d81f76e685 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetMetricsInstrumentationOptions.cs @@ -19,7 +19,7 @@ public sealed class AspNetMetricsInstrumentationOptions public delegate void EnrichWithHttpContextAction(HttpContext context, ref TagList tags); /// - /// Gets or sets a function to enrich a recorded metric with additional custom tags. + /// Gets or sets a delegate to enrich a recorded metric with additional custom tags. /// public EnrichWithHttpContextAction? EnrichWithHttpContext { get; set; }