Skip to content

Commit

Permalink
Refactor TracingJobDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
i-vukman committed Oct 13, 2023
1 parent f6630f6 commit 199ea8b
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/AnagramSolver/BackgroundJobs/TracingJobDecorator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

using System.Runtime.ExceptionServices;
using Microsoft.Extensions.Options;
using Sentry;
using Sentry.AspNetCore;

namespace AnagramSolver.BackgroundJobs;

Expand All @@ -27,30 +29,35 @@ public async Task ExecuteAsync(T jobData)
return;
}

var transaction = _getHub().StartTransaction($"BackgroundJob {_decorated.GetType().Name}", "hangfire.server");

hub.ConfigureScope(scope => {
scope.Transaction = transaction;
});

Exception? exception = null;
try
{
await _decorated.ExecuteAsync(jobData).ConfigureAwait(false);
}
catch(Exception e)
{
exception = e;
}
finally
using (hub.PushAndLockScope())
{
if (exception is null)
var transaction = hub.StartTransaction($"BackgroundJob {_decorated.GetType().Name}", "hangfire.server");

hub.ConfigureScope(scope =>
{
scope.Transaction = transaction;
});

Exception? exception = null;

try
{
await _decorated.ExecuteAsync(jobData).ConfigureAwait(false);
}
catch (Exception e)
{
transaction.Finish(SpanStatus.Ok);
exception = e;
}
else
finally
{
transaction.Finish(exception);
if (exception is null)
{
transaction.Finish(SpanStatus.Ok);
}
else
{
transaction.Finish(exception);
}
}
}
}
Expand Down

0 comments on commit 199ea8b

Please sign in to comment.