简体   繁体   English

如何使用 javascript 发送带有客户端应用程序洞察的“应用程序版本”?

[英]How to send 'Application Version' with client side application insights using javascript?

We can send 'application version' property with every insight in c# like in this tutorial by adding a initializer.我们可以像在本教程中一样通过添加初始化程序来发送带有 c# 中所有见解的“应用程序版本”属性。

    class AppVersionTelemetryInitializer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
    public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
    {
        telemetry.Context.Component.Version = ApplicationInsightsHelper.ApplicationVersion;
    }
}

https://blogs.msdn.microsoft.com/visualstudioalm/2015/01/07/application-insights-support-for-multiple-environments-stamps-and-app-versions/ https://blogs.msdn.microsoft.com/visualstudioalm/2015/01/07/application-insights-support-for-multiple-environments-stamps-and-app-versions/

How can I do this with javascript?我怎样才能用 javascript 做到这一点?

If you are using the @microsoft/applicationinsights-web SDK (for client-side Javascript), you can set the application version in this way:如果您使用的是@microsoft/applicationinsights-web SDK(用于客户端 Javascript),您可以通过以下方式设置应用程序版本:

const appInsights = new ApplicationInsights(...);
appInsights.loadAppInsights();  // important, otherwise the `application` object is missing
appInsights.context.application.ver = "YOUR_VERSION_HERE";

This way, you'll be able to drill down into metrics by application version in the dashboards.这样,您就可以在仪表板中按应用程序版本深入了解指标。

You can formulate the App version/Tags and send it in custom property or metrics via trackpageview.您可以制定应用程序版本/标签,并通过 trackpageview 将其发送到自定义属性或指标中。

Config file is not possible, but enum or some key/value pair can be maintained for each release in webpages & slice the custom param in Azure portal AI blade or API calls.配置文件是不可能的,但可以为网页中的每个版本维护枚举或某些键/值对,并在 Azure 门户 AI 刀片或 API 调用中分割自定义参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM