From 735a1032a35cee56d42e905dd07b4cd4875e3676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:20:12 +0100 Subject: [PATCH 01/10] Fix IDE 0300 --- .../ActivityExtensionsTest.cs | 8 ++++---- .../StackdriverExporterTests.cs | 2 +- .../TestTraceServiceClient.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs index 5e1b9a5f0b..f1b0e4a7b3 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs @@ -48,12 +48,12 @@ public void ActivityExtensions_Export_Duplicate_ActivityLink_Tag_Key() ActivityContext context1 = new ActivityContext(traceId, spanId1, ActivityTraceFlags.Recorded, isRemote: true); ActivityContext context2 = new ActivityContext(traceId, spanId2, ActivityTraceFlags.Recorded, isRemote: true); - KeyValuePair[] dupTags = new[] - { + KeyValuePair[] dupTags = + [ new KeyValuePair("key1", "value1"), new KeyValuePair("key2", "value2"), - new KeyValuePair("key1", "value3"), - }; + new KeyValuePair("key1", "value3") + ]; ActivityLink link1 = new ActivityLink(context1, tags: new ActivityTagsCollection(dupTags)); ActivityLink link2 = new ActivityLink(context2); diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs index 854fb7bd0d..2974a655f8 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs @@ -167,7 +167,7 @@ internal static Activity CreateTestActivity( var eventTimestamp = DateTime.UtcNow; var traceId = ActivityTraceId.CreateFromString("e8ea7e9ac72de94e91fabc613f9686b2".AsSpan()); - var parentSpanId = ActivitySpanId.CreateFromBytes(new byte[] { 12, 23, 34, 45, 56, 67, 78, 89 }); + var parentSpanId = ActivitySpanId.CreateFromBytes([12, 23, 34, 45, 56, 67, 78, 89]); var attributes = new Dictionary { diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestTraceServiceClient.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestTraceServiceClient.cs index dd1aceb4a7..8baebef691 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestTraceServiceClient.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestTraceServiceClient.cs @@ -11,7 +11,7 @@ internal class TestTraceServiceClient(bool throwException) : TraceServiceClient { private readonly bool throwException = throwException; - public List Spans { get; } = new List(); + public List Spans { get; } = []; public override void BatchWriteSpans(BatchWriteSpansRequest request, CallSettings callSettings) { From be9b514d79d44069935dd0d881776e6070247a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:20:47 +0100 Subject: [PATCH 02/10] Fix IDE0007 --- .../ActivityExtensionsTest.cs | 8 ++++---- .../StackdriverExporterTests.cs | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs index f1b0e4a7b3..a820ead532 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs @@ -45,8 +45,8 @@ public void ActivityExtensions_Export_Duplicate_ActivityLink_Tag_Key() var spanId1 = ActivitySpanId.CreateRandom(); var spanId2 = ActivitySpanId.CreateRandom(); - ActivityContext context1 = new ActivityContext(traceId, spanId1, ActivityTraceFlags.Recorded, isRemote: true); - ActivityContext context2 = new ActivityContext(traceId, spanId2, ActivityTraceFlags.Recorded, isRemote: true); + var context1 = new ActivityContext(traceId, spanId1, ActivityTraceFlags.Recorded, isRemote: true); + var context2 = new ActivityContext(traceId, spanId2, ActivityTraceFlags.Recorded, isRemote: true); KeyValuePair[] dupTags = [ @@ -54,8 +54,8 @@ public void ActivityExtensions_Export_Duplicate_ActivityLink_Tag_Key() new KeyValuePair("key2", "value2"), new KeyValuePair("key1", "value3") ]; - ActivityLink link1 = new ActivityLink(context1, tags: new ActivityTagsCollection(dupTags)); - ActivityLink link2 = new ActivityLink(context2); + var link1 = new ActivityLink(context1, tags: new ActivityTagsCollection(dupTags)); + var link2 = new ActivityLink(context2); var links = new List { link1, link2 }; diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs index 2974a655f8..fdf84c6046 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs @@ -29,11 +29,11 @@ static StackdriverExporterTests() public void StackdriverExporter_CustomActivityProcessor() { const string ActivitySourceName = "stackdriver.test"; - Guid requestId = Guid.NewGuid(); - TestActivityProcessor testActivityProcessor = new TestActivityProcessor(); + var requestId = Guid.NewGuid(); + var testActivityProcessor = new TestActivityProcessor(); - bool startCalled = false; - bool endCalled = false; + var startCalled = false; + var endCalled = false; testActivityProcessor.StartAction = (a) => @@ -86,7 +86,7 @@ public void StackdriverExporter_WithServiceNameMetadata() public void StackdriverExporter_TraceClientThrows_ExportResultFailure() { Exception? exception; - ExportResult result = ExportResult.Success; + var result = ExportResult.Success; var exportedItems = new List(); const string ActivitySourceName = "stackdriver.test"; var source = new ActivitySource(ActivitySourceName); @@ -95,9 +95,9 @@ public void StackdriverExporter_TraceClientThrows_ExportResultFailure() var processor = new BatchActivityExportProcessor(new InMemoryExporter(exportedItems)); - for (int i = 0; i < 10; i++) + for (var i = 0; i < 10; i++) { - using Activity activity = CreateTestActivity(); + using var activity = CreateTestActivity(); processor.OnEnd(activity); } @@ -122,7 +122,7 @@ void RunTest(Batch batch) public void StackdriverExporter_TraceClientDoesNotTrow_ExportResultSuccess() { Exception? exception; - ExportResult result = ExportResult.Failure; + var result = ExportResult.Failure; var exportedItems = new List(); const string ActivitySourceName = "stackdriver.test"; var source = new ActivitySource(ActivitySourceName); @@ -131,9 +131,9 @@ public void StackdriverExporter_TraceClientDoesNotTrow_ExportResultSuccess() var processor = new BatchActivityExportProcessor(new InMemoryExporter(exportedItems)); - for (int i = 0; i < 10; i++) + for (var i = 0; i < 10; i++) { - using Activity activity = CreateTestActivity(); + using var activity = CreateTestActivity(); processor.OnEnd(activity); } From ece8dd2f66cd68cb54221a59d4352d0c528b957e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:21:22 +0100 Subject: [PATCH 03/10] target typed --- .../ActivityExtensionsTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs index a820ead532..2adf881ce8 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/ActivityExtensionsTest.cs @@ -50,9 +50,9 @@ public void ActivityExtensions_Export_Duplicate_ActivityLink_Tag_Key() KeyValuePair[] dupTags = [ - new KeyValuePair("key1", "value1"), - new KeyValuePair("key2", "value2"), - new KeyValuePair("key1", "value3") + new("key1", "value1"), + new("key2", "value2"), + new("key1", "value3") ]; var link1 = new ActivityLink(context1, tags: new ActivityTagsCollection(dupTags)); var link2 = new ActivityLink(context2); From f1b219f1ff34fd2a6c00c66209e9fbcb62f5ea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:21:44 +0100 Subject: [PATCH 04/10] Fix IDE0007 --- .../StackdriverTraceExporter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs index 46899657f0..dd7cbfd174 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs @@ -78,7 +78,7 @@ internal StackdriverTraceExporter(string projectId, TraceServiceClient traceServ /// public override ExportResult Export(in Batch batch) { - TraceServiceClient? traceWriter = this.traceServiceClient; + var traceWriter = this.traceServiceClient; if (traceWriter == null) { traceWriter = new TraceServiceClientBuilder @@ -92,13 +92,13 @@ public override ExportResult Export(in Batch batch) ProjectName = this.googleCloudProjectId, }; - Resource? resource = this.ParentProvider?.GetResource(); + var resource = this.ParentProvider?.GetResource(); foreach (var activity in batch) { // It should never happen that the time has no correct kind, only if OpenTelemetry is used incorrectly. if (activity.StartTimeUtc.Kind == DateTimeKind.Utc) { - Span span = activity.ToSpan(this.googleCloudProjectId.ProjectId); + var span = activity.ToSpan(this.googleCloudProjectId.ProjectId); if (resource != null) { span.AnnotateWith(resource); From 433009d02ab9c8b6389a743192eead2e4b66ee7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:22:54 +0100 Subject: [PATCH 05/10] Fix IDE0074 --- .../StackdriverTraceExporter.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs index dd7cbfd174..b546003fce 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs @@ -78,14 +78,10 @@ internal StackdriverTraceExporter(string projectId, TraceServiceClient traceServ /// public override ExportResult Export(in Batch batch) { - var traceWriter = this.traceServiceClient; - if (traceWriter == null) + var traceWriter = this.traceServiceClient ?? new TraceServiceClientBuilder { - traceWriter = new TraceServiceClientBuilder - { - Settings = this.traceServiceSettings, - }.Build(); - } + Settings = this.traceServiceSettings, + }.Build(); var batchSpansRequest = new BatchWriteSpansRequest { From 3981b9992a1f4dca897ecb6dc8810af42fe1ad74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:23:13 +0100 Subject: [PATCH 06/10] Fix IDE0005 --- .../StackdriverTraceExporter.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs index b546003fce..5aa5067fd2 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs @@ -8,7 +8,6 @@ using Google.Cloud.Trace.V2; using Grpc.Core; using OpenTelemetry.Exporter.Stackdriver.Implementation; -using OpenTelemetry.Resources; namespace OpenTelemetry.Exporter.Stackdriver; From 0324ce7a618147ee79ed5e300b7c3a66c46d703e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:24:13 +0100 Subject: [PATCH 07/10] Fix IDE0090 --- .../Implementation/ActivityExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs index 39b4cde0d5..2a8f32fab2 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs @@ -11,7 +11,7 @@ namespace OpenTelemetry.Exporter.Stackdriver.Implementation; internal static class ActivityExtensions { - private static readonly Dictionary LabelsToReplace = new Dictionary + private static readonly Dictionary LabelsToReplace = new() { { "component", "/component" }, { "http.method", "/http/method" }, From 56c87a548fa3c355f66ee07ff5baa0cfca6267bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:25:21 +0100 Subject: [PATCH 08/10] Fix IDE0066 --- .../Implementation/ActivityExtensions.cs | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs index 2a8f32fab2..d833dc9eed 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs @@ -110,29 +110,17 @@ public static Span.Types.Link ToLink(this ActivityLink link) public static AttributeValue ToAttributeValue(this object? av) { - switch (av) + return av switch { - case string s: - return new AttributeValue - { - StringValue = new TruncatableString { Value = s }, - }; - case bool b: - return new AttributeValue { BoolValue = b }; - case long l: - return new AttributeValue { IntValue = l }; - case double d: - return new AttributeValue - { - StringValue = new TruncatableString { Value = d.ToString(CultureInfo.InvariantCulture) }, - }; - case null: - return new AttributeValue(); - default: - return new AttributeValue - { - StringValue = new TruncatableString { Value = av.ToString() }, - }; - } + string s => new AttributeValue { StringValue = new TruncatableString { Value = s } }, + bool b => new AttributeValue { BoolValue = b }, + long l => new AttributeValue { IntValue = l }, + double d => new AttributeValue + { + StringValue = new TruncatableString { Value = d.ToString(CultureInfo.InvariantCulture) }, + }, + null => new AttributeValue(), + _ => new AttributeValue { StringValue = new TruncatableString { Value = av.ToString() } }, + }; } } From 9e5b44f2efedc9ce0f6e4f911a57f459ebdae408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:26:23 +0100 Subject: [PATCH 09/10] Fix CA1515 --- .../TestActivityProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs index eab6437c06..e82193e16a 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs @@ -5,7 +5,7 @@ namespace OpenTelemetry.Exporter.Stackdriver.Tests; -public class TestActivityProcessor : BaseProcessor, IDisposable +internal class TestActivityProcessor : BaseProcessor, IDisposable { public Action? StartAction; public Action? EndAction; From 33203553d859ae288abd2f8a7cea995cc89fda29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 29 Oct 2024 13:27:26 +0100 Subject: [PATCH 10/10] Fix IDE0060 --- .../StackdriverExporterTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs index fdf84c6046..5d6a65772c 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/StackdriverExporterTests.cs @@ -159,7 +159,6 @@ internal static Activity CreateTestActivity( Dictionary? additionalAttributes = null, bool addEvents = true, bool addLinks = true, - Resource? resource = null, ActivityKind kind = ActivityKind.Client) { var startTimestamp = DateTime.UtcNow;