Skip to content

Commit

Permalink
Merge pull request #88 from wemogy/87-add-activity-for-tracing-for-az…
Browse files Browse the repository at this point in the history
…ureservicebushealthcheck

fix: #87 add activity to AzureServiceBusHealthCheck
  • Loading branch information
SebastianKuesters authored Jun 13, 2024
2 parents 3e1b3c6 + 377298f commit a45aacc
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,6 +31,7 @@ public AzureServiceBusHealthCheck(string connectionString, string queueName)

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
using var activity = Observability.DefaultActivities.StartActivity();
try
{
var client = ClientConnections.GetOrAdd(_queueName, _ => new ServiceBusClient(_connectionString));
Expand All @@ -39,6 +41,8 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
}
catch (TaskCanceledException ex)
{
activity?.RecordException(ex);

// propagate the exception if the cancellation token has been canceled
if (cancellationToken.IsCancellationRequested)
{
Expand All @@ -49,6 +53,7 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
}
catch (Exception ex)
{
activity?.RecordException(ex);
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
Expand Down

0 comments on commit a45aacc

Please sign in to comment.