Application Insights - 如何设置 OperationId

Leo*_*rdo 1 azure-application-insights asp.net-core

有没有办法设置/通知将从前端映射到 Application Insights 的 OperationID?也许我可以在特殊标头或其他内容中将所需的操作ID发送到后端?

kri*_*shg 6

Application Insights作为一等公民支持W3C 分布式跟踪标准。如果 http 请求中存在以下标头,SDK 会自动负责在整个上下文中设置操作 id。

  • traceparent:携带全局唯一的操作ID和调用的唯一标识。
  • Tracestate(可选,以防万一您需要):携带系统特定的跟踪上下文。

由于您提到您的后端是 asp.net core,因此从Microsoft.ApplicationInsights.AspNetCore nuget 版本 2.8.0开始,不需要配置。有关更多详细信息,请参阅https://learn.microsoft.com/en-us/azure/azure-monitor/app/correlation#enable-w3c-distributed-tracing-support-for-aspnet-core-apps