public static ITelemetrySettings Get() { var s = new HostTelemetrySettings() { SessionId = Guid.NewGuid().ToString(), IsNewSession = true, UserId = GetHash($"{Environment.UserName}@{Environment.MachineName}"), DeviceId = GetHash(Environment.MachineName), }; s.Enabled = !GetEnvironmentVariableAsBool("AGGREGATOR_TELEMETRY_DISABLED", false); return(s); }
public static void InitializeTelemetry() { string dll = Assembly.GetEntryAssembly().GetName().Name; if (dll == "aggregator-cli") { telemetrySettings = CliTelemetrySettings.Get(); WaitAtShutdown = false; } else if (dll == "aggregator-host") { telemetrySettings = HostTelemetrySettings.Get(); WaitAtShutdown = true; } else { // another option would be to disable telemetry throw new InvalidOperationException("Telemetry can be used only in CLI or Host"); } TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault(); configuration.InstrumentationKey = ApplicationInsightsKey; // use default InMemory channel, if there are network issues, who cares configuration.TelemetryChannel.DeveloperMode = Debugger.IsAttached; #if DEBUG configuration.TelemetryChannel.DeveloperMode = true; #endif Enabled = telemetrySettings.Enabled; if (Enabled) { telemetryClient = new TelemetryClient(configuration); // this is portable telemetryClient.Context.User.Id = telemetrySettings.UserId; // this is time based, cannot be a new one at each run telemetryClient.Context.Session.Id = telemetrySettings.SessionId; telemetryClient.Context.Session.IsFirst = telemetrySettings.IsNewSession; ///Environment.Is64BitOperatingSystem; telemetryClient.Context.Device.OperatingSystem = Environment.OSVersion.ToString(); telemetryClient.Context.Device.Id = telemetrySettings.DeviceId; telemetryClient.Context.Component.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); Trace.WriteLine(string.Format("SessionID: {0}", telemetryClient.Context.Session.Id)); } }