From f01a266fabc1cc44e13d535f888b542ae1923340 Mon Sep 17 00:00:00 2001 From: Dhaval Doshi Date: Fri, 2 Nov 2018 15:51:31 -0700 Subject: [PATCH] Fix the filter order in starter (#766) * fixing the filter order in starter * add smoke test for 500 capturing * add autoconfigure before for Azure metrics springboot starter and revert the version number update for core sdk * Polish --- .../gradle.properties | 2 +- ...plicationInsightsTelemetryAutoConfiguration.java | 3 ++- .../ApplicationInsightsWebMvcAutoConfiguration.java | 2 +- .../controller/TestController.java | 5 +++++ .../src/main/resources/application.properties | 1 + .../smoketest/SpringbootSmokeTest.java | 13 +++++++++++++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/azure-application-insights-spring-boot-starter/gradle.properties b/azure-application-insights-spring-boot-starter/gradle.properties index b7fba5e1dc9..47f07483200 100644 --- a/azure-application-insights-spring-boot-starter/gradle.properties +++ b/azure-application-insights-spring-boot-starter/gradle.properties @@ -1 +1 @@ -spring.boot.starter.version-number=1.1.0-BETA \ No newline at end of file +spring.boot.starter.version-number=1.1.1-BETA \ No newline at end of file diff --git a/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsTelemetryAutoConfiguration.java b/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsTelemetryAutoConfiguration.java index 79114779150..4a331fa076b 100644 --- a/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsTelemetryAutoConfiguration.java +++ b/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsTelemetryAutoConfiguration.java @@ -73,7 +73,8 @@ ApplicationInsightsWebModuleConfiguration.class }) @AutoConfigureBefore(name = { - "io.micrometer.spring.autoconfigure.export.azuremonitor.AzureMonitorMetricsExportAutoConfiguration" + "io.micrometer.spring.autoconfigure.export.azuremonitor.AzureMonitorMetricsExportAutoConfiguration", + "com.microsoft.azure.spring.autoconfigure.metrics.AzureMonitorMetricsExportAutoConfiguration" }) public class ApplicationInsightsTelemetryAutoConfiguration { diff --git a/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsWebMvcAutoConfiguration.java b/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsWebMvcAutoConfiguration.java index 6466aef655e..9238588d042 100644 --- a/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsWebMvcAutoConfiguration.java +++ b/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/ApplicationInsightsWebMvcAutoConfiguration.java @@ -69,7 +69,7 @@ public FilterRegistrationBean webRequestTrackingFilterRegistrationBean(WebReques FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(webRequestTrackingFilter); registration.addUrlPatterns("/*"); - registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 10); + registration.setOrder(Ordered.HIGHEST_PRECEDENCE); return registration; } diff --git a/test/smoke/testApps/SpringBootTest/src/main/java/com/springbootstartertest/controller/TestController.java b/test/smoke/testApps/SpringBootTest/src/main/java/com/springbootstartertest/controller/TestController.java index db0efc0555e..bda80290cb4 100644 --- a/test/smoke/testApps/SpringBootTest/src/main/java/com/springbootstartertest/controller/TestController.java +++ b/test/smoke/testApps/SpringBootTest/src/main/java/com/springbootstartertest/controller/TestController.java @@ -36,4 +36,9 @@ public String trackEventSpringBoot() { client.trackEvent("EventDataPropertyTest", properties, metrics); return "hello"; } + + @GetMapping("/throwsException") + public void resultCodeTest() throws Exception { + throw new Exception("This is an exception"); + } } diff --git a/test/smoke/testApps/SpringBootTest/src/main/resources/application.properties b/test/smoke/testApps/SpringBootTest/src/main/resources/application.properties index 741e0983b10..3b5e0148db6 100644 --- a/test/smoke/testApps/SpringBootTest/src/main/resources/application.properties +++ b/test/smoke/testApps/SpringBootTest/src/main/resources/application.properties @@ -3,3 +3,4 @@ azure.application-insights.channel.in-process.endpoint-address=http://fakeingest azure.application-insights.instrumentation-key=00000000-0000-0000-0000-cba987654321 azure.application-insights.logger.level=TRACE azure.application-insights.default-modules.ProcessPerformanceCountersModule.enabled=false +azure.application-insights.heart-beat.enabled=false diff --git a/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java b/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java index 872cedfaf28..3a033e99d3b 100644 --- a/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java +++ b/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java @@ -3,8 +3,11 @@ import static org.junit.Assert.assertEquals; import com.microsoft.applicationinsights.internal.schemav2.EventData; +import com.microsoft.applicationinsights.internal.schemav2.RequestData; import com.microsoft.applicationinsights.smoketest.AiSmokeTest; import com.microsoft.applicationinsights.smoketest.TargetUri; +import com.microsoft.applicationinsights.telemetry.Duration; +import com.microsoft.localforwarder.library.inputs.contracts.Request; import org.junit.Test; public class SpringbootSmokeTest extends AiSmokeTest{ @@ -34,4 +37,14 @@ public void trackEvent() throws Exception { assertEquals(expectedProperties, d2.getProperties().get("key")); assertEquals(expectedMetric, d2.getMeasurements().get("key")); } + + @Test + @TargetUri("/throwsException") + public void testResultCodeWhenRestControllerThrows() throws Exception { + assertEquals(1, mockedIngestion.getCountForType("RequestData")); + RequestData d = getTelemetryDataForType(0, "RequestData"); + final String expectedResponseCode = "500"; + assertEquals(expectedResponseCode, d.getResponseCode()); + assertEquals(false, d.getSuccess()); + } }