3
votes

I've got an ASP .Net Core 3.0 Web API hosted on Azure App Service. I'm am trying to figure out why it's throwing a 500 Internal Server Error in one of the controller action methods. I've got Application Insights set up, and I can see on the "Failures" page on Azure Portal that there are a number of 500 exceptions. However, I cannot see a stack trace for them. Is there something I need to do to turn on stack trace reporting in Application Insights or Azure Monitor. P.S. Even when my API was on .Net Core 2.2, it also wasn't showing stack traces, so it's not a .Net Core 3.0 thing.

Here's some screenshots:

enter image description here

enter image description here

3
did you try this : docs.microsoft.com/en-us/azure/azure-monitor/app/…? are you catching and tracing?Anass Kartit
Thanks Anass. I saw that, but further down in the documentation, I saw this docs.microsoft.com/en-us/azure/azure-monitor/app/… which states "Starting with Application Insights Web SDK version 2.6 (beta3 and later), Application Insights collects unhandled exceptions thrown in the controller methods automatically for WebAPI 2+". Now I think this entire document is referring to the .Net Framework and not .Net Core anyway...Fabricio Rodriguez
Having the same exact issue. @FabricioRodriguez - did you ever figure out how to get the stack trace / exception details?Mike Smith

3 Answers

2
votes

In app insights query window, write a query to display exceptions and project the property called "details". That contains the stack trace information.

 exceptions
| where timestamp > ago(30d)
| order by timestamp asc
| project timestamp, message = iff(message != '', message, iff(innermostMessage != '', innermostMessage, customDimensions.['prop__{OriginalFormat}'])), details
1
votes

If you are not seeing the stack trace you have to make sure your code logs the exceptions in one of the ways described in here:

https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-exceptions#exceptions

in MVC you have to use this:

public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
            {
                //If customError is Off, then AI HTTPModule will report the exception
                if (filterContext.HttpContext.IsCustomErrorEnabled)
                {   //or reuse instance (recommended!). see note above
                    var ai = new TelemetryClient();
                    ai.TrackException(filterContext.Exception);
                }
            }
            base.OnException(filterContext);
        }

in .net core it is done at the configureservice level:

public void ConfigureServices(IServiceCollection services)
{
    Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions
                = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
    // Disables adaptive sampling.
    aiOptions.EnableAdaptiveSampling = false;

    // Disables QuickPulse (Live Metrics stream).
    aiOptions.EnableQuickPulseMetricStream = false;
    services.AddApplicationInsightsTelemetry(aiOptions);
}

as described in here:

https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core

0
votes

I figured that looking at "Failed Requests" in the "Operations" tab of the "Failures" page of Application Insights does not show a stack trace. I guess this is because this section has to do with HTTP requests and nothing more. But if I instead switch to the Exceptions tab, I can see the stack trace there. I guess this is the section that relates to the execution of the code, and that's why it has a stack trace.