Exemplo n.º 1
0
        public void ContextFactoryNull()
        {
            var config = new AspNetCoreCorrelationConfiguration()
                         .WithContextFactory(null);

            Assert.Throws <ArgumentNullException>(() => ContextTracingInstrumentation.Enable(config));
        }
        public ProfilerFixture()
        {
            Injector = new InjectorMock();
            Notifier = new RequestNotifier();

            var profilerConfig = new ProfilerCorrelationConfiguration()
                                 .WithContextInjectors(new[] { Injector })
                                 .WithOutgoingRequestNotifier(Notifier);

            ContextTracingInstrumentation.Enable(profilerConfig);
        }
Exemplo n.º 3
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     // Add framework services.
     services.AddMvc();
     services.AddLogging();
     services.AddSingleton(serviceProvider =>
     {
         var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <LoggingHandler>();
         return(CorrelationHttpClientBuilder.CreateClient(new LoggingHandler(logger)));
     });
     services.AddSingleton(ContextTracingInstrumentation.Enable(Configuration.GetSection("Correlation")));
 }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
        {
            loggerFactory.AddDebug();

            var config = new AspNetCoreCorrelationConfiguration(Configuration.GetSection("Correlation"))
            {
                RequestNotifier = new OutgoingRequestNotifier()
            };
            var instrumentation = ContextTracingInstrumentation.Enable(config);

            applicationLifetime.ApplicationStopped.Register(() => instrumentation?.Dispose());

            app.UseMiddleware <IncomingRequestMiddleware>();
            app.UseMvc();
        }
Exemplo n.º 5
0
        public async Task SuccessFlowNotifier()
        {
            var notifier = new RequestNotifier();
            var config   = new AspNetCoreCorrelationConfiguration().WithOutgoingRequestNotifier(notifier);

            ContextTracingInstrumentation.Enable(config);

            var correlationId = Guid.NewGuid().ToString();

            ContextResolver.SetRequestContext(new CorrelationContext(correlationId));

            var client = new HttpClient();
            await client.GetAsync("http://google.com");

            Assert.True(notifier.BeforeWasCalled);
            Assert.True(notifier.AfterWasCalled);
        }
Exemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            var config = new AspNetCoreCorrelationConfiguration
            {
                RequestNotifier = new OutgoingRequestNotifier()
            };
            var instrumentation = ContextTracingInstrumentation.Enable(config);

            applicationLifetime.ApplicationStopped.Register(() => { instrumentation?.Dispose(); });

            app.UseApplicationInsightsRequestTelemetry();
            app.UseApplicationInsightsExceptionTelemetry();

            app.UseMvc();
        }
Exemplo n.º 7
0
        public async Task SuccessFlowCustomInjector()
        {
            var injector = new InjectorMock();

            var config = new AspNetCoreCorrelationConfiguration()
                         .WithContextInjectors(new[] { injector });

            ContextTracingInstrumentation.Enable(config);

            var correlationId = Guid.NewGuid().ToString();

            ContextResolver.SetRequestContext(new CorrelationContext(correlationId));

            var client = new HttpClient();
            await client.GetAsync("http://bing.com");

            Assert.True(injector.WasCalled);
        }
Exemplo n.º 8
0
        public async Task SuccessFlowCustomInjectorBlockedEndpoint()
        {
            var injector  = new InjectorMock();
            var validator = new EndpointValidator();

            validator.AddEndpoint("google.com");

            var config = new AspNetCoreCorrelationConfiguration()
                         .WithEndpointValidator(validator);

            ContextTracingInstrumentation.Enable(config);

            var correlationId = Guid.NewGuid().ToString();

            ContextResolver.SetRequestContext(new CorrelationContext(correlationId));

            var client = new HttpClient();
            await client.GetAsync("http://google.com");

            Assert.False(injector.WasCalled);
        }
Exemplo n.º 9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
        {
            loggerFactory.WithFilter(new FilterLoggerSettings
            {
//                    {"Microsoft", LogLevel.Warning},
//                    {"System", LogLevel.Warning}
            })
            .AddDebug()
            .AddElasicSearch();

            var configuration = new AspNetCoreCorrelationConfiguration(Configuration.GetSection("Correlation"))
            {
                RequestNotifier = new OutgoingRequestNotifier(loggerFactory.CreateLogger <OutgoingRequestNotifier>())
            };
            var instrumentation         = ContextTracingInstrumentation.Enable(configuration);
            var incomingRequestsHandler = registerIncomingRequestHandler(loggerFactory);

            applicationLifetime.ApplicationStopped.Register(() =>
            {
                instrumentation?.Dispose();
                incomingRequestsHandler?.Dispose();
            });
            app.UseMvc();
        }
        public void ContextInjectorNull()
        {
            var profilerConfig = new Configuration <CorrelationContext, WebRequest, WebResponse>();

            Assert.Throws <ArgumentNullException>(() => ContextTracingInstrumentation.Enable(profilerConfig));
        }
Exemplo n.º 11
0
        public void ContextInjectorNull()
        {
            var config = new AspNetCoreConfiguration <CorrelationContext>();

            Assert.Throws <ArgumentNullException>(() => ContextTracingInstrumentation.Enable(config));
        }
Exemplo n.º 12
0
 public void ConfigurationNull()
 {
     Assert.Throws <ArgumentNullException>(() => ContextTracingInstrumentation.Enable(null));
 }