diff --git a/src/OpenTelemetry/Metrics/AggregatorStore.cs b/src/OpenTelemetry/Metrics/AggregatorStore.cs index 17e20ad42be..5271a329e40 100644 --- a/src/OpenTelemetry/Metrics/AggregatorStore.cs +++ b/src/OpenTelemetry/Metrics/AggregatorStore.cs @@ -221,14 +221,7 @@ internal void SnapshotDelta(int indexSnapshot) continue; } - if (this.IsExemplarEnabled()) - { - metricPoint.TakeSnapshotWithExemplar(outputDelta: true); - } - else - { - metricPoint.TakeSnapshot(outputDelta: true); - } + this.TakeMetricPointSnapshot(ref metricPoint, outputDelta: true); this.currentMetricPointBatch[this.batchSize] = i; this.batchSize++; @@ -246,14 +239,7 @@ internal void SnapshotDeltaWithMetricPointReclaim() ref var metricPointWithNoTags = ref this.metricPoints[0]; if (metricPointWithNoTags.MetricPointStatus != MetricPointStatus.NoCollectPending) { - if (this.IsExemplarEnabled()) - { - metricPointWithNoTags.TakeSnapshotWithExemplar(outputDelta: true); - } - else - { - metricPointWithNoTags.TakeSnapshot(outputDelta: true); - } + this.TakeMetricPointSnapshot(ref metricPointWithNoTags, outputDelta: true); this.currentMetricPointBatch[this.batchSize] = 0; this.batchSize++; @@ -265,14 +251,7 @@ internal void SnapshotDeltaWithMetricPointReclaim() ref var metricPointForOverflow = ref this.metricPoints[1]; if (metricPointForOverflow.MetricPointStatus != MetricPointStatus.NoCollectPending) { - if (this.IsExemplarEnabled()) - { - metricPointForOverflow.TakeSnapshotWithExemplar(outputDelta: true); - } - else - { - metricPointForOverflow.TakeSnapshot(outputDelta: true); - } + this.TakeMetricPointSnapshot(ref metricPointForOverflow, outputDelta: true); this.currentMetricPointBatch[this.batchSize] = 1; this.batchSize++; @@ -329,14 +308,7 @@ internal void SnapshotDeltaWithMetricPointReclaim() continue; } - if (this.IsExemplarEnabled()) - { - metricPoint.TakeSnapshotWithExemplar(outputDelta: true); - } - else - { - metricPoint.TakeSnapshot(outputDelta: true); - } + this.TakeMetricPointSnapshot(ref metricPoint, outputDelta: true); this.currentMetricPointBatch[this.batchSize] = i; this.batchSize++; @@ -358,14 +330,7 @@ internal void SnapshotCumulative(int indexSnapshot) continue; } - if (this.IsExemplarEnabled()) - { - metricPoint.TakeSnapshotWithExemplar(outputDelta: false); - } - else - { - metricPoint.TakeSnapshot(outputDelta: false); - } + this.TakeMetricPointSnapshot(ref metricPoint, outputDelta: false); this.currentMetricPointBatch[this.batchSize] = i; this.batchSize++; @@ -395,6 +360,18 @@ private static double[] FindDefaultHistogramBounds(in MetricStreamIdentity metri return Metric.DefaultHistogramBounds; } + private void TakeMetricPointSnapshot(ref MetricPoint metricPoint, bool outputDelta) + { + if (this.IsExemplarEnabled()) + { + metricPoint.TakeSnapshotWithExemplar(outputDelta); + } + else + { + metricPoint.TakeSnapshot(outputDelta); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void InitializeZeroTagPointIfNotInitialized() {