Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patkleef/ed22f3e1a0dbfd3e830fbd939c8a7b9e to your computer and use it in GitHub Desktop.
Save patkleef/ed22f3e1a0dbfd3e830fbd939c8a7b9e to your computer and use it in GitHub Desktop.
Application Insights Blog - ApplicationInsightsClientIpHeaderTelemetryInitializer.cs
/// <summary>
/// Implements initialization logic.
/// </summary>
/// <param name="platformContext">Http context.</param>
/// <param name="requestTelemetry">Request telemetry object associated with the current request.</param>
/// <param name="telemetry">Telemetry item to initialize.</param>
protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
{
if (string.IsNullOrEmpty(telemetry.Context.Location.Ip))
{
LocationContext location = requestTelemetry.Context.Location;
if (string.IsNullOrEmpty(location.Ip))
{
this.UpdateRequestTelemetry(platformContext, location);
}
telemetry.Context.Location.Ip = location.Ip;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment