Skip to content

Commit

Permalink
Merge pull request #76 from wemogy/feature/record-exceptions
Browse files Browse the repository at this point in the history
Added RecordException to Azure Service Bus Processors
  • Loading branch information
SebastianKuesters committed Jan 9, 2024
2 parents 8d15b73 + a3a8c84 commit 0e2facd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Azure.Messaging.ServiceBus;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenTelemetry.Trace;
using Wemogy.Core.Errors;
using Wemogy.Core.Json;
using Wemogy.CQRS.Commands.Abstractions;
Expand All @@ -19,6 +20,7 @@ public class AzureServiceBusCommandProcessor<TCommand> : IAzureServiceBusCommand
private readonly ServiceBusProcessor _serviceBusProcessor;
private readonly IServiceCollection _serviceCollection;
private readonly ScheduledCommandDependencies _scheduledCommandDependencies;
private readonly string _handleMessageActivityName;
private bool _isStarted;

/// <summary>
Expand All @@ -41,10 +43,12 @@ public AzureServiceBusCommandProcessor(
_scheduledCommandDependencies = serviceCollection
.BuildServiceProvider()
.GetRequiredService<ScheduledCommandDependencies>();
_handleMessageActivityName = $"HandleMessageOf{typeof(TCommand).Name}";
}

public async Task HandleMessageAsync(ProcessMessageEventArgs arg)
{
using var activity = Observability.DefaultActivities.StartActivity(_handleMessageActivityName);
var services = new ServiceCollection();
foreach (var serviceDescriptor in _serviceCollection)
{
Expand Down Expand Up @@ -87,8 +91,7 @@ public async Task HandleMessageAsync(ProcessMessageEventArgs arg)
}
catch (Exception e)
{
// ToDo: Dead letter message ==> Maybe remove try/catch let AutoComplete manage this
Console.WriteLine(e);
activity?.RecordException(e);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Azure.Messaging.ServiceBus;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenTelemetry.Trace;
using Wemogy.Core.Errors;
using Wemogy.Core.Json;
using Wemogy.CQRS.Commands.Abstractions;
Expand Down Expand Up @@ -92,8 +93,7 @@ public async Task HandleMessageAsync(ProcessSessionMessageEventArgs arg)
}
catch (Exception e)
{
// ToDo: Dead letter message ==> Maybe remove try/catch let AutoComplete manage this
Console.WriteLine(e);
activity?.RecordException(e);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 0e2facd

Please sign in to comment.