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 config = new TelemetryConfigurationBuilder() .WithChannel(Channel) .WithTelemetryInitializer(new OperationIdTelemetryInitializer()) .Build(); DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule(); DependencyTrackingTelemetryModule.Initialize(config); app.UseApplicationInsights( middlewareConfiguration: new OperationIdContextMiddlewareConfiguration {ShouldTryGetIdFromHeader = true}, telemetryConfiguration: config); }
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 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_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); }
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); }