Skip to content

Commit 8d895f1

Browse files
authored
Adding a new sample initializer for client ip
We get this ask more often from customers and would like to add a sample initializer that helps customers control which client ip address get used as part of the geo-location mapping. Ingestion service will check x-forward-for headers first, then the location.ip tag which this sample code sets, then socket remote address. For customers who want to override the default client socket ip, this sample should do the trick.
1 parent 8a30ab3 commit 8d895f1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

articles/azure-monitor/app/api-filtering-sampling.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,21 @@ public void Initialize(ITelemetry telemetry)
479479
}
480480
}
481481
```
482+
483+
#### Control the client IP address used for gelocation mappings
484+
485+
The following sample initializer sets the client IP which will be used for geolocation mapping, instead of the client socket IP address, during telemetry ingestion.
486+
487+
```csharp
488+
public void Initialize(ITelemetry telemetry)
489+
{
490+
var request = telemetry as RequestTelemetry;
491+
if (request == null) return true;
492+
request.Context.Location.Ip = "{client ip address}"; // Could utilize System.Web.HttpContext.Current.Request.UserHostAddress;
493+
return true;
494+
}
495+
```
496+
482497
## ITelemetryProcessor and ITelemetryInitializer
483498

484499
What's the difference between telemetry processors and telemetry initializers?

0 commit comments

Comments
 (0)