Last active
January 22, 2017 07:33
-
-
Save lawrencegripper/a59040d043dfafc483a8896c662f4f06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppInsightsTelemetryInitializer : ITelemetryInitializer | |
{ | |
public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry) | |
{ | |
var userId = HttpContext.Current?.User?.Identity?.GetUserId(); | |
telemetry.Context.User.AccountId = userId; | |
CheckAndAdd(telemetry, "UserId", userId); | |
CheckAndAdd(telemetry, "InstanceId", Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")); | |
} | |
private void CheckAndAdd(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry, string key, string value) | |
{ | |
if (!telemetry.Context.Properties.ContainsKey(key)) | |
{ | |
telemetry.Context.Properties.Add(key, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment