Skip to content

Commit

Permalink
Use default Batch if no metrics are available to collect (#2391)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Sep 21, 2021
1 parent 47e1c5e commit 29110dc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ internal Batch<Metric> Collect()
// Record all observable instruments
this.listener.RecordObservableInstruments();
var indexSnapShot = Math.Min(this.metricIndex, MaxMetrics - 1);
for (int i = 0; i < indexSnapShot + 1; i++)
var target = indexSnapShot + 1;
for (int i = 0; i < target; i++)
{
this.metrics[i].SnapShot();
}

return new Batch<Metric>(this.metrics, indexSnapShot + 1);
return (target > 0) ? new Batch<Metric>(this.metrics, indexSnapShot + 1) : default;
}
catch (Exception)
{
Expand Down

0 comments on commit 29110dc

Please sign in to comment.