Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
-->
<!-- 'net7.0' is the default `TargetFramework`. Use `VersionOverride` in the project to override the package versions from a different `TargetFramework` -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="[0.13.6,0.14)" />
<PackageVersion Include="BenchmarkDotNet" Version="[0.13.10,0.14)" />
<PackageVersion Include="CommandLineParser" Version="[2.9.1,3.0)" />
<PackageVersion Include="Grpc.AspNetCore" Version="[2.55.0,3.0)" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="[2.55.0, 3.0)" />
Expand Down
8 changes: 5 additions & 3 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
`autoGenerateServiceInstanceId` is `true`.
([#4988](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4988))

* Fixed a bug where isSampled parameter wasn't properly checked in certain cases
within the `UpdateWithExemplar` method of `MetricPoint`.
([#4851](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5004))
* Fixed a Metrics SDK bug which led to `ExemplarReservoir.Offer` always being
called regardless of whether or not the `ExemplarFilter` sampled the
measurement.
([#5004](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5004))
([#5016](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5016))

## 1.7.0-alpha.1

Expand Down
32 changes: 16 additions & 16 deletions src/OpenTelemetry/Metrics/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,25 +535,25 @@ internal void UpdateWithExemplar(long number, ReadOnlySpan<KeyValuePair<string,

case AggregationType.Histogram:
{
this.UpdateHistogram((double)number, tags, true);
this.UpdateHistogram((double)number, tags, reportExemplar: true, isSampled);
break;
}

case AggregationType.HistogramWithMinMax:
{
this.UpdateHistogramWithMinMax((double)number, tags, true);
this.UpdateHistogramWithMinMax((double)number, tags, reportExemplar: true, isSampled);
break;
}

case AggregationType.HistogramWithBuckets:
{
this.UpdateHistogramWithBuckets((double)number, tags, true);
this.UpdateHistogramWithBuckets((double)number, tags, reportExemplar: true, isSampled);
break;
}

case AggregationType.HistogramWithMinMaxBuckets:
{
this.UpdateHistogramWithBucketsAndMinMax((double)number, tags, true);
this.UpdateHistogramWithBucketsAndMinMax((double)number, tags, reportExemplar: true, isSampled);
break;
}

Expand Down Expand Up @@ -762,25 +762,25 @@ internal void UpdateWithExemplar(double number, ReadOnlySpan<KeyValuePair<string

case AggregationType.Histogram:
{
this.UpdateHistogram(number, tags, true);
this.UpdateHistogram(number, tags, reportExemplar: true, isSampled);
break;
}

case AggregationType.HistogramWithMinMax:
{
this.UpdateHistogramWithMinMax(number, tags, true);
this.UpdateHistogramWithMinMax(number, tags, reportExemplar: true, isSampled);
break;
}

case AggregationType.HistogramWithBuckets:
{
this.UpdateHistogramWithBuckets(number, tags, true);
this.UpdateHistogramWithBuckets(number, tags, reportExemplar: true, isSampled);
break;
}

case AggregationType.HistogramWithMinMaxBuckets:
{
this.UpdateHistogramWithBucketsAndMinMax(number, tags, true);
this.UpdateHistogramWithBucketsAndMinMax(number, tags, reportExemplar: true, isSampled);
break;
}

Expand Down Expand Up @@ -1384,7 +1384,7 @@ private static void ReleaseLock(ref int isCriticalSectionOccupied)
Interlocked.Exchange(ref isCriticalSectionOccupied, 0);
}

private void UpdateHistogram(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false)
private void UpdateHistogram(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false, bool isSampled = false)
{
Debug.Assert(this.mpComponents?.HistogramBuckets != null, "HistogramBuckets was null");

Expand All @@ -1398,7 +1398,7 @@ private void UpdateHistogram(double number, ReadOnlySpan<KeyValuePair<string, ob
histogramBuckets.RunningSum += number;
}

if (reportExemplar)
if (reportExemplar && isSampled)
{
Debug.Assert(this.mpComponents.ExemplarReservoir != null, "ExemplarReservoir was null");

Expand All @@ -1410,7 +1410,7 @@ private void UpdateHistogram(double number, ReadOnlySpan<KeyValuePair<string, ob
ReleaseLock(ref histogramBuckets.IsCriticalSectionOccupied);
}

private void UpdateHistogramWithMinMax(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false)
private void UpdateHistogramWithMinMax(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false, bool isSampled = false)
{
Debug.Assert(this.mpComponents?.HistogramBuckets != null, "HistogramBuckets was null");

Expand All @@ -1426,7 +1426,7 @@ private void UpdateHistogramWithMinMax(double number, ReadOnlySpan<KeyValuePair<
histogramBuckets.RunningMax = Math.Max(histogramBuckets.RunningMax, number);
}

if (reportExemplar)
if (reportExemplar && isSampled)
{
Debug.Assert(this.mpComponents.ExemplarReservoir != null, "ExemplarReservoir was null");

Expand All @@ -1438,7 +1438,7 @@ private void UpdateHistogramWithMinMax(double number, ReadOnlySpan<KeyValuePair<
ReleaseLock(ref histogramBuckets.IsCriticalSectionOccupied);
}

private void UpdateHistogramWithBuckets(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false)
private void UpdateHistogramWithBuckets(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false, bool isSampled = false)
{
Debug.Assert(this.mpComponents?.HistogramBuckets != null, "HistogramBuckets was null");

Expand All @@ -1456,7 +1456,7 @@ private void UpdateHistogramWithBuckets(double number, ReadOnlySpan<KeyValuePair
histogramBuckets.RunningSum += number;
histogramBuckets.RunningBucketCounts![i]++;

if (reportExemplar)
if (reportExemplar && isSampled)
{
Debug.Assert(this.mpComponents.ExemplarReservoir != null, "ExemplarReservoir was null");

Expand All @@ -1469,7 +1469,7 @@ private void UpdateHistogramWithBuckets(double number, ReadOnlySpan<KeyValuePair
ReleaseLock(ref histogramBuckets.IsCriticalSectionOccupied);
}

private void UpdateHistogramWithBucketsAndMinMax(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false)
private void UpdateHistogramWithBucketsAndMinMax(double number, ReadOnlySpan<KeyValuePair<string, object?>> tags = default, bool reportExemplar = false, bool isSampled = false)
{
Debug.Assert(this.mpComponents?.HistogramBuckets != null, "histogramBuckets was null");

Expand All @@ -1487,7 +1487,7 @@ private void UpdateHistogramWithBucketsAndMinMax(double number, ReadOnlySpan<Key
histogramBuckets.RunningSum += number;
histogramBuckets.RunningBucketCounts![i]++;

if (reportExemplar)
if (reportExemplar && isSampled)
{
Debug.Assert(this.mpComponents.ExemplarReservoir != null, "ExemplarReservoir was null");

Expand Down
28 changes: 14 additions & 14 deletions test/Benchmarks/Metrics/ExemplarBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
using OpenTelemetry.Tests;

/*
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.23424.1000)
BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
.NET SDK=7.0.203
[Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
| Method | ExemplarFilter | Mean | Error | StdDev | Allocated |
|-------------------------- |--------------- |---------:|--------:|--------:|----------:|
| HistogramNoTagReduction | AlwaysOff | 315.5 ns | 5.93 ns | 5.55 ns | - |
| HistogramWithTagReduction | AlwaysOff | 296.4 ns | 0.95 ns | 0.89 ns | - |
| HistogramNoTagReduction | AlwaysOn | 366.5 ns | 6.96 ns | 7.74 ns | - |
| HistogramWithTagReduction | AlwaysOn | 397.1 ns | 4.09 ns | 3.82 ns | - |
| HistogramNoTagReduction | HighValueOnly | 364.8 ns | 2.73 ns | 2.28 ns | - |
| HistogramWithTagReduction | HighValueOnly | 391.9 ns | 4.38 ns | 4.10 ns | - |
.NET SDK 8.0.100-rc.2.23502.2
[Host] : .NET 7.0.13 (7.0.1323.51816), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.13 (7.0.1323.51816), X64 RyuJIT AVX2
| Method | ExemplarFilter | Mean | Error | StdDev |
|-------------------------- |--------------- |---------:|--------:|--------:|
| HistogramNoTagReduction | AlwaysOff | 316.7 ns | 1.01 ns | 0.89 ns |
| HistogramWithTagReduction | AlwaysOff | 298.9 ns | 2.44 ns | 2.16 ns |
| HistogramNoTagReduction | AlwaysOn | 359.6 ns | 1.26 ns | 1.11 ns |
| HistogramWithTagReduction | AlwaysOn | 400.1 ns | 4.16 ns | 3.90 ns |
| HistogramNoTagReduction | HighValueOnly | 325.3 ns | 3.33 ns | 2.78 ns |
Copy link
Member

Choose a reason for hiding this comment

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

💯 ! Thanks for fixing this! I was discussing last week why the perf was not improving a lot despite the Filter!

| HistogramWithTagReduction | HighValueOnly | 320.7 ns | 4.91 ns | 4.60 ns |
*/

namespace Benchmarks.Metrics;
Expand Down