Esempio n. 1
0
        public virtual void Initialize(string version, IApplicationSettings settings)
        {
            if (settings.SendErrors)
            {
                var instrumentationKey = GetInstrumentationKey();

                if (!string.IsNullOrEmpty(instrumentationKey))
                {
                    _client = new TelemetryClient
                    {
                        InstrumentationKey = instrumentationKey
                    };

                    _client.Context.Component.Version = version;

                    _client.TrackPageView("Main");
                }
            }

            if (_client != null)
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;
            }
        }
Esempio n. 2
0
        public Telemetry(
            IOptions <TelemetryOptions> options,
            IEnumerable <ITelemetryInitializer> initializers,
            IFirstTimeUseNoticeSentinel sentinel)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options.Value;

            Enabled = _options.IsEnabled && !EnvironmentHelper.GetEnvironmentVariableAsBool(_options.TelemetryOptout) && PermissionExists(sentinel);

            if (!Enabled)
            {
                return;
            }

            _telemetryConfig = TelemetryConfiguration.CreateDefault();

            foreach (var initializer in initializers)
            {
                _telemetryConfig.TelemetryInitializers.Add(initializer);
            }

            _client = new TelemetryClient(_telemetryConfig)
            {
                InstrumentationKey = _options.InstrumentationKey
            };

            _client.Context.Session.Id             = _options.CurrentSessionId;
            _client.Context.Device.OperatingSystem = RuntimeEnvironment.OperatingSystem;
        }
        public static void Initialize()
        {
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new AppVersionTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new EnvironmentTelemetryInitializer());

            Application.Current.DispatcherUnhandledException += App_DispatcherUnhandledException;
            _client = new TelemetryClient();
        }
Esempio n. 4
0
 internal SyncWatcherConnector(AppSettings appSettings, ISynchronize synchronize,
                               IWebSocketConnectionsService connectionsService, IQuery query, IWebLogger logger, TelemetryClient?telemetryClient)
 {
     _appSettings        = appSettings;
     _synchronize        = synchronize;
     _connectionsService = connectionsService;
     _query           = query;
     _logger          = logger;
     _telemetryClient = telemetryClient;
 }
Esempio n. 5
0
        public SetupDatabaseTypes(AppSettings appSettings, IServiceCollection?services = null, IWebLogger?logger = null)
        {
            _appSettings = appSettings;
            _services    = services;

            // if null get from service collection
            logger ??= _services?.BuildServiceProvider().GetService <IWebLogger>();
            _telemetryClient = _services?.BuildServiceProvider().GetService <TelemetryClient>();

            _logger = logger;
        }
Esempio n. 6
0
        public static void Initialize()
        {
#pragma warning disable CA2000 // Dispose objects before losing scope
            var config = TelemetryConfiguration.CreateDefault();
#pragma warning restore CA2000 // Dispose objects before losing scope

            config.TelemetryInitializers.Add(new AppVersionTelemetryInitializer());
            config.TelemetryInitializers.Add(new EnvironmentTelemetryInitializer());

            Application.Current.DispatcherUnhandledException += App_DispatcherUnhandledException;
            _client = new TelemetryClient(config);
        }
 public AutoServerRestartJob(
     ILogger <AutoServerRestartJob> logger,
     PolychatSettings settings,
     IPolychatService polychatService,
     IMediator mediator,
     TelemetryClient?telemetryClient = null
     )
 {
     _logger          = logger;
     _settings        = settings;
     _polychatService = polychatService;
     _mediator        = mediator;
     _telemetryClient = telemetryClient;
 }
 public static void SetEnabled(bool enabled)
 {
     Enabled = enabled;
     using var config = TelemetryConfiguration.CreateDefault();
     config.InstrumentationKey = INSTRUMENTATION_KEY;
     config.DisableTelemetry = Enabled;
     Client = new TelemetryClient(config);
     Client.Context.Component.Version = AsaHelpers.GetVersionString();
     // Force some values to static values to prevent gathering unneeded data
     Client.Context.Cloud.RoleInstance = "Asa";
     Client.Context.Cloud.RoleName = "Asa";
     Client.Context.Location.Ip = "1.1.1.1";
     DatabaseManager.SetTelemetryEnabled(Enabled);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MetricsService"/> class.
        /// </summary>
        /// <param name="telemetryClient">The ApplicationInsights telemetry client (null if AppInsights is off).</param>
        public MetricsService(TelemetryClient?telemetryClient)
        {
            var name = "sum_computation_api_call_duration_s";
            var help = "Duration in seconds of calls to the SumComputationAPI.";

            this.SumComputationAPICallDuration = new Histogram(
                Prometheus.Metrics.CreateHistogram(name, help, new HistogramConfiguration
            {
                Buckets = Prometheus.Histogram.ExponentialBuckets(start: 0.001, factor: 2, count: 15),
            }),
                name,
                help,
                telemetryClient?.GetMetric(name));
        }
Esempio n. 10
0
        private TelemetryClient GetOrCreateTelemetryClient()
        {
            if (_client == null)
            {
                lock (_syncRoot)
                {
                    if (_client == null)
                    {
                        //override instrumentation key or use default telemetry
                        //configuration active on the project.

                        var configuration = string.IsNullOrWhiteSpace(_instrumentationKey)
                            ? _telemetryConfiguration
                            : new TelemetryConfiguration(_instrumentationKey);

                        _client = new TelemetryClient(configuration);
                    }
                }
            }
            return(_client);
        }
Esempio n. 11
0
        internal bool InjectScopes()
        {
            if (_serviceScope == null)
            {
                return(false);
            }
            // ISynchronize is a scoped service
            _synchronize        = _serviceScope.ServiceProvider.GetRequiredService <ISynchronize>();
            _appSettings        = _serviceScope.ServiceProvider.GetRequiredService <AppSettings>();
            _connectionsService = _serviceScope.ServiceProvider.GetRequiredService <IWebSocketConnectionsService>();
            var query = _serviceScope.ServiceProvider.GetRequiredService <IQuery>();

            _logger = _serviceScope.ServiceProvider.GetRequiredService <IWebLogger>();
            var memoryCache = _serviceScope.ServiceProvider.GetService <IMemoryCache>();

            _query = new QueryFactory(new SetupDatabaseTypes(_appSettings), query,
                                      memoryCache, _appSettings, _logger).Query();
            _telemetryClient = _serviceScope.ServiceProvider
                               .GetService <TelemetryClient>();
            return(true);
        }
Esempio n. 12
0
        public static void Initialize(bool isDirty)
        {
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new AppEnvironmentTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new AppInfoTelemetryInitializer(isDirty));
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new MonitorsTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new ThemingTelemetryInitializer());

            Application.ApplicationExit += (s, e) =>
            {
                TrackEvent("AppExit");
                OnExit();
            };

            _client = new TelemetryClient();

            // override capture of the hostname
            // https://github.com/Microsoft/ApplicationInsights-dotnet/blob/80025b5d79cc52485510d422cfa5a0a8159dac83/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L544
            _client.Context.Cloud.RoleInstance = AppSettings.ApplicationName;
            _client.Context.Cloud.RoleName     = AppSettings.ApplicationName;

            _initialized = true;
        }
 public DatabaseTelemetryInterceptor(TelemetryClient?telemetryClient)
 {
     _telemetryClient = telemetryClient;
 }
        public static TelemetryClient?InitTelemetryClient(string appInsightsConnectionString, string roleName, IWebLogger?logger, TelemetryClient?telemetryClient)
        {
            TelemetryClient?Clean(Exception exception)
            {
                logger?.LogInformation($"catch-ed exception; {exception.Message} ", exception);
                logger?.LogInformation("run GC.Collect next -->");
                GC.Collect();
                return(null);
            }

            try
            {
                // Should skip to avoid memory issues
                if (telemetryClient == null)
                {
                    var telemetryConfiguration =
                        CreateTelemetryConfiguration(appInsightsConnectionString);
                    if (telemetryConfiguration == null)
                    {
                        return(null);
                    }
                    telemetryClient =
                        new TelemetryClient(telemetryConfiguration);
                    telemetryClient.Context.Cloud.RoleName     = roleName;
                    telemetryClient.Context.Cloud.RoleInstance =
                        Environment.MachineName;
                    logger?.LogInformation("Added TelemetryClient [should avoid due memory issues]");
                }

                var module = CreateDatabaseDependencyTrackingTelemetryModule();
                module.Initialize(telemetryClient.TelemetryConfiguration);
                return(telemetryClient);
            }
            catch (OutOfMemoryException exception)
            {
                return(Clean(exception));
            }
            catch (System.Threading.Tasks.TaskSchedulerException exception)
            {
                return(Clean(exception));
            }
        }
Esempio n. 15
0
 public TrackDependency(TelemetryClient?telemetryClient)
 {
     _telemetryClient = telemetryClient;
 }