Example #1
0
        private static ApplicationInsightsConfiguration ConfigureApplicationInsights(
            string instrumentationKey,
            int heartbeatIntervalSeconds,
            string jobName,
            string instanceName,
            out ITelemetryClient telemetryClient,
            out IDictionary <string, string> telemetryGlobalDimensions)
        {
            ApplicationInsightsConfiguration applicationInsightsConfiguration;

            if (heartbeatIntervalSeconds == 0)
            {
                applicationInsightsConfiguration = ApplicationInsights.Initialize(instrumentationKey);
            }
            else
            {
                applicationInsightsConfiguration = ApplicationInsights.Initialize(
                    instrumentationKey,
                    TimeSpan.FromSeconds(heartbeatIntervalSeconds));
            }

            telemetryClient = new TelemetryClientWrapper(
                new TelemetryClient(applicationInsightsConfiguration.TelemetryConfiguration));

            telemetryGlobalDimensions = new Dictionary <string, string>();

            // Enrich telemetry with job properties and global custom dimensions
            applicationInsightsConfiguration.TelemetryConfiguration.TelemetryInitializers.Add(
                new JobPropertiesTelemetryInitializer(jobName, instanceName, telemetryGlobalDimensions));

            return(applicationInsightsConfiguration);
        }
        public TelemetryService(TelemetryClient telemetryClient)
        {
            if (telemetryClient == null)
            {
                throw new ArgumentNullException(nameof(telemetryClient));
            }

            _telemetryClient = new TelemetryClientWrapper(telemetryClient);
            GlobalDimensions = new Dictionary <string, string>();
        }
Example #3
0
        public void TrackException_DoesNotThrow()
        {
            ITelemetryClientWrapper wrapper = new TelemetryClientWrapper(new TelemetryClient());

            wrapper.TrackException(new InvalidOperationException(), new Dictionary <string, string>());
        }
Example #4
0
        public void TrackEvent_DoesNotThrow()
        {
            ITelemetryClientWrapper wrapper = new TelemetryClientWrapper(new TelemetryClient());

            wrapper.TrackEvent(new EventTelemetry());
        }
Example #5
0
        protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot)
        {
            services.Configure <AccountDeleteConfiguration>(configurationRoot.GetSection(AccountDeleteConfigurationSectionName));
            SetupDefaultSubscriptionProcessorConfiguration(services, configurationRoot);

            services.AddTransient <IBrokeredMessageSerializer <AccountDeleteMessage>, AccountDeleteMessageSerializer>();
            services.AddTransient <IMessageHandler <AccountDeleteMessage>, AccountDeleteMessageHandler>();

            services.AddTransient <IAccountManager, GalleryAccountManager>();

            services.AddTransient <IAccountDeleteTelemetryService, AccountDeleteTelemetryService>();
            services.AddTransient <ISubscriptionProcessorTelemetryService, AccountDeleteTelemetryService>();

            services.AddScoped <AlwaysRejectEvaluator>();
            services.AddScoped <AlwaysAllowEvaluator>();
            services.AddScoped <AccountConfirmedEvaluator>();
            services.AddScoped <NuGetDeleteEvaluator>();

            services.AddScoped <IUserEvaluatorFactory, UserEvaluatorFactory>();
            services.AddScoped <Func <EvaluatorKey, IUserEvaluator> >(sp =>
            {
                return(evaluatorKey =>
                {
                    switch (evaluatorKey)
                    {
                    case EvaluatorKey.AccountConfirmed:
                        return sp.GetRequiredService <AccountConfirmedEvaluator>();

                    case EvaluatorKey.AlwaysAllow:
                        return sp.GetRequiredService <AlwaysAllowEvaluator>();

                    case EvaluatorKey.AlwaysReject:
                        return sp.GetRequiredService <AlwaysRejectEvaluator>();

                    case EvaluatorKey.NuGetDelete:
                        return sp.GetRequiredService <NuGetDeleteEvaluator>();

                    default:
                        throw new UnknownEvaluatorException();
                    }
                });
            });

            if (IsDebugMode)
            {
                services.AddTransient <IMessageService, DebugMessageService>();
            }
            else
            {
                services.AddTransient <IMessageService, AsynchronousEmailMessageService>();
                services.AddTransient <IEmailMessageEnqueuer, EmailMessageEnqueuer>();
                services.AddTransient <IServiceBusMessageSerializer, ServiceBusMessageSerializer>();
                services.AddTransient <ITopicClient>(serviceProvider =>
                {
                    var configuration = serviceProvider.GetRequiredService <IOptionsSnapshot <AccountDeleteConfiguration> >().Value;
                    var emailServiceBusConfiguration = configuration.EmailConfiguration.ServiceBus;
                    return(new TopicClientWrapper(emailServiceBusConfiguration.ConnectionString, emailServiceBusConfiguration.TopicPath));
                });
                services.AddTransient <IMessageServiceConfiguration, CoreMessageServiceConfiguration>();
            }

            services.AddScoped <IEmailBuilderFactory, EmailBuilderFactory>();
            services.AddScoped <ITelemetryClient, TelemetryClientWrapper>(
                sp => TelemetryClientWrapper.UseTelemetryConfiguration(ApplicationInsightsConfiguration.TelemetryConfiguration));

            ConfigureGalleryServices(services);
        }