为何Azure App Insights中.NET 6应用的innermostAssembly为空?
.NET 6应用中Azure App Insights的innermostAssembly字段为空的原因及解决方法
未开启完整堆栈跟踪收集
默认情况下App Insights不会收集完整的堆栈跟踪信息,导致无法解析出innermostAssembly。你可以在appsettings.json中配置DependencyTracking模块开启堆栈收集:"ApplicationInsights": { "InstrumentationKey": "你的仪表板密钥", "DependencyTracking": { "EnableStackTraces": true, "StackTraceIncludedTypes": "All" } }堆栈信息被截断或未生成
如果代码中抛出异常时直接使用throw new Exception("消息")覆盖了原有堆栈,或者依赖调用的堆栈被运行时优化截断,都会导致innermostAssembly无法获取。建议捕获异常后用throw重新抛出,保留完整堆栈链。SDK版本不兼容
旧版的Application Insights SDK对.NET 6的堆栈解析支持有限,确保升级到最新稳定版的Microsoft.ApplicationInsights.AspNetCore包,在项目文件中更新:<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" /> <!-- 替换为当前最新稳定版 -->发布编译优化丢失堆栈信息
发布模式下.NET 6默认开启编译优化,会移除部分调试和堆栈数据。可以临时调整发布配置来保留信息(注意会影响性能,排查完成后建议恢复):<PropertyGroup Condition="'$(Configuration)' == 'Release'"> <Optimize>false</Optimize> <DebugType>full</DebugType> </PropertyGroup>自定义遥测逻辑修改了字段
检查项目中的自定义TelemetryProcessor或TelemetryInitializer代码,确认是否存在清空或修改innermostAssembly字段的逻辑,如有需要调整代码保留该字段数据。
内容的提问来源于stack exchange,提问作者Steve
相关产品推荐
相关产品推荐

