[英]How to send 'Application Version' with client side application insights using javascript?
[英]Build version information in Application Insights telemetry (client-side)
我們有一個SPA托管在ASP.NET應用程序上。 我們要跟蹤整個應用程序的構建版本。
所以這個遙測初始化器
public class VersionInfoTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
telemetry.Context.Component.Version =
typeof(Startup).Assembly.GetName().Version.ToString();
}
}
將在Gloabal.asax中使用
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
var tc = TelemetryConfiguration.Active;
tc.InstrumentationKey = ConfigurationManager.AppSettings["AI Instrumentation Key"];
tc.TelemetryInitializers.Add(new VersionInfoTelemetryInitializer());
...
}
}
服務器端遙測將附加版本信息。 但是我無法對客戶端遙測執行相同的操作。 我已經試過了
var appInsights = window.appInsights || function(config) {
// standard js snippet from azure portal
}({
instrumentationKey: '{{INSTRUMENTATIONKEY}}'
});
window.appInsights = appInsights;
window.appInsights.context.application.ver = 'some version number';
這導致以下JS錯誤
Uncaught TypeError: Cannot read property 'application' of undefined
我也試過
appInsights.queue.push(function () {
appInsights.context.addTelemetryInitializer(versionInfoTelemetryInitialier);
});
function versionInfoTelemetryInitialier(envelope) {
var telemetryItem = envelope.data.baseData;
telemetry.context.component.version = 'some version number';
}
將會警告以下消息
AI: TelemetryInitializerFailed message:"One of telemetry initializers failed, telemetry
item will not be sent: TypeError" props:"{exception:[object Error]{ stack: 'TypeError:
Unable to get property 'component' of undefined or null reference\n at
versionInfoTelemetryInitialier (https://localhost:44301/landing/index:107:9)\n at
n.prototype._track (https://az416426.vo.msecnd.net/scripts/a/ai.0.js:1:65589)\n at
n.prototype.track...
我應該怎么做才能使客戶端遙測附加版本信息。
我認為您的第二次嘗試非常接近。 您需要通過隊列執行此操作,以確保它在所有AI腳本實際加載后發生,所以我認為這是正確的:
appInsights.queue.push(function () {
appInsights.context.addTelemetryInitializer(versionInfoTelemetryInitialier);
});
但在你的初始化你切換context.application.ver
在你的第一個例子,以context.component.version
在你的第二個。
的JavaScript SDK被記錄在github上回購: https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md
那里的例子顯示:
context.application.ver: string
context.application.build : string
所以那個初始化方法不應該是:
function versionInfoTelemetryInitialier(envelope) {
var telemetryItem = envelope.data.baseData;
telemetry.context.application.ver = 'some version number';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.