[英]different trace-id for each api request
我的 Angular SPA 應用程序正在調用后端 api,而后者又可以調用多個 api。
要查看端到端跟蹤,我們正在使用應用程序洞察 sdk "@microsoft/applicationinsights-web": "^2.5.4"
啟用W3C跟蹤模式。
問題是來自 SPA 的所有不同 api 調用都具有相同的trace-id 。 因此,在 azure application insight 端到端跟蹤中,我在同一個瀏覽器父級下看到了太多請求跟蹤。
我想要的是每個新 api 請求的不同跟蹤 ID。
traceparent就像00-1e9d1a6e585e4d35afc5af825fadaa86-f50cda29ee924950-01
其中1e9d1a6e585e4d35afc5af825fadaa86
是跟蹤 ID。
無論我如何更改設置,它都無法按預期工作。
this.appInsights = new ApplicationInsights({
config: {
instrumentationKey: settings.appInsightsConfig.instrumentationKey,
distributedTracingMode: DistributedTracingModes.W3C,
disableCorrelationHeaders: false,
enableDebug: false,
enableCorsCorrelation: true,
enableRequestHeaderTracking: true,
enableAutoRouteTracking: true,
autoTrackPageVisitTime: true,
enableAjaxErrorStatusText: true
}
});
設置distributedTracingMode: DistributedTracingModes.W3C
將啟用基於 W3C TraceContext 的分布式跟蹤。 在當前情況下,似乎 traceID 沒有為更新的操作刷新,導致每個操作都顯示在單個事務中。
您可以通過調用appInsights.properties.context.telemetryTrace.traceID = Microsoft.ApplicationInsights.Telemetry.Util.generateW3CId()
手動刷新操作 ID。
手動觸發 PageView 事件也會重置 Operation ID,但使用 SPA,只會生成一個頁面查看事件。 因此,我建議在適當的代碼中使用generateW3CId()
方法設置traceID
。 有關詳細信息,請參閱以下內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.