Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

ASP.NET Core Health check publisher for Azure Application Insights.

License

Notifications You must be signed in to change notification settings

PeterOrneholm/Orneholm.ApplicationInsights

Repository files navigation

Orneholm - Application Insights - Health Checks

License: MIT NuGet Nuget Twitter Follow

ASP.NET Core Health check publisher for Azure Application Insights that will publish the health check reports as availibility telemetry, including details and data. As described in the Microsoft Docs custom availibility telemetry does not show up in all dashboards, but you can easily trigger alerts on them and show data by custom Log Analytics queries.

Please read the announcement blogpost for some backstory and a few images: https://peter.orneholm.com/post/181922490118/introducing-orneholmapplicationinsightshealthchec

Install the NuGet package

Orneholm.ApplicationInsights.HealthChecks is distributed as packages on NuGet, install using the tool of your choice, for example dotnet cli.

dotnet add package Orneholm.ApplicationInsights.HealthChecks

Getting started

To get started, configure your ASP.NET Core app to use Application Insights:

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry(Configuration);

    ...
}

Then, in your Startup.cs, where you register your services, add the Application Insights Availability Publisher:

services.AddHealthChecks()
        .AddCheck("SampleCheck1", () => HealthCheckResult.Healthy())
        .AddCheck("SampleCheck2", () => HealthCheckResult.Degraded())
        .AddCheck("SampleCheck3", () => HealthCheckResult.Unhealthy())
        .AddApplicationInsightsAggregatedAvailabilityPublisher()
        .AddApplicationInsightsAvailabilityPublisher();
  • .AddApplicationInsightsAggregatedAvailabilityPublisher(): Aggregate all health check reports into one availability telemetry and send it to Application Insights. Only contains general details and details on status, duration and description for each health check.
  • .AddApplicationInsightsAvailabilityPublisher(): This will publish each health check report as individual availability telemetry and send it to Application Insights. Contains more details such as data returned from each check.

Both of them can be used side by side, to get one item for the general health of the system and then multiple ones with more details.

Customization

You can customize some options, by using an overload:

.AddApplicationInsightsAggregatedAvailabilityPublisher(options =>
{
    options.TestName = "AspNetHealthChecks";
    options.TestRunLocation = "Application";
    options.TreatDegradedAsSuccess = false;
})
.AddApplicationInsightsAvailabilityPublisher(options =>
{
    options.TestNamePrefix = "AspNetHealthCheck";
    options.TestRunLocation = "Application";
    options.TreatDegradedAsSuccess = false;
});

Troubleshooting

If you are running ASP.NET Core 2.2 and have an issue where the health check results are not sent to Application Insights you might be affected by a bug. The workaround is to add the following line after you call services.AddHealthChecks() in ConfigureServices

services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IHostedService), typeof(HealthCheckPublisherOptions).Assembly.GetType("Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService")));

Samples & Test

For more use cases, samples and inspiration; feel free to browse our sample.

Contribute

We are very open to community contributions. Please see our contribution guidelines before getting started.

License & acknowledgements

Orneholm.PEAccountingNet is licensed under the very permissive MIT license for you to be able to use it in commercial or non-commercial applications without many restrictions.

The brand Application Insights belongs to Microsoft.

About

ASP.NET Core Health check publisher for Azure Application Insights.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages