0
votes

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.

1
Have you tried clicking "View all telemetry"?Neville Nazerane
what's the version of the SDK of Application Insights you're using?Ivan Yang
have you verified the config has the correct APPINSIGHTS_INSTRUMENTATIONKEYRon
1. Yes, there was nothing displaying in 'View all telemtry' 2. 2.14.0 3. Yes, it's the correct key. Interestingly, I've come back this morning and the exceptions are now in AI. Do we know if exceptions take longer to propagate into the AI UI than standard errors?Jaffacakes82
@Jaffacakes82, no, it should not take so longer time. But sometimes(it's rarely), all the telemetry may take a longer time to arrive at AI due to backend issue. Another situation is that you turn on the sampling feature but it seems that you didn't do that.Ivan Yang

1 Answers

0
votes

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.