1

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.

Jaffacakes82
  • 178
  • 17
  • Have you tried clicking "View all telemetry"? – Neville Nazerane Jul 16 '20 at 22:31
  • what's the version of the SDK of Application Insights you're using? – Ivan Glasenberg Jul 17 '20 at 01:06
  • have you verified the config has the correct APPINSIGHTS_INSTRUMENTATIONKEY – Ron Jul 17 '20 at 04:23
  • 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 Jul 17 '20 at 08:00
  • @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 Glasenberg Jul 17 '20 at 09:02
  • I'm going to strip back the app and work out exactly what combination of configuration works and will report back. – Jaffacakes82 Jul 17 '20 at 15:48
  • @Jaffacakes82, I posted an answer for it. If it's helpful, could you please help accept it as answer? Thanks. – Ivan Glasenberg Aug 03 '20 at 01:00
  • @Jaffacakes82, there will be a delay of 2-5 minutes to reflect the logs in App insights. – Prawin Aug 03 '20 at 14:44
  • @Jaffacakes82 did you have any luck, i'm having the same issue – JBoothUA Jan 15 '22 at 15:26

1 Answers1

-1

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.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • Thanks - I haven't had the chance to re-test my configuration and work out what the trigger was. It's likely I was missing the services.AddApplicationInsightsTelemetry(); call, which I'm assuming MUST be there. Good to know there can be a delay though - I'll need to be more patient next time. – Jaffacakes82 Jul 24 '20 at 08:58
  • @Jaffacakes82, yes, the `services.AddApplicationInsightsTelemetry()` should be added. And if the answer is helpful, could you please help accept it as answer? Thanks:) – Ivan Glasenberg Jul 24 '20 at 09:57