Skip to content

Commit

Permalink
Use extensions to set health check result
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Ionescu committed Jan 6, 2025
1 parent 83c10be commit beda8b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Abstractions/Activities/ActivityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Omex.Extensions.Abstractions.Activities.Processing;

namespace Microsoft.Omex.Extensions.Abstractions.Activities
Expand Down Expand Up @@ -72,6 +73,13 @@ public static Activity MarkAsHealthCheck(this Activity activity) =>
public static Activity SetResult(this Activity activity, ActivityResult result) =>
activity.SetTag(ActivityTagKeys.Result, ActivityResultStrings.ResultToString(result));

/// <summary>
/// Set health check result
/// </summary>
/// <remarks>This property won't be transferred to child activity or via web requests</remarks>
public static Activity SetHealthCheckResult(this Activity activity, HealthStatus result) =>
activity.SetTag(ActivityTagKeys.HealthCheckResult, result.ToString());

/// <summary>
/// Set activity result to Success
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Content Include="BuildTransitive\*" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Diagnostics;
Expand Down Expand Up @@ -66,7 +67,7 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
? result.Status
: context.Registration.FailureStatus;

activity?.SetTag(ActivityTagKeys.HealthCheckResult, healthCheckStatus.ToString());
activity?.SetHealthCheckResult(healthCheckStatus);

return new HealthCheckResult(
healthCheckStatus,
Expand Down

0 comments on commit beda8b2

Please sign in to comment.