【问题标题】:Application Insights Takes time to send eventApplication Insights 发送事件需要时间
【发布时间】:2017-05-18 21:55:47
【问题描述】:

我开发了一个 UWP 应用程序,我在其中使用 Application Insights 跟踪应用程序的页面视图和自定义事件。我还在应用程序关闭事件期间添加了自定义事件,但应用程序关闭事件没有被跟踪正在跟踪其他自定义事件和页面浏览量。经分析,我们发现 AI 需要一些时间来发送事件。有什么办法可以减少这个时间?

【问题讨论】:

  • Application Insights 是一种可扩展的应用程序性能管理 (APM) 服务,适用于多个平台上的 Web 开发人员。从 2016 年 6 月 15 日起,我们将停止在 Application Insights 中显示 iOS、Android、Windows Store 和 Windows Phone 应用程序的数据。相反,您将能够通过 HockeyApp 访问这些数据。请参考Transitioning Mobile Apps from Application Insights to HockeyApp

标签: uwp azure-application-insights


【解决方案1】:

Application Insights SDK 中的 flush 推荐努力刷新缓冲区中剩余的遥测数据,但不保证交付。

确保发送最后一个事件的一种方法是在结束进程之前添加一个简单的thread.sleep 调用。但是,如果您想确保所有事件都以同步方式发送,您可以实现自己的遥测通道,在返回之前发送事件。

您可以看到the full example here,但一个简单的同步遥测通道将如下所示:

class SyncTelemetryChannel : ITelemetryChannel
{
    private Uri endpoint = new Uri("https://dc.services.visualstudio.com/v2/track");

    public bool? DeveloperMode { get; set; }

    public string EndpointAddress { get; set; }

    public void Dispose() { }

    public void Flush() { }

    public void Send(ITelemetry item)
    {
        byte[] json = JsonSerializer.Serialize(new List<ITelemetry>() { item }, true);
        Transmission transimission = new Transmission(endpoint, json, "application/x-json-stream", JsonSerializer.CompressionType);
        var t = transimission.SendAsync();
        t.Wait();
    }
}

【讨论】:

    猜你喜欢
    • 2016-07-24
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多