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

Added RecordException to Azure Service Bus Processors #76

Merged
merged 1 commit into from
Jan 9, 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 @@ -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
Loading