Jaffacakes82
Jaffacakes82

Reputation: 188

No exceptions or stack traces in Azure Application Insights

I have an ASP.NET Core 3.1 solution deployed into an Azure Web App hooked up to Application Insights. I can't for the life of me get exceptions and stack traces to log into Application Insights, instead I get a basic request trace with no exception information attached: enter image description here

I've tried most combinations of setting up logging/application insights telemetry, here are some of the things I've tried:

  1. services.AddApplicationInsightsTelemetry(); in the ConfigureServices() method of Startup.cs
  2. Adding logging.AddApplicationInsights(); to my logging builder in Program.cs
  3. Removing the custom error page exception handler in case that was affecting things

I have the APPINSIGHTS_INSTRUMENTATIONKEY environment variable set on my Web App in Azure.

I'm using the following code to generate exceptions in Application Insights:

[AllowAnonymous]
[Route("autoupdate")]
public async Task<IActionResult> ProfileWebhook()
{
    var formData = await this.Request.ReadFormAsync();

    var config = TelemetryConfiguration.CreateDefault();
    var client = new TelemetryClient(config);

    client.TrackException(new Exception(string.Join("~", formData.Keys)));
    logger.LogError(new Exception(string.Join("~", formData.Keys)), "Fail");
    throw new Exception(string.Join("~", formData.Keys));
}

Nothing is working and I'm going crazy! Any help greatly appreciated.

Upvotes: 1

Views: 2419

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30025

Usually, Application insights will guarantee that all the kinds of telemetries(like exceptions, trace, event etc.) will be arrived around 5 minutes, please refer this doc: How long does it take for telemetry to be collected?. But there is still a chance that it will take a longer time due to beckend issue(a very small chance).

If you're using visual studio, you can check if the telemetry is sent or not via Application Insights search.

You can also check if you're using a correct IKey, or if you have enabled sampling.

But if it keeps this behavior in your side, you should consider contacting MS support to find the root cause.

Hope it helps.

Upvotes: -1

Related Questions