Skip to content

Commit 31cea68

Browse files
KielekCodeBlanch
andauthored
[repo] Metrics instrumentations - utilize advice API for histogram boundaries (#2430)
Co-authored-by: Mikel Blanchard <[email protected]>
1 parent ab278bb commit 31cea68

File tree

13 files changed

+77
-13
lines changed

13 files changed

+77
-13
lines changed

src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
* The `http.server.request.duration` histogram (measured in seconds) produced by
6+
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)
7+
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).
8+
([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430))
9+
510
## 1.10.0-beta.1
611

712
Released 2024-Dec-09

src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInMetricsListener.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ internal sealed class HttpInMetricsListener : IDisposable
1818

1919
public HttpInMetricsListener(Meter meter, AspNetMetricsInstrumentationOptions options)
2020
{
21-
this.httpServerDuration = meter.CreateHistogram<double>(
21+
this.httpServerDuration = meter.CreateHistogram(
2222
"http.server.request.duration",
2323
unit: "s",
24-
description: "Duration of HTTP server requests.");
24+
description: "Duration of HTTP server requests.",
25+
advice: new InstrumentAdvice<double> { 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] });
2526
TelemetryHttpModule.Options.OnRequestStoppedCallback += this.OnStopActivity;
2627
this.options = options;
2728
}

src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
* The `http.server.request.duration` histogram (measured in seconds) produced by
6+
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)
7+
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).
8+
([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430))
9+
510
## 1.10.1
611

712
Released 2024-Dec-10

src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ internal sealed class HttpInMetricsListener : ListenerHandler
3333
private static readonly PropertyFetcher<HttpContext> HttpContextPropertyFetcher = new("HttpContext");
3434
private static readonly object ErrorTypeHttpContextItemsKey = new();
3535

36-
private static readonly Histogram<double> HttpServerRequestDuration = Meter.CreateHistogram<double>(HttpServerRequestDurationMetricName, "s", "Duration of HTTP server requests.");
36+
private static readonly Histogram<double> HttpServerRequestDuration = Meter.CreateHistogram(
37+
HttpServerRequestDurationMetricName,
38+
unit: "s",
39+
description: " Duration of HTTP server requests.",
40+
advice: new InstrumentAdvice<double> { 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] });
3741

3842
internal HttpInMetricsListener(string name)
3943
: base(name)

src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
span status. For details see: [Setting Status](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/README.md#setting-status).
1515
([#2358](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2358))
1616

17+
* The `messaging.receive.duration` and `messaging.publish.duration` histograms
18+
(measured in seconds) produced by the metrics instrumentation in this package
19+
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)
20+
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).
21+
([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430))
22+
1723
## 0.1.0-alpha.2
1824

1925
Released 2024-Sep-18

src/OpenTelemetry.Instrumentation.ConfluentKafka/ConfluentKafkaCommon.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,23 @@ internal static class ConfluentKafkaCommon
1919
internal static readonly string InstrumentationVersion = typeof(ConfluentKafkaCommon).Assembly.GetPackageVersion();
2020
internal static readonly ActivitySource ActivitySource = new(InstrumentationName, InstrumentationVersion);
2121
internal static readonly Meter Meter = new(InstrumentationName, InstrumentationVersion);
22-
internal static readonly Counter<long> ReceiveMessagesCounter = Meter.CreateCounter<long>(SemanticConventions.MetricMessagingReceiveMessages);
23-
internal static readonly Histogram<double> ReceiveDurationHistogram = Meter.CreateHistogram<double>(SemanticConventions.MetricMessagingReceiveDuration);
24-
internal static readonly Counter<long> PublishMessagesCounter = Meter.CreateCounter<long>(SemanticConventions.MetricMessagingPublishMessages);
25-
internal static readonly Histogram<double> PublishDurationHistogram = Meter.CreateHistogram<double>(SemanticConventions.MetricMessagingPublishDuration);
22+
internal static readonly Counter<long> ReceiveMessagesCounter = Meter.CreateCounter<long>(
23+
SemanticConventions.MetricMessagingReceiveMessages,
24+
description: "Measures the number of received messages.");
25+
26+
internal static readonly Histogram<double> ReceiveDurationHistogram = Meter.CreateHistogram(
27+
SemanticConventions.MetricMessagingReceiveDuration,
28+
unit: "s",
29+
description: "Measures the duration of receive operation.",
30+
advice: new InstrumentAdvice<double> { 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] });
31+
32+
internal static readonly Counter<long> PublishMessagesCounter = Meter.CreateCounter<long>(
33+
SemanticConventions.MetricMessagingPublishMessages,
34+
description: "Measures the number of published messages.");
35+
36+
internal static readonly Histogram<double> PublishDurationHistogram = Meter.CreateHistogram(
37+
SemanticConventions.MetricMessagingPublishDuration,
38+
unit: "s",
39+
description: "Measures the duration of publish operation.",
40+
advice: new InstrumentAdvice<double> { 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] });
2641
}

src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
* The `http.client.request.duration` histogram (measured in seconds) produced by
6+
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)
7+
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).
8+
([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430))
9+
510
## 1.10.0
611

712
Released 2024-Nov-27

src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
2222
internal static readonly string MeterVersion = AssemblyName.Version!.ToString();
2323
internal static readonly Meter Meter = new(MeterName, MeterVersion);
2424
private const string OnUnhandledExceptionEvent = "System.Net.Http.Exception";
25-
private static readonly Histogram<double> HttpClientRequestDuration = Meter.CreateHistogram<double>("http.client.request.duration", "s", "Duration of HTTP client requests.");
25+
private static readonly Histogram<double> HttpClientRequestDuration = Meter.CreateHistogram(
26+
"http.client.request.duration",
27+
unit: "s",
28+
description: "Duration of HTTP client requests.",
29+
advice: new InstrumentAdvice<double> { 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] });
2630

2731
private static readonly PropertyFetcher<HttpRequestMessage> StopRequestFetcher = new("Request");
2832
private static readonly PropertyFetcher<HttpResponseMessage> StopResponseFetcher = new("Response");

src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ internal static class HttpWebRequestActivitySource
3838
private static readonly string Version = AssemblyName.Version.ToString();
3939
private static readonly ActivitySource WebRequestActivitySource = new(ActivitySourceName, Version);
4040
private static readonly Meter WebRequestMeter = new(MeterName, Version);
41-
private static readonly Histogram<double> HttpClientRequestDuration = WebRequestMeter.CreateHistogram<double>("http.client.request.duration", "s", "Duration of HTTP client requests.");
41+
private static readonly Histogram<double> HttpClientRequestDuration = WebRequestMeter.CreateHistogram(
42+
"http.client.request.duration",
43+
unit: "s",
44+
description: "Duration of HTTP client requests.",
45+
advice: new InstrumentAdvice<double> { 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] });
4246

4347
// Fields for reflection
4448
private static FieldInfo connectionGroupListField;

src/OpenTelemetry.Instrumentation.Owin/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
span status. For details see: [Setting Status](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/README.md#setting-status).
2525
([#2358](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2358))
2626

27+
* The `http.server.request.duration` histogram (measured in seconds) produced by
28+
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)
29+
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).
30+
([#2430](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2430))
31+
2732
## 1.0.0-rc.6
2833

2934
Released 2024-Apr-19

0 commit comments

Comments
 (0)