Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[repo/Quartz] Prepare to .NET9 #2293

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -44,6 +44,8 @@ public override void OnEventWritten(string name, object? payload)
case "Quartz.Job.Veto.Exception":
this.OnException(activity, payload);
break;
default:
break;
}
}

Expand Down Expand Up @@ -127,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public QuartzDiagnosticListenerTests()
public async Task Should_Create_Activity()
{
// Arrange
Barrier barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = new List<DateTime>();
var barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = [];

var exportedItems = new List<Activity>();
using var tel = Sdk.CreateTracerProviderBuilder()
Expand All @@ -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<TestJob>()
Expand Down Expand Up @@ -74,8 +74,8 @@ public async Task Should_Create_Activity()
public async Task Should_Create_Activity_And_Enrich_When_Enrich()
{
// Arrange
Barrier barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = new List<DateTime>();
var barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = [];

var exportedItems = new List<Activity>();

Expand Down Expand Up @@ -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<TestJob>()
Expand Down Expand Up @@ -141,8 +141,8 @@ 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);
List<DateTime> jobExecTimestamps = new List<DateTime>();
var barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = [];

var exportedItems = new List<Activity>();

Expand All @@ -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<TestJobExecutionExceptionJob>()
Expand Down Expand Up @@ -195,8 +195,8 @@ 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);
List<DateTime> jobExecTimestamps = new List<DateTime>();
var barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = [];

var exportedItems = new List<Activity>();

Expand Down Expand Up @@ -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<TestJobExecutionExceptionJob>()
Expand Down Expand Up @@ -262,8 +262,8 @@ 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);
List<DateTime> jobExecTimestamps = new List<DateTime>();
var barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = [];

var exportedItems = new List<Activity>();
using var tel = Sdk.CreateTracerProviderBuilder()
Expand Down Expand Up @@ -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<TestJobExecutionExceptionJob>()
Expand Down Expand Up @@ -323,16 +323,16 @@ 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);
List<DateTime> jobExecTimestamps = new List<DateTime>();
var barrier = new Barrier(2);
List<DateTime> jobExecTimestamps = [];

var exportedItems = new List<Activity>();

using var tel = Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOnSampler())
.AddQuartzInstrumentation(q =>
{
q.TracedOperations = new HashSet<string>();
q.TracedOperations = [];
})
.AddInMemoryExporter(exportedItems)
.Build();
Expand All @@ -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<TestJob>()
Expand Down
6 changes: 3 additions & 3 deletions test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace OpenTelemetry.Instrumentation.Quartz.Tests;

public class TestJob : IJob
internal class TestJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
try
{
List<DateTime> jobExecTimestamps = (List<DateTime>)context.Scheduler.Context.Get("DATESTAMPS");
Barrier barrier = (Barrier)context.Scheduler.Context.Get("BARRIER");
var jobExecTimestamps = (List<DateTime>)context.Scheduler.Context.Get("DATESTAMPS");
var barrier = (Barrier)context.Scheduler.Context.Get("BARRIER");

jobExecTimestamps.Add(DateTime.UtcNow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OpenTelemetry.Instrumentation.Quartz.Tests;

public class TestJobExecutionExceptionJob : IJob
internal class TestJobExecutionExceptionJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
Expand Down
Loading