From cca539cbf78ae4e168b9d1632abc2a188a54bd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 5 Nov 2024 13:35:00 +0100 Subject: [PATCH] [repo/Hangfire] Prepare to .NET9 (#2296) --- ...ngfireInstrumentationJobFilterAttribute.cs | 2 +- .../HangfireFixture.cs | 2 ++ ...eInstrumentationJobFilterAttributeTests.cs | 22 +++++++++---------- .../ProcessorMock.cs | 2 +- .../TestJob.cs | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs index f793e52a62..0f0afaaa2a 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs +++ b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs @@ -122,7 +122,7 @@ private static void InjectActivityProperties(IDictionary jobPara private static IEnumerable ExtractActivityProperties(Dictionary telemetryData, string key) { - return telemetryData.TryGetValue(key, out var value) ? new[] { value } : Enumerable.Empty(); + return telemetryData.TryGetValue(key, out var value) ? [value] : []; } private void SetStatusAndRecordException(Activity activity, Exception exception) diff --git a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireFixture.cs b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireFixture.cs index 614882d572..7157660583 100644 --- a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireFixture.cs +++ b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireFixture.cs @@ -7,7 +7,9 @@ namespace OpenTelemetry.Instrumentation.Hangfire.Tests; +#pragma warning disable CA1515 public class HangfireFixture : IDisposable +#pragma warning restore CA1515 { public HangfireFixture() { diff --git a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireInstrumentationJobFilterAttributeTests.cs b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireInstrumentationJobFilterAttributeTests.cs index 2b301d0f34..37fb369af7 100644 --- a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireInstrumentationJobFilterAttributeTests.cs +++ b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireInstrumentationJobFilterAttributeTests.cs @@ -34,8 +34,8 @@ public async Task Should_Create_Activity() await this.WaitJobProcessedAsync(jobId, 5); // Assert - Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId); - var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId); + Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId); + var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId); Assert.Contains("JOB TestJob.Execute", activity.DisplayName); Assert.Equal(ActivityKind.Internal, activity.Kind); } @@ -55,8 +55,8 @@ public async Task Should_Create_Activity_With_Status_Error_When_Job_Failed() await this.WaitJobProcessedAsync(jobId, 5); // Assert - Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId); - var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId); + Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId); + var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId); Assert.Contains("JOB TestJob.ThrowException", activity.DisplayName); Assert.Equal(ActivityKind.Internal, activity.Kind); Assert.Equal(ActivityStatusCode.Error, activity.Status); @@ -79,8 +79,8 @@ public async Task Should_Create_Activity_With_Exception_Event_When_Job_Failed_An await this.WaitJobProcessedAsync(jobId, 5); // Assert - Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId); - var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId); + Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId); + var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId); Assert.Contains("JOB TestJob.ThrowException", activity.DisplayName); Assert.Equal(ActivityKind.Internal, activity.Kind); Assert.Equal(ActivityStatusCode.Error, activity.Status); @@ -103,8 +103,8 @@ public async Task Should_Create_Activity_Without_Exception_Event_When_Job_Failed await this.WaitJobProcessedAsync(jobId, 5); // Assert - Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId); - var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId); + Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId); + var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId); Assert.Contains("JOB TestJob.ThrowException", activity.DisplayName); Assert.Equal(ActivityKind.Internal, activity.Kind); Assert.Equal(ActivityStatusCode.Error, activity.Status); @@ -128,8 +128,8 @@ public async Task Should_Create_Activity_With_Custom_DisplayName() await this.WaitJobProcessedAsync(jobId, 5); // Assert - Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId); - var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId); + Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId); + var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId); Assert.Contains($"JOB {jobId}", activity.DisplayName); Assert.Equal(ActivityKind.Internal, activity.Kind); } @@ -174,7 +174,7 @@ public async Task Should_Respect_Filter_Option(string filter, bool shouldRecord) private async Task WaitJobProcessedAsync(string jobId, int timeToWaitInSeconds) { var timeout = DateTime.Now.AddSeconds(timeToWaitInSeconds); - string[] states = new[] { "Enqueued", "Processing" }; + string[] states = ["Enqueued", "Processing"]; JobDetailsDto jobDetails; while (((jobDetails = this.hangfireFixture.MonitoringApi.JobDetails(jobId)) == null || jobDetails.History.All(h => states.Contains(h.StateName))) && DateTime.Now < timeout) diff --git a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/ProcessorMock.cs b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/ProcessorMock.cs index 81620efad1..e7652b7ff4 100644 --- a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/ProcessorMock.cs +++ b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/ProcessorMock.cs @@ -3,7 +3,7 @@ namespace OpenTelemetry.Instrumentation.Hangfire.Tests; -public class ProcessorMock : BaseProcessor +internal class ProcessorMock : BaseProcessor { private readonly Action? onStart; private readonly Action? onEnd; diff --git a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/TestJob.cs b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/TestJob.cs index ae2d973450..795e4e73df 100644 --- a/test/OpenTelemetry.Instrumentation.Hangfire.Tests/TestJob.cs +++ b/test/OpenTelemetry.Instrumentation.Hangfire.Tests/TestJob.cs @@ -3,7 +3,7 @@ namespace OpenTelemetry.Instrumentation.Hangfire.Tests; -public class TestJob +internal class TestJob { public void Execute() {