From a108db4d931db6e57a3630df375b15c0309f0721 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 27 Jan 2025 11:10:12 +1100 Subject: [PATCH 1/9] use some collection expressions --- docs/metrics/customizing-the-sdk/Program.cs | 6 +- .../Controllers/WeatherForecastController.cs | 8 +- examples/Console/TestPrometheusExporter.cs | 2 +- .../Utils/Messaging/MessageReceiver.cs | 2 +- .../Context/Propagation/B3Propagator.cs | 2 +- .../Context/Propagation/BaggagePropagator.cs | 4 +- .../Logs/LogRecordSeverityExtensions.cs | 8 +- .../OtlpExporterOptionsExtensions.cs | 6 +- .../PrometheusHttpListenerOptions.cs | 2 +- .../ZipkinExporterHelperExtensions.cs | 2 +- .../B3Propagator.cs | 2 +- .../JaegerPropagator.cs | 2 +- .../TracerShim.cs | 2 +- src/Shared/MathHelper.cs | 8 +- src/Shared/Shims/NullableAttributes.cs | 2 +- test/Benchmarks/Metrics/ExemplarBenchmarks.cs | 4 +- .../Benchmarks/Metrics/HistogramBenchmarks.cs | 2 +- .../Metrics/MetricCollectBenchmarks.cs | 2 +- test/Benchmarks/Metrics/MetricsBenchmarks.cs | 2 +- .../Metrics/MetricsViewBenchmarks.cs | 6 +- .../Propagation/CompositePropagatorTest.cs | 2 +- .../Trace/SpanAttributesTest.cs | 8 +- .../ConsoleActivityExporterTest.cs | 2 +- .../OtlpLogExporterTests.cs | 4 +- .../PrometheusHttpListenerTests.cs | 8 +- ...nTelemetryMetricsBuilderExtensionsTests.cs | 4 +- .../JaegerPropagatorTest.cs | 4 +- .../Program.cs | 6 +- test/OpenTelemetry.Tests.Stress/StressTest.cs | 2 +- .../Metrics/MetricExemplarTests.cs | 12 +-- .../Metrics/MetricTestData.cs | 4 +- .../Metrics/MetricViewTests.cs | 28 +++---- .../Trace/CompositeActivityProcessorTests.cs | 12 +-- test/OpenTelemetry.Tests/Trace/LinkTest.cs | 8 +- .../Propagation/TraceContextPropagatorTest.cs | 18 ++--- .../Trace/TraceIdRatioBasedSamplerTest.cs | 74 +++++++++---------- .../Controllers/ValuesController.cs | 2 +- 37 files changed, 135 insertions(+), 137 deletions(-) diff --git a/docs/metrics/customizing-the-sdk/Program.cs b/docs/metrics/customizing-the-sdk/Program.cs index bbfd4bea98f..d7f59098f87 100644 --- a/docs/metrics/customizing-the-sdk/Program.cs +++ b/docs/metrics/customizing-the-sdk/Program.cs @@ -29,19 +29,19 @@ public static void Main() .AddView(instrumentName: "MyCounter", name: "MyCounterRenamed") // Change Histogram boundaries using the Explicit Bucket Histogram aggregation. - .AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } }) + .AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20] }) // Change Histogram to use the Base2 Exponential Bucket Histogram aggregation. .AddView(instrumentName: "MyExponentialBucketHistogram", new Base2ExponentialBucketHistogramConfiguration()) // For the instrument "MyCounterCustomTags", aggregate with only the keys "tag1", "tag2". - .AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = new string[] { "tag1", "tag2" } }) + .AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = ["tag1", "tag2"] }) // Drop the instrument "MyCounterDrop". .AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop) // Configure the Explicit Bucket Histogram aggregation with custom boundaries and new name. - .AddView(instrumentName: "histogramWithMultipleAggregations", new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 }, Name = "MyHistogramWithExplicitHistogram" }) + .AddView(instrumentName: "histogramWithMultipleAggregations", new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20], Name = "MyHistogramWithExplicitHistogram" }) // Use Base2 Exponential Bucket Histogram aggregation and new name. .AddView(instrumentName: "histogramWithMultipleAggregations", new Base2ExponentialBucketHistogramConfiguration() { Name = "MyHistogramWithBase2ExponentialBucketHistogram" }) diff --git a/examples/AspNetCore/Controllers/WeatherForecastController.cs b/examples/AspNetCore/Controllers/WeatherForecastController.cs index 3d09fe9ed61..44b8b30cbe3 100644 --- a/examples/AspNetCore/Controllers/WeatherForecastController.cs +++ b/examples/AspNetCore/Controllers/WeatherForecastController.cs @@ -12,10 +12,10 @@ namespace Examples.AspNetCore.Controllers; [Route("[controller]")] public class WeatherForecastController : ControllerBase { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching", - }; + private static readonly string[] Summaries = + [ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + ]; private static readonly HttpClient HttpClient = new(); diff --git a/examples/Console/TestPrometheusExporter.cs b/examples/Console/TestPrometheusExporter.cs index a6bc1888f2b..02a313005de 100644 --- a/examples/Console/TestPrometheusExporter.cs +++ b/examples/Console/TestPrometheusExporter.cs @@ -35,7 +35,7 @@ internal static int Run(PrometheusOptions options) .AddMeter(MyMeter.Name) .AddMeter(MyMeter2.Name) .AddPrometheusHttpListener( - o => o.UriPrefixes = new string[] { $"http://localhost:{options.Port}/" }) + o => o.UriPrefixes = [$"http://localhost:{options.Port}/"]) .Build(); var process = Process.GetCurrentProcess(); diff --git a/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs b/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs index 09de208df21..65ea650c3b1 100644 --- a/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs +++ b/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs @@ -76,7 +76,7 @@ private IEnumerable ExtractTraceContextFromBasicProperties(IBasicPropert if (props.Headers.TryGetValue(key, out var value)) { var bytes = value as byte[]; - return new[] { Encoding.UTF8.GetString(bytes) }; + return [Encoding.UTF8.GetString(bytes)]; } } catch (Exception ex) diff --git a/src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs b/src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs index 18276172106..6e3ac7450b3 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs @@ -35,7 +35,7 @@ public sealed class B3Propagator : TextMapPropagator // "Debug" sampled value. internal const string FlagsValue = "1"; - private static readonly HashSet AllFields = new() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags }; + private static readonly HashSet AllFields = [XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags]; private static readonly HashSet SampledValues = new(StringComparer.Ordinal) { SampledValue, LegacySampledValue }; diff --git a/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs index 938980931e9..927ee78b68e 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs @@ -20,8 +20,8 @@ public class BaggagePropagator : TextMapPropagator private const int MaxBaggageLength = 8192; private const int MaxBaggageItems = 180; - private static readonly char[] EqualSignSeparator = new[] { '=' }; - private static readonly char[] CommaSignSeparator = new[] { ',' }; + private static readonly char[] EqualSignSeparator = ['=']; + private static readonly char[] CommaSignSeparator = [',']; /// public override ISet Fields => new HashSet { BaggageHeaderName }; diff --git a/src/OpenTelemetry.Api/Logs/LogRecordSeverityExtensions.cs b/src/OpenTelemetry.Api/Logs/LogRecordSeverityExtensions.cs index 81453d0302f..6ca5e1bc2fe 100644 --- a/src/OpenTelemetry.Api/Logs/LogRecordSeverityExtensions.cs +++ b/src/OpenTelemetry.Api/Logs/LogRecordSeverityExtensions.cs @@ -57,8 +57,8 @@ static class LogRecordSeverityExtensions internal const string Fatal3ShortName = FatalShortName + "3"; internal const string Fatal4ShortName = FatalShortName + "4"; - private static readonly string[] LogRecordSeverityShortNames = new string[] - { + private static readonly string[] LogRecordSeverityShortNames = + [ UnspecifiedShortName, TraceShortName, @@ -89,8 +89,8 @@ static class LogRecordSeverityExtensions FatalShortName, Fatal2ShortName, Fatal3ShortName, - Fatal4ShortName, - }; + Fatal4ShortName + ]; /// /// Returns the OpenTelemetry Specification short name for the (this OtlpExporterOptions options, Ac { // Specify the maximum number of substrings to return to 2 // This treats everything that follows the first `=` in the string as the value to be added for the metadata key - var keyValueData = pair.Split(new char[] { '=' }, 2); + var keyValueData = pair.Split(['='], 2); if (keyValueData.Length != 2) { throw new ArgumentException("Headers provided in an invalid format."); @@ -174,11 +174,11 @@ public static void TryEnableIHttpClientFactoryIntegration(this OtlpExporterOptio "CreateClient", BindingFlags.Public | BindingFlags.Instance, binder: null, - new Type[] { typeof(string) }, + [typeof(string)], modifiers: null); if (createClientMethod != null) { - HttpClient? client = (HttpClient?)createClientMethod.Invoke(httpClientFactory, new object[] { httpClientName }); + HttpClient? client = (HttpClient?)createClientMethod.Invoke(httpClientFactory, [httpClientName]); if (client != null) { diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs index dbe20b726c4..8909a3bd82e 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs @@ -12,7 +12,7 @@ public class PrometheusHttpListenerOptions { internal const string DefaultScrapeEndpointPath = "/metrics"; - private IReadOnlyCollection uriPrefixes = new[] { "http://localhost:9464/" }; + private IReadOnlyCollection uriPrefixes = ["http://localhost:9464/"]; /// /// Gets or sets the path to use for the scraping endpoint. Default value: "/metrics". diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs index b7142b985a5..f29315a3f25 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs @@ -91,7 +91,7 @@ private static BaseProcessor BuildZipkinExporterProcessor( "CreateClient", BindingFlags.Public | BindingFlags.Instance, binder: null, - new Type[] { typeof(string) }, + [typeof(string)], modifiers: null); if (createClientMethod != null) { diff --git a/src/OpenTelemetry.Extensions.Propagators/B3Propagator.cs b/src/OpenTelemetry.Extensions.Propagators/B3Propagator.cs index 45239981f0a..41720f24835 100644 --- a/src/OpenTelemetry.Extensions.Propagators/B3Propagator.cs +++ b/src/OpenTelemetry.Extensions.Propagators/B3Propagator.cs @@ -35,7 +35,7 @@ public sealed class B3Propagator : TextMapPropagator // "Debug" sampled value. internal const string FlagsValue = "1"; - private static readonly HashSet AllFields = new() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags }; + private static readonly HashSet AllFields = [XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags]; private static readonly HashSet SampledValues = new(StringComparer.Ordinal) { SampledValue, LegacySampledValue }; diff --git a/src/OpenTelemetry.Extensions.Propagators/JaegerPropagator.cs b/src/OpenTelemetry.Extensions.Propagators/JaegerPropagator.cs index 045fd93e581..6ec28389d98 100644 --- a/src/OpenTelemetry.Extensions.Propagators/JaegerPropagator.cs +++ b/src/OpenTelemetry.Extensions.Propagators/JaegerPropagator.cs @@ -17,7 +17,7 @@ public class JaegerPropagator : TextMapPropagator internal const string JaegerDelimiterEncoded = "%3A"; // while the spec defines the delimiter as a ':', some clients will url encode headers. internal const string SampledValue = "1"; - internal static readonly string[] JaegerDelimiters = { JaegerDelimiter, JaegerDelimiterEncoded }; + internal static readonly string[] JaegerDelimiters = [JaegerDelimiter, JaegerDelimiterEncoded]; private static readonly int TraceId128BitLength = "0af7651916cd43dd8448eb211c80319c".Length; private static readonly int SpanIdLength = "00f067aa0ba902b7".Length; diff --git a/src/OpenTelemetry.Shims.OpenTracing/TracerShim.cs b/src/OpenTelemetry.Shims.OpenTracing/TracerShim.cs index 504b28c5a52..cbdbd9dfc76 100644 --- a/src/OpenTelemetry.Shims.OpenTracing/TracerShim.cs +++ b/src/OpenTelemetry.Shims.OpenTracing/TracerShim.cs @@ -76,7 +76,7 @@ private TextMapPropagator Propagator foreach (var entry in textMapCarrier) { - carrierMap.Add(entry.Key, new[] { entry.Value }); + carrierMap.Add(entry.Key, [entry.Value]); } static IEnumerable? GetCarrierKeyValue(Dictionary> source, string key) diff --git a/src/Shared/MathHelper.cs b/src/Shared/MathHelper.cs index 21367918d51..bb6edaa00a9 100644 --- a/src/Shared/MathHelper.cs +++ b/src/Shared/MathHelper.cs @@ -12,8 +12,8 @@ namespace OpenTelemetry.Internal; internal static class MathHelper { // https://en.wikipedia.org/wiki/Leading_zero - private static readonly byte[] LeadingZeroLookupTable = new byte[] - { + private static readonly byte[] LeadingZeroLookupTable = + [ 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -29,8 +29,8 @@ internal static class MathHelper 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LeadingZero8(byte value) diff --git a/src/Shared/Shims/NullableAttributes.cs b/src/Shared/Shims/NullableAttributes.cs index 3126b557623..a5f776258e4 100644 --- a/src/Shared/Shims/NullableAttributes.cs +++ b/src/Shared/Shims/NullableAttributes.cs @@ -51,7 +51,7 @@ internal sealed class MemberNotNullWhenAttribute : Attribute public MemberNotNullWhenAttribute(bool returnValue, string member) { ReturnValue = returnValue; - Members = new[] { member }; + Members = [member]; } public MemberNotNullWhenAttribute(bool returnValue, params string[] members) diff --git a/test/Benchmarks/Metrics/ExemplarBenchmarks.cs b/test/Benchmarks/Metrics/ExemplarBenchmarks.cs index d9369d26e3e..08592d5bc70 100644 --- a/test/Benchmarks/Metrics/ExemplarBenchmarks.cs +++ b/test/Benchmarks/Metrics/ExemplarBenchmarks.cs @@ -41,7 +41,7 @@ namespace Benchmarks.Metrics; public class ExemplarBenchmarks { private static readonly ThreadLocal ThreadLocalRandom = new(() => new Random()); - private readonly string[] dimensionValues = new string[] { "DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10" }; + private readonly string[] dimensionValues = ["DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10"]; private Histogram? histogramWithoutTagReduction; private Histogram? histogramWithTagReduction; private Counter? counterWithoutTagReduction; @@ -86,7 +86,7 @@ public void Setup() { return new MetricStreamConfiguration() { - TagKeys = new string[] { "DimName1", "DimName2", "DimName3" }, + TagKeys = ["DimName1", "DimName2", "DimName3"], ExemplarReservoirFactory = CreateExemplarReservoir, }; } diff --git a/test/Benchmarks/Metrics/HistogramBenchmarks.cs b/test/Benchmarks/Metrics/HistogramBenchmarks.cs index e30ae2ffad9..acfca3e0374 100644 --- a/test/Benchmarks/Metrics/HistogramBenchmarks.cs +++ b/test/Benchmarks/Metrics/HistogramBenchmarks.cs @@ -46,7 +46,7 @@ public class HistogramBenchmarks { private const int MaxValue = 10000; private readonly Random random = new(); - private readonly string[] dimensionValues = new string[] { "DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10" }; + private readonly string[] dimensionValues = ["DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10"]; private Histogram? histogram; private MeterProvider? meterProvider; private Meter? meter; diff --git a/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs b/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs index ac3f0cf20cb..2f236e50938 100644 --- a/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs +++ b/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs @@ -25,7 +25,7 @@ namespace Benchmarks.Metrics; public class MetricCollectBenchmarks { - private readonly string[] dimensionValues = new string[] { "DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10" }; + private readonly string[] dimensionValues = ["DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10"]; // TODO: Confirm if this needs to be thread-safe private readonly Random random = new(); diff --git a/test/Benchmarks/Metrics/MetricsBenchmarks.cs b/test/Benchmarks/Metrics/MetricsBenchmarks.cs index 117bf59a5e1..f745a7e3424 100644 --- a/test/Benchmarks/Metrics/MetricsBenchmarks.cs +++ b/test/Benchmarks/Metrics/MetricsBenchmarks.cs @@ -59,7 +59,7 @@ namespace Benchmarks.Metrics; public class MetricsBenchmarks { private readonly Random random = new(); - private readonly string[] dimensionValues = new string[] { "DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10" }; + private readonly string[] dimensionValues = ["DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10"]; private Counter? counter; private MeterProvider? meterProvider; private Meter? meter; diff --git a/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs b/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs index ce9cb40b6c5..9d40078d920 100644 --- a/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs +++ b/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs @@ -30,7 +30,7 @@ namespace Benchmarks.Metrics; public class MetricsViewBenchmarks { private static readonly ThreadLocal ThreadLocalRandom = new(() => new Random()); - private static readonly string[] DimensionValues = new string[] { "DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10" }; + private static readonly string[] DimensionValues = ["DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10"]; private static readonly int DimensionsValuesLength = DimensionValues.Length; private List? metrics; private Counter? counter; @@ -96,7 +96,7 @@ public void Setup() { this.meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter(this.meter.Name) - .AddView("nomatch", new MetricStreamConfiguration() { TagKeys = new string[] { "DimName1", "DimName2", "DimName3" } }) + .AddView("nomatch", new MetricStreamConfiguration() { TagKeys = ["DimName1", "DimName2", "DimName3"] }) .AddInMemoryExporter(this.metrics) .Build(); } @@ -104,7 +104,7 @@ public void Setup() { this.meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter(this.meter.Name) - .AddView(this.counter.Name, new MetricStreamConfiguration() { TagKeys = new string[] { "DimName1", "DimName2", "DimName3" } }) + .AddView(this.counter.Name, new MetricStreamConfiguration() { TagKeys = ["DimName1", "DimName2", "DimName3"] }) .AddInMemoryExporter(this.metrics) .Build(); } diff --git a/test/OpenTelemetry.Api.Tests/Context/Propagation/CompositePropagatorTest.cs b/test/OpenTelemetry.Api.Tests/Context/Propagation/CompositePropagatorTest.cs index b70565affa8..4c3e64c3729 100644 --- a/test/OpenTelemetry.Api.Tests/Context/Propagation/CompositePropagatorTest.cs +++ b/test/OpenTelemetry.Api.Tests/Context/Propagation/CompositePropagatorTest.cs @@ -14,7 +14,7 @@ public class CompositePropagatorTest count++; if (headers.TryGetValue(name, out var value)) { - return new[] { value }; + return [value]; } return Empty; diff --git a/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs b/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs index abf35e39350..3db2f00d47e 100644 --- a/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs +++ b/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs @@ -19,16 +19,16 @@ public void ValidateAddMethods() { var spanAttribute = new SpanAttributes(); spanAttribute.Add("key_string", "string"); - spanAttribute.Add("key_a_string", new string[] { "string" }); + spanAttribute.Add("key_a_string", ["string"]); spanAttribute.Add("key_double", 1.01); - spanAttribute.Add("key_a_double", new double[] { 1.01 }); + spanAttribute.Add("key_a_double", [1.01]); spanAttribute.Add("key_bool", true); - spanAttribute.Add("key_a_bool", new bool[] { true }); + spanAttribute.Add("key_a_bool", [true]); spanAttribute.Add("key_long", 1); - spanAttribute.Add("key_a_long", new long[] { 1 }); + spanAttribute.Add("key_a_long", [1]); Assert.Equal(8, spanAttribute.Attributes.Count); } diff --git a/test/OpenTelemetry.Exporter.Console.Tests/ConsoleActivityExporterTest.cs b/test/OpenTelemetry.Exporter.Console.Tests/ConsoleActivityExporterTest.cs index e3305513d1d..205b98d5739 100644 --- a/test/OpenTelemetry.Exporter.Console.Tests/ConsoleActivityExporterTest.cs +++ b/test/OpenTelemetry.Exporter.Console.Tests/ConsoleActivityExporterTest.cs @@ -43,6 +43,6 @@ public void VerifyConsoleActivityExporterDoesntFailWithoutActivityLinkTags() // Test that the ConsoleExporter correctly handles an Activity without Tags. using var consoleExporter = new ConsoleActivityExporter(new ConsoleExporterOptions()); - Assert.Equal(ExportResult.Success, consoleExporter.Export(new Batch(new[] { activity }, 1))); + Assert.Equal(ExportResult.Success, consoleExporter.Export(new Batch([activity], 1))); } } diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 9d14aafefe4..368ddbf1e6d 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -1449,7 +1449,7 @@ public void LogRecordLoggerNameIsExportedWhenUsingBridgeApi(string? loggerName, Assert.Single(logRecords); - var batch = new Batch(new[] { logRecords[0] }, 1); + var batch = new Batch([logRecords[0]], 1); OtlpCollector.ExportLogsServiceRequest request = CreateLogsExportRequest(DefaultSdkLimitOptions, new ExperimentalOptions(), batch, ResourceBuilder.CreateEmpty().Build()); Assert.NotNull(request); @@ -1480,7 +1480,7 @@ public void LogSerialization_ExpandsBufferForLogsAndSerializes() Assert.Single(logRecords); - var batch = new Batch(new[] { logRecords[0] }, 1); + var batch = new Batch([logRecords[0]], 1); var buffer = new byte[50]; var writePosition = ProtobufOtlpLogSerializer.WriteLogsData(ref buffer, 0, DefaultSdkLimitOptions, new(), ResourceBuilder.CreateEmpty().Build(), batch); diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs index b9b6201183e..0ac04d2f299 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs @@ -56,7 +56,7 @@ public void UriPrefixesInvalid() { Assert.Throws(() => { - TestPrometheusHttpListenerUriPrefixOptions(new string[] { "ftp://example.com" }); + TestPrometheusHttpListenerUriPrefixOptions(["ftp://example.com"]); }); } @@ -132,7 +132,7 @@ public void PrometheusHttpListenerThrowsOnStart() exporter, new() { - UriPrefixes = new string[] { address }, + UriPrefixes = [address], }); listener.Start(); @@ -158,7 +158,7 @@ public void PrometheusHttpListenerThrowsOnStart() exporter, new() { - UriPrefixes = new string[] { address! }, + UriPrefixes = [address!], }); listener.Start(); @@ -238,7 +238,7 @@ private static MeterProvider BuildMeterProvider(Meter meter, IEnumerable x.Clear().AddService("my_service", serviceInstanceId: "id1").AddAttributes(attributes)) .AddPrometheusHttpListener(options => { - options.UriPrefixes = new string[] { generatedAddress }; + options.UriPrefixes = [generatedAddress]; }) .Build(); diff --git a/test/OpenTelemetry.Extensions.Hosting.Tests/OpenTelemetryMetricsBuilderExtensionsTests.cs b/test/OpenTelemetry.Extensions.Hosting.Tests/OpenTelemetryMetricsBuilderExtensionsTests.cs index d34dc060f1e..74fe338a8cf 100644 --- a/test/OpenTelemetry.Extensions.Hosting.Tests/OpenTelemetryMetricsBuilderExtensionsTests.cs +++ b/test/OpenTelemetry.Extensions.Hosting.Tests/OpenTelemetryMetricsBuilderExtensionsTests.cs @@ -75,7 +75,7 @@ public void ReloadOfMetricsViaIConfigurationWithExportCleanupTest(bool useWithMe var source = new MemoryConfigurationSource(); var memory = new MemoryConfigurationProvider(source); - var configuration = new ConfigurationRoot(new[] { memory }); + var configuration = new ConfigurationRoot([memory]); using var host = MetricTestsBase.BuildHost( useWithMetricsStyle, @@ -167,7 +167,7 @@ public void ReloadOfMetricsViaIConfigurationWithoutExportCleanupTest(bool useWit var source = new MemoryConfigurationSource(); var memory = new MemoryConfigurationProvider(source); memory.Set($"Metrics:EnabledMetrics:{meter.Name}:Default", "true"); - var configuration = new ConfigurationRoot(new[] { memory }); + var configuration = new ConfigurationRoot([memory]); using var host = MetricTestsBase.BuildHost( useWithMetricsStyle, diff --git a/test/OpenTelemetry.Extensions.Propagators.Tests/JaegerPropagatorTest.cs b/test/OpenTelemetry.Extensions.Propagators.Tests/JaegerPropagatorTest.cs index 4e2b0486f6e..79a7b90af47 100644 --- a/test/OpenTelemetry.Extensions.Propagators.Tests/JaegerPropagatorTest.cs +++ b/test/OpenTelemetry.Extensions.Propagators.Tests/JaegerPropagatorTest.cs @@ -104,7 +104,7 @@ public void ExtractReturnsOriginalContextIfHeaderIsNotValid(string traceId, stri parentSpanId, flags); - var headers = new Dictionary { { JaegerHeader, new[] { formattedHeader } } }; + var headers = new Dictionary { { JaegerHeader, [formattedHeader] } }; // act var result = new JaegerPropagator().Extract(propagationContext, headers, Getter); @@ -128,7 +128,7 @@ public void ExtractReturnsNewContextIfHeaderIsValid(string traceId, string spanI parentSpanId, flags); - var headers = new Dictionary { { JaegerHeader, new[] { formattedHeader } } }; + var headers = new Dictionary { { JaegerHeader, [formattedHeader] } }; // act var result = new JaegerPropagator().Extract(propagationContext, headers, Getter); diff --git a/test/OpenTelemetry.Tests.Stress.Metrics/Program.cs b/test/OpenTelemetry.Tests.Stress.Metrics/Program.cs index 17360444c8e..88ae37d72c4 100644 --- a/test/OpenTelemetry.Tests.Stress.Metrics/Program.cs +++ b/test/OpenTelemetry.Tests.Stress.Metrics/Program.cs @@ -51,7 +51,7 @@ public MetricsStressTest(MetricsStressTestOptions options) if (options.PrometheusTestMetricsPort != 0) { - builder.AddPrometheusHttpListener(o => o.UriPrefixes = new string[] { $"http://localhost:{options.PrometheusTestMetricsPort}/" }); + builder.AddPrometheusHttpListener(o => o.UriPrefixes = [$"http://localhost:{options.PrometheusTestMetricsPort}/"]); } if (options.EnableExemplars) @@ -62,8 +62,8 @@ public MetricsStressTest(MetricsStressTestOptions options) if (options.AddViewToFilterTags) { builder - .AddView("TestCounter", new MetricStreamConfiguration { TagKeys = new string[] { "DimName1" } }) - .AddView("TestHistogram", new MetricStreamConfiguration { TagKeys = new string[] { "DimName1" } }); + .AddView("TestCounter", new MetricStreamConfiguration { TagKeys = ["DimName1"] }) + .AddView("TestHistogram", new MetricStreamConfiguration { TagKeys = ["DimName1"] }); } if (options.AddOtlpExporter) diff --git a/test/OpenTelemetry.Tests.Stress/StressTest.cs b/test/OpenTelemetry.Tests.Stress/StressTest.cs index cc4e1cb14fd..6daed5eb92b 100644 --- a/test/OpenTelemetry.Tests.Stress/StressTest.cs +++ b/test/OpenTelemetry.Tests.Stress/StressTest.cs @@ -71,7 +71,7 @@ public void RunSynchronously() using var meterProvider = options.PrometheusInternalMetricsPort != 0 ? Sdk.CreateMeterProviderBuilder() .AddMeter(meter.Name) .AddRuntimeInstrumentation() - .AddPrometheusHttpListener(o => o.UriPrefixes = new string[] { $"http://localhost:{options.PrometheusInternalMetricsPort}/" }) + .AddPrometheusHttpListener(o => o.UriPrefixes = [$"http://localhost:{options.PrometheusInternalMetricsPort}/"]) .Build() : null; var statistics = new MeasurementData[options.Concurrency]; diff --git a/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs b/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs index b6122c97005..16264a7ec2b 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs @@ -184,11 +184,11 @@ public void TestExemplarsObservable(MetricReaderTemporalityPreference temporalit DateTime testStartTime = DateTime.UtcNow; var exportedItems = new List(); - (double Value, bool ExpectTraceId)[] measurementValues = new (double Value, bool ExpectTraceId)[] - { + (double Value, bool ExpectTraceId)[] measurementValues = + [ (18D, false), - (19D, false), - }; + (19D, false) + ]; int measurementIndex = 0; @@ -329,7 +329,7 @@ public void TestExemplarsHistogramWithBuckets(MetricReaderTemporalityPreference var measurementValues = buckets /* 2000 is here to test overflow measurement */ - .Concat(new double[] { 2000 }) + .Concat([2000]) .Select(b => (Value: b, ExpectTraceId: false)) .ToArray(); foreach (var value in measurementValues) @@ -734,7 +734,7 @@ public void TestExemplarsFilterTags(bool enableTagFiltering) histogram.Name, new MetricStreamConfiguration() { - TagKeys = enableTagFiltering ? new string[] { "key1" } : null, + TagKeys = enableTagFiltering ? ["key1"] : null, ExemplarReservoirFactory = () => { if (testExemplarReservoir != null) diff --git a/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs b/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs index 669212a103a..28f59084036 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs @@ -45,7 +45,7 @@ public static IEnumerable ValidHistogramMinMax new object[] { new double[] { double.NegativeInfinity }, new HistogramConfiguration(), double.NegativeInfinity, double.NegativeInfinity }, new object[] { new double[] { double.NegativeInfinity, 0, double.PositiveInfinity }, new HistogramConfiguration(), double.NegativeInfinity, double.PositiveInfinity }, new object[] { new double[] { 1 }, new HistogramConfiguration(), 1, 1 }, - new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } }, -2, 101 }, + new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20] }, -2, 101 }, new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new Base2ExponentialBucketHistogramConfiguration(), 4, 101 }, }; @@ -53,7 +53,7 @@ public static IEnumerable InvalidHistogramMinMax => new List { new object[] { new double[] { 1 }, new HistogramConfiguration() { RecordMinMax = false } }, - new object[] { new double[] { 1 }, new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 }, RecordMinMax = false } }, + new object[] { new double[] { 1 }, new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20], RecordMinMax = false } }, new object[] { new double[] { 1 }, new Base2ExponentialBucketHistogramConfiguration() { RecordMinMax = false } }, }; } diff --git a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs index 109c68acebd..26506edf945 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs @@ -559,7 +559,7 @@ public void ViewToProduceCustomHistogramBound() index = 0; actualCount = 0; - expectedBucketCounts = new long[] { 5, 2, 0 }; + expectedBucketCounts = [5, 2, 0]; foreach (var histogramMeasurement in histogramPoint.GetHistogramBuckets()) { Assert.Equal(expectedBucketCounts[index], histogramMeasurement.BucketCount); @@ -652,7 +652,7 @@ public void HistogramWithAdviceBoundaries_HandlesAllTypes() var index = 0; var actualCount = 0; - long[] expectedBucketCounts = new long[] { 2, 1, 0 }; + long[] expectedBucketCounts = [2, 1, 0]; foreach (var histogramMeasurement in histogramPoint.GetHistogramBuckets()) { @@ -673,7 +673,7 @@ public void HistogramWithAdviceBoundariesSpecifiedTests(bool useViewToOverride) using var meter = new Meter(Utils.GetCurrentMethodName()); var exportedItems = new List(); IReadOnlyList adviceBoundaries = new List() { 5, 10, 20 }; - double[] viewBoundaries = new double[] { 10, 20 }; + double[] viewBoundaries = [10, 20]; using var container = this.BuildMeterProvider(out var meterProvider, builder => { @@ -729,7 +729,7 @@ public void HistogramWithAdviceBoundariesSpecifiedTests(bool useViewToOverride) var index = 0; var actualCount = 0; - long[] expectedBucketCounts = useViewToOverride ? new long[] { 5, 2, 1 } : new long[] { 3, 2, 2, 1 }; + long[] expectedBucketCounts = useViewToOverride ? [5, 2, 1] : [3, 2, 2, 1]; foreach (var histogramMeasurement in histogramPoint.GetHistogramBuckets()) { @@ -867,12 +867,12 @@ public void ViewToSelectTagKeys() .AddMeter(meter.Name) .AddView("FruitCounter", new MetricStreamConfiguration() { - TagKeys = new string[] { "name" }, + TagKeys = ["name"], Name = "NameOnly", }) .AddView("FruitCounter", new MetricStreamConfiguration() { - TagKeys = new string[] { "size" }, + TagKeys = ["size"], Name = "SizeOnly", }) .AddView("FruitCounter", new MetricStreamConfiguration() @@ -1222,11 +1222,11 @@ public void ViewConflict_TwoIdenticalInstruments_TwoViews_DifferentTags() .AddMeter(meter.Name) .AddView((instrument) => { - return new MetricStreamConfiguration { TagKeys = new[] { "key1" } }; + return new MetricStreamConfiguration { TagKeys = ["key1"] }; }) .AddView((instrument) => { - return new MetricStreamConfiguration { TagKeys = new[] { "key2" } }; + return new MetricStreamConfiguration { TagKeys = ["key2"] }; }) .AddInMemoryExporter(exportedItems)); @@ -1269,11 +1269,11 @@ public void ViewConflict_TwoIdenticalInstruments_TwoViews_SameTags() .AddMeter(meter.Name) .AddView((instrument) => { - return new MetricStreamConfiguration { TagKeys = new[] { "key1" } }; + return new MetricStreamConfiguration { TagKeys = ["key1"] }; }) .AddView((instrument) => { - return new MetricStreamConfiguration { TagKeys = new[] { "key1" } }; + return new MetricStreamConfiguration { TagKeys = ["key1"] }; }) .AddInMemoryExporter(exportedItems)); @@ -1317,11 +1317,11 @@ public void ViewConflict_TwoIdenticalInstruments_TwoViews_DifferentHistogramBoun .AddMeter(meter.Name) .AddView((instrument) => { - return new ExplicitBucketHistogramConfiguration { Boundaries = new[] { 5.0, 10.0 } }; + return new ExplicitBucketHistogramConfiguration { Boundaries = [5.0, 10.0] }; }) .AddView((instrument) => { - return new ExplicitBucketHistogramConfiguration { Boundaries = new[] { 10.0, 20.0 } }; + return new ExplicitBucketHistogramConfiguration { Boundaries = [10.0, 20.0] }; }) .AddInMemoryExporter(exportedItems)); @@ -1374,7 +1374,7 @@ public void ViewConflict_TwoIdenticalInstruments_TwoViews_DifferentHistogramBoun index = 0; actualCount = 0; - expectedBucketCounts = new long[] { 0, 2, 0 }; + expectedBucketCounts = [0, 2, 0]; foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets()) { Assert.Equal(expectedBucketCounts[index], histogramMeasurement.BucketCount); @@ -1396,7 +1396,7 @@ public void ViewConflict_TwoInstruments_OneMatchesView() { if (instrument.Name == "name") { - return new MetricStreamConfiguration { Name = "othername", TagKeys = new[] { "key1" } }; + return new MetricStreamConfiguration { Name = "othername", TagKeys = ["key1"] }; } else { diff --git a/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs b/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs index 343bfa6eec4..78f53a26714 100644 --- a/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs +++ b/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs @@ -16,7 +16,7 @@ public void CompositeActivityProcessor_BadArgs() Assert.Throws(() => new CompositeProcessor(Array.Empty>())); using var p1 = new TestActivityProcessor(null, null); - using var processor = new CompositeProcessor(new[] { p1 }); + using var processor = new CompositeProcessor([p1]); Assert.Throws(() => processor.AddProcessor(null!)); } @@ -34,7 +34,7 @@ public void CompositeActivityProcessor_CallsAllProcessorSequentially() using var activity = new Activity("test"); - using (var processor = new CompositeProcessor(new[] { p1, p2 })) + using (var processor = new CompositeProcessor([p1, p2])) { processor.OnStart(activity); processor.OnEnd(activity); @@ -52,7 +52,7 @@ public void CompositeActivityProcessor_ProcessorThrows() using var activity = new Activity("test"); - using var processor = new CompositeProcessor(new[] { p1 }); + using var processor = new CompositeProcessor([p1]); Assert.Throws(() => { processor.OnStart(activity); }); Assert.Throws(() => { processor.OnEnd(activity); }); } @@ -63,7 +63,7 @@ public void CompositeActivityProcessor_ShutsDownAll() using var p1 = new TestActivityProcessor(null, null); using var p2 = new TestActivityProcessor(null, null); - using var processor = new CompositeProcessor(new[] { p1, p2 }); + using var processor = new CompositeProcessor([p1, p2]); processor.Shutdown(); Assert.True(p1.ShutdownCalled); Assert.True(p2.ShutdownCalled); @@ -78,7 +78,7 @@ public void CompositeActivityProcessor_ForceFlush(int timeout) using var p1 = new TestActivityProcessor(null, null); using var p2 = new TestActivityProcessor(null, null); - using var processor = new CompositeProcessor(new[] { p1, p2 }); + using var processor = new CompositeProcessor([p1, p2]); processor.ForceFlush(timeout); Assert.True(p1.ForceFlushCalled); @@ -93,7 +93,7 @@ public void CompositeActivityProcessor_ForwardsParentProvider() using var p1 = new TestActivityProcessor(null, null); using var p2 = new TestActivityProcessor(null, null); - using var processor = new CompositeProcessor(new[] { p1, p2 }); + using var processor = new CompositeProcessor([p1, p2]); Assert.Null(processor.ParentProvider); Assert.Null(p1.ParentProvider); diff --git a/test/OpenTelemetry.Tests/Trace/LinkTest.cs b/test/OpenTelemetry.Tests/Trace/LinkTest.cs index b0a64793597..facff82ed76 100644 --- a/test/OpenTelemetry.Tests/Trace/LinkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/LinkTest.cs @@ -29,10 +29,10 @@ public LinkTest() this.tags.Add("MyAttributeKey1", 10L); this.tags.Add("MyAttributeKey2", true); this.tags.Add("MyAttributeKey3", 0.005); - this.tags.Add("MyAttributeKey4", new long[] { 1, 2 }); - this.tags.Add("MyAttributeKey5", new string[] { "a", "b" }); - this.tags.Add("MyAttributeKey6", new bool[] { true, false }); - this.tags.Add("MyAttributeKey7", new double[] { 0.1, -0.1 }); + this.tags.Add("MyAttributeKey4", [1, 2]); + this.tags.Add("MyAttributeKey5", ["a", "b"]); + this.tags.Add("MyAttributeKey6", [true, false]); + this.tags.Add("MyAttributeKey7", [0.1, -0.1]); } [Fact] diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs index 9c3f566b380..93d6ae49e29 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs @@ -220,13 +220,13 @@ public void Key_IllegalVendorFormat() public void MemberCountLimit() { // test_tracestate_member_count_limit - var output1 = CallTraceContextPropagator(new string[] - { + var output1 = CallTraceContextPropagator( + [ "bar01=01,bar02=02,bar03=03,bar04=04,bar05=05,bar06=06,bar07=07,bar08=08,bar09=09,bar10=10", "bar11=11,bar12=12,bar13=13,bar14=14,bar15=15,bar16=16,bar17=17,bar18=18,bar19=19,bar20=20", "bar21=21,bar22=22,bar23=23,bar24=24,bar25=25,bar26=26,bar27=27,bar28=28,bar29=29,bar30=30", - "bar31=31,bar32=32", - }); + "bar31=31,bar32=32" + ]); var expected = "bar01=01,bar02=02,bar03=03,bar04=04,bar05=05,bar06=06,bar07=07,bar08=08,bar09=09,bar10=10" + "," + "bar11=11,bar12=12,bar13=13,bar14=14,bar15=15,bar16=16,bar17=17,bar18=18,bar19=19,bar20=20" + "," + @@ -234,13 +234,13 @@ public void MemberCountLimit() "bar31=31,bar32=32"; Assert.Equal(expected, output1); - var output2 = CallTraceContextPropagator(new string[] - { + var output2 = CallTraceContextPropagator( + [ "bar01=01,bar02=02,bar03=03,bar04=04,bar05=05,bar06=06,bar07=07,bar08=08,bar09=09,bar10=10", "bar11=11,bar12=12,bar13=13,bar14=14,bar15=15,bar16=16,bar17=17,bar18=18,bar19=19,bar20=20", "bar21=21,bar22=22,bar23=23,bar24=24,bar25=25,bar26=26,bar27=27,bar28=28,bar29=29,bar30=30", - "bar31=31,bar32=32,bar33=33", - }); + "bar31=31,bar32=32,bar33=33" + ]); Assert.Empty(output2); } @@ -323,7 +323,7 @@ private static string CallTraceContextPropagator(string[] tracestate) { var headers = new Dictionary { - { TraceParent, new[] { $"00-{TraceId}-{SpanId}-01" } }, + { TraceParent, [$"00-{TraceId}-{SpanId}-01"]}, { TraceState, tracestate }, }; var f = new TraceContextPropagator(); diff --git a/test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs b/test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs index bfcdb21a3b9..f0d9d0344e3 100644 --- a/test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs +++ b/test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs @@ -32,25 +32,24 @@ public void SampleBasedOnTraceId() // is not less than probability * Long.MAX_VALUE; var notSampledtraceId = ActivityTraceId.CreateFromBytes( - new byte[] - { - 0x8F, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - }); + [ + 0x8F, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ]); Assert.Equal( SamplingDecision.Drop, defaultProbability.ShouldSample(new SamplingParameters(default, notSampledtraceId, ActivityDisplayName, ActivityKindServer, null, null)).Decision); @@ -59,25 +58,24 @@ public void SampleBasedOnTraceId() // is less than probability * Long.MAX_VALUE; var sampledtraceId = ActivityTraceId.CreateFromBytes( - new byte[] - { - 0x00, - 0x00, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - }); + [ + 0x00, + 0x00, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ]); Assert.Equal( SamplingDecision.RecordAndSample, defaultProbability.ShouldSample(new SamplingParameters(default, sampledtraceId, ActivityDisplayName, ActivityKindServer, null, null)).Decision); diff --git a/test/TestApp.AspNetCore/Controllers/ValuesController.cs b/test/TestApp.AspNetCore/Controllers/ValuesController.cs index 27a9ab0d2d3..4c8a591980e 100644 --- a/test/TestApp.AspNetCore/Controllers/ValuesController.cs +++ b/test/TestApp.AspNetCore/Controllers/ValuesController.cs @@ -12,7 +12,7 @@ public class ValuesController : Controller [HttpGet] public IEnumerable Get() { - return new string[] { "value1", "value2" }; + return ["value1", "value2"]; } // GET api/values/5 From 16a842890ad352f307906e9331c4cf967cf74e90 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 27 Jan 2025 11:11:03 +1100 Subject: [PATCH 2/9] Update TraceContextPropagatorTest.cs --- .../Trace/Propagation/TraceContextPropagatorTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs index 93d6ae49e29..a1d36aa2ccc 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs @@ -323,7 +323,7 @@ private static string CallTraceContextPropagator(string[] tracestate) { var headers = new Dictionary { - { TraceParent, [$"00-{TraceId}-{SpanId}-01"]}, + { TraceParent, [$"00-{TraceId}-{SpanId}-01"] }, { TraceState, tracestate }, }; var f = new TraceContextPropagator(); From acf179183da7958fc9cb68e3b393a568f747799c Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 30 Jan 2025 07:18:24 +1100 Subject: [PATCH 3/9] Update docs/metrics/customizing-the-sdk/Program.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Piotr Kiełkowicz --- docs/metrics/customizing-the-sdk/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/metrics/customizing-the-sdk/Program.cs b/docs/metrics/customizing-the-sdk/Program.cs index d7f59098f87..f7dee887dc7 100644 --- a/docs/metrics/customizing-the-sdk/Program.cs +++ b/docs/metrics/customizing-the-sdk/Program.cs @@ -29,7 +29,7 @@ public static void Main() .AddView(instrumentName: "MyCounter", name: "MyCounterRenamed") // Change Histogram boundaries using the Explicit Bucket Histogram aggregation. - .AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20] }) + .AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = [10.0, 20.0] }) // Change Histogram to use the Base2 Exponential Bucket Histogram aggregation. .AddView(instrumentName: "MyExponentialBucketHistogram", new Base2ExponentialBucketHistogramConfiguration()) From d4fa94a0a50a5d186f9114a33704ff17e9106733 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Feb 2025 07:28:00 +1100 Subject: [PATCH 4/9] . --- test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs | 2 +- test/OpenTelemetry.Tests/Metrics/MetricTestData.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs b/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs index 16264a7ec2b..5dff417c202 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs @@ -329,7 +329,7 @@ public void TestExemplarsHistogramWithBuckets(MetricReaderTemporalityPreference var measurementValues = buckets /* 2000 is here to test overflow measurement */ - .Concat([2000]) + .Concat([2000.0]) .Select(b => (Value: b, ExpectTraceId: false)) .ToArray(); foreach (var value in measurementValues) diff --git a/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs b/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs index 28f59084036..4392482d67a 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs @@ -45,7 +45,7 @@ public static IEnumerable ValidHistogramMinMax new object[] { new double[] { double.NegativeInfinity }, new HistogramConfiguration(), double.NegativeInfinity, double.NegativeInfinity }, new object[] { new double[] { double.NegativeInfinity, 0, double.PositiveInfinity }, new HistogramConfiguration(), double.NegativeInfinity, double.PositiveInfinity }, new object[] { new double[] { 1 }, new HistogramConfiguration(), 1, 1 }, - new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20] }, -2, 101 }, + new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new ExplicitBucketHistogramConfiguration() { Boundaries = [10.0, 20.0] }, -2, 101 }, new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new Base2ExponentialBucketHistogramConfiguration(), 4, 101 }, }; From 02a4754cc2aca1c9708c37c7a295c4a413ea2dd4 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Feb 2025 07:29:19 +1100 Subject: [PATCH 5/9] Update MetricTestData.cs --- test/OpenTelemetry.Tests/Metrics/MetricTestData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs b/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs index 4392482d67a..76084371ce1 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricTestData.cs @@ -53,7 +53,7 @@ public static IEnumerable InvalidHistogramMinMax => new List { new object[] { new double[] { 1 }, new HistogramConfiguration() { RecordMinMax = false } }, - new object[] { new double[] { 1 }, new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20], RecordMinMax = false } }, + new object[] { new double[] { 1 }, new ExplicitBucketHistogramConfiguration() { Boundaries = [10.0, 20.0], RecordMinMax = false } }, new object[] { new double[] { 1 }, new Base2ExponentialBucketHistogramConfiguration() { RecordMinMax = false } }, }; } From 2157851fe626bb884059c2ea7e51c38d69765083 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Feb 2025 07:30:38 +1100 Subject: [PATCH 6/9] Update Program.cs --- docs/metrics/customizing-the-sdk/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/metrics/customizing-the-sdk/Program.cs b/docs/metrics/customizing-the-sdk/Program.cs index f7dee887dc7..9d6fb7e546e 100644 --- a/docs/metrics/customizing-the-sdk/Program.cs +++ b/docs/metrics/customizing-the-sdk/Program.cs @@ -41,7 +41,7 @@ public static void Main() .AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop) // Configure the Explicit Bucket Histogram aggregation with custom boundaries and new name. - .AddView(instrumentName: "histogramWithMultipleAggregations", new ExplicitBucketHistogramConfiguration() { Boundaries = [10, 20], Name = "MyHistogramWithExplicitHistogram" }) + .AddView(instrumentName: "histogramWithMultipleAggregations", new ExplicitBucketHistogramConfiguration() { Boundaries = [10.0, 20.0], Name = "MyHistogramWithExplicitHistogram" }) // Use Base2 Exponential Bucket Histogram aggregation and new name. .AddView(instrumentName: "histogramWithMultipleAggregations", new Base2ExponentialBucketHistogramConfiguration() { Name = "MyHistogramWithBase2ExponentialBucketHistogram" }) From 0b3bae8b29d0356b55f8bbf30291e61be1cc6afe Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Feb 2025 17:01:20 +1100 Subject: [PATCH 7/9] Update test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Piotr Kiełkowicz --- test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs b/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs index 3db2f00d47e..94e3cff1c96 100644 --- a/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs +++ b/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs @@ -28,7 +28,7 @@ public void ValidateAddMethods() spanAttribute.Add("key_a_bool", [true]); spanAttribute.Add("key_long", 1); - spanAttribute.Add("key_a_long", [1]); + spanAttribute.Add("key_a_long", [1l]); Assert.Equal(8, spanAttribute.Attributes.Count); } From c62a1d5c9f47ec26e9df9c1c498a51d73ee5efdd Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Feb 2025 17:01:27 +1100 Subject: [PATCH 8/9] Update test/OpenTelemetry.Tests/Trace/LinkTest.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Piotr Kiełkowicz --- test/OpenTelemetry.Tests/Trace/LinkTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Tests/Trace/LinkTest.cs b/test/OpenTelemetry.Tests/Trace/LinkTest.cs index facff82ed76..79415fd617d 100644 --- a/test/OpenTelemetry.Tests/Trace/LinkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/LinkTest.cs @@ -29,7 +29,7 @@ public LinkTest() this.tags.Add("MyAttributeKey1", 10L); this.tags.Add("MyAttributeKey2", true); this.tags.Add("MyAttributeKey3", 0.005); - this.tags.Add("MyAttributeKey4", [1, 2]); + this.tags.Add("MyAttributeKey4", [1l, 2l]); this.tags.Add("MyAttributeKey5", ["a", "b"]); this.tags.Add("MyAttributeKey6", [true, false]); this.tags.Add("MyAttributeKey7", [0.1, -0.1]); From 2f53a5e8505316266f442c22efdb026286d7dde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 14 Feb 2025 11:03:39 +0100 Subject: [PATCH 9/9] fix format --- test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs | 2 +- test/OpenTelemetry.Tests/Trace/LinkTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs b/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs index 94e3cff1c96..3e327551bad 100644 --- a/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs +++ b/test/OpenTelemetry.Api.Tests/Trace/SpanAttributesTest.cs @@ -28,7 +28,7 @@ public void ValidateAddMethods() spanAttribute.Add("key_a_bool", [true]); spanAttribute.Add("key_long", 1); - spanAttribute.Add("key_a_long", [1l]); + spanAttribute.Add("key_a_long", [1L]); Assert.Equal(8, spanAttribute.Attributes.Count); } diff --git a/test/OpenTelemetry.Tests/Trace/LinkTest.cs b/test/OpenTelemetry.Tests/Trace/LinkTest.cs index 79415fd617d..e327f2a855c 100644 --- a/test/OpenTelemetry.Tests/Trace/LinkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/LinkTest.cs @@ -29,7 +29,7 @@ public LinkTest() this.tags.Add("MyAttributeKey1", 10L); this.tags.Add("MyAttributeKey2", true); this.tags.Add("MyAttributeKey3", 0.005); - this.tags.Add("MyAttributeKey4", [1l, 2l]); + this.tags.Add("MyAttributeKey4", [1L, 2L]); this.tags.Add("MyAttributeKey5", ["a", "b"]); this.tags.Add("MyAttributeKey6", [true, false]); this.tags.Add("MyAttributeKey7", [0.1, -0.1]);