Example #1
0
        internal TelemetryConfiguration InitializeConfiguration()
        {
            TelemetryConfiguration config = new TelemetryConfiguration()
            {
                InstrumentationKey = _instrumentationKey
            };

            AddInitializers(config);

            // TODO: FACAVAL - We're losing a lot of AI capability with the port to core.
            // A lot of the features we use are defined in the WindowsServer package, which is not currently being ported.
            // Woring with brettsam and the AI team to address the gaps.

            // Configure the TelemetryChannel
            ITelemetryChannel channel = CreateTelemetryChannel();

            // call Initialize if available
            if (channel is ITelemetryModule module)
            {
                module.Initialize(config);
            }

            config.TelemetryChannel = channel;


            return(config);
        }
Example #2
0
            public static void RegistersTelemetryClientToGetTelemetryConfigurationFromContainerAndNotGlobalInstance()
            {
                ITelemetry sentTelemetry    = null;
                var        telemetryChannel = new FakeTelemetryChannel {
                    OnSend = telemetry => sentTelemetry = telemetry
                };
                var services = CreateServicesAndAddApplicationinsightsTelemetry(null, null);
                IServiceProvider serviceProvider = services.BuildServiceProvider();
                var configuration = serviceProvider.GetTelemetryConfiguration();

                configuration.InstrumentationKey = Guid.NewGuid().ToString();
                ITelemetryChannel oldChannel = configuration.TelemetryChannel;

                try
                {
                    configuration.TelemetryChannel = telemetryChannel;

                    var telemetryClient = serviceProvider.GetRequiredService <TelemetryClient>();
                    telemetryClient.TrackEvent("myevent");

                    // We want to check that configuration from container was used but configuration is a private field so we check instrumentation key instead.
                    Assert.Equal(configuration.InstrumentationKey, sentTelemetry.Context.InstrumentationKey);
                }
                finally
                {
                    configuration.TelemetryChannel = oldChannel;
                }
            }
Example #3
0
        public static TResponse Request <TRequest, TResponse>(this ITelemetryChannel channel, IRequest <TResponse> request) where TRequest : IRequest <TResponse>
        {
            var task = channel.Request(request);

            task.Await();
            return((TResponse)task.Result);
        }
Example #4
0
        internal TelemetryClient GetClient(ITelemetryChannel channel)
        {
            var client = this.GetClient();

            client.TelemetryConfiguration.TelemetryChannel = channel;
            return(client);
        }
Example #5
0
        public EventTelemetry(
            string telemetryConnectionString,
            string telemetryTable,
            IDictionary <string, string> globalProperties,
            Action <Exception> exceptionHandler)
        {
            try
            {
                this.channel = new SqlTelemetryChannel(telemetryConnectionString, telemetryTable, exceptionHandler);

                this.configuration = new TelemetryConfiguration();

                this.configuration
                .InitializeWithDefaults()
                .InitializeWith(new GlobalPropertyInitializer(globalProperties))
                .SetInstrumentationKey("Ditto.DataLoad")
                .SetChannel(this.channel);

                this.channel = null;

                this.telemetry = new TelemetryClient(this.configuration);
            }
            finally
            {
                var disposableChannel = this.channel as IDisposable;

                if (disposableChannel != null)
                {
                    disposableChannel.Dispose();
                }
            }
        }
Example #6
0
        public void Dispose()
        {
            this.FilingClient?.Dispose();
            this.FilingClient = null;

            ITelemetryChannel channel = ServiceProviderFactory.ServiceProvider.GetService<ITelemetryChannel>();
            channel?.Flush();
            channel?.Dispose();
        }
Example #7
0
        internal void InitializeTelemetryClient(ITelemetryChannel channel)
        {
            TelemetryClientBuilder builder = new TelemetryClientBuilder(this.telimenaProperties);

#pragma warning disable 618
            this.TelemetryClient = builder.GetClient(channel);
#pragma warning restore 618
            this.InitializeSession();
        }
Example #8
0
        public void ChannelIsLazilyInitializedFromConfiguration()
        {
            var             configuration = new TelemetryConfiguration();
            TelemetryClient client        = new TelemetryClient(configuration);

            configuration.TelemetryChannel = new StubTelemetryChannel();
            ITelemetryChannel clientChannel = client.Channel;

            Assert.Same(configuration.TelemetryChannel, clientChannel);
        }
        internal UnhandledExceptionTelemetryModule(
            Action<UnhandledExceptionEventHandler> registerAction,
            Action<UnhandledExceptionEventHandler> unregisterAction,
            ITelemetryChannel channel)
        {
            this.unregisterAction = unregisterAction;
            this.channel = channel;

            registerAction(this.CurrentDomainOnUnhandledException);
        }
        internal UnhandledExceptionTelemetryModule(
            Action <UnhandledExceptionEventHandler> registerAction,
            Action <UnhandledExceptionEventHandler> unregisterAction,
            ITelemetryChannel channel)
        {
            this.unregisterAction = unregisterAction;
            this.channel          = channel;

            registerAction(this.CurrentDomainOnUnhandledException);
        }
Example #11
0
        public AppInsightsLogger(LogLevel logLevel, string connectionString, ITelemetryChannel telemetryChannel)
        {
            _logLevel         = logLevel;
            _connectionString = connectionString;

            _telemetryConfiguration = new TelemetryConfiguration
            {
                TelemetryChannel = telemetryChannel
            };
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the TelemetryConfiguration class.
        /// </summary>
        /// <param name="instrumentationKey">The instrumentation key this configuration instance will provide.</param>
        /// <param name="channel">The telemetry channel to provide with this configuration instance.</param>
        public TelemetryConfiguration(string instrumentationKey, ITelemetryChannel channel)
        {
            this.instrumentationKey = instrumentationKey ?? throw new ArgumentNullException(nameof(instrumentationKey));

            SetTelemetryChannelEndpoint(channel, this.EndpointContainer.FormattedIngestionEndpoint, force: true);
            var defaultSink = new TelemetrySink(this, channel);

            defaultSink.Name = "default";
            this.telemetrySinks.Add(defaultSink);
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:TelemetryConfigurationOptionsSetup"/> class.
 /// </summary>
 public TelemetryConfigurationOptionsSetup(
     IServiceProvider serviceProvider,
     IOptions <ApplicationInsightsServiceOptions> applicationInsightsServiceOptions,
     IEnumerable <ITelemetryInitializer> initializers,
     IEnumerable <ITelemetryModule> modules)
 {
     this.applicationInsightsServiceOptions = applicationInsightsServiceOptions.Value;
     this.initializers     = initializers;
     this.modules          = modules;
     this.telemetryChannel = serviceProvider.GetService <ITelemetryChannel>();
 }
Example #14
0
            protected override ITelemetryChannel CreateTelemetryChannel()
            {
                ITelemetryChannel channel = base.CreateTelemetryChannel();

                channel.EndpointAddress = _channelUrl;

                // DeveloperMode prevents buffering so items are sent immediately.
                channel.DeveloperMode = true;
                ((ServerTelemetryChannel)channel).MaxTelemetryBufferDelay = TimeSpan.FromSeconds(1);

                return(channel);
            }
Example #15
0
        private static TelemetryClient GetTestTelemetryClient(ITelemetryChannel channel)
        {
            var config = new TelemetryConfiguration()
            {
                TelemetryChannel   = channel,
                InstrumentationKey = "fake"
            };

            TelemetryModules.Instance.Modules.Add(new AggregateMetricsTelemetryModule());

            return(new TelemetryClient(config));
        }
Example #16
0
 public TelemetryConfigurationOptionsSetup(
     IServiceProvider serviceProvider,
     IEnumerable <ITelemetryInitializer> initializers,
     IEnumerable <ITelemetryModule> modules,
     ITelemetryChannel telemetryChannel,
     IConfigurationRoot configuration)
 {
     this._serviceProvider  = serviceProvider;
     this._initializers     = initializers;
     this._modules          = modules;
     this._telemetryChannel = telemetryChannel;
     this._configuration    = configuration;
 }
Example #17
0
 /// <summary>
 /// This will check the TelemetryChannel and attempt to set the endpoint.
 /// This only supports our first party providers <see cref="InMemoryChannel"/> and ServerTelemetryChannel.
 /// </summary>
 /// <param name="channel">TelemetryChannel to set.</param>
 /// <param name="endpoint">Endpoint value to set.</param>
 /// /// <param name="force">When the ConnectionString is set, Channel Endpoint should be forced to update. If the Channel has been set separately, we will only set endpoint if it is null.</param>
 private static void SetTelemetryChannelEndpoint(ITelemetryChannel channel, string endpoint, bool force = false)
 {
     if (channel != null)
     {
         if (channel is InMemoryChannel || channel.GetType().FullName == "Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel")
         {
             if (force || channel.EndpointAddress == null)
             {
                 channel.EndpointAddress = endpoint;
             }
         }
     }
 }
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                Interlocked.CompareExchange(ref active, null, this);

                ITelemetryChannel telemetryChannel = this.TelemetryChannel;
                if (telemetryChannel != null)
                {
                    telemetryChannel.Dispose();
                }
            }
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the TelemetryConfiguration class.
        /// </summary>
        /// <param name="instrumentationKey">The instrumentation key this configuration instance will provide.</param>
        /// <param name="channel">The telemetry channel to provide with this configuration instance.</param>
        public TelemetryConfiguration(string instrumentationKey, ITelemetryChannel channel)
        {
            if (instrumentationKey == null)
            {
                throw new ArgumentNullException(nameof(instrumentationKey));
            }

            this.instrumentationKey = instrumentationKey;
            var defaultSink = new TelemetrySink(this, channel);

            defaultSink.Name = "default";
            this.telemetrySinks.Add(defaultSink);
        }
        internal TelemetryConfiguration InitializeConfiguration()
        {
            TelemetryConfiguration config = new TelemetryConfiguration()
            {
                InstrumentationKey = _instrumentationKey
            };

            AddInitializers(config);

            // Plug in Live stream and adaptive sampling
            QuickPulseTelemetryProcessor   processor = null;
            TelemetryProcessorChainBuilder builder   = config.TelemetryProcessorChainBuilder
                                                       .Use((next) =>
            {
                processor = new QuickPulseTelemetryProcessor(next);
                return(processor);
            });

            if (_samplingSettings != null)
            {
                builder.Use((next) =>
                {
                    return(new AdaptiveSamplingTelemetryProcessor(_samplingSettings, null, next));
                });
            }

            builder.Build();

            _quickPulseModule = new QuickPulseTelemetryModule();
            _quickPulseModule.Initialize(config);
            _quickPulseModule.RegisterTelemetryProcessor(processor);

            // Plug in perf counters
            _perfModule = new PerformanceCollectorModule();
            _perfModule.Initialize(config);

            // Configure the TelemetryChannel
            ITelemetryChannel channel = CreateTelemetryChannel();

            // call Initialize if available
            ITelemetryModule module = channel as ITelemetryModule;

            if (module != null)
            {
                module.Initialize(config);
            }

            config.TelemetryChannel = channel;

            return(config);
        }
        /// <summary>
        /// Initializes a new instance of the TelemetryConfiguration class.
        /// </summary>
        /// <param name="instrumentationKey">The instrumentation key this configuration instance will provide.</param>
        /// <param name="channel">The telemetry channel to provide with this configuration instance.</param>
        public TelemetryConfiguration(string instrumentationKey, ITelemetryChannel channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            if (instrumentationKey == null)
            {
                throw new ArgumentNullException("instrumentationKey");
            }

            this.instrumentationKey = instrumentationKey;
            this.telemetryChannel   = channel;
        }
Example #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TelemetrySink"/> class.
        /// </summary>
        /// <param name="telemetryConfiguration">Telemetry configuration to use for the new <see cref="TelemetrySink"/> instance.</param>
        /// <param name="telemetryChannel">Telemetry channel to use for the new <see cref="TelemetrySink"/> instance.</param>
        public TelemetrySink(TelemetryConfiguration telemetryConfiguration, ITelemetryChannel telemetryChannel = null)
        {
            this.telemetryConfiguration = telemetryConfiguration ?? throw new ArgumentNullException(nameof(telemetryConfiguration));

            if (telemetryChannel != null)
            {
                this.telemetryChannel     = telemetryChannel;
                this.shouldDisposeChannel = false;
            }
            else
            {
                this.telemetryChannel     = new InMemoryChannel();
                this.shouldDisposeChannel = true;
            }
        }
Example #23
0
        public TelemetrySink(ITelemetryChannel channel, ITelemetryProcessChain processChain, bool isConfigured = false)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }
            this.Channel = channel;

            if (processChain == null)
            {
                throw new ArgumentNullException("processChain");
            }
            this.ProcessChain = processChain;

            this.IsConfigured = isConfigured;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TelemetrySink"/> class.
        /// </summary>
        /// <param name="telemetryConfiguration">Telemetry configuration to use for the new <see cref="TelemetrySink"/> instance.</param>
        /// <param name="telemetryChannel">Telemetry channel to use for the new <see cref="TelemetrySink"/> instance.</param>
        public TelemetrySink(TelemetryConfiguration telemetryConfiguration, ITelemetryChannel telemetryChannel = null)
        {
            this.telemetryConfiguration = telemetryConfiguration ?? throw new ArgumentNullException(nameof(telemetryConfiguration));

            if (telemetryChannel != null)
            {
                this.telemetryChannel     = telemetryChannel;
                this.shouldDisposeChannel = false;
            }
            else
            {
                this.telemetryChannel = new InMemoryChannel
                {
                    EndpointAddress = telemetryConfiguration.EndpointContainer.FormattedIngestionEndpoint,
                };
                this.shouldDisposeChannel = true;
            }
        }
Example #25
0
        public BLoggingServiceAzure(
            string _InstrumentationKey,
            Action <string> _ErrorMessageAction = null)
        {
            InstrumentationKey = _InstrumentationKey;

            try
            {
                // Create the DI container.
                IServiceCollection services = new ServiceCollection();

                // Channel is explicitly configured to do flush on it later.
                AzureTelemetryChannel = new InMemoryChannel();
                services.Configure <TelemetryConfiguration>(
                    (telemetryConfiguration) =>
                {
                    telemetryConfiguration.TelemetryChannel = AzureTelemetryChannel;
                }
                    );

                // Add the logging pipelines to use. We are using Application Insights only here.
                services.AddLogging(loggingBuilder =>
                {
                    // Optional: Apply filters to configure LogLevel Debug or above is sent to
                    // Application Insights for all categories. (It won't send LogLevel Trace)
                    loggingBuilder.AddFilter <ApplicationInsightsLoggerProvider>("", LogLevel.Debug);

                    loggingBuilder.AddApplicationInsights(InstrumentationKey);
                });

                // Build ServiceProvider.
                IServiceProvider serviceProvider = services.BuildServiceProvider();

                AzureLogger = serviceProvider.GetRequiredService <ILogger <BLoggingServiceAzure> >();

                bInitializationSucceed = true;
            }
            catch (System.Exception e)
            {
                _ErrorMessageAction?.Invoke("BLoggingServiceAzure->Constructor: " + e.Message + ", Trace: " + e.StackTrace);
                bInitializationSucceed = false;
            }
        }
        /// <summary>
        /// Disposes of resources.
        /// </summary>
        /// <param name="disposing">Indicates if managed code is being disposed.</param>
        private void Dispose(bool disposing)
        {
            if (!this.isDisposed && disposing)
            {
                this.isDisposed = true;
                Interlocked.CompareExchange(ref active, null, this);

                if (this.shouldDisposeChannel && this.telemetryChannel != null)
                {
                    this.telemetryChannel.Dispose();
                    this.telemetryChannel = null;
                }

                if (this.telemetryProcessorChain != null)
                {
                    // Not setting this.telemetryProcessorChain to null because calls to the property getter would reinitialize it.
                    this.telemetryProcessorChain.Dispose();
                }
            }
        }
Example #27
0
        public TelemetryClient(IPEndPoint endPoint,
                               ProcessTelemetryRequest processTelemetryRequest,
                               ProcessTelemetryEvent processTelemetryEvent,
                               IContractSerializer contractSerializer,
                               ITelemetryCryptoProvider cryptoProvider)
        {
            _processTelemetryRequest = processTelemetryRequest;
            _processTelemetryEvent   = processTelemetryEvent;
            _contractSerializer      = contractSerializer;
            _cryptoProvider          = cryptoProvider;
            _endPoint = endPoint;

            Channel = new MultiplexTelemetryChannel(
                contractSerializer,
                processTelemetryRequest,
                processTelemetryEvent,
                new MultiplexInputSource(channelResources.GetResource, cryptoProvider),
                new MultiplexOutputSink(channelResources.GetResource, cryptoProvider));

            Connect();
        }
Example #28
0
        public void Initialize(string sessionId, string userId)
        {
            CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(sessionId, "sessionId");
            TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.CreateDefault();

            if (telemetryConfiguration.TelemetryChannel != null)
            {
                telemetryConfiguration.TelemetryChannel.Dispose();
                telemetryConfiguration.TelemetryChannel = null;
            }
            telemetryConfiguration.TelemetryInitializers.Remove(telemetryConfiguration.TelemetryInitializers.FirstOrDefault((ITelemetryInitializer o) => o is TimestampPropertyInitializer));
            appInsightsChannel = CreateAppInsightsChannel(telemetryConfiguration);
            TelemetryClient telemetryClient = new TelemetryClient(telemetryConfiguration);

            Coding4Fun.VisualStudio.ApplicationInsights.DataContracts.TelemetryContext context = telemetryClient.Context;
            context.InstrumentationKey = InstrumentationKey;
            context.Session.Id         = sessionId;
            context.User.Id            = userId;
            context.Device.Type        = "0";
            context.Device.Id          = "0";
            appInsightsClient          = telemetryClient;
        }
Example #29
0
        public void Initialize()
        {
            this.TelemetryBuffer  = new TelemetryBuffer();
            this.TelemetryChannel = new InMemoryChannel(this.TelemetryBuffer, new InMemoryTransmitter(this.TelemetryBuffer));
            this.TelemetryClient  = new TelemetryClient(new Extensibility.TelemetryConfiguration(instrumentationKey: TestInstrumentationKey, channel: this.TelemetryChannel));

            this.TelemetryClient.Context.Component.Version = TestComponentVersion;

            this.TelemetryClient.Context.Device.Type            = TestDeviceType;
            this.TelemetryClient.Context.Device.Id              = TestDeviceId;
            this.TelemetryClient.Context.Device.OperatingSystem = TestDeviceOperatingSystem;
            this.TelemetryClient.Context.Device.OemName         = TestDeviceOemName;
            this.TelemetryClient.Context.Device.Model           = TestDeviceModel;

            this.TelemetryClient.Context.Cloud.RoleName     = TestCloudRoleName;
            this.TelemetryClient.Context.Cloud.RoleInstance = TestCloudRoleInstance;

            this.TelemetryClient.Context.Session.Id      = TestSessionId;
            this.TelemetryClient.Context.Session.IsFirst = TestSessionIsFirst;

            this.TelemetryClient.Context.User.Id                  = TestUserId;
            this.TelemetryClient.Context.User.AccountId           = TestUserAccountId;
            this.TelemetryClient.Context.User.UserAgent           = TestUserUserAgent;
            this.TelemetryClient.Context.User.AuthenticatedUserId = TestUserAuthenticatedUserId;

            this.TelemetryClient.Context.Operation.Id                = TestOperationId;
            this.TelemetryClient.Context.Operation.ParentId          = TestOperationParentId;
            this.TelemetryClient.Context.Operation.CorrelationVector = TestOperationCorrelationVector;
            this.TelemetryClient.Context.Operation.SyntheticSource   = TestOperationSyntheticSource;
            this.TelemetryClient.Context.Operation.Name              = TestOperationName;

            this.TelemetryClient.Context.Location.Ip = TestLocationIp;

            this.TelemetryClient.Context.Internal.SdkVersion   = TestInternalSdkVersion;
            this.TelemetryClient.Context.Internal.AgentVersion = TestInternalAgentVersion;
            this.TelemetryClient.Context.Internal.NodeName     = TestInternalNodeName;
        }
        private static TelemetryClient GetTestTelemetryClient(ITelemetryChannel channel)
        {
            var config = new TelemetryConfiguration()
            {
                TelemetryChannel = channel,
                InstrumentationKey = "fake"
            };

            TelemetryModules.Instance.Modules.Add(new AggregateMetricsTelemetryModule());

            return new TelemetryClient(config);
        }
 public TelemetryDiagnosticControls(ITelemetryChannel client, TelemetryConnector connection)
 {
     channel = client;
     this.connection = connection;
 }
Example #32
0
        public static IServiceCollection AddApplicationInsights(this IServiceCollection services)
        {
            // Bind to the configuration section registered with
            services.AddOptions <ApplicationInsightsLoggerOptions>()
            .Configure <ILoggerProviderConfiguration <ApplicationInsightsLoggerProvider> >((options, config) =>
            {
                config.Configuration?.Bind(options);
            });

            services.AddSingleton <ITelemetryInitializer, HttpDependenciesParsingTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, WebJobsRoleEnvironmentTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, WebJobsTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, WebJobsSanitizingInitializer>();
            services.AddSingleton <ITelemetryModule, QuickPulseTelemetryModule>();

            services.AddSingleton <IApplicationIdProvider, ApplicationInsightsApplicationIdProvider>();

            services.AddSingleton <ITelemetryModule, DependencyTrackingTelemetryModule>(provider =>
            {
                var dependencyCollector = new DependencyTrackingTelemetryModule();
                var excludedDomains     = dependencyCollector.ExcludeComponentCorrelationHttpHeadersOnDomains;
                excludedDomains.Add("core.windows.net");
                excludedDomains.Add("core.chinacloudapi.cn");
                excludedDomains.Add("core.cloudapi.de");
                excludedDomains.Add("core.usgovcloudapi.net");
                excludedDomains.Add("localhost");
                excludedDomains.Add("127.0.0.1");

                var includedActivities = dependencyCollector.IncludeDiagnosticSourceActivities;
                includedActivities.Add("Microsoft.Azure.ServiceBus");

                return(dependencyCollector);
            });
            services.AddSingleton <ITelemetryModule, AppServicesHeartbeatTelemetryModule>();

            services.AddSingleton <ITelemetryChannel, ServerTelemetryChannel>();
            services.AddSingleton <TelemetryConfiguration>(provider =>
            {
                ApplicationInsightsLoggerOptions options = provider.GetService <IOptions <ApplicationInsightsLoggerOptions> >().Value;
                LoggerFilterOptions filterOptions        = CreateFilterOptions(provider.GetService <IOptions <LoggerFilterOptions> >().Value);

                ITelemetryChannel channel     = provider.GetService <ITelemetryChannel>();
                TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();

                IApplicationIdProvider appIdProvider = provider.GetService <IApplicationIdProvider>();

                SetupTelemetryConfiguration(
                    config,
                    options.InstrumentationKey,
                    options.SamplingSettings,
                    options.SnapshotConfiguration,
                    channel,
                    provider.GetServices <ITelemetryInitializer>(),
                    provider.GetServices <ITelemetryModule>(),
                    appIdProvider,
                    filterOptions);

                return(config);
            });

            services.AddSingleton <TelemetryClient>(provider =>
            {
                TelemetryConfiguration configuration = provider.GetService <TelemetryConfiguration>();
                TelemetryClient client = new TelemetryClient(configuration);

                string assemblyVersion = GetAssemblyFileVersion(typeof(JobHost).Assembly);
                client.Context.GetInternalContext().SdkVersion = $"webjobs: {assemblyVersion}";

                return(client);
            });

            services.AddSingleton <ILoggerProvider, ApplicationInsightsLoggerProvider>();

            return(services);
        }
Example #33
0
        private static void SetupTelemetryConfiguration(
            TelemetryConfiguration configuration,
            string instrumentationKey,
            SamplingPercentageEstimatorSettings samplingSettings,
            SnapshotCollectorConfiguration snapshotCollectorConfiguration,
            ITelemetryChannel channel,
            IEnumerable <ITelemetryInitializer> telemetryInitializers,
            IEnumerable <ITelemetryModule> telemetryModules,
            IApplicationIdProvider applicationIdProvider,
            LoggerFilterOptions filterOptions)
        {
            if (instrumentationKey != null)
            {
                configuration.InstrumentationKey = instrumentationKey;

                // Because of https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/943
                // we have to touch (and create) Active configuration before initializing telemetry modules
                TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
            }

            configuration.TelemetryChannel = channel;

            foreach (ITelemetryInitializer initializer in telemetryInitializers)
            {
                configuration.TelemetryInitializers.Add(initializer);
            }

            (channel as ServerTelemetryChannel)?.Initialize(configuration);

            QuickPulseTelemetryModule quickPulseModule = null;

            foreach (ITelemetryModule module in telemetryModules)
            {
                if (module is QuickPulseTelemetryModule telemetryModule)
                {
                    quickPulseModule = telemetryModule;
                }

                module.Initialize(configuration);
            }

            QuickPulseTelemetryProcessor quickPulseProcessor = null;

            configuration.TelemetryProcessorChainBuilder
            .Use((next) =>
            {
                quickPulseProcessor = new QuickPulseTelemetryProcessor(next);
                return(quickPulseProcessor);
            })
            .Use((next) => new FilteringTelemetryProcessor(filterOptions, next));

            if (samplingSettings != null)
            {
                configuration.TelemetryProcessorChainBuilder.Use((next) =>
                                                                 new AdaptiveSamplingTelemetryProcessor(samplingSettings, null, next));
            }

            if (snapshotCollectorConfiguration != null)
            {
                configuration.TelemetryProcessorChainBuilder.UseSnapshotCollector(snapshotCollectorConfiguration);
            }

            configuration.TelemetryProcessorChainBuilder.Build();
            quickPulseModule?.RegisterTelemetryProcessor(quickPulseProcessor);

            foreach (ITelemetryProcessor processor in configuration.TelemetryProcessors)
            {
                if (processor is ITelemetryModule module)
                {
                    module.Initialize(configuration);
                }
            }

            configuration.ApplicationIdProvider = applicationIdProvider;
        }