Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Application Insights with Asp.Net-Core HealthChecks

Tags:

Asp.Net Core released version 2.2 and together with it comes HealthChecks feature. (Read more). One of the features it has is to push health check results to Azure Application Insights. But I have not found any way how to see those results in Azure portal. To send the results I am using following extension:

        services.AddHealthChecks()
            .AddSqlServer("...")
            .AddApplicationInsightsPublisher();

Is there a way to view those Health Check reports in Application Insights?

EDIT 1: I took the example from official github docs.

EDIT 2: If I go to the Azure portal query analytics I see following results:

Querying requests:

enter image description here

Querying customEvents

enter image description here

here: GET /health is my healthCheck endpoint. By querying requests logs I can see if health check failed or not, but I want to see more details about each health check, also I don't think I need any extension for this, so I don't understand what AddApplicationInsightsPublisher() actually does.

like image 916
Ramūnas Avatar asked Jan 17 '19 16:01

Ramūnas


People also ask

How do you integrate application insights in .NET Core?

Open your project in Visual Studio. Go to Project > Add Application Insights Telemetry. Choose Azure Application Insights, then select Next. Choose your subscription and Application Insights instance (or create a new instance with Create new), then select Next.

How do you implement application insights?

Add Application Insights automatically From within your ASP.NET web app project in Visual Studio: Select Project > Add Application Insights Telemetry > Application Insights Sdk (local) > Next > Finish > Close.

How do I monitor Microservices in .NET Core?

Implementing basic health monitoring When developing ASP.NET Core Microservices, you can use a built-in health monitoring feature by using a nuget package Microsoft. Extension. Diagnostic. HealthCheck.


2 Answers

There is currently an issue with the registration of the publisher (HealthCheckPublisherHostedService) which will be fixed for aspnet core 3. Currently the workaround is to manually register correctly the class :

services.AddHealthChecks()
        .AddApplicationInsightsPublisher();

// This is a hack to fix an issue with the AddApplicationInsightsPublisher() call above
services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IHostedService), typeof(HealthCheckPublisherOptions).Assembly.GetType("Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService")));

See : https://github.com/aspnet/Extensions/issues/639

like image 158
Nathanael Marchand Avatar answered Sep 28 '22 19:09

Nathanael Marchand


It looks the health events are sent to Application Insights as custom events using TravkEvent api. You can see them in Analytics or Search in the portal.

like image 33
cijothomas Avatar answered Sep 28 '22 17:09

cijothomas