Skip to content

HTTP Health check spam in telemetry when chaining health checks #8878

@MermaidIsla

Description

@MermaidIsla

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This bug is related to #8580. Creating a custom health check class that implements IHealthCheck interface with an HTTP call to another service causes health check spam in the Dashboard's Traces tab. Even after applying a fix from #8643 the issue still persists.

Expected Behavior

No health check spam.

Steps To Reproduce

GitHub repo: https://github.com/MermaidIsla/aspire-health-check-bug/

Steps to reproduce this bug

  1. Create a new project using the template .NET Aspire Starter App
  2. In the Web project create a new class called ApiServiceHealthCheck
  3. Copy the following code into ApiServiceHealthCheck.cs file:
public class ApiServiceHealthCheck(HttpClient httpClient) : IHealthCheck
{
    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
    {
        var response = await httpClient.GetAsync("http://apiservice/health", cancellationToken).ConfigureAwait(false);

        return response.IsSuccessStatusCode ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy();
    }
}
  1. In the Web project open Program.cs file and add the following code builder.Services.AddHealthChecks().AddCheck<ApiServiceHealthCheck>("apiservice"); just before var app = builder.Build();
  2. In the AppHost project ensure that both projects (apiservice and webfrontend) have .WithHttpHealthCheck("/health", 200, "http")
  3. Run the AppHost project, open the dashboard and click on Traces tab
  4. You should now see a health check spam

Exceptions (if any)

No response

.NET Version info

SADA .NET SDK:
Version: 9.0.203
Commit: dc7acfa194
Workload version: 9.0.200-manifests.12d79ccf
MSBuild version: 17.13.20+a4ef1e90f

Běhové prostředí:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.203\

Nainstalované úlohy .NET:
[aspire]
Zdroj instalace: VS 17.13.35931.197
Verze manifestu: 8.2.2/8.0.100
Cesta manifestu: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Typ instalace: Msi

Nakonfigurováno pro použití loose manifests při instalaci nových manifestů

Host:
Version: 9.0.4
Architecture: x64
Commit: f57e6dc747

.NET SDKs installed:
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.701 [C:\Program Files\dotnet\sdk]
9.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Anything else?

.NET Aspire version: 9.2
Visual Studio Community 2022, version: 17.13.6

Related issues and pull requests: #8580, #8643

A possible way to fix this bug: I found out that by editing AddHttpClientInstrumentation in Extensions.cs file in ServiceDefaults project, I can filter out the health check. Exact steps for this can be found in a README file the repo.

Image of a health check spam:

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions