Application Insight未记录异常详情:5xx状态码仅显示Request failed
解决Application Insights中5xx请求仅显示“Request failed”无异常详情的问题
当应用返回5xx状态码时,在Application Insights中只能看到“Request failed”的提示,无法获取具体的异常堆栈或错误细节,可通过以下步骤排查解决:
检查应用端异常捕获配置
确保应用代码已正确捕获并将异常信息上报至Application Insights。以ASP.NET为例,需确认全局异常处理逻辑中包含异常追踪:// Startup.cs 配置示例 services.AddApplicationInsightsTelemetry(); app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { var exceptionFeature = context.Features.Get<IExceptionHandlerPathFeature>(); if (exceptionFeature?.Error != null) { var telemetryClient = context.RequestServices.GetRequiredService<ITelemetryClient>(); telemetryClient.TrackException(exceptionFeature.Error); } context.Response.StatusCode = StatusCodes.Status500InternalServerError; await context.Response.WriteAsync("An unexpected error occurred."); }); });切换到AI的特定面板查看详情
不要仅查看请求的基础信息,切换到失败请求面板,点击对应请求条目后查看“异常”标签页;同时在异常面板中按时间范围、请求ID筛选,通常能找到完整的异常堆栈信息。排查采样率配置
若启用了自适应采样,可能导致部分异常数据被过滤。检查ApplicationInsights.config中的采样设置,确保异常类型未被排除:<TelemetryProcessors> <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel"> <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond> <ExcludedTypes>Exception</ExcludedTypes> <!-- 移除这行或确保不包含Exception --> </Add> </TelemetryProcessors>查看服务器本地日志
若AI未捕获到异常,可先从服务器本地日志(如IIS日志、应用自定义日志文件)中获取错误详情,再排查AI上报逻辑的问题。升级Application Insights SDK版本
旧版SDK可能存在异常捕获漏洞,尝试将相关NuGet包(如Microsoft.ApplicationInsights.AspNetCore)升级至最新稳定版。
内容的提问来源于stack exchange,提问作者Massimiliano Peluso
相关产品推荐
相关产品推荐

