From 134b7a2eb072cf976d95c6645000375fc7ca25e9 Mon Sep 17 00:00:00 2001 From: andrei5090 <60118296+andrei5090@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:37:28 +0000 Subject: [PATCH] Add tag for health check (#707) * 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 Co-authored-by: Neil <49037171+neilr81@users.noreply.github.com> --- .../Composables/ObservableHealthCheck.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Diagnostics.HealthChecks/Composables/ObservableHealthCheck.cs b/src/Diagnostics.HealthChecks/Composables/ObservableHealthCheck.cs index c664fc9a..286e867b 100644 --- a/src/Diagnostics.HealthChecks/Composables/ObservableHealthCheck.cs +++ b/src/Diagnostics.HealthChecks/Composables/ObservableHealthCheck.cs @@ -56,10 +56,20 @@ public async Task 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;