Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing HealthCheck report to Application insights #72

Closed
RamunasAdamonis opened this issue Jan 24, 2019 · 6 comments
Closed

Publishing HealthCheck report to Application insights #72

RamunasAdamonis opened this issue Jan 24, 2019 · 6 comments

Comments

@RamunasAdamonis
Copy link

I set up health checks as per Readme:

services.AddHealthChecks()
        .AddSqlServer("MyConnectionString")
        .AddApplicationInsightsPublisher();
...
 app.UseHealthChecks("/health");

If I navigate to my /health endpoint I can see status of health check. But if I go to Azure portal and check application insights logs I cannot see any custom events related to health checks. Is there any example/tutorial/whatsoever on how AddApplicationInsightsPublisher() extension should behave? I also posted a question to stack overflow, but no luck there.

@unaizorrilla
Copy link
Collaborator

This is a configuration sample on
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/samples/HealthChecks.Sample/Startup.cs

But you need also configure Application Insights in your project, you have UseApplicationInsights and the instrumentation key configured?

I try to create a complete sample this afternoon using AI with a preconfigured Instrumentation Key, ok?

@NatMarchand
Copy link

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 : dotnet/extensions#639

@unaizorrilla
Copy link
Collaborator

Hi @NatMarchand

This issue apply only if you have other hosted service registered, I don't now if this is related with this issue.

@unaizorrilla
Copy link
Collaborator

Hi @RamunasAdamonis

Can you try add the instrumentation key on AddApplicationInsightsPublisher method and check if work well?

@unaizorrilla
Copy link
Collaborator

Hi @RamunasAdamonis

I modify the sample "HealthChecks.Sample" to include all necesary to work with ApplicationInsightPublisher, can you checkout? You only need to modify the appsettings.json and set your instrumentation key.

When the hosted service work this send custom metrics to AI, you can view this custom metrics on Metrics section

imagen

P.S: Be patient because custom metric don't are visible inmediatly!!

Hope this help

@RamunasAdamonis
Copy link
Author

Hi @unaizorrilla

Thanks for quick reply. I had application insights configured, in fact I also use hosted services in my project and the workaround provided by @NatMarchand helped (Thank you!). I can see AspNetCoreHealthCheck custom events now. Is it possible to also send a name of failing health check to app insights? This would allow to have all information in single place without need of using HealthCheckUI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants