diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66e1d3f4ed1..a8455b9c787 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ On all platforms, the minimum requirements are: ### Linux or MacOS -* Visual Studio for Mac or Visual Studio Code +* Visual Studio 2022+ for Mac or Visual Studio Code Mono might be required by your IDE but is not required by this project. This is because unit tests targeting .NET Framework (i.e: `net461`) are disabled outside @@ -56,7 +56,7 @@ of Windows. ### Windows -* Visual Studio 2017+ or Visual Studio Code +* Visual Studio 2022+ or Visual Studio Code * .NET Framework 4.6.1+ ### Public API diff --git a/docs/metrics/extending-the-sdk/MyExporterExtensions.cs b/docs/metrics/extending-the-sdk/MyExporterExtensions.cs index 1caf3197f98..23e174e3eb9 100644 --- a/docs/metrics/extending-the-sdk/MyExporterExtensions.cs +++ b/docs/metrics/extending-the-sdk/MyExporterExtensions.cs @@ -15,7 +15,6 @@ // using System; -using OpenTelemetry; using OpenTelemetry.Metrics; internal static class MyExporterExtensions diff --git a/examples/Console/Program.cs b/examples/Console/Program.cs index 3ee742505f3..d00d11db443 100644 --- a/examples/Console/Program.cs +++ b/examples/Console/Program.cs @@ -15,7 +15,6 @@ // using CommandLine; -using OpenTelemetry.Exporter; namespace Examples.Console { diff --git a/examples/Console/TestLogs.cs b/examples/Console/TestLogs.cs index d9ed4dc88c3..195fe41fefc 100644 --- a/examples/Console/TestLogs.cs +++ b/examples/Console/TestLogs.cs @@ -15,11 +15,7 @@ // using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using OpenTelemetry; using OpenTelemetry.Logs; namespace Examples.Console @@ -33,7 +29,7 @@ internal static object Run(LogsOptions options) builder.AddOpenTelemetry((opt) => { opt.IncludeFormattedMessage = true; - if (options.UseExporter.ToLower() == "otlp") + if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase)) { /* * Prerequisite to run this example: diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index 4f726a5c6f4..1f41b5380f3 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -36,7 +36,7 @@ internal static object Run(MetricsOptions options) .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("myservice")) .AddMeter(meter.Name); // All instruments from this meter are enabled. - if (options.UseExporter.ToLower() == "otlp") + if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase)) { /* * Prerequisite to run this example: diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs index cd045f089d9..938cde89d6c 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs @@ -75,7 +75,7 @@ public override ExportResult Export(in Batch batch) Console.WriteLine(msg.ToString()); - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { string valueDisplay = string.Empty; StringBuilder tagsBuilder = new StringBuilder(); diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs index 5ec44df3c16..eafacb2f979 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs @@ -148,7 +148,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) sum.IsMonotonic = true; sum.AggregationTemporality = temporality; - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var dataPoint = new OtlpMetrics.NumberDataPoint { @@ -172,7 +172,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) sum.IsMonotonic = true; sum.AggregationTemporality = temporality; - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var dataPoint = new OtlpMetrics.NumberDataPoint { @@ -193,7 +193,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) case MetricType.LongGauge: { var gauge = new OtlpMetrics.Gauge(); - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var dataPoint = new OtlpMetrics.NumberDataPoint { @@ -214,7 +214,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) case MetricType.DoubleGauge: { var gauge = new OtlpMetrics.Gauge(); - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var dataPoint = new OtlpMetrics.NumberDataPoint { @@ -237,7 +237,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) var histogram = new OtlpMetrics.Histogram(); histogram.AggregationTemporality = temporality; - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var dataPoint = new OtlpMetrics.HistogramDataPoint { diff --git a/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs b/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs index 226c45ad559..805a51a2488 100644 --- a/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs +++ b/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs @@ -40,7 +40,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) if (!metric.MetricType.IsHistogram()) { - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var tags = metricPoint.Tags; var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds(); @@ -52,18 +52,13 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) { buffer[cursor++] = unchecked((byte)'{'); - int i = 0; foreach (var tag in tags) { - if (i++ > 0) - { - buffer[cursor++] = unchecked((byte)','); - } - cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value); + buffer[cursor++] = unchecked((byte)','); } - buffer[cursor++] = unchecked((byte)'}'); + buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra. } buffer[cursor++] = unchecked((byte)' '); @@ -103,7 +98,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) } else { - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { var tags = metricPoint.Tags; var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds(); @@ -151,18 +146,13 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) { buffer[cursor++] = unchecked((byte)'{'); - int i = 0; foreach (var tag in tags) { - if (i++ > 0) - { - buffer[cursor++] = unchecked((byte)','); - } - cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value); + buffer[cursor++] = unchecked((byte)','); } - buffer[cursor++] = unchecked((byte)'}'); + buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra. } buffer[cursor++] = unchecked((byte)' '); @@ -182,18 +172,13 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) { buffer[cursor++] = unchecked((byte)'{'); - int i = 0; foreach (var tag in tags) { - if (i++ > 0) - { - buffer[cursor++] = unchecked((byte)','); - } - cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value); + buffer[cursor++] = unchecked((byte)','); } - buffer[cursor++] = unchecked((byte)'}'); + buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra. } buffer[cursor++] = unchecked((byte)' '); diff --git a/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterOptions.cs b/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterOptions.cs index cea95b37c04..e42fcb89bc3 100644 --- a/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterOptions.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using OpenTelemetry.Internal; namespace OpenTelemetry.Exporter { @@ -65,10 +66,7 @@ public int ScrapeResponseCacheDurationMilliseconds get => this.scrapeResponseCacheDurationMilliseconds; set { - if (value < 0) - { - throw new ArgumentOutOfRangeException(nameof(value), "Value should be greater than or equal to zero."); - } + Guard.Range(value, nameof(value), min: 0); this.scrapeResponseCacheDurationMilliseconds = value; } diff --git a/src/OpenTelemetry.Exporter.Zipkin/README.md b/src/OpenTelemetry.Exporter.Zipkin/README.md index 49689c7d39a..ba7775805f4 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/README.md +++ b/src/OpenTelemetry.Exporter.Zipkin/README.md @@ -40,8 +40,8 @@ take precedence over the environment variables. instance that will be used at runtime to transmit spans over HTTP. See [Configure HttpClient](#configure-httpclient) for more details. -* `MaxPayloadSizeInBytes`: Maximum payload size - for .NET versions **other** - than 4.5.2 (default 4096). +* `MaxPayloadSizeInBytes`: Maximum payload size of UTF8 JSON chunks sent to + Zipkin (default 4096). * `ServiceName`: Name of the service reporting telemetry. If the `Resource` associated with the telemetry has "service.name" defined, then it'll be diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index 14d254ec782..4441a861cbd 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -4,7 +4,7 @@ * Fixed an issue with `Filter` and `Enrich` callbacks not firing under certain conditions when gRPC is used - ([#2698](https://github.com/open-telemetry/opentelemetry-dotnet/issues/2698)) + ([#2698](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2698)) ## 1.0.0-rc8 diff --git a/src/OpenTelemetry/Metrics/AggregatorStore.cs b/src/OpenTelemetry/Metrics/AggregatorStore.cs index 8b495209a8b..a4b3df38aef 100644 --- a/src/OpenTelemetry/Metrics/AggregatorStore.cs +++ b/src/OpenTelemetry/Metrics/AggregatorStore.cs @@ -79,12 +79,7 @@ internal AggregatorStore( { this.updateLongCallback = this.UpdateLongCustomTags; this.updateDoubleCallback = this.UpdateDoubleCustomTags; - var hs = new HashSet(StringComparer.Ordinal); - foreach (var key in tagKeysInteresting) - { - hs.Add(key); - } - + var hs = new HashSet(tagKeysInteresting, StringComparer.Ordinal); this.tagKeysInteresting = hs; this.tagsKeysInterestingCount = hs.Count; } diff --git a/src/OpenTelemetry/Metrics/MeterProviderSdk.cs b/src/OpenTelemetry/Metrics/MeterProviderSdk.cs index eb8e87dfbec..992061f38a8 100644 --- a/src/OpenTelemetry/Metrics/MeterProviderSdk.cs +++ b/src/OpenTelemetry/Metrics/MeterProviderSdk.cs @@ -89,12 +89,7 @@ internal MeterProviderSdk( } else if (meterSources.Any()) { - var meterSourcesToSubscribe = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (var meterSource in meterSources) - { - meterSourcesToSubscribe.Add(meterSource); - } - + var meterSourcesToSubscribe = new HashSet(meterSources, StringComparer.OrdinalIgnoreCase); shouldListenTo = instrument => meterSourcesToSubscribe.Contains(instrument.Meter.Name); } diff --git a/src/OpenTelemetry/Metrics/MetricPointsAccessor.cs b/src/OpenTelemetry/Metrics/MetricPointsAccessor.cs index 5bd2f1a211a..1fd3cac7cd2 100644 --- a/src/OpenTelemetry/Metrics/MetricPointsAccessor.cs +++ b/src/OpenTelemetry/Metrics/MetricPointsAccessor.cs @@ -76,7 +76,7 @@ internal Enumerator(MetricPoint[] metricsPoints, int[] metricPointsToProcess, lo /// /// Gets the at the current position of the enumerator. /// - public ref MetricPoint Current + public ref readonly MetricPoint Current { get { diff --git a/src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs b/src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs index ef88b44f353..01f87cba712 100644 --- a/src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs +++ b/src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs @@ -30,7 +30,7 @@ public abstract class TracerProviderBuilderBase : TracerProviderBuilder private readonly List instrumentationFactories = new List(); private readonly List> processors = new List>(); private readonly List sources = new List(); - private readonly Dictionary legacyActivityOperationNames = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly HashSet legacyActivityOperationNames = new HashSet(StringComparer.OrdinalIgnoreCase); private ResourceBuilder resourceBuilder = ResourceBuilder.CreateDefault(); private Sampler sampler = new ParentBasedSampler(new AlwaysOnSampler()); @@ -76,7 +76,7 @@ public override TracerProviderBuilder AddLegacySource(string operationName) { Guard.NullOrWhitespace(operationName, nameof(operationName)); - this.legacyActivityOperationNames[operationName] = true; + this.legacyActivityOperationNames.Add(operationName); return this; } diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index 980d2028788..200cd33e791 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -43,7 +43,7 @@ internal TracerProviderSdk( IEnumerable instrumentationFactories, Sampler sampler, List> processors, - Dictionary legacyActivityOperationNames) + HashSet legacyActivityOperationNames) { this.Resource = resource; this.sampler = sampler; @@ -53,10 +53,10 @@ internal TracerProviderSdk( Regex legacyActivityWildcardModeRegex = null; foreach (var legacyName in legacyActivityOperationNames) { - if (legacyName.Key.Contains('*')) + if (legacyName.Contains('*')) { legacyActivityWildcardMode = true; - legacyActivityWildcardModeRegex = GetWildcardRegex(legacyActivityOperationNames.Keys); + legacyActivityWildcardModeRegex = GetWildcardRegex(legacyActivityOperationNames); break; } } @@ -85,7 +85,7 @@ internal TracerProviderSdk( } else { - legacyActivityPredicate = activity => legacyActivityOperationNames.ContainsKey(activity.OperationName); + legacyActivityPredicate = activity => legacyActivityOperationNames.Contains(activity.OperationName); } listener.ActivityStarted = activity => @@ -242,12 +242,7 @@ internal TracerProviderSdk( } else { - var activitySources = new HashSet(StringComparer.OrdinalIgnoreCase); - - foreach (var name in sources) - { - activitySources.Add(name); - } + var activitySources = new HashSet(sources, StringComparer.OrdinalIgnoreCase); if (this.supportLegacyActivity) { diff --git a/test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs b/test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs index 65b58caa811..05126d5b092 100644 --- a/test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs +++ b/test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs @@ -16,10 +16,8 @@ extern alias Prometheus; -using System; using System.Collections.Generic; using System.Diagnostics.Metrics; -using System.IO; using BenchmarkDotNet.Attributes; using OpenTelemetry; using OpenTelemetry.Metrics; diff --git a/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs b/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs index ba87cb3adfa..11cbb0fdf0c 100644 --- a/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs +++ b/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs @@ -69,7 +69,7 @@ void ProcessExport(Batch batch) if (this.UseWithRef) { // The performant way of iterating. - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { sum += metricPoint.GetSumDouble(); } diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/ExportClient/OtlpHttpTraceExportClientTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/ExportClient/OtlpHttpTraceExportClientTests.cs index 964e4b0ac7a..fe5b8d7b5a4 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/ExportClient/OtlpHttpTraceExportClientTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/ExportClient/OtlpHttpTraceExportClientTests.cs @@ -20,7 +20,9 @@ using System.Linq; using System.Net.Http; using System.Threading; +#if !NET5_0_OR_GREATER using System.Threading.Tasks; +#endif using Moq; using Moq.Protected; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; diff --git a/test/OpenTelemetry.Exporter.Prometheus.Tests/PrometheusSerializerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.Tests/PrometheusSerializerTests.cs index a204f330bb1..9ce27c9d63b 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.Tests/PrometheusSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.Tests/PrometheusSerializerTests.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using System; using System.Collections.Generic; using System.Diagnostics.Metrics; using System.Text; diff --git a/test/OpenTelemetry.Extensions.Hosting.Tests/HostingMeterExtensionTests.cs b/test/OpenTelemetry.Extensions.Hosting.Tests/HostingMeterExtensionTests.cs index ea55aa58d93..9ed9e3a1f75 100644 --- a/test/OpenTelemetry.Extensions.Hosting.Tests/HostingMeterExtensionTests.cs +++ b/test/OpenTelemetry.Extensions.Hosting.Tests/HostingMeterExtensionTests.cs @@ -15,7 +15,6 @@ // using System; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; diff --git a/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/HttpContextHelper.cs b/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/HttpContextHelper.cs index 0c0e2827803..ebb5ede4f05 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/HttpContextHelper.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/HttpContextHelper.cs @@ -89,7 +89,7 @@ public override string GetUnknownRequestHeader(string name) public override string GetKnownRequestHeader(int index) { - var name = HttpWorkerRequest.GetKnownRequestHeaderName(index); + var name = GetKnownRequestHeaderName(index); if (this.headers.ContainsKey(name)) { diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs index b5845ca4775..bfeda28b387 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Mvc.Testing; using OpenTelemetry.Exporter; using OpenTelemetry.Metrics; -using OpenTelemetry.Tests; using OpenTelemetry.Trace; #if NETCOREAPP3_1 using TestApp.AspNetCore._3._1; diff --git a/test/OpenTelemetry.Shims.OpenTracing.Tests/SpanBuilderShimTests.cs b/test/OpenTelemetry.Shims.OpenTracing.Tests/SpanBuilderShimTests.cs index 8ee3a9d85d9..42625e14783 100644 --- a/test/OpenTelemetry.Shims.OpenTracing.Tests/SpanBuilderShimTests.cs +++ b/test/OpenTelemetry.Shims.OpenTracing.Tests/SpanBuilderShimTests.cs @@ -122,7 +122,7 @@ public void Start_ActivityOperationRootSpanChecks() { // Create an activity var activity = new Activity("foo") - .SetIdFormat(System.Diagnostics.ActivityIdFormat.W3C) + .SetIdFormat(ActivityIdFormat.W3C) .Start(); // matching root operation name diff --git a/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs b/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs index 995db8daac1..5f5914be28e 100644 --- a/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs @@ -48,7 +48,7 @@ public void InMemoryExporterShouldDeepCopyMetricPoints() var metric = exportedItems[0]; // Only one Metric object is added to the collection at this point var metricPointsEnumerator = metric.GetMetricPoints().GetEnumerator(); Assert.True(metricPointsEnumerator.MoveNext()); // One MetricPoint is emitted for the Metric - ref var metricPointForFirstExport = ref metricPointsEnumerator.Current; + ref readonly var metricPointForFirstExport = ref metricPointsEnumerator.Current; Assert.Equal(10, metricPointForFirstExport.GetSumLong()); // Emit 25 for the MetricPoint with a single key-vaue pair: ("tag1", "value1") diff --git a/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs b/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs index d157fbeedd8..edf65d9d75c 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs @@ -58,7 +58,7 @@ public void ObserverCallbackTest() var metric = exportedItems[0]; Assert.Equal("myGauge", metric.Name); List metricPoints = new List(); - foreach (ref var mp in metric.GetMetricPoints()) + foreach (ref readonly var mp in metric.GetMetricPoints()) { metricPoints.Add(mp); } @@ -88,7 +88,7 @@ public void ObserverCallbackExceptionTest() var metric = exportedItems[0]; Assert.Equal("myGauge", metric.Name); List metricPoints = new List(); - foreach (ref var mp in metric.GetMetricPoints()) + foreach (ref readonly var mp in metric.GetMetricPoints()) { metricPoints.Add(mp); } @@ -450,7 +450,7 @@ int MetricPointCount() foreach (var metric in exportedItems) { - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { count++; } @@ -696,7 +696,7 @@ private static long GetLongSum(List metrics) long sum = 0; foreach (var metric in metrics) { - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { if (metric.MetricType.IsSum()) { @@ -717,7 +717,7 @@ private static double GetDoubleSum(List metrics) double sum = 0; foreach (var metric in metrics) { - foreach (ref var metricPoint in metric.GetMetricPoints()) + foreach (ref readonly var metricPoint in metric.GetMetricPoints()) { if (metric.MetricType.IsSum()) { diff --git a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs index d3e356072bc..2f76de70efc 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs @@ -380,7 +380,7 @@ public void ViewToProduceCustomHistogramBound() Assert.Equal("MyHistogram", metricCustom.Name); List metricPointsDefault = new List(); - foreach (ref var mp in metricDefault.GetMetricPoints()) + foreach (ref readonly var mp in metricDefault.GetMetricPoints()) { metricPointsDefault.Add(mp); } @@ -407,7 +407,7 @@ public void ViewToProduceCustomHistogramBound() Assert.Equal(Metric.DefaultHistogramBounds.Length + 1, actualCount); List metricPointsCustom = new List(); - foreach (ref var mp in metricCustom.GetMetricPoints()) + foreach (ref readonly var mp in metricCustom.GetMetricPoints()) { metricPointsCustom.Add(mp); } @@ -465,7 +465,7 @@ public void ViewToSelectTagKeys() var metric = exportedItems[0]; Assert.Equal("NameOnly", metric.Name); List metricPoints = new List(); - foreach (ref var mp in metric.GetMetricPoints()) + foreach (ref readonly var mp in metric.GetMetricPoints()) { metricPoints.Add(mp); } @@ -476,7 +476,7 @@ public void ViewToSelectTagKeys() metric = exportedItems[1]; Assert.Equal("SizeOnly", metric.Name); metricPoints.Clear(); - foreach (ref var mp in metric.GetMetricPoints()) + foreach (ref readonly var mp in metric.GetMetricPoints()) { metricPoints.Add(mp); } @@ -487,7 +487,7 @@ public void ViewToSelectTagKeys() metric = exportedItems[2]; Assert.Equal("NoTags", metric.Name); metricPoints.Clear(); - foreach (ref var mp in metric.GetMetricPoints()) + foreach (ref readonly var mp in metric.GetMetricPoints()) { metricPoints.Add(mp); } diff --git a/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs b/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs index 03a87f92a52..ba08b0644a5 100644 --- a/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using System; using System.Collections.Generic; using System.Diagnostics.Metrics; using OpenTelemetry.Exporter; @@ -112,7 +111,7 @@ private void AssertLongSumValueForMetric(Metric metric, long value) var metricPoints = metric.GetMetricPoints(); var metricPointsEnumerator = metricPoints.GetEnumerator(); Assert.True(metricPointsEnumerator.MoveNext()); // One MetricPoint is emitted for the Metric - ref var metricPointForFirstExport = ref metricPointsEnumerator.Current; + ref readonly var metricPointForFirstExport = ref metricPointsEnumerator.Current; if (metric.MetricType.IsSum()) { Assert.Equal(value, metricPointForFirstExport.GetSumLong());