From afe43426a9e23d4e2f26d5992730e0282b19a24b Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 13 Nov 2024 09:29:15 -0800 Subject: [PATCH] [geneva] Tweak OtlpProtobufSerializer to access MetricPoint by ref (#2310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Piotr Kiełkowicz --- .../OtlpProtobuf/OtlpProtobufSerializer.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/Metrics/OtlpProtobuf/OtlpProtobufSerializer.cs b/src/OpenTelemetry.Exporter.Geneva/Metrics/OtlpProtobuf/OtlpProtobufSerializer.cs index e837fc327c..68c3ab36b5 100644 --- a/src/OpenTelemetry.Exporter.Geneva/Metrics/OtlpProtobuf/OtlpProtobufSerializer.cs +++ b/src/OpenTelemetry.Exporter.Geneva/Metrics/OtlpProtobuf/OtlpProtobufSerializer.cs @@ -354,7 +354,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) this.metricPointTagAndLengthIndex = cursor; this.metricPointValueIndex = cursor + TagAndLengthSize; - foreach (var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { try { @@ -363,7 +363,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) var sum = metricPoint.GetSumLong(); - this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, metricPoint, sum); + this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, in metricPoint, sum); // Finish writing current batch this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType); @@ -394,7 +394,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) this.metricPointTagAndLengthIndex = cursor; this.metricPointValueIndex = cursor + TagAndLengthSize; - foreach (var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { try { @@ -403,7 +403,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) var sum = metricPoint.GetSumDouble(); - this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, metricPoint, sum); + this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, in metricPoint, sum); // Finish writing current batch this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType); @@ -427,7 +427,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) this.metricPointTagAndLengthIndex = cursor; this.metricPointValueIndex = cursor + TagAndLengthSize; - foreach (var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { try { @@ -436,7 +436,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) var lastValue = metricPoint.GetGaugeLastValueLong(); - this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, metricPoint, lastValue); + this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, in metricPoint, lastValue); // Finish writing current batch this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType); @@ -460,7 +460,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) this.metricPointTagAndLengthIndex = cursor; this.metricPointValueIndex = cursor + TagAndLengthSize; - foreach (var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { try { @@ -469,7 +469,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) var lastValue = metricPoint.GetGaugeLastValueDouble(); - this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, metricPoint, lastValue); + this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, in metricPoint, lastValue); // Finish writing current batch this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType); @@ -496,7 +496,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) this.metricPointTagAndLengthIndex = cursor; this.metricPointValueIndex = cursor + TagAndLengthSize; - foreach (var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { try { @@ -579,7 +579,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) this.metricPointTagAndLengthIndex = cursor; this.metricPointValueIndex = cursor + TagAndLengthSize; - foreach (var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { try { @@ -664,7 +664,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric) } } - private void WriteNumberDataPoint(byte[] buffer, ref int cursor, int fieldNumber, MetricPoint metricPoint, T value) + private void WriteNumberDataPoint(byte[] buffer, ref int cursor, int fieldNumber, in MetricPoint metricPoint, T value) { if (typeof(T) == typeof(long)) {