skip to Main Content

I noticed all the exception loggings in the ‘Failures’ come client Ip zeroed. How do I turn this one or unmask so the client IP is visible on every logging?

2

Answers


  1. You need to disable IP-masking. Though it is not possible to through Azure Portal directly you can do it using ARM templates, PowerShell, etc.

    https://learn.microsoft.com/en-us/azure/azure-monitor/app/ip-collection?tabs=framework%2Cnodejs

    Login or Signup to reply.
  2. Thanks @ZakiMa for inputs, I do agree and I followed the same Microsoft-Document and as an alternative(if you do not have permissions to use Powershell or ARM and change the settings) way use telemetry with code:

    RithIpTest.cs:

    public class RithIpTest : ITelemetryInitializer
    {
        public void Initialize(ITelemetry ri_tel)
        {
            ISupportProperties ri_pt = ri_tel as ISupportProperties;
    
            if (ri_pt != null && !ri_pt.Properties.ContainsKey("client-ip"))
            {
                string ri_cl = ri_tel.Context.Location.Ip;
                ri_pt.Properties.Add("client-ip", ri_cl);
            }
        }
    }
    

    In program.cs added:

    var rb = WebApplication.CreateBuilder(args);
    rb.Services.AddControllersWithViews();
    rb.Services.AddApplicationInsightsTelemetry(rb.Configuration["ApplicationInsights:ConnectionString"]);
    rb.Services.AddSingleton<ITelemetryInitializer, RithIpTest>();
    ------
    ------
    app.Run();
    

    With the above code, in customdimensions you will able to get the client ip .

    Output:

    When Client is running:

    enter image description here

    When run from local:

    enter image description here

    This will work for traces , failures, requests, etc.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search