Initialize() public method

Initializes the telemetry module.
public Initialize ( Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration configuration ) : void
configuration Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration Telemetry Configuration used for creating TelemetryClient for sending exceptions to ApplicationInsights.
return void
        public void InitializeCallsRegisterOnceThreadSafe()
        {
            int count = 0;

            Task[] tasks = new Task[50];

            using (var module = new UnobservedExceptionTelemetryModule(
                       _ => ++ count,
                       _ => { }))
            {
                for (int i = 0; i < 50; ++i)
                {
#if NET40
                    tasks[i] = System.Threading.Tasks.TaskEx.Run(() => module.Initialize(this.moduleConfiguration));
#else
                    tasks[i] = System.Threading.Tasks.Task.Run(() => module.Initialize(this.moduleConfiguration));
#endif
                }

#if NET40
                System.Threading.Tasks.TaskEx.WhenAll(tasks).Wait();
#else
                System.Threading.Tasks.Task.WhenAll(tasks).Wait();
#endif
            }

            Assert.Equal(1, count);
        }
        public void InitializeCallsRegister()
        {
            EventHandler<UnobservedTaskExceptionEventArgs> handler = null;
            using (var module = new UnobservedExceptionTelemetryModule(
                h => handler = h,
                _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
            }

            Assert.NotNull(handler);
        }
        public void TrackedExceptionsHavePrefixUsedForTelemetry()
        {
            EventHandler<UnobservedTaskExceptionEventArgs> handler = null;
            using (var module = new UnobservedExceptionTelemetryModule(
                h => handler = h,
                _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
                handler.Invoke(null, new UnobservedTaskExceptionEventArgs(new AggregateException(string.Empty)));
            }

            Assert.True(this.items[0].Context.GetInternalContext().SdkVersion.StartsWith("unobs: ", StringComparison.OrdinalIgnoreCase));
        }
        public void TrackedExceptionsHaveMessageFromException()
        {
            EventHandler<UnobservedTaskExceptionEventArgs> handler = null;
            using (var module = new UnobservedExceptionTelemetryModule(
                h => handler = h,
                _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
                handler.Invoke(null, new UnobservedTaskExceptionEventArgs(new AggregateException("Test")));
            }

            Assert.Equal("Test", ((ExceptionTelemetry)this.items[0]).Exception.Message);
        }
        public void InitializeCallsRegisterOnce()
        {
            int count = 0;

            using (var module = new UnobservedExceptionTelemetryModule(
                _ => ++count,
                _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
            }

            Assert.Equal(1, count);
        }
        public void InitializeCallsRegisterOnce()
        {
            int count = 0;

            using (var module = new UnobservedExceptionTelemetryModule(
                       _ => ++ count,
                       _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
            }

            Assert.Equal(1, count);
        }
        public void InitializeCallsRegister()
        {
            EventHandler <UnobservedTaskExceptionEventArgs> handler = null;

            using (var module = new UnobservedExceptionTelemetryModule(
                       h => handler = h,
                       _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
            }

            Assert.NotNull(handler);
        }
        public void TrackedExceptionsHaveMessageFromException()
        {
            EventHandler <UnobservedTaskExceptionEventArgs> handler = null;

            using (var module = new UnobservedExceptionTelemetryModule(
                       h => handler = h,
                       _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
                handler.Invoke(null, new UnobservedTaskExceptionEventArgs(new AggregateException("Test")));
            }

            Assert.Equal("Test", ((ExceptionTelemetry)this.items[0]).Exception.Message);
        }
        public void TrackedExceptionsHavePrefixUsedForTelemetry()
        {
            EventHandler <UnobservedTaskExceptionEventArgs> handler = null;

            using (var module = new UnobservedExceptionTelemetryModule(
                       h => handler = h,
                       _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
                handler.Invoke(null, new UnobservedTaskExceptionEventArgs(new AggregateException(string.Empty)));
            }

            Assert.True(this.items[0].Context.GetInternalContext().SdkVersion.StartsWith("unobs: ", StringComparison.OrdinalIgnoreCase));
        }
        public void TrackedExceptionsHavePrefixUsedForTelemetry()
        {
            string expectedVersion = SdkVersionHelper.GetExpectedSdkVersion(typeof(UnobservedExceptionTelemetryModule), prefix: "unobs:");

            EventHandler <UnobservedTaskExceptionEventArgs> handler = null;

            using (var module = new UnobservedExceptionTelemetryModule(
                       h => handler = h,
                       _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
                handler.Invoke(null, new UnobservedTaskExceptionEventArgs(new AggregateException(string.Empty)));
            }

            Assert.Equal(expectedVersion, this.items[0].Context.GetInternalContext().SdkVersion);
        }
        public void InitializeCallsRegisterOnceThreadSafe()
        {
            int count = 0;

            Task[] tasks = new Task[50];

            using (var module = new UnobservedExceptionTelemetryModule(
                _ => ++count,
                _ => { }))
            {
                for (int i = 0; i < 50; ++i)
                {
                    tasks[i] = TaskEx.Run(() => module.Initialize(this.moduleConfiguration));
                }

                TaskEx.WhenAll(tasks).Wait();
            }

            Assert.Equal(1, count);
        }
        public void TrackedExceptionsHavePrefixUsedForTelemetry()
        {
            string expectedVersion = SdkVersionHelper.GetExpectedSdkVersion(typeof(UnobservedExceptionTelemetryModule), prefix: "unobs:");

            EventHandler<UnobservedTaskExceptionEventArgs> handler = null;
            using (var module = new UnobservedExceptionTelemetryModule(
                h => handler = h,
                _ => { }))
            {
                module.Initialize(this.moduleConfiguration);
                handler.Invoke(null, new UnobservedTaskExceptionEventArgs(new AggregateException(string.Empty)));
            }

            Assert.Equal(expectedVersion, this.items[0].Context.GetInternalContext().SdkVersion);
        }