public async Task LEGACY_Should_Send_Request_Telemetry_When_Not_Filtered_Out()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, (req, resp) => true),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();
        }
Esempio n. 2
0
        public async Task Can_Send_Request_Telemetry(int statusCode, bool expectedSuccess)
        {
            // given
            var channel = new MockTelemetryChannel();

            var response = Mock.Of <IOwinResponse>(r => r.StatusCode == statusCode);

            var context = new MockOwinContextBuilder()
                          .WithResponse(response)
                          .Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithChannel(channel)
                                .Build();

            var sut = new HttpRequestTrackingMiddleware(new NoopMiddleware(), configuration);

            // when
            await sut.Invoke(context);

            // then
            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Success.Should().Be(expectedSuccess);
        }
Esempio n. 3
0
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var config = new TelemetryConfigurationBuilder()
                             .WithChannel(Channel)
                             .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                             .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(config);

                app.UseApplicationInsights(
                    new RequestTrackingConfiguration
                {
                    TelemetryConfiguration         = config,
                    GetAdditionalContextProperties = async ctx =>
                    {
                        // do some async stuff
                        await Task.Delay(100).ConfigureAwait(false);
                        return(Enumerable.Empty <KeyValuePair <string, string> >());
                    }
                },
                    new OperationIdContextMiddlewareConfiguration
                {
                    OperationIdFactory = IdFactory.FromHeader(Consts.OperationIdHeaderName)
                }
                    );
            }
        public async Task Can_Filter_Exceptions_To_Trace()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new ThrowingMiddleware(), new RequestTrackingConfiguration
            {
                TelemetryConfiguration = configuration,
                ShouldTrackException   = async(ctx, e) =>
                                         await DefaultFilters.ShouldTrackException(ctx, e) && !(e is OlabogaException)
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            try
            {
                await sut.Invoke(context);
            }
            catch (OlabogaException)
            {
                // ignored
            }

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count(t => t is ExceptionTelemetry).Should().Be(0);
        }
        public async Task Can_Pass_Request_Details_For_Filtering()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var          configuration   = new TelemetryConfigurationBuilder().Build();
            IOwinContext filteredContext = null;

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(),
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration = configuration,
                ShouldTrackRequest     = ctx =>
                {
                    filteredContext = ctx;
                    return(Task.FromResult(false));
                }
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            filteredContext.ShouldBeEquivalentTo(context);
        }
        public async Task LEGACY_Can_Send_Request_Telemetry()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();

            VerifyDefaultsOnRequestTelemetry(telemetry);
            telemetry.ResponseCode.Should().Be("200");
            telemetry.Success.Should().BeTrue();
        }
        public async Task Should_Skip_Request_Telemetry_When_Filtered_Out()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(),
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration = configuration,
                ShouldTrackRequest     = ctx => Task.FromResult(false)
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(0);
        }
        public async Task Can_Handle_Async_Filtering_Delegate()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(),
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration = configuration,
                ShouldTrackRequest     = async ctx =>
                {
                    await Task.Delay(100);
                    return(false);
                }
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(0);
        }
Esempio n. 9
0
        public async Task Should_Skip_Request_Telemetry_When_Filtered_Out()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of <IOwinRequest>(r =>
                                                 r.Method == "GET" &&
                                                 r.Path == new PathString("/path") &&
                                                 r.Uri == new Uri("http://google.com/path")
                                                 );

            var response = Mock.Of <IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                          .WithRequest(request)
                          .WithResponse(response)
                          .Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithChannel(channel)
                                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, (req, resp) => false),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            channel.SentTelemetries.Count.Should().Be(0);
        }
        public async Task LEGACY_Can_Pass_Request_Details_For_Filtering()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var           configuration    = new TelemetryConfigurationBuilder().Build();
            IOwinRequest  filteredRequest  = null;
            IOwinResponse filteredResponse = null;

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, (req, resp) =>
            {
                filteredRequest  = req;
                filteredResponse = resp;
                return(false);
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            filteredRequest.ShouldBeEquivalentTo(context.Request);
            filteredResponse.ShouldBeEquivalentTo(context.Response);
        }
Esempio n. 11
0
        public async Task Should_Add_Properties_To_Request_Telemetry_Context_When_They_Are_Provided()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of <IOwinRequest>(r =>
                                                 r.Method == "GET" &&
                                                 r.Path == new PathString("/path") &&
                                                 r.Uri == new Uri("http://google.com/path")
                                                 );

            var response = Mock.Of <IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                          .WithRequest(request)
                          .WithResponse(response)
                          .Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithChannel(channel)
                                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, getContextProperties: (req, res) => new[]
            {
                new KeyValuePair <string, string>("key1", "val1"),
                new KeyValuePair <string, string>("key2", "val2"),
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();

            telemetry.HttpMethod.Should().Be("GET");
            telemetry.Name.Should().Be("GET /path");
            telemetry.Context.Operation.Name.Should().Be("GET /path");
            telemetry.Id.Should().NotBeNullOrEmpty();
            telemetry.Success.Should().BeTrue();
            telemetry.Url.Should().Be(new Uri("http://google.com/path"));
            telemetry.StartTime.Date.Should().Be(DateTimeOffset.Now.Date);
            telemetry.Context.Properties.Should().Contain(new[]
            {
                new KeyValuePair <string, string>("key1", "val1"),
                new KeyValuePair <string, string>("key2", "val2"),
            });
        }
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var telemetryConfig = new TelemetryConfigurationBuilder()
                    .WithChannel(Channel)
                    .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                    .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(telemetryConfig);
                app.UseApplicationInsights(telemetryConfiguration: telemetryConfig);
            }
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var telemetryConfig = new TelemetryConfigurationBuilder()
                                      .WithChannel(Channel)
                                      .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                                      .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(telemetryConfig);
                app.UseApplicationInsights(telemetryConfiguration: telemetryConfig);
            }
        public async Task LEGACY_On_Exception_Should_Pass_It_Further()
        {
            // given
            var configuration = new TelemetryConfigurationBuilder().Build();

            var context = new MockOwinContextBuilder().Build();

            var sut = new HttpRequestTrackingMiddleware(new ThrowingMiddleware(), configuration);

            // when / then
            Func <Task> sutAction = async() => await sut.Invoke(context);

            sutAction.ShouldThrow <OlabogaException>();
        }
        public async Task Can_Handle_Async_Additional_Properties_Delegate()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(),
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration         = configuration,
                GetAdditionalContextProperties = async ctx =>
                {
                    await Task.Delay(100);
                    return(new[]
                    {
                        new KeyValuePair <string, string>("key1", "val1"),
                        new KeyValuePair <string, string>("key2", "val2")
                    });
                }
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();

            telemetry.Context.Properties.Should().Contain(new[]
            {
                new KeyValuePair <string, string>("key1", "val1"),
                new KeyValuePair <string, string>("key2", "val2"),
            });

            VerifyDefaultsOnRequestTelemetry(telemetry);
            telemetry.ResponseCode.Should().Be("200");
            telemetry.Success.Should().BeTrue();
        }
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var config = new TelemetryConfigurationBuilder()
                    .WithChannel(Channel)
                    .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                    .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(config);

                app.UseApplicationInsights(
                    middlewareConfiguration:
                        new OperationIdContextMiddlewareConfiguration {ShouldTryGetIdFromHeader = true},
                    telemetryConfiguration: config);
            }
Esempio n. 17
0
        public async Task Can_Send_Request_Telemetry()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of <IOwinRequest>(r =>
                                                 r.Method == "GET" &&
                                                 r.Path == new PathString("/path") &&
                                                 r.Uri == new Uri("http://google.com/path")
                                                 );

            var response = Mock.Of <IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                          .WithRequest(request)
                          .WithResponse(response)
                          .Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithChannel(channel)
                                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();

            telemetry.HttpMethod.Should().Be("GET");
            telemetry.Name.Should().Be("GET /path");
            telemetry.Context.Operation.Name.Should().Be("GET /path");
            telemetry.Id.Should().NotBeNullOrEmpty();
            telemetry.Success.Should().BeTrue();
            telemetry.Url.Should().Be(new Uri("http://google.com/path"));
            telemetry.StartTime.Date.Should().Be(DateTimeOffset.Now.Date);
        }
        public async Task Can_Send_Request_Telemetry()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of<IOwinRequest>(r =>
                r.Method == "GET" &&
                r.Path == new PathString("/path") &&
                r.Uri == new Uri("http://google.com/path")
                );

            var response = Mock.Of<IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                .WithRequest(request)
                .WithResponse(response)
                .Build();

            var configuration = new TelemetryConfigurationBuilder()
                .WithChannel(channel)
                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;
            telemetry.Should().NotBeNull();

            telemetry.HttpMethod.Should().Be("GET");
            telemetry.Name.Should().Be("GET /path");
            telemetry.Context.Operation.Name.Should().Be("GET /path");
            telemetry.Id.Should().NotBeNullOrEmpty();
            telemetry.Success.Should().BeTrue();
            telemetry.Url.Should().Be(new Uri("http://google.com/path"));
            telemetry.StartTime.Date.Should().Be(DateTimeOffset.Now.Date);
        }
        public async Task On_Exception_Should_Log_500_Request_And_Exception_Telemetry()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new ThrowingMiddleware(),
                    new RequestTrackingConfiguration {
                TelemetryConfiguration = configuration
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            try
            {
                await sut.Invoke(context);
            }
            catch (OlabogaException)
            {
                // ignored
            }

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(2);

            var requestTelemetry = channel.SentTelemetries.First(t => t is RequestTelemetry) as RequestTelemetry;

            requestTelemetry.Success.Should().BeFalse();
            requestTelemetry.ResponseCode.Should().Be("500");

            VerifyDefaultsOnRequestTelemetry(requestTelemetry);

            var exceptionTelemetry = channel.SentTelemetries.First(t => t is ExceptionTelemetry) as ExceptionTelemetry;

            exceptionTelemetry.Context.Operation.Id.Should().NotBeNullOrEmpty();
            exceptionTelemetry.Exception.Should().BeOfType <OlabogaException>();
        }
        public async Task Should_Add_Properties_To_Request_Telemetry_Context_When_They_Are_Provided()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(),
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration         = configuration,
                GetAdditionalContextProperties = ctx =>
                                                 Task.FromResult(new[]
                {
                    new KeyValuePair <string, string>("key1", "val1"),
                    new KeyValuePair <string, string>("key2", "val2")
                }.AsEnumerable())
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();

            telemetry.Context.Properties.Should().Contain(new[]
            {
                new KeyValuePair <string, string>("key1", "val1"),
                new KeyValuePair <string, string>("key2", "val2"),
            });

            VerifyDefaultsOnRequestTelemetry(telemetry);
            telemetry.ResponseCode.Should().Be("200");
            telemetry.Success.Should().BeTrue();
        }
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var config = new TelemetryConfigurationBuilder()
                             .WithChannel(Channel)
                             .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                             .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(config);

                app.UseApplicationInsights(
                    middlewareConfiguration:
                    new OperationIdContextMiddlewareConfiguration {
                    ShouldTryGetIdFromHeader = true
                },
                    telemetryConfiguration: config);
            }
Esempio n. 22
0
        public async Task Can_Pass_Request_Details_For_Filtering()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of <IOwinRequest>(r =>
                                                 r.Method == "GET" &&
                                                 r.Path == new PathString("/path") &&
                                                 r.Uri == new Uri("http://google.com/path")
                                                 );

            var response = Mock.Of <IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                          .WithRequest(request)
                          .WithResponse(response)
                          .Build();

            var configuration = new TelemetryConfigurationBuilder()
                                .WithChannel(channel)
                                .Build();
            IOwinRequest  filteredRequest  = null;
            IOwinResponse filteredResponse = null;

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, (req, resp) =>
            {
                filteredRequest  = req;
                filteredResponse = resp;
                return(false);
            }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            filteredRequest.ShouldBeEquivalentTo(request);
            filteredResponse.ShouldBeEquivalentTo(response);
        }
        public async Task Should_Establish_New_OperationContext_With_ReqestId_As_ParentId()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();

            var actual = new OperationContextCollectingMiddleware();

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    actual,
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration = configuration,
                RequestIdFactory       = _ => "requestid"
            }),
                new OperationIdContextMiddlewareConfiguration
            {
                OperationIdFactory = _ => "operationid"
            });

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();
            telemetry.Id.Should().Be("requestid");

            actual.ParentOperationIdFromAmbientContext.Should().Be("requestid");
            actual.ParentOperationIdFromEnvironment.Should().Be("requestid");
            actual.OperationIdFromEnvironment.Should().Be("operationid");
            actual.OperationIdFromAmbientContext.Should().Be("operationid");
        }
        public async Task Should_Send_Request_Telemetry_When_Not_Filtered_Out()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of<IOwinRequest>(r =>
                r.Method == "GET" &&
                r.Path == new PathString("/path") &&
                r.Uri == new Uri("http://google.com/path")
                );

            var response = Mock.Of<IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                .WithRequest(request)
                .WithResponse(response)
                .Build();

            var configuration = new TelemetryConfigurationBuilder()
                .WithChannel(channel)
                .Build();


            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, (req, resp) => true),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            channel.SentTelemetries.Count.Should().Be(1);

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;
            telemetry.Should().NotBeNull();
        }
        public async Task Can_Pass_Request_Details_For_Filtering()
        {
            // given
            var channel = new MockTelemetryChannel();

            var request = Mock.Of<IOwinRequest>(r =>
                r.Method == "GET" &&
                r.Path == new PathString("/path") &&
                r.Uri == new Uri("http://google.com/path")
                );

            var response = Mock.Of<IOwinResponse>(r => r.StatusCode == 200);

            var context = new MockOwinContextBuilder()
                .WithRequest(request)
                .WithResponse(response)
                .Build();

            var configuration = new TelemetryConfigurationBuilder()
                .WithChannel(channel)
                .Build();
            IOwinRequest filteredRequest = null;
            IOwinResponse filteredResponse = null;

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    new NoopMiddleware(), configuration, (req, resp) =>
                    {
                        filteredRequest = req;
                        filteredResponse = resp;
                        return false;
                    }),
                new OperationIdContextMiddlewareConfiguration());

            // when
            await sut.Invoke(context);

            // then
            filteredRequest.ShouldBeEquivalentTo(request);
            filteredResponse.ShouldBeEquivalentTo(response);

        }
        public async Task Can_Send_Request_Telemetry(int statusCode, bool expectedSuccess)
        {
            // given
            var channel = new MockTelemetryChannel();

            var response = Mock.Of<IOwinResponse>(r => r.StatusCode == statusCode);

            var context = new MockOwinContextBuilder()
                .WithResponse(response)
                .Build();

            var configuration = new TelemetryConfigurationBuilder()
                .WithChannel(channel)
                .Build();

            var sut = new HttpRequestTrackingMiddleware(new NoopMiddleware(), configuration);

            // when
            await sut.Invoke(context);

            // then
            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;
            telemetry.Success.Should().Be(expectedSuccess);
        }