use some collection expressions (#6106)
Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com> Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
This commit is contained in:
parent
ec9f76127e
commit
71e6cb49aa
|
|
@ -29,19 +29,19 @@ public class Program
|
|||
.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.0, 20.0] })
|
||||
|
||||
// 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.0, 20.0], Name = "MyHistogramWithExplicitHistogram" })
|
||||
|
||||
// Use Base2 Exponential Bucket Histogram aggregation and new name.
|
||||
.AddView(instrumentName: "histogramWithMultipleAggregations", new Base2ExponentialBucketHistogramConfiguration() { Name = "MyHistogramWithBase2ExponentialBucketHistogram" })
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ using Microsoft.AspNetCore.Mvc;
|
|||
[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();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ internal class TestPrometheusExporter
|
|||
.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();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public sealed class B3Propagator : TextMapPropagator
|
|||
// "Debug" sampled value.
|
||||
internal const string FlagsValue = "1";
|
||||
|
||||
private static readonly HashSet<string> AllFields = new() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags };
|
||||
private static readonly HashSet<string> AllFields = [XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags];
|
||||
|
||||
private static readonly HashSet<string> SampledValues = new(StringComparer.Ordinal) { SampledValue, LegacySampledValue };
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = [','];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ISet<string> Fields => new HashSet<string> { BaggageHeaderName };
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ internal
|
|||
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 @@ internal
|
|||
FatalShortName,
|
||||
Fatal2ShortName,
|
||||
Fatal3ShortName,
|
||||
Fatal4ShortName,
|
||||
};
|
||||
Fatal4ShortName
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Returns the OpenTelemetry Specification short name for the <see
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ internal static class OtlpExporterOptionsExtensions
|
|||
{
|
||||
// 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 @@ internal static class OtlpExporterOptionsExtensions
|
|||
"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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class PrometheusHttpListenerOptions
|
|||
{
|
||||
internal const string DefaultScrapeEndpointPath = "/metrics";
|
||||
|
||||
private IReadOnlyCollection<string> uriPrefixes = new[] { "http://localhost:9464/" };
|
||||
private IReadOnlyCollection<string> uriPrefixes = ["http://localhost:9464/"];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to use for the scraping endpoint. Default value: "/metrics".
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public static class ZipkinExporterHelperExtensions
|
|||
"CreateClient",
|
||||
BindingFlags.Public | BindingFlags.Instance,
|
||||
binder: null,
|
||||
new Type[] { typeof(string) },
|
||||
[typeof(string)],
|
||||
modifiers: null);
|
||||
if (createClientMethod != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public sealed class B3Propagator : TextMapPropagator
|
|||
// "Debug" sampled value.
|
||||
internal const string FlagsValue = "1";
|
||||
|
||||
private static readonly HashSet<string> AllFields = new() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags };
|
||||
private static readonly HashSet<string> AllFields = [XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags];
|
||||
|
||||
private static readonly HashSet<string> SampledValues = new(StringComparer.Ordinal) { SampledValue, LegacySampledValue };
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class TracerShim : global::OpenTracing.ITracer
|
|||
|
||||
foreach (var entry in textMapCarrier)
|
||||
{
|
||||
carrierMap.Add(entry.Key, new[] { entry.Value });
|
||||
carrierMap.Add(entry.Key, [entry.Value]);
|
||||
}
|
||||
|
||||
static IEnumerable<string>? GetCarrierKeyValue(Dictionary<string, IEnumerable<string>> source, string key)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace System.Diagnostics.CodeAnalysis
|
|||
public MemberNotNullWhenAttribute(bool returnValue, string member)
|
||||
{
|
||||
ReturnValue = returnValue;
|
||||
Members = new[] { member };
|
||||
Members = [member];
|
||||
}
|
||||
|
||||
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace Benchmarks.Metrics;
|
|||
public class ExemplarBenchmarks
|
||||
{
|
||||
private static readonly ThreadLocal<Random> 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<double>? histogramWithoutTagReduction;
|
||||
private Histogram<double>? histogramWithTagReduction;
|
||||
private Counter<long>? counterWithoutTagReduction;
|
||||
|
|
@ -86,7 +86,7 @@ public class ExemplarBenchmarks
|
|||
{
|
||||
return new MetricStreamConfiguration()
|
||||
{
|
||||
TagKeys = new string[] { "DimName1", "DimName2", "DimName3" },
|
||||
TagKeys = ["DimName1", "DimName2", "DimName3"],
|
||||
ExemplarReservoirFactory = CreateExemplarReservoir,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<long>? histogram;
|
||||
private MeterProvider? meterProvider;
|
||||
private Meter? meter;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<long>? counter;
|
||||
private MeterProvider? meterProvider;
|
||||
private Meter? meter;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Benchmarks.Metrics;
|
|||
public class MetricsViewBenchmarks
|
||||
{
|
||||
private static readonly ThreadLocal<Random> 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<Metric>? metrics;
|
||||
private Counter<long>? counter;
|
||||
|
|
@ -96,7 +96,7 @@ public class MetricsViewBenchmarks
|
|||
{
|
||||
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 class MetricsViewBenchmarks
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class CompositePropagatorTest
|
|||
count++;
|
||||
if (headers.TryGetValue(name, out var value))
|
||||
{
|
||||
return new[] { value };
|
||||
return [value];
|
||||
}
|
||||
|
||||
return Empty;
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@ public class SpanAttributesTest
|
|||
{
|
||||
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", [1L]);
|
||||
|
||||
Assert.Equal(8, spanAttribute.Attributes.Count);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ public class ConsoleActivityExporterTest
|
|||
|
||||
// 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<Activity>(new[] { activity }, 1)));
|
||||
Assert.Equal(ExportResult.Success, consoleExporter.Export(new Batch<Activity>([activity], 1)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1449,7 +1449,7 @@ public class OtlpLogExporterTests
|
|||
|
||||
Assert.Single(logRecords);
|
||||
|
||||
var batch = new Batch<LogRecord>(new[] { logRecords[0] }, 1);
|
||||
var batch = new Batch<LogRecord>([logRecords[0]], 1);
|
||||
OtlpCollector.ExportLogsServiceRequest request = CreateLogsExportRequest(DefaultSdkLimitOptions, new ExperimentalOptions(), batch, ResourceBuilder.CreateEmpty().Build());
|
||||
|
||||
Assert.NotNull(request);
|
||||
|
|
@ -1480,7 +1480,7 @@ public class OtlpLogExporterTests
|
|||
|
||||
Assert.Single(logRecords);
|
||||
|
||||
var batch = new Batch<LogRecord>(new[] { logRecords[0] }, 1);
|
||||
var batch = new Batch<LogRecord>([logRecords[0]], 1);
|
||||
|
||||
var buffer = new byte[50];
|
||||
var writePosition = ProtobufOtlpLogSerializer.WriteLogsData(ref buffer, 0, DefaultSdkLimitOptions, new(), ResourceBuilder.CreateEmpty().Build(), batch);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class PrometheusHttpListenerTests
|
|||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
TestPrometheusHttpListenerUriPrefixOptions(new string[] { "ftp://example.com" });
|
||||
TestPrometheusHttpListenerUriPrefixOptions(["ftp://example.com"]);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ public class PrometheusHttpListenerTests
|
|||
exporter,
|
||||
new()
|
||||
{
|
||||
UriPrefixes = new string[] { address },
|
||||
UriPrefixes = [address],
|
||||
});
|
||||
|
||||
listener.Start();
|
||||
|
|
@ -158,7 +158,7 @@ public class PrometheusHttpListenerTests
|
|||
exporter,
|
||||
new()
|
||||
{
|
||||
UriPrefixes = new string[] { address! },
|
||||
UriPrefixes = [address!],
|
||||
});
|
||||
|
||||
listener.Start();
|
||||
|
|
@ -238,7 +238,7 @@ public class PrometheusHttpListenerTests
|
|||
.ConfigureResource(x => x.Clear().AddService("my_service", serviceInstanceId: "id1").AddAttributes(attributes))
|
||||
.AddPrometheusHttpListener(options =>
|
||||
{
|
||||
options.UriPrefixes = new string[] { generatedAddress };
|
||||
options.UriPrefixes = [generatedAddress];
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class OpenTelemetryMetricsBuilderExtensionsTests
|
|||
|
||||
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 class OpenTelemetryMetricsBuilderExtensionsTests
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class JaegerPropagatorTest
|
|||
parentSpanId,
|
||||
flags);
|
||||
|
||||
var headers = new Dictionary<string, string[]> { { JaegerHeader, new[] { formattedHeader } } };
|
||||
var headers = new Dictionary<string, string[]> { { JaegerHeader, [formattedHeader] } };
|
||||
|
||||
// act
|
||||
var result = new JaegerPropagator().Extract(propagationContext, headers, Getter);
|
||||
|
|
@ -128,7 +128,7 @@ public class JaegerPropagatorTest
|
|||
parentSpanId,
|
||||
flags);
|
||||
|
||||
var headers = new Dictionary<string, string[]> { { JaegerHeader, new[] { formattedHeader } } };
|
||||
var headers = new Dictionary<string, string[]> { { JaegerHeader, [formattedHeader] } };
|
||||
|
||||
// act
|
||||
var result = new JaegerPropagator().Extract(propagationContext, headers, Getter);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public static class Program
|
|||
|
||||
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 static class Program
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public abstract class StressTest<T> : IDisposable
|
|||
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];
|
||||
|
|
|
|||
|
|
@ -184,11 +184,11 @@ public class MetricExemplarTests : MetricTestsBase
|
|||
DateTime testStartTime = DateTime.UtcNow;
|
||||
var exportedItems = new List<Metric>();
|
||||
|
||||
(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 class MetricExemplarTests : MetricTestsBase
|
|||
|
||||
var measurementValues = buckets
|
||||
/* 2000 is here to test overflow measurement */
|
||||
.Concat(new double[] { 2000 })
|
||||
.Concat([2000.0])
|
||||
.Select(b => (Value: b, ExpectTraceId: false))
|
||||
.ToArray();
|
||||
foreach (var value in measurementValues)
|
||||
|
|
@ -734,7 +734,7 @@ public class MetricExemplarTests : MetricTestsBase
|
|||
histogram.Name,
|
||||
new MetricStreamConfiguration()
|
||||
{
|
||||
TagKeys = enableTagFiltering ? new string[] { "key1" } : null,
|
||||
TagKeys = enableTagFiltering ? ["key1"] : null,
|
||||
ExemplarReservoirFactory = () =>
|
||||
{
|
||||
if (testExemplarReservoir != null)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class MetricTestData
|
|||
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.0, 20.0] }, -2, 101 },
|
||||
new object[] { new double[] { 5, 100, 4, 101, -2, 97 }, new Base2ExponentialBucketHistogramConfiguration(), 4, 101 },
|
||||
};
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public class MetricTestData
|
|||
=> new List<object[]>
|
||||
{
|
||||
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.0, 20.0], RecordMinMax = false } },
|
||||
new object[] { new double[] { 1 }, new Base2ExponentialBucketHistogramConfiguration() { RecordMinMax = false } },
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ public class MetricViewTests : MetricTestsBase
|
|||
|
||||
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 class MetricViewTests : MetricTestsBase
|
|||
|
||||
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 class MetricViewTests : MetricTestsBase
|
|||
using var meter = new Meter(Utils.GetCurrentMethodName());
|
||||
var exportedItems = new List<Metric>();
|
||||
IReadOnlyList<long> adviceBoundaries = new List<long>() { 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 class MetricViewTests : MetricTestsBase
|
|||
|
||||
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 class MetricViewTests : MetricTestsBase
|
|||
.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 class MetricViewTests : MetricTestsBase
|
|||
.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 class MetricViewTests : MetricTestsBase
|
|||
.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 class MetricViewTests : MetricTestsBase
|
|||
.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 class MetricViewTests : MetricTestsBase
|
|||
|
||||
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 class MetricViewTests : MetricTestsBase
|
|||
{
|
||||
if (instrument.Name == "name")
|
||||
{
|
||||
return new MetricStreamConfiguration { Name = "othername", TagKeys = new[] { "key1" } };
|
||||
return new MetricStreamConfiguration { Name = "othername", TagKeys = ["key1"] };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class CompositeActivityProcessorTests
|
|||
Assert.Throws<ArgumentException>(() => new CompositeProcessor<Activity>(Array.Empty<BaseProcessor<Activity>>()));
|
||||
|
||||
using var p1 = new TestActivityProcessor(null, null);
|
||||
using var processor = new CompositeProcessor<Activity>(new[] { p1 });
|
||||
using var processor = new CompositeProcessor<Activity>([p1]);
|
||||
Assert.Throws<ArgumentNullException>(() => processor.AddProcessor(null!));
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ public class CompositeActivityProcessorTests
|
|||
|
||||
using var activity = new Activity("test");
|
||||
|
||||
using (var processor = new CompositeProcessor<Activity>(new[] { p1, p2 }))
|
||||
using (var processor = new CompositeProcessor<Activity>([p1, p2]))
|
||||
{
|
||||
processor.OnStart(activity);
|
||||
processor.OnEnd(activity);
|
||||
|
|
@ -52,7 +52,7 @@ public class CompositeActivityProcessorTests
|
|||
|
||||
using var activity = new Activity("test");
|
||||
|
||||
using var processor = new CompositeProcessor<Activity>(new[] { p1 });
|
||||
using var processor = new CompositeProcessor<Activity>([p1]);
|
||||
Assert.Throws<Exception>(() => { processor.OnStart(activity); });
|
||||
Assert.Throws<Exception>(() => { processor.OnEnd(activity); });
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ public class CompositeActivityProcessorTests
|
|||
using var p1 = new TestActivityProcessor(null, null);
|
||||
using var p2 = new TestActivityProcessor(null, null);
|
||||
|
||||
using var processor = new CompositeProcessor<Activity>(new[] { p1, p2 });
|
||||
using var processor = new CompositeProcessor<Activity>([p1, p2]);
|
||||
processor.Shutdown();
|
||||
Assert.True(p1.ShutdownCalled);
|
||||
Assert.True(p2.ShutdownCalled);
|
||||
|
|
@ -78,7 +78,7 @@ public class CompositeActivityProcessorTests
|
|||
using var p1 = new TestActivityProcessor(null, null);
|
||||
using var p2 = new TestActivityProcessor(null, null);
|
||||
|
||||
using var processor = new CompositeProcessor<Activity>(new[] { p1, p2 });
|
||||
using var processor = new CompositeProcessor<Activity>([p1, p2]);
|
||||
processor.ForceFlush(timeout);
|
||||
|
||||
Assert.True(p1.ForceFlushCalled);
|
||||
|
|
@ -93,7 +93,7 @@ public class CompositeActivityProcessorTests
|
|||
using var p1 = new TestActivityProcessor(null, null);
|
||||
using var p2 = new TestActivityProcessor(null, null);
|
||||
|
||||
using var processor = new CompositeProcessor<Activity>(new[] { p1, p2 });
|
||||
using var processor = new CompositeProcessor<Activity>([p1, p2]);
|
||||
|
||||
Assert.Null(processor.ParentProvider);
|
||||
Assert.Null(p1.ParentProvider);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ public class LinkTest : IDisposable
|
|||
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", [1L, 2L]);
|
||||
this.tags.Add("MyAttributeKey5", ["a", "b"]);
|
||||
this.tags.Add("MyAttributeKey6", [true, false]);
|
||||
this.tags.Add("MyAttributeKey7", [0.1, -0.1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -220,13 +220,13 @@ public class TraceContextPropagatorTest
|
|||
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 class TraceContextPropagatorTest
|
|||
"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 @@ public class TraceContextPropagatorTest
|
|||
{
|
||||
var headers = new Dictionary<string, string[]>
|
||||
{
|
||||
{ TraceParent, new[] { $"00-{TraceId}-{SpanId}-01" } },
|
||||
{ TraceParent, [$"00-{TraceId}-{SpanId}-01"] },
|
||||
{ TraceState, tracestate },
|
||||
};
|
||||
var f = new TraceContextPropagator();
|
||||
|
|
|
|||
|
|
@ -32,25 +32,24 @@ public class TraceIdRatioBasedSamplerTest
|
|||
// 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 class TraceIdRatioBasedSamplerTest
|
|||
// 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);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class ValuesController : Controller
|
|||
[HttpGet]
|
||||
public IEnumerable<string> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
return ["value1", "value2"];
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
|
|
|
|||
Loading…
Reference in New Issue