Search code examples
asp.net-corehangfiretelemetryappinsights

Tracking hangfire background jobs with app insights


I have set up app insights in Asp.net core application. All my web api requests are tracked on app insights and if I have any failures I can simply find them in Failures section.

app insights

However, I have also Hangfire background jobs running and if they are failing I can't find them on app insights. Also I have alert rule Whenever the total http server errors is greater than or equal to 1 count and I am not sure if hangfire 5xx errors will go under this condition.

So is there any way to track Hangfire jobs failures and get notified about them?


Solution

  • There was a nice nuget package created Hangfire.Extensions.ApplicationInsights.

    So, install the package:

    Install-Package Hangfire.Extensions.ApplicationInsights

    and add the line to ConfigureService method:

    services.AddHangfireApplicationInsights();

    If your solution requires some custom details you can adjust the code from github repository.