Dotnetsqlcoder
Dotnetsqlcoder

Reputation: 890

Application Insights skipping events

I am using this code to send events to application insights in a console application

        TelemetryConfiguration.Active.InstrumentationKey = "XXXXXXXXX";

        TelemetryClient telemetryClient = new TelemetryClient(); 

        for (int i = 0; i < 100; i++)
        {

            telemetryClient.TrackEvent("Hello World!");

            telemetryClient.TrackException(new OutOfMemoryException());
        }

        telemetryClient.Flush();
        Task.Delay(60000).Wait();

Now the problem i am having is that it is not seeming to log all my events , sometimes the visual studio toolbar says 44 , sometimes it is 68 and never 100 .

The type of information i am going to send is important cause i will be monitoring several console applications from this service .

Is there any way to have application insights send every thing to azure and not skip events ? I think i am giving it enough time to send every thing before exiting .

Upvotes: 0

Views: 546

Answers (1)

cijothomas
cijothomas

Reputation: 3196

Without full code, its hard to say the configuration used.Couple of things to look for:

  1. Have you enabled sampling? If you really want accurate count of events, then disable sampling (https://learn.microsoft.com/en-us/azure/azure-monitor/app/sampling)
  2. Have you configured channel explicitly? If not, the default will be InMemoryChannel, which does not do any retries for transient issues. Its best to use ServerTelemetryChannel, to protect data loss in the even of network issue or application insights backend transient issues.
var config = new TelemetryConfiguration(); // or active or create default...
var channel = new ServerTelemetryChannel();
channel.initialize(config)

// create client from the config.
TelemetryClient tc= new TelemetryClient(config);

Upvotes: 1

Related Questions