Skip to content

Commit 299a6c1

Browse files
authored
Remove zero bucket for the histogram buckets for ASP.NET Core and HttpClient metrics (#5021)
1 parent d91be77 commit 299a6c1

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/OpenTelemetry/CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@
1717
([#5004](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5004))
1818
([#5016](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5016))
1919

20-
* Update `AggregatorStore` to provide known connection metrics with larger
21-
histogram buckets.
20+
* Update Metrics SDK to override the default histogram buckets for the following
21+
metrics from ASP.NET Core and HttpClient runtime:
22+
* `signalr.server.connection.duration`
23+
* `kestrel.connection.duration`
24+
* `http.client.connection.duration`
25+
26+
These histogram metrics which have their `Unit` as `s` (second) will have
27+
their default histogram buckets as `[ 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2,
28+
5, 10, 30, 60, 120, 300 ]`.
2229
([#5008](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5008))
30+
([#5021](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5021))
31+
32+
* Remove the bucket with value `0` for histogram buckets for all metrics from
33+
ASP.NET Core and HttpClient.
34+
([#5021](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5021))
2335

2436
## 1.7.0-alpha.1
2537

src/OpenTelemetry/Metrics/Metric.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public sealed class Metric
3030
internal static readonly double[] DefaultHistogramBounds = new double[] { 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000 };
3131

3232
// Short default histogram bounds. Based on the recommended semantic convention values for http.server.request.duration.
33-
internal static readonly double[] DefaultHistogramBoundsShortSeconds = new double[] { 0, 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 };
33+
internal static readonly double[] DefaultHistogramBoundsShortSeconds = new double[] { 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 };
3434
internal static readonly HashSet<(string, string)> DefaultHistogramBoundShortMappings = new()
3535
{
3636
("Microsoft.AspNetCore.Hosting", "http.server.request.duration"),
@@ -45,7 +45,7 @@ public sealed class Metric
4545
};
4646

4747
// Long default histogram bounds. Not based on a standard. May change in the future.
48-
internal static readonly double[] DefaultHistogramBoundsLongSeconds = new double[] { 0, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300 };
48+
internal static readonly double[] DefaultHistogramBoundsLongSeconds = new double[] { 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300 };
4949
internal static readonly HashSet<(string, string)> DefaultHistogramBoundLongMappings = new()
5050
{
5151
("Microsoft.AspNetCore.Http.Connections", "signalr.server.connection.duration"),

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,15 @@ private static KeyValuePair<string, object>[] AssertMetricPoint_New(
583583
histogramBounds.Add(t.ExplicitBound);
584584
}
585585

586-
Assert.Equal(
587-
expected: new List<double> { 0, 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, double.PositiveInfinity },
588-
actual: histogramBounds);
586+
// TODO: Remove the check for the older bounds once 1.7.0 is released. This is a temporary fix for instrumentation libraries CI workflow.
587+
588+
var expectedHistogramBoundsOld = new List<double> { 0, 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, double.PositiveInfinity };
589+
var expectedHistogramBoundsNew = new List<double> { 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, double.PositiveInfinity };
590+
591+
var histogramBoundsMatchCorrectly = Enumerable.SequenceEqual(expectedHistogramBoundsOld, histogramBounds) ||
592+
Enumerable.SequenceEqual(expectedHistogramBoundsNew, histogramBounds);
593+
594+
Assert.True(histogramBoundsMatchCorrectly);
589595

590596
return attributes;
591597
}

test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,15 @@ private static async Task HttpOutCallsAreCollectedSuccessfullyBodyAsync(
545545
histogramBounds.Add(t.ExplicitBound);
546546
}
547547

548-
Assert.Equal(
549-
expected: new List<double> { 0, 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, double.PositiveInfinity },
550-
actual: histogramBounds);
548+
// TODO: Remove the check for the older bounds once 1.7.0 is released. This is a temporary fix for instrumentation libraries CI workflow.
549+
550+
var expectedHistogramBoundsOld = new List<double> { 0, 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, double.PositiveInfinity };
551+
var expectedHistogramBoundsNew = new List<double> { 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, double.PositiveInfinity };
552+
553+
var histogramBoundsMatchCorrectly = Enumerable.SequenceEqual(expectedHistogramBoundsOld, histogramBounds) ||
554+
Enumerable.SequenceEqual(expectedHistogramBoundsNew, histogramBounds);
555+
556+
Assert.True(histogramBoundsMatchCorrectly);
551557
}
552558
}
553559
}

0 commit comments

Comments
 (0)