{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/issues/281","repository_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet","labels_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/issues/281/comments","events_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/issues/281/events","html_url":"https://github.com/Microsoft/ApplicationInsights-dotnet/issues/281","id":170679567,"number":281,"title":"Telemetry Items not sent on shutdown","user":{"login":"NielsFilter","id":4918407,"avatar_url":"https://avatars.githubusercontent.com/u/4918407?v=3","gravatar_id":"","url":"https://api.github.com/users/NielsFilter","html_url":"https://github.com/NielsFilter","followers_url":"https://api.github.com/users/NielsFilter/followers","following_url":"https://api.github.com/users/NielsFilter/following{/other_user}","gists_url":"https://api.github.com/users/NielsFilter/gists{/gist_id}","starred_url":"https://api.github.com/users/NielsFilter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NielsFilter/subscriptions","organizations_url":"https://api.github.com/users/NielsFilter/orgs","repos_url":"https://api.github.com/users/NielsFilter/repos","events_url":"https://api.github.com/users/NielsFilter/events{/privacy}","received_events_url":"https://api.github.com/users/NielsFilter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-11T15:49:09Z","updated_at":"2016-08-15T17:55:53Z","closed_at":null,"body":"# My Context\r\nSome custom events do not get sent just before shutdown (desktop application).\r\n\r\nI'm using the `ServerTelemetryChannel` and `Flush` the channel on shutdown to ensure items get sent.\r\n\r\nI understand that `ServerTelemetryChannel`'s `Flush()` is **synchronous** and therefore I assumed that my events will be sent before shutdown completes. However this isn't working as expected.\r\n\r\n# Simplifying the problem\r\nI created a simple console application that:\r\n- sends a custom event just before shutdown\r\n- I added various delays after flushing\r\n- I used both Telemetry client and serverchannel flushing (which shouldn't make a difference in my scenario)\r\n- Each test ran 100 times\r\n- I checked how many items made it to the portal.\r\n- Ran the tests with developer mode `true` and `false` to compare\r\n\r\n# Results\r\n_Note: Delay is in seconds and received means items showed up in the portal_\r\n## Results for Dev Mode (DeveloperMode = true)\r\n![image](https://cloud.githubusercontent.com/assets/4918407/17594341/3fbe4d9c-5fe9-11e6-9ed5-d6a93cdef0c7.png)\r\n\r\n\r\n## Results for Release Mode (DeveloperMode = false)\r\n![image](https://cloud.githubusercontent.com/assets/4918407/17594330/3a2014ba-5fe9-11e6-9dd0-6a7ff5fe1d2a.png)\r\n\r\n# Conclusion\r\nTests showed me that in my context:\r\n- Dev Mode is irrelevant\r\n- Flushing with Client or Channel is irrelevant\r\n- Only from 2 seconds delay after flushing do telemetry items come through consistently\r\n- I'm still losing telemetry items even after a minute delay.\r\n\r\n# My Concerns\r\n1. Why is the flush not synchronous as I thought it to be?\r\n2. Why did I never get 100% of the telemetry items, even after a long delay?\r\n\r\n# Sample code\r\n\r\n    static void Main(string[] args)\r\n    {\r\n        TelemetryConfiguration.Active.InstrumentationKey = \"*** My Key ***\";\r\n    \r\n        var telemetryChannel = new ServerTelemetryChannel();\r\n        telemetryChannel.Initialize(TelemetryConfiguration.Active);\r\n        TelemetryConfiguration.Active.TelemetryChannel = telemetryChannel;\r\n    \r\n        new TelemetryClient().TrackEvent($\"Test event\");\r\n    \r\n        TelemetryConfiguration.Active.TelemetryChannel?.Flush();\r\n        Thread.Sleep(1000 * 1); // 1 second delay\r\n    \r\n        // Shutdown\r\n    }\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/issues/comments/239876025","html_url":"https://github.com/Microsoft/ApplicationInsights-dotnet/issues/281#issuecomment-239876025","issue_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-dotnet/issues/281","id":239876025,"user":{"login":"abaranch","id":10120301,"avatar_url":"https://avatars.githubusercontent.com/u/10120301?v=3","gravatar_id":"","url":"https://api.github.com/users/abaranch","html_url":"https://github.com/abaranch","followers_url":"https://api.github.com/users/abaranch/followers","following_url":"https://api.github.com/users/abaranch/following{/other_user}","gists_url":"https://api.github.com/users/abaranch/gists{/gist_id}","starred_url":"https://api.github.com/users/abaranch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abaranch/subscriptions","organizations_url":"https://api.github.com/users/abaranch/orgs","repos_url":"https://api.github.com/users/abaranch/repos","events_url":"https://api.github.com/users/abaranch/events{/privacy}","received_events_url":"https://api.github.com/users/abaranch/received_events","type":"User","site_admin":false},"created_at":"2016-08-15T17:55:53Z","updated_at":"2016-08-15T17:55:53Z","body":"Yes, it is synchronous. Great that it works for you, it is the easiest solution."}}
{"actor":{"display_login":"abaranch"}}