diff --git a/src/extensions/azureServiceBus/Wemogy.CQRS.Extensions.AzureServiceBus/Health/AzureServiceBusHealthCheck.cs b/src/extensions/azureServiceBus/Wemogy.CQRS.Extensions.AzureServiceBus/Health/AzureServiceBusHealthCheck.cs index 4f8e378..2c05404 100644 --- a/src/extensions/azureServiceBus/Wemogy.CQRS.Extensions.AzureServiceBus/Health/AzureServiceBusHealthCheck.cs +++ b/src/extensions/azureServiceBus/Wemogy.CQRS.Extensions.AzureServiceBus/Health/AzureServiceBusHealthCheck.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Azure.Messaging.ServiceBus; using Microsoft.Extensions.Diagnostics.HealthChecks; +using OpenTelemetry.Trace; namespace Wemogy.CQRS.Extensions.AzureServiceBus.Health { @@ -30,6 +31,7 @@ public AzureServiceBusHealthCheck(string connectionString, string queueName) public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { + using var activity = Observability.DefaultActivities.StartActivity(); try { var client = ClientConnections.GetOrAdd(_queueName, _ => new ServiceBusClient(_connectionString)); @@ -39,6 +41,8 @@ public async Task CheckHealthAsync(HealthCheckContext context } catch (TaskCanceledException ex) { + activity?.RecordException(ex); + // propagate the exception if the cancellation token has been canceled if (cancellationToken.IsCancellationRequested) { @@ -49,6 +53,7 @@ public async Task CheckHealthAsync(HealthCheckContext context } catch (Exception ex) { + activity?.RecordException(ex); return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); } }