Skip to content

Commit 71e6cb4

Browse files
SimonCroppKielekrajkumar-rangaraj
authored
use some collection expressions (#6106)
Co-authored-by: Piotr Kiełkowicz <[email protected]> Co-authored-by: Rajkumar Rangaraj <[email protected]>
1 parent ec9f761 commit 71e6cb4

File tree

36 files changed

+134
-136
lines changed

36 files changed

+134
-136
lines changed

docs/metrics/customizing-the-sdk/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ public static void Main()
2929
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")
3030

3131
// Change Histogram boundaries using the Explicit Bucket Histogram aggregation.
32-
.AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } })
32+
.AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = [10.0, 20.0] })
3333

3434
// Change Histogram to use the Base2 Exponential Bucket Histogram aggregation.
3535
.AddView(instrumentName: "MyExponentialBucketHistogram", new Base2ExponentialBucketHistogramConfiguration())
3636

3737
// For the instrument "MyCounterCustomTags", aggregate with only the keys "tag1", "tag2".
38-
.AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = new string[] { "tag1", "tag2" } })
38+
.AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = ["tag1", "tag2"] })
3939

4040
// Drop the instrument "MyCounterDrop".
4141
.AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop)
4242

4343
// Configure the Explicit Bucket Histogram aggregation with custom boundaries and new name.
44-
.AddView(instrumentName: "histogramWithMultipleAggregations", new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 }, Name = "MyHistogramWithExplicitHistogram" })
44+
.AddView(instrumentName: "histogramWithMultipleAggregations", new ExplicitBucketHistogramConfiguration() { Boundaries = [10.0, 20.0], Name = "MyHistogramWithExplicitHistogram" })
4545

4646
// Use Base2 Exponential Bucket Histogram aggregation and new name.
4747
.AddView(instrumentName: "histogramWithMultipleAggregations", new Base2ExponentialBucketHistogramConfiguration() { Name = "MyHistogramWithBase2ExponentialBucketHistogram" })

examples/AspNetCore/Controllers/WeatherForecastController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace Examples.AspNetCore.Controllers;
1212
[Route("[controller]")]
1313
public class WeatherForecastController : ControllerBase
1414
{
15-
private static readonly string[] Summaries = new[]
16-
{
17-
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching",
18-
};
15+
private static readonly string[] Summaries =
16+
[
17+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
18+
];
1919

2020
private static readonly HttpClient HttpClient = new();
2121

examples/Console/TestPrometheusExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal static int Run(PrometheusOptions options)
3535
.AddMeter(MyMeter.Name)
3636
.AddMeter(MyMeter2.Name)
3737
.AddPrometheusHttpListener(
38-
o => o.UriPrefixes = new string[] { $"http://localhost:{options.Port}/" })
38+
o => o.UriPrefixes = [$"http://localhost:{options.Port}/"])
3939
.Build();
4040

4141
var process = Process.GetCurrentProcess();

src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class B3Propagator : TextMapPropagator
3535
// "Debug" sampled value.
3636
internal const string FlagsValue = "1";
3737

38-
private static readonly HashSet<string> AllFields = new() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags };
38+
private static readonly HashSet<string> AllFields = [XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags];
3939

4040
private static readonly HashSet<string> SampledValues = new(StringComparer.Ordinal) { SampledValue, LegacySampledValue };
4141

src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class BaggagePropagator : TextMapPropagator
2020
private const int MaxBaggageLength = 8192;
2121
private const int MaxBaggageItems = 180;
2222

23-
private static readonly char[] EqualSignSeparator = new[] { '=' };
24-
private static readonly char[] CommaSignSeparator = new[] { ',' };
23+
private static readonly char[] EqualSignSeparator = ['='];
24+
private static readonly char[] CommaSignSeparator = [','];
2525

2626
/// <inheritdoc/>
2727
public override ISet<string> Fields => new HashSet<string> { BaggageHeaderName };

src/OpenTelemetry.Api/Logs/LogRecordSeverityExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ static class LogRecordSeverityExtensions
5757
internal const string Fatal3ShortName = FatalShortName + "3";
5858
internal const string Fatal4ShortName = FatalShortName + "4";
5959

60-
private static readonly string[] LogRecordSeverityShortNames = new string[]
61-
{
60+
private static readonly string[] LogRecordSeverityShortNames =
61+
[
6262
UnspecifiedShortName,
6363

6464
TraceShortName,
@@ -89,8 +89,8 @@ static class LogRecordSeverityExtensions
8989
FatalShortName,
9090
Fatal2ShortName,
9191
Fatal3ShortName,
92-
Fatal4ShortName,
93-
};
92+
Fatal4ShortName
93+
];
9494

9595
/// <summary>
9696
/// Returns the OpenTelemetry Specification short name for the <see

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Ac
6565
{
6666
// Specify the maximum number of substrings to return to 2
6767
// This treats everything that follows the first `=` in the string as the value to be added for the metadata key
68-
var keyValueData = pair.Split(new char[] { '=' }, 2);
68+
var keyValueData = pair.Split(['='], 2);
6969
if (keyValueData.Length != 2)
7070
{
7171
throw new ArgumentException("Headers provided in an invalid format.");
@@ -174,11 +174,11 @@ public static void TryEnableIHttpClientFactoryIntegration(this OtlpExporterOptio
174174
"CreateClient",
175175
BindingFlags.Public | BindingFlags.Instance,
176176
binder: null,
177-
new Type[] { typeof(string) },
177+
[typeof(string)],
178178
modifiers: null);
179179
if (createClientMethod != null)
180180
{
181-
HttpClient? client = (HttpClient?)createClientMethod.Invoke(httpClientFactory, new object[] { httpClientName });
181+
HttpClient? client = (HttpClient?)createClientMethod.Invoke(httpClientFactory, [httpClientName]);
182182

183183
if (client != null)
184184
{

src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class PrometheusHttpListenerOptions
1212
{
1313
internal const string DefaultScrapeEndpointPath = "/metrics";
1414

15-
private IReadOnlyCollection<string> uriPrefixes = new[] { "http://localhost:9464/" };
15+
private IReadOnlyCollection<string> uriPrefixes = ["http://localhost:9464/"];
1616

1717
/// <summary>
1818
/// Gets or sets the path to use for the scraping endpoint. Default value: "/metrics".

src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static BaseProcessor<Activity> BuildZipkinExporterProcessor(
9191
"CreateClient",
9292
BindingFlags.Public | BindingFlags.Instance,
9393
binder: null,
94-
new Type[] { typeof(string) },
94+
[typeof(string)],
9595
modifiers: null);
9696
if (createClientMethod != null)
9797
{

src/OpenTelemetry.Extensions.Propagators/B3Propagator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class B3Propagator : TextMapPropagator
3535
// "Debug" sampled value.
3636
internal const string FlagsValue = "1";
3737

38-
private static readonly HashSet<string> AllFields = new() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags };
38+
private static readonly HashSet<string> AllFields = [XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags];
3939

4040
private static readonly HashSet<string> SampledValues = new(StringComparer.Ordinal) { SampledValue, LegacySampledValue };
4141

0 commit comments

Comments
 (0)