首页 文章

应用程序见解需要时间发送事件

提问于
浏览
2

我已经开发了一个UWP应用程序,我使用Application Insights来跟踪应用程序的页面视图和自定义事件 . 我还在应用程序关闭事件期间添加了自定义事件,但是没有跟踪应用程序关闭事件,因为所有其他自定义事件我们发现人工智能需要一些时间来发送事件 . 有什么办法可以减少这个时间吗?

1 回答

  • 4

    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();
        }
    }
    

相关问题