From 31cea68a81fbaeacbde1431898746ce4454b08d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 19 Dec 2024 20:33:33 +0100 Subject: [PATCH] [repo] Metrics instrumentations - utilize advice API for histogram boundaries (#2430) Co-authored-by: Mikel Blanchard --- .../CHANGELOG.md | 5 ++++ .../Implementation/HttpInMetricsListener.cs | 5 ++-- .../CHANGELOG.md | 5 ++++ .../Implementation/HttpInMetricsListener.cs | 6 ++++- .../CHANGELOG.md | 6 +++++ .../ConfluentKafkaCommon.cs | 23 +++++++++++++++---- .../CHANGELOG.md | 5 ++++ .../HttpHandlerMetricsDiagnosticListener.cs | 6 ++++- .../HttpWebRequestActivitySource.netfx.cs | 6 ++++- .../CHANGELOG.md | 5 ++++ .../OwinInstrumentationMetrics.cs | 6 ++++- .../CHANGELOG.md | 5 ++++ .../Implementation/SqlActivitySourceHelper.cs | 7 +++--- 13 files changed, 77 insertions(+), 13 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md index 567a32e291..eea2ca09f3 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* The `http.server.request.duration` histogram (measured in seconds) produced by + the metrics instrumentation in this package now uses the [Advice API](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.10.0/docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation) + to set default explicit buckets following the [OpenTelemetry Specification](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/http/http-metrics.md). + ([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430)) + ## 1.10.0-beta.1 Released 2024-Dec-09 diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInMetricsListener.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInMetricsListener.cs index 0dac906cb0..cf17fc867e 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInMetricsListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInMetricsListener.cs @@ -18,10 +18,11 @@ internal sealed class HttpInMetricsListener : IDisposable public HttpInMetricsListener(Meter meter, AspNetMetricsInstrumentationOptions options) { - this.httpServerDuration = meter.CreateHistogram( + this.httpServerDuration = meter.CreateHistogram( "http.server.request.duration", unit: "s", - description: "Duration of HTTP server requests."); + description: "Duration of HTTP server requests.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); TelemetryHttpModule.Options.OnRequestStoppedCallback += this.OnStopActivity; this.options = options; } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 2bb349e1fc..a4f0dc0941 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* The `http.server.request.duration` histogram (measured in seconds) produced by + the metrics instrumentation in this package now uses the [Advice API](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.10.0/docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation) + to set default explicit buckets following the [OpenTelemetry Specification](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/http/http-metrics.md). + ([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430)) + ## 1.10.1 Released 2024-Dec-10 diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs index c9040d0248..551421403a 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs @@ -33,7 +33,11 @@ internal sealed class HttpInMetricsListener : ListenerHandler private static readonly PropertyFetcher HttpContextPropertyFetcher = new("HttpContext"); private static readonly object ErrorTypeHttpContextItemsKey = new(); - private static readonly Histogram HttpServerRequestDuration = Meter.CreateHistogram(HttpServerRequestDurationMetricName, "s", "Duration of HTTP server requests."); + private static readonly Histogram HttpServerRequestDuration = Meter.CreateHistogram( + HttpServerRequestDurationMetricName, + unit: "s", + description: " Duration of HTTP server requests.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); internal HttpInMetricsListener(string name) : base(name) diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md index bd314a325b..75e3e56b90 100644 --- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md @@ -14,6 +14,12 @@ span status. For details see: [Setting Status](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/README.md#setting-status). ([#2358](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2358)) +* The `messaging.receive.duration` and `messaging.publish.duration` histograms + (measured in seconds) produced by the metrics instrumentation in this package + now uses the [Advice API](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.10.0/docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation) + to set default explicit buckets following the [OpenTelemetry Specification](https://github.com/open-telemetry/semantic-conventions/blob/v1.24.0/docs/messaging/messaging-metrics.md). + ([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430)) + ## 0.1.0-alpha.2 Released 2024-Sep-18 diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/ConfluentKafkaCommon.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/ConfluentKafkaCommon.cs index b4c024db0e..e7572b0463 100644 --- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/ConfluentKafkaCommon.cs +++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/ConfluentKafkaCommon.cs @@ -19,8 +19,23 @@ internal static class ConfluentKafkaCommon internal static readonly string InstrumentationVersion = typeof(ConfluentKafkaCommon).Assembly.GetPackageVersion(); internal static readonly ActivitySource ActivitySource = new(InstrumentationName, InstrumentationVersion); internal static readonly Meter Meter = new(InstrumentationName, InstrumentationVersion); - internal static readonly Counter ReceiveMessagesCounter = Meter.CreateCounter(SemanticConventions.MetricMessagingReceiveMessages); - internal static readonly Histogram ReceiveDurationHistogram = Meter.CreateHistogram(SemanticConventions.MetricMessagingReceiveDuration); - internal static readonly Counter PublishMessagesCounter = Meter.CreateCounter(SemanticConventions.MetricMessagingPublishMessages); - internal static readonly Histogram PublishDurationHistogram = Meter.CreateHistogram(SemanticConventions.MetricMessagingPublishDuration); + internal static readonly Counter ReceiveMessagesCounter = Meter.CreateCounter( + SemanticConventions.MetricMessagingReceiveMessages, + description: "Measures the number of received messages."); + + internal static readonly Histogram ReceiveDurationHistogram = Meter.CreateHistogram( + SemanticConventions.MetricMessagingReceiveDuration, + unit: "s", + description: "Measures the duration of receive operation.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); + + internal static readonly Counter PublishMessagesCounter = Meter.CreateCounter( + SemanticConventions.MetricMessagingPublishMessages, + description: "Measures the number of published messages."); + + internal static readonly Histogram PublishDurationHistogram = Meter.CreateHistogram( + SemanticConventions.MetricMessagingPublishDuration, + unit: "s", + description: "Measures the duration of publish operation.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); } diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index 6b909b08ac..350df7e937 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* The `http.client.request.duration` histogram (measured in seconds) produced by + the metrics instrumentation in this package now uses the [Advice API](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.10.0/docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation) + to set default explicit buckets following the [OpenTelemetry Specification](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/http/http-metrics.md). + ([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430)) + ## 1.10.0 Released 2024-Nov-27 diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs index dd3dc6970c..b6f0fb48d7 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs @@ -22,7 +22,11 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler internal static readonly string MeterVersion = AssemblyName.Version!.ToString(); internal static readonly Meter Meter = new(MeterName, MeterVersion); private const string OnUnhandledExceptionEvent = "System.Net.Http.Exception"; - private static readonly Histogram HttpClientRequestDuration = Meter.CreateHistogram("http.client.request.duration", "s", "Duration of HTTP client requests."); + private static readonly Histogram HttpClientRequestDuration = Meter.CreateHistogram( + "http.client.request.duration", + unit: "s", + description: "Duration of HTTP client requests.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); private static readonly PropertyFetcher StopRequestFetcher = new("Request"); private static readonly PropertyFetcher StopResponseFetcher = new("Response"); diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs index c28670cbd7..e9b1c6f135 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs @@ -38,7 +38,11 @@ internal static class HttpWebRequestActivitySource private static readonly string Version = AssemblyName.Version.ToString(); private static readonly ActivitySource WebRequestActivitySource = new(ActivitySourceName, Version); private static readonly Meter WebRequestMeter = new(MeterName, Version); - private static readonly Histogram HttpClientRequestDuration = WebRequestMeter.CreateHistogram("http.client.request.duration", "s", "Duration of HTTP client requests."); + private static readonly Histogram HttpClientRequestDuration = WebRequestMeter.CreateHistogram( + "http.client.request.duration", + unit: "s", + description: "Duration of HTTP client requests.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); // Fields for reflection private static FieldInfo connectionGroupListField; diff --git a/src/OpenTelemetry.Instrumentation.Owin/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Owin/CHANGELOG.md index 89a4131868..9bd787ae02 100644 --- a/src/OpenTelemetry.Instrumentation.Owin/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Owin/CHANGELOG.md @@ -24,6 +24,11 @@ span status. For details see: [Setting Status](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/README.md#setting-status). ([#2358](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2358)) +* The `http.server.request.duration` histogram (measured in seconds) produced by + the metrics instrumentation in this package now uses the [Advice API](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.10.0/docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation) + to set default explicit buckets following the [OpenTelemetry Specification](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/http/http-metrics.md). + ([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430)) + ## 1.0.0-rc.6 Released 2024-Apr-19 diff --git a/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationMetrics.cs b/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationMetrics.cs index e5d2280194..735555239c 100644 --- a/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationMetrics.cs @@ -13,5 +13,9 @@ internal static class OwinInstrumentationMetrics internal static readonly AssemblyName AssemblyName = Assembly.GetName(); internal static readonly string MeterName = AssemblyName.Name; internal static readonly Meter Instance = new(MeterName, Assembly.GetPackageVersion()); - internal static readonly Histogram HttpServerDuration = Instance.CreateHistogram("http.server.request.duration", "s", "Duration of HTTP server requests."); + internal static readonly Histogram HttpServerDuration = Instance.CreateHistogram( + "http.server.request.duration", + unit: "s", + description: "Duration of HTTP server requests.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] }); } diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md index 16f15d141d..e1e5f5c1ee 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md @@ -5,6 +5,11 @@ * **Breaking change** The `EnableConnectionLevelAttributes` option has been removed. ([#2414](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2414)) +* The `db.client.operation.duration` histogram (measured in seconds) produced by + the metrics instrumentation in this package now uses the [Advice API](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.10.0/docs/metrics/customizing-the-sdk/README.md#explicit-bucket-histogram-aggregation) + to set default explicit buckets following the [OpenTelemetry Specification](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/database/database-metrics.md). + ([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430)) + ## 1.10.0-beta.1 Released 2024-Dec-09 diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs index a332be18b7..b1ad4815ab 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs @@ -25,10 +25,11 @@ internal sealed class SqlActivitySourceHelper public static readonly string MeterName = AssemblyName.Name!; public static readonly Meter Meter = new(MeterName, Assembly.GetPackageVersion()); - public static readonly Histogram DbClientOperationDuration = Meter.CreateHistogram( + public static readonly Histogram DbClientOperationDuration = Meter.CreateHistogram( "db.client.operation.duration", - "s", - "Duration of database client operations."); + unit: "s", + description: "Duration of database client operations.", + advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10] }); internal static readonly string[] SharedTagNames = [