0
votes

I have a Web Application and want to track user logins in AppInsights with the following code:

    [HttpPost]
    public async Task<ActionResult> Login(AccountViewModel model, string returnUrl)
    {
        var success = await _userManager.CheckPasswordAsync(model);

        _telemetryClient.TrackEvent("Login",
            new Dictionary<string, string>
            {
                { "UserName", model.UserName },
                { "UsingPin", model.UsingPin.ToString()},
                { "ReturnUrl", returnUrl},
                { "LastUsedUrl", model.LastUsedUrl },
                { "Success", success.ToString() }
            });

         return View(model);
    }

The code works, I get events in analytics portal... but only a subset of events! In the sessions table on the database side I have about 1000 unique user logins, but AI reports around 100...

What I have already checked:

  1. _telemetryClient is a singleton configured through Unity (<lifetime type="singleton" />)
  2. there is no quota configured in Azure portal
  3. I have more than 1000 POST requests to the Login method, this looks just right (I mean every request comes to this exact server, returns 200 status, etc.)

So it looks like Azure just drops some of custom events... or they are not send to azure for some reason. Is there any configuration part I am missing?

1
The TelemetryClient send data to Azure in Batches, you can try to flush the buffer using _telemetryClient.Flush();Peter Bons

1 Answers

2
votes

As far as I know, if your application sends a lot of data and you are using the Application Insights SDK for ASP.NET version 2.0.0-beta3 or later, the adaptive sampling feature may operate and send only a percentage of your telemetry.

So I guess this the reason why you just see 100 records in the AI.

If you want to send all the records to the AI, I suggest you could disable the adaptive sampling. More details about how to disable the adaptive sampling, you could refer to this article.

Notice: This is not recommended. Sampling is designed so that related telemetry is correctly transmitted, for diagnostic purposes.