Skip to content

Commit

Permalink
Add tag for health check (#707)
Browse files Browse the repository at this point in the history
* Add optional tag for health check

* Update src/Diagnostics.HealthChecks/Composables/ObservableHealthCheck.cs

Co-authored-by: Neil <49037171+neilr81@users.noreply.github.com>

* Update src/Diagnostics.HealthChecks/Composables/ObservableHealthCheck.cs

Co-authored-by: Neil <49037171+neilr81@users.noreply.github.com>

---------

Co-authored-by: Andrei Ionescu <t-andionescu@microsoft.com>
Co-authored-by: Neil <49037171+neilr81@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent ed64ef0 commit 134b7a2
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
try
{
HealthCheckResult result = await m_wrappedHealthCheck.CheckHealthAsync(context, cancellationToken);

try
{
activity?.SetTag("HealthCheckResult", result.Status.ToString());
}
catch (Exception ex)
{
m_logger.LogError(Tag.Create(), ex, "'{registrationName}' health check tag addition failed", context.Registration.Name);
}

activity?.MarkAsSuccess();

// The health status for the health check result: if the status is healthy, it will be returned as it is,
// if not then then registration failure status will be sent in its place.
// if not then registration failure status will be sent in its place.
HealthStatus healthCheckStatus = result.Status == HealthStatus.Healthy
? result.Status
: context.Registration.FailureStatus;
Expand Down

0 comments on commit 134b7a2

Please sign in to comment.