Skip to content

Commit

Permalink
Check isSampled parameter in UpdateWithExemplar method (#5004)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImoutoChan authored Oct 31, 2023
1 parent 86a6ba0 commit b45b8a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
`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))

## 1.7.0-alpha.1

Released 2023-Oct-16
Expand Down
44 changes: 28 additions & 16 deletions src/OpenTelemetry/Metrics/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,14 @@ internal void UpdateWithExemplar(long number, ReadOnlySpan<KeyValuePair<string,

this.runningValue.AsLong = number;

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

// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
}

ReleaseLock(ref this.mpComponents!.IsCriticalSectionOccupied);

Expand All @@ -516,11 +519,14 @@ internal void UpdateWithExemplar(long number, ReadOnlySpan<KeyValuePair<string,

this.runningValue.AsLong = number;

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

// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
}

ReleaseLock(ref this.mpComponents!.IsCriticalSectionOccupied);

Expand Down Expand Up @@ -717,11 +723,14 @@ internal void UpdateWithExemplar(double number, ReadOnlySpan<KeyValuePair<string
this.runningValue.AsDouble = number;
}

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

// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
}

ReleaseLock(ref this.mpComponents!.IsCriticalSectionOccupied);

Expand All @@ -737,11 +746,14 @@ internal void UpdateWithExemplar(double number, ReadOnlySpan<KeyValuePair<string
this.runningValue.AsDouble = number;
}

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

// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
// TODO: Need to ensure that the lock is always released.
// A custom implementation of `ExemplarReservoir.Offer` might throw an exception.
this.mpComponents.ExemplarReservoir!.Offer(number, tags);
}

ReleaseLock(ref this.mpComponents!.IsCriticalSectionOccupied);

Expand Down

0 comments on commit b45b8a9

Please sign in to comment.