From 9f77ead9f2d4058c319aa08caee6b6a523f7182c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 14:53:42 +0100 Subject: [PATCH 1/5] Fix IDE0010 --- .../Implementation/QuartzDiagnosticListener.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs index bb6e68b523..c2fa27f9fa 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs @@ -44,6 +44,8 @@ public override void OnEventWritten(string name, object? payload) case "Quartz.Job.Veto.Exception": this.OnException(activity, payload); break; + default: + break; } } From 926d689e2c2ca396d4bb7538c271bba39237d80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 14:54:28 +0100 Subject: [PATCH 2/5] Fix IDE0028 --- .../QuartzDiagnosticListenerTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs index b2faa5ea71..ef4ef213da 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs @@ -22,7 +22,7 @@ public async Task Should_Create_Activity() { // Arrange Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + List jobExecTimestamps = []; var exportedItems = new List(); using var tel = Sdk.CreateTracerProviderBuilder() @@ -75,7 +75,7 @@ public async Task Should_Create_Activity_And_Enrich_When_Enrich() { // Arrange Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -142,7 +142,7 @@ public async Task Should_Record_Exception_When_Record_Exception_Enabled() { // Arrange Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -196,7 +196,7 @@ public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enri { // Arrange Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -263,7 +263,7 @@ public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() { // Arrange Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + List jobExecTimestamps = []; var exportedItems = new List(); using var tel = Sdk.CreateTracerProviderBuilder() @@ -324,7 +324,7 @@ public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present { // Arrange Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -332,7 +332,7 @@ public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present .SetSampler(new AlwaysOnSampler()) .AddQuartzInstrumentation(q => { - q.TracedOperations = new HashSet(); + q.TracedOperations = []; }) .AddInMemoryExporter(exportedItems) .Build(); From 1cc7a0de50824788ed4265e8c7f0f4c667d4189a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 14:54:44 +0100 Subject: [PATCH 3/5] Fix IDE0019 --- .../Implementation/QuartzDiagnosticListener.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs index c2fa27f9fa..671d2c1114 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs @@ -129,8 +129,7 @@ private void OnException(Activity activity, object? payload) { if (activity.IsAllDataRequested) { - var exc = payload as Exception; - if (exc == null) + if (payload is not Exception exc) { QuartzInstrumentationEventSource.Log.NullPayload(nameof(QuartzDiagnosticListener), nameof(this.OnStopActivity)); return; From 69d3bb709fd49a0487a9dba619b9947edfa87a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 14:55:14 +0100 Subject: [PATCH 4/5] Fix IDE0007 --- .../Implementation/QuartzDiagnosticListener.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs index 671d2c1114..9f390287d9 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs @@ -28,7 +28,7 @@ public QuartzDiagnosticListener(string sourceName, QuartzInstrumentationOptions public override void OnEventWritten(string name, object? payload) { - Activity? activity = Activity.Current; + var activity = Activity.Current; Guard.ThrowIfNull(activity); switch (name) { From 1b87e0f766321f5bcd679886d163f03f74c5796b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 14:55:50 +0100 Subject: [PATCH 5/5] Fix CA1515 --- .../QuartzDiagnosticListenerTests.cs | 24 +++++++++---------- .../TestJob.cs | 6 ++--- .../TestJobExecutionExceptionJob.cs | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs index ef4ef213da..09289ecf17 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs @@ -21,7 +21,7 @@ public QuartzDiagnosticListenerTests() public async Task Should_Create_Activity() { // Arrange - Barrier barrier = new Barrier(2); + var barrier = new Barrier(2); List jobExecTimestamps = []; var exportedItems = new List(); @@ -38,7 +38,7 @@ public async Task Should_Create_Activity() scheduler.Context.Put("DATESTAMPS", jobExecTimestamps); await scheduler.Start(); - JobDataMap jobDataMap = new JobDataMap { { "A", "B" } }; + var jobDataMap = new JobDataMap { { "A", "B" } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -74,7 +74,7 @@ public async Task Should_Create_Activity() public async Task Should_Create_Activity_And_Enrich_When_Enrich() { // Arrange - Barrier barrier = new Barrier(2); + var barrier = new Barrier(2); List jobExecTimestamps = []; var exportedItems = new List(); @@ -105,7 +105,7 @@ public async Task Should_Create_Activity_And_Enrich_When_Enrich() await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -141,7 +141,7 @@ public async Task Should_Create_Activity_And_Enrich_When_Enrich() public async Task Should_Record_Exception_When_Record_Exception_Enabled() { // Arrange - Barrier barrier = new Barrier(2); + var barrier = new Barrier(2); List jobExecTimestamps = []; var exportedItems = new List(); @@ -162,7 +162,7 @@ public async Task Should_Record_Exception_When_Record_Exception_Enabled() await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -195,7 +195,7 @@ public async Task Should_Record_Exception_When_Record_Exception_Enabled() public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enrich() { // Arrange - Barrier barrier = new Barrier(2); + var barrier = new Barrier(2); List jobExecTimestamps = []; var exportedItems = new List(); @@ -229,7 +229,7 @@ public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enri await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -262,7 +262,7 @@ public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enri public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() { // Arrange - Barrier barrier = new Barrier(2); + var barrier = new Barrier(2); List jobExecTimestamps = []; var exportedItems = new List(); @@ -291,7 +291,7 @@ public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -323,7 +323,7 @@ public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present() { // Arrange - Barrier barrier = new Barrier(2); + var barrier = new Barrier(2); List jobExecTimestamps = []; var exportedItems = new List(); @@ -346,7 +346,7 @@ public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs index 7be379f91c..e1fbee1e48 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs @@ -5,14 +5,14 @@ namespace OpenTelemetry.Instrumentation.Quartz.Tests; -public class TestJob : IJob +internal class TestJob : IJob { public Task Execute(IJobExecutionContext context) { try { - List jobExecTimestamps = (List)context.Scheduler.Context.Get("DATESTAMPS"); - Barrier barrier = (Barrier)context.Scheduler.Context.Get("BARRIER"); + var jobExecTimestamps = (List)context.Scheduler.Context.Get("DATESTAMPS"); + var barrier = (Barrier)context.Scheduler.Context.Get("BARRIER"); jobExecTimestamps.Add(DateTime.UtcNow); diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs index 6ebed283b5..bb81998837 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs @@ -5,7 +5,7 @@ namespace OpenTelemetry.Instrumentation.Quartz.Tests; -public class TestJobExecutionExceptionJob : IJob +internal class TestJobExecutionExceptionJob : IJob { public Task Execute(IJobExecutionContext context) {