Skip to content

Commit

Permalink
Check isSampled parameter in UpdateWithExemplar method and call Exemp…
Browse files Browse the repository at this point in the history
…larReservoir!.Offer only when it's true
  • Loading branch information
ImoutoChan committed Oct 28, 2023
1 parent 86a6ba0 commit eccfe68
Showing 1 changed file with 28 additions and 16 deletions.
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 eccfe68

Please sign in to comment.