marcingrzejszczak commented on code in PR #1346: URL: https://github.com/apache/cxf/pull/1346#discussion_r1291743653
########## systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java: ########## @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.systest.jaxrs.spring.boot; + +import java.time.Duration; + +import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; + +import brave.sampler.Sampler; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; +import org.apache.cxf.Bus; +import org.apache.cxf.feature.Feature; +import org.apache.cxf.systest.ArrayListSpanReporter; +import org.apache.cxf.systest.jaxrs.resources.Library; +import org.apache.cxf.tracing.micrometer.ObservationClientFeature; +import org.apache.cxf.tracing.micrometer.ObservationFeature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import zipkin2.Span; +import zipkin2.reporter.Reporter; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.observation.ObservationRegistry; +import io.micrometer.tracing.Span.Kind; +import io.micrometer.tracing.test.simple.SpansAssert; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.hasSize; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsObservabiityTest.TestConfig.class) +@ActiveProfiles("jaxrs") +@AutoConfigureObservability +public class SpringJaxrsObservabiityTest { + + @Autowired + private MeterRegistry registry; + + @Autowired + private ObservationRegistry observationRegistry; + + @Autowired + private ArrayListSpanReporter arrayListSpanReporter; + + @LocalServerPort + private int port; + + @EnableAutoConfiguration(exclude = WebMvcObservationAutoConfiguration.class) + @ComponentScan(basePackageClasses = Library.class) + static class TestConfig { + @Bean + public Feature observationFeature(ObservationRegistry observationRegistry) { + return new ObservationFeature(observationRegistry); + } + + @Bean + public JacksonJsonProvider jacksonJsonProvider() { + return new JacksonJsonProvider(); + } + + @Bean + Sampler sampler() { + return Sampler.ALWAYS_SAMPLE; + } + + @Bean + ArrayListSpanReporter arrayListSpanReporter() { + return new ArrayListSpanReporter(); + } + + @Bean + Reporter<Span> reporter() { + return Reporter.CONSOLE; + } + } + + @Autowired + public void setBus(Bus bus) { + // By default, the exception are propagated and out fault interceptors are not called + bus.setProperty("org.apache.cxf.propagate.exception", Boolean.FALSE); + } + + @AfterEach + public void clear() { + registry.clear(); + arrayListSpanReporter.close(); + } + + @Test + public void testJaxrsSuccessMetric() { + final WebTarget target = createWebTarget(); + + try (Response r = target.request().get()) { + assertThat(r.getStatus()).isEqualTo(200); + } + + await() + .atMost(Duration.ofSeconds(1)) + .until(() -> arrayListSpanReporter.getSpans(), hasSize(2)); + + // Micrometer Observation with Micrometer Tracing + SpansAssert.assertThat(arrayListSpanReporter.getSpans()) + .haveSameTraceId() + .hasASpanWithName("GET", spanAssert -> { + spanAssert.hasKindEqualTo(Kind.CLIENT) + .hasTag("rpc.service", "WebClient") + .hasTag("rpc.system", "cxf") + .hasTagWithKey("server.address") + .hasTagWithKey("server.port") + .isStarted() + .isEnded(); + }) + .hasASpanWithName("rpc.server.duration", spanAssert -> { Review Comment: Interesting. That would mean that the default, "metric" related name hooked in and the contextual name wasn't called. Here you can see how the contextual name should be set (https://github.com/apache/cxf/pull/1346/files#diff-05b29f9cca6ab07f827c4985ccf14e61f6c878510b4e18c37634b360041ed658R42) and here (https://github.com/apache/cxf/pull/1346/files#diff-3a451c2c9618eb5753ffd9960d384ffa6685f97fedf6605d787c7c018556d871R77) but maybe I messed sth up 😬 ########## systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java: ########## @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.systest.jaxrs.spring.boot; + +import java.time.Duration; + +import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; + +import brave.sampler.Sampler; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; +import org.apache.cxf.Bus; +import org.apache.cxf.feature.Feature; +import org.apache.cxf.systest.ArrayListSpanReporter; +import org.apache.cxf.systest.jaxrs.resources.Library; +import org.apache.cxf.tracing.micrometer.ObservationClientFeature; +import org.apache.cxf.tracing.micrometer.ObservationFeature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import zipkin2.Span; +import zipkin2.reporter.Reporter; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.observation.ObservationRegistry; +import io.micrometer.tracing.Span.Kind; +import io.micrometer.tracing.test.simple.SpansAssert; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.hasSize; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsObservabiityTest.TestConfig.class) +@ActiveProfiles("jaxrs") +@AutoConfigureObservability +public class SpringJaxrsObservabiityTest { + + @Autowired + private MeterRegistry registry; + + @Autowired + private ObservationRegistry observationRegistry; + + @Autowired + private ArrayListSpanReporter arrayListSpanReporter; + + @LocalServerPort + private int port; + + @EnableAutoConfiguration(exclude = WebMvcObservationAutoConfiguration.class) + @ComponentScan(basePackageClasses = Library.class) + static class TestConfig { + @Bean + public Feature observationFeature(ObservationRegistry observationRegistry) { + return new ObservationFeature(observationRegistry); + } + + @Bean + public JacksonJsonProvider jacksonJsonProvider() { + return new JacksonJsonProvider(); + } + + @Bean + Sampler sampler() { + return Sampler.ALWAYS_SAMPLE; + } + + @Bean + ArrayListSpanReporter arrayListSpanReporter() { + return new ArrayListSpanReporter(); + } + + @Bean + Reporter<Span> reporter() { + return Reporter.CONSOLE; + } + } + + @Autowired + public void setBus(Bus bus) { + // By default, the exception are propagated and out fault interceptors are not called + bus.setProperty("org.apache.cxf.propagate.exception", Boolean.FALSE); + } + + @AfterEach + public void clear() { + registry.clear(); + arrayListSpanReporter.close(); + } + + @Test + public void testJaxrsSuccessMetric() { + final WebTarget target = createWebTarget(); + + try (Response r = target.request().get()) { + assertThat(r.getStatus()).isEqualTo(200); + } + + await() + .atMost(Duration.ofSeconds(1)) + .until(() -> arrayListSpanReporter.getSpans(), hasSize(2)); + + // Micrometer Observation with Micrometer Tracing + SpansAssert.assertThat(arrayListSpanReporter.getSpans()) + .haveSameTraceId() + .hasASpanWithName("GET", spanAssert -> { + spanAssert.hasKindEqualTo(Kind.CLIENT) + .hasTag("rpc.service", "WebClient") + .hasTag("rpc.system", "cxf") + .hasTagWithKey("server.address") + .hasTagWithKey("server.port") + .isStarted() + .isEnded(); + }) + .hasASpanWithName("rpc.server.duration", spanAssert -> { Review Comment: Interesting. That would mean that the default, "metric" related name hooked in and the contextual name wasn't called. Here you can see how the contextual name should be set (https://github.com/apache/cxf/pull/1346/files#diff-05b29f9cca6ab07f827c4985ccf14e61f6c878510b4e18c37634b360041ed658R42) and here (https://github.com/apache/cxf/pull/1346/files#diff-3a451c2c9618eb5753ffd9960d384ffa6685f97fedf6605d787c7c018556d871R77) but maybe I messed sth up 😬 ########## systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java: ########## @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.systest.jaxrs.spring.boot; + +import java.time.Duration; + +import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; + +import brave.sampler.Sampler; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; +import org.apache.cxf.Bus; +import org.apache.cxf.feature.Feature; +import org.apache.cxf.systest.ArrayListSpanReporter; +import org.apache.cxf.systest.jaxrs.resources.Library; +import org.apache.cxf.tracing.micrometer.ObservationClientFeature; +import org.apache.cxf.tracing.micrometer.ObservationFeature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import zipkin2.Span; +import zipkin2.reporter.Reporter; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.observation.ObservationRegistry; +import io.micrometer.tracing.Span.Kind; +import io.micrometer.tracing.test.simple.SpansAssert; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.hasSize; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsObservabiityTest.TestConfig.class) +@ActiveProfiles("jaxrs") +@AutoConfigureObservability +public class SpringJaxrsObservabiityTest { + + @Autowired + private MeterRegistry registry; + + @Autowired + private ObservationRegistry observationRegistry; + + @Autowired + private ArrayListSpanReporter arrayListSpanReporter; + + @LocalServerPort + private int port; + + @EnableAutoConfiguration(exclude = WebMvcObservationAutoConfiguration.class) + @ComponentScan(basePackageClasses = Library.class) + static class TestConfig { + @Bean + public Feature observationFeature(ObservationRegistry observationRegistry) { Review Comment: Here you are creating the feature manually and I guess we want that to happen out of the box? ########## systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java: ########## @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.systest.jaxrs.spring.boot; + +import java.time.Duration; + +import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; + +import brave.sampler.Sampler; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; +import org.apache.cxf.Bus; +import org.apache.cxf.feature.Feature; +import org.apache.cxf.systest.ArrayListSpanReporter; +import org.apache.cxf.systest.jaxrs.resources.Library; +import org.apache.cxf.tracing.micrometer.ObservationClientFeature; +import org.apache.cxf.tracing.micrometer.ObservationFeature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import zipkin2.Span; +import zipkin2.reporter.Reporter; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.observation.ObservationRegistry; +import io.micrometer.tracing.Span.Kind; +import io.micrometer.tracing.test.simple.SpansAssert; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.hasSize; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsObservabiityTest.TestConfig.class) +@ActiveProfiles("jaxrs") +@AutoConfigureObservability +public class SpringJaxrsObservabiityTest { + + @Autowired + private MeterRegistry registry; + + @Autowired + private ObservationRegistry observationRegistry; + + @Autowired + private ArrayListSpanReporter arrayListSpanReporter; + + @LocalServerPort + private int port; + + @EnableAutoConfiguration(exclude = WebMvcObservationAutoConfiguration.class) Review Comment: You did it right - I think I did the same thing. So `WebMvcObservationAutoConfiguration` is the configuration that hooks in for MVC observations on the Servlet level. The Cxf instrumentation is on a different level and should take precedense for that matter. You would have the same problem with e.g. Tomcat Valve instrumentation. Tomcat would hook in earlier and we would have to disable the `WebMvcAutoConfiguration` (or just the observation filter) so as not to do double instrumentation. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
