none
Wrong Geolocation being shown in Application Insights customEvent RRS feed

  • Question

  • Hello,

    We have configured Application Insights for Web App and have also added few custom events.

    What we are observing is, even though an event gets executed from Country A, Country B is shown in geolocation.

    The Resource Group/App Service are hosted in Country B. Could that be an issue?

    Also, within Country B, various cities get shown, which do not appear to be correct.

    Is this a known issue in Application Insights?


    Wednesday, September 25, 2019 11:32 AM

Answers

  • Each instance of a web app will share a single inbound IP, but it will use multiple outbound IPs. You can view the ones for your app in the Properties blade. Converting IP addresses to physical locations isn't exact, so it's very possible that is what is happening with the cities.

    The reason you are getting the server location is that the new TelemetryClient doesn't have the contextual info about the user. When you setup the Application Insights SDK it adds middleware to collect that information on the default client, but when you setup a new one it isn't there. If I set a breakpoint then the IP address in the client is null.

    Looking in the portal, this results in the event getting tagged with the location of the App Service account. In this case the app is in the Central US region.

    Once I grab the IP address from the HttpContext and add it to the client, I get the correct location (Atlanta, GA).

    var telemetryClient = new TelemetryClient(new TelemetryConfiguration(instrumentationKey));
    telemetryClient.Context.Location.Ip = HttpContext.Connection.RemoteIpAddress.ToString();
    
    telemetryClient.TrackEvent("TestEvent");

    Tuesday, October 1, 2019 6:36 PM
    Moderator

All replies

  • Hello,

    Could you share the code you are using to generate the custom events? It does sound like you are inadvertently sending the server location to App Insights instead of the user location.

    The city data is set by looking up the IP address in the GeoLite2 geolocation database. I would need to do some more investigation into your specific case, but I suspect the different cities might be coming via the fact that each web app has multiple outbound IP addresses. It is possible that the different outbound IPs are being geocoded to different locations. I would like to first focus on making sure you are saving user data instead of server data- that may resolve both the city and country issue.

    Wednesday, September 25, 2019 9:16 PM
    Moderator
  • Hi Samara,

    Here is the code being used for customEvents.

    var telemetryClient = new TelemetryClient(new TelemetryConfiguration(instrumentationKey));
    telemetryClient.TrackEvent(eventType.ToString(), eventInfo);

    And, there is only one Web App instance. One city gets shown correctly at times, but in most of the instances, totally different city gets shown.

    Friday, September 27, 2019 4:39 AM
  • Each instance of a web app will share a single inbound IP, but it will use multiple outbound IPs. You can view the ones for your app in the Properties blade. Converting IP addresses to physical locations isn't exact, so it's very possible that is what is happening with the cities.

    The reason you are getting the server location is that the new TelemetryClient doesn't have the contextual info about the user. When you setup the Application Insights SDK it adds middleware to collect that information on the default client, but when you setup a new one it isn't there. If I set a breakpoint then the IP address in the client is null.

    Looking in the portal, this results in the event getting tagged with the location of the App Service account. In this case the app is in the Central US region.

    Once I grab the IP address from the HttpContext and add it to the client, I get the correct location (Atlanta, GA).

    var telemetryClient = new TelemetryClient(new TelemetryConfiguration(instrumentationKey));
    telemetryClient.Context.Location.Ip = HttpContext.Connection.RemoteIpAddress.ToString();
    
    telemetryClient.TrackEvent("TestEvent");

    Tuesday, October 1, 2019 6:36 PM
    Moderator