Azure Monitor/Application Insights未显示错误的堆栈跟踪

Azure Monitor/Application Insights未显示错误的堆栈跟踪,azure,asp.net-core-mvc,azure-application-insights,azure-monitoring,Azure,Asp.net Core Mvc,Azure Application Insights,Azure Monitoring,我有一个ASP.NETCore3.0WebAPI托管在Azure应用程序服务上。 我正在试图弄清楚为什么它在一个控制器操作方法中抛出500个内部服务器错误。 我已经设置了应用程序洞察,我可以在Azure门户的“失败”页面上看到有500个异常。但是,我看不到它们的堆栈跟踪。我是否需要在Application Insights或Azure Monitor中打开堆栈跟踪报告。 另外,即使我的API在.Net Core 2.2上,它也没有显示堆栈跟踪,所以它不是.Net Core 3.0的东西 以下是一

我有一个ASP.NETCore3.0WebAPI托管在Azure应用程序服务上。 我正在试图弄清楚为什么它在一个控制器操作方法中抛出500个内部服务器错误。 我已经设置了应用程序洞察,我可以在Azure门户的“失败”页面上看到有500个异常。但是,我看不到它们的堆栈跟踪。我是否需要在Application Insights或Azure Monitor中打开堆栈跟踪报告。 另外,即使我的API在.Net Core 2.2上,它也没有显示堆栈跟踪,所以它不是.Net Core 3.0的东西

以下是一些屏幕截图:


如果您没有看到堆栈跟踪,则必须确保您的代码以此处描述的方式之一记录异常:

在MVC中,您必须使用:

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);
        }
在.net core中,它是在配置服务级别完成的:

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);
}
如本文所述:


我发现查看Application Insights“Failures”页面的“Operations”选项卡中的“Failed Requests”不会显示堆栈跟踪。我想这是因为这一部分与HTTP请求有关,仅此而已。但是如果我切换到Exceptions选项卡,我可以在那里看到堆栈跟踪。我猜这是与代码执行相关的部分,这就是为什么它有堆栈跟踪。

您尝试过这个吗:?你在追踪吗?谢谢你,阿纳斯。我看到了这一点,但在文档的后面,我看到了这一点,即“从ApplicationInsightsWebSDK版本2.6(beta3及更高版本)开始,ApplicationInsights自动收集WebAPI 2+的控制器方法中抛出的未经处理的异常”。现在我认为整个文档都是指.Net框架,而不是.Net核心…有着同样的问题@Fabricio Rodriguez-你知道如何获取堆栈跟踪/异常详细信息吗?谢谢你。我回复了您在我的原始帖子上的评论:“我看到了,但在文档的更深处,我看到了这样一句话:“从ApplicationInsightsWebSDK版本2.6(beta3及更高版本)开始,ApplicationInsights自动收集WebAPI 2控制器方法中抛出的未处理异常+“。现在我认为整个文档所指的是.Net框架,而不是.Net核心“你看到了吗?我想我正在使用Application Insights 9.1.913.1版作为记录。啊,不,我没有看到。非常感谢。这可能就是答案。现在就开始。很快就会让您知道…可能是nuget问题,请尝试使用visual studio进行调试并手动创建异常,以查看相关性是否不起作用。如果它起作用,那么异常将显示在“前3个异常”网格的操作选项卡上,在端到端事务详细信息体验中(作为单独的行和请求的一部分)。您能否分享您如何检测应用程序的更多详细信息?如果相关起作用,您将看到类似的图片: