Fix warnings from the spring boot starter (#10086)
This commit is contained in:
parent
1ee51e410e
commit
04da58e5e4
|
@ -12,6 +12,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.Otlp
|
||||||
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpMetricExporterAutoConfiguration;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpMetricExporterAutoConfiguration;
|
||||||
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration;
|
||||||
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.MapConverter;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.MapConverter;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration;
|
||||||
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringResourceConfigProperties;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringResourceConfigProperties;
|
||||||
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
|
@ -34,7 +35,9 @@ import io.opentelemetry.sdk.trace.export.SpanExporter;
|
||||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
@ -42,6 +45,7 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesBindin
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Role;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
|
|
||||||
|
@ -189,4 +193,12 @@ public class OpenTelemetryAutoConfiguration {
|
||||||
return OpenTelemetry.noop();
|
return OpenTelemetry.noop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
// we declared this bean as an infrastructure bean to avoid warning from BeanPostProcessorChecker
|
||||||
|
// when it is injected into a BeanPostProcessor
|
||||||
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
|
public static OpenTelemetrySupplier openTelemetrySupplier(BeanFactory beanFactory) {
|
||||||
|
return () -> beanFactory.getBean(OpenTelemetry.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,18 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.kafka;
|
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.kafka;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import io.opentelemetry.instrumentation.spring.kafka.v2_7.SpringKafkaTelemetry;
|
import io.opentelemetry.instrumentation.spring.kafka.v2_7.SpringKafkaTelemetry;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||||
|
|
||||||
class ConcurrentKafkaListenerContainerFactoryPostProcessor implements BeanPostProcessor {
|
class ConcurrentKafkaListenerContainerFactoryPostProcessor implements BeanPostProcessor {
|
||||||
|
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetrySupplier openTelemetrySupplier;
|
||||||
|
|
||||||
ConcurrentKafkaListenerContainerFactoryPostProcessor(OpenTelemetry openTelemetry) {
|
ConcurrentKafkaListenerContainerFactoryPostProcessor(
|
||||||
this.openTelemetry = openTelemetry;
|
OpenTelemetrySupplier openTelemetrySupplier) {
|
||||||
|
this.openTelemetrySupplier = openTelemetrySupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +27,8 @@ class ConcurrentKafkaListenerContainerFactoryPostProcessor implements BeanPostPr
|
||||||
|
|
||||||
ConcurrentKafkaListenerContainerFactory<?, ?> listenerContainerFactory =
|
ConcurrentKafkaListenerContainerFactory<?, ?> listenerContainerFactory =
|
||||||
(ConcurrentKafkaListenerContainerFactory<?, ?>) bean;
|
(ConcurrentKafkaListenerContainerFactory<?, ?>) bean;
|
||||||
SpringKafkaTelemetry springKafkaTelemetry = SpringKafkaTelemetry.create(openTelemetry);
|
SpringKafkaTelemetry springKafkaTelemetry =
|
||||||
|
SpringKafkaTelemetry.create(openTelemetrySupplier.get());
|
||||||
listenerContainerFactory.setBatchInterceptor(springKafkaTelemetry.createBatchInterceptor());
|
listenerContainerFactory.setBatchInterceptor(springKafkaTelemetry.createBatchInterceptor());
|
||||||
listenerContainerFactory.setRecordInterceptor(springKafkaTelemetry.createRecordInterceptor());
|
listenerContainerFactory.setRecordInterceptor(springKafkaTelemetry.createRecordInterceptor());
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.ka
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import io.opentelemetry.instrumentation.kafkaclients.v2_6.KafkaTelemetry;
|
import io.opentelemetry.instrumentation.kafkaclients.v2_6.KafkaTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
@ -30,8 +31,9 @@ public class KafkaInstrumentationAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
ConcurrentKafkaListenerContainerFactoryPostProcessor
|
static ConcurrentKafkaListenerContainerFactoryPostProcessor
|
||||||
otelKafkaListenerContainerFactoryBeanPostProcessor(OpenTelemetry openTelemetry) {
|
otelKafkaListenerContainerFactoryBeanPostProcessor(
|
||||||
return new ConcurrentKafkaListenerContainerFactoryPostProcessor(openTelemetry);
|
OpenTelemetrySupplier openTelemetrySupplier) {
|
||||||
|
return new ConcurrentKafkaListenerContainerFactoryPostProcessor(openTelemetrySupplier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.web;
|
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.web;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry;
|
import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
@ -14,10 +14,10 @@ import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
final class RestTemplateBeanPostProcessor implements BeanPostProcessor {
|
final class RestTemplateBeanPostProcessor implements BeanPostProcessor {
|
||||||
|
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetrySupplier openTelemetrySupplier;
|
||||||
|
|
||||||
RestTemplateBeanPostProcessor(OpenTelemetry openTelemetry) {
|
RestTemplateBeanPostProcessor(OpenTelemetrySupplier openTelemetrySupplier) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetrySupplier = openTelemetrySupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,7 +28,7 @@ final class RestTemplateBeanPostProcessor implements BeanPostProcessor {
|
||||||
|
|
||||||
RestTemplate restTemplate = (RestTemplate) bean;
|
RestTemplate restTemplate = (RestTemplate) bean;
|
||||||
ClientHttpRequestInterceptor interceptor =
|
ClientHttpRequestInterceptor interceptor =
|
||||||
SpringWebTelemetry.create(openTelemetry).newInterceptor();
|
SpringWebTelemetry.create(openTelemetrySupplier.get()).newInterceptor();
|
||||||
addRestTemplateInterceptorIfNotPresent(restTemplate, interceptor);
|
addRestTemplateInterceptorIfNotPresent(restTemplate, interceptor);
|
||||||
return restTemplate;
|
return restTemplate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.web;
|
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.web;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
@ -24,8 +25,11 @@ import org.springframework.web.client.RestTemplate;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SpringWebInstrumentationAutoConfiguration {
|
public class SpringWebInstrumentationAutoConfiguration {
|
||||||
|
|
||||||
|
public SpringWebInstrumentationAutoConfiguration() {}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
RestTemplateBeanPostProcessor otelRestTemplateBeanPostProcessor(OpenTelemetry openTelemetry) {
|
static RestTemplateBeanPostProcessor otelRestTemplateBeanPostProcessor(
|
||||||
return new RestTemplateBeanPostProcessor(openTelemetry);
|
OpenTelemetrySupplier openTelemetrySupplier) {
|
||||||
|
return new RestTemplateBeanPostProcessor(openTelemetrySupplier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.webflux;
|
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.webflux;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
@ -24,8 +25,11 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SpringWebfluxInstrumentationAutoConfiguration {
|
public class SpringWebfluxInstrumentationAutoConfiguration {
|
||||||
|
|
||||||
|
public SpringWebfluxInstrumentationAutoConfiguration() {}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
WebClientBeanPostProcessor otelWebClientBeanPostProcessor(OpenTelemetry openTelemetry) {
|
static WebClientBeanPostProcessor otelWebClientBeanPostProcessor(
|
||||||
return new WebClientBeanPostProcessor(openTelemetry);
|
OpenTelemetrySupplier openTelemetrySupplier) {
|
||||||
|
return new WebClientBeanPostProcessor(openTelemetrySupplier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.webflux;
|
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.webflux;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry;
|
import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
@ -17,10 +17,10 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||||
*/
|
*/
|
||||||
final class WebClientBeanPostProcessor implements BeanPostProcessor {
|
final class WebClientBeanPostProcessor implements BeanPostProcessor {
|
||||||
|
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetrySupplier openTelemetrySupplier;
|
||||||
|
|
||||||
WebClientBeanPostProcessor(OpenTelemetry openTelemetry) {
|
WebClientBeanPostProcessor(OpenTelemetrySupplier openTelemetrySupplier) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetrySupplier = openTelemetrySupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,7 +36,8 @@ final class WebClientBeanPostProcessor implements BeanPostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebClient.Builder wrapBuilder(WebClient.Builder webClientBuilder) {
|
private WebClient.Builder wrapBuilder(WebClient.Builder webClientBuilder) {
|
||||||
SpringWebfluxTelemetry instrumentation = SpringWebfluxTelemetry.create(openTelemetry);
|
SpringWebfluxTelemetry instrumentation =
|
||||||
|
SpringWebfluxTelemetry.create(openTelemetrySupplier.get());
|
||||||
return webClientBuilder.filters(instrumentation::addClientTracingFilter);
|
return webClientBuilder.filters(instrumentation::addClientTracingFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.spring.autoconfigure.internal;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to provide access to the OpenTelemetry instance in bean post processors.
|
||||||
|
*
|
||||||
|
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||||
|
* at any time.
|
||||||
|
*/
|
||||||
|
public interface OpenTelemetrySupplier extends Supplier<OpenTelemetry> {}
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satis
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import io.opentelemetry.api.trace.SpanKind;
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
|
||||||
import io.opentelemetry.semconv.SemanticAttributes;
|
import io.opentelemetry.semconv.SemanticAttributes;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
@ -68,6 +69,10 @@ class KafkaIntegrationTest {
|
||||||
KafkaInstrumentationAutoConfiguration.class,
|
KafkaInstrumentationAutoConfiguration.class,
|
||||||
TestConfig.class))
|
TestConfig.class))
|
||||||
.withBean("openTelemetry", OpenTelemetry.class, testing::getOpenTelemetry)
|
.withBean("openTelemetry", OpenTelemetry.class, testing::getOpenTelemetry)
|
||||||
|
.withBean(
|
||||||
|
"openTelemetrySupplier",
|
||||||
|
OpenTelemetrySupplier.class,
|
||||||
|
() -> testing::getOpenTelemetry)
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.kafka.bootstrap-servers=" + kafka.getBootstrapServers(),
|
"spring.kafka.bootstrap-servers=" + kafka.getBootstrapServers(),
|
||||||
"spring.kafka.consumer.auto-offset-reset=earliest",
|
"spring.kafka.consumer.auto-offset-reset=earliest",
|
||||||
|
|
|
@ -19,7 +19,7 @@ class RestTemplateBeanPostProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("when processed bean is not of type RestTemplate should return object")
|
@DisplayName("when processed bean is not of type RestTemplate should return object")
|
||||||
void returnsObject() {
|
void returnsObject() {
|
||||||
BeanPostProcessor underTest = new RestTemplateBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new RestTemplateBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
assertThat(underTest.postProcessAfterInitialization(new Object(), "testObject"))
|
assertThat(underTest.postProcessAfterInitialization(new Object(), "testObject"))
|
||||||
.isExactlyInstanceOf(Object.class);
|
.isExactlyInstanceOf(Object.class);
|
||||||
|
@ -28,7 +28,7 @@ class RestTemplateBeanPostProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("when processed bean is of type RestTemplate should return RestTemplate")
|
@DisplayName("when processed bean is of type RestTemplate should return RestTemplate")
|
||||||
void returnsRestTemplate() {
|
void returnsRestTemplate() {
|
||||||
BeanPostProcessor underTest = new RestTemplateBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new RestTemplateBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
assertThat(underTest.postProcessAfterInitialization(new RestTemplate(), "testRestTemplate"))
|
assertThat(underTest.postProcessAfterInitialization(new RestTemplate(), "testRestTemplate"))
|
||||||
.isInstanceOf(RestTemplate.class);
|
.isInstanceOf(RestTemplate.class);
|
||||||
|
@ -37,7 +37,7 @@ class RestTemplateBeanPostProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("when processed bean is of type RestTemplate should add ONE RestTemplateInterceptor")
|
@DisplayName("when processed bean is of type RestTemplate should add ONE RestTemplateInterceptor")
|
||||||
void addsRestTemplateInterceptor() {
|
void addsRestTemplateInterceptor() {
|
||||||
BeanPostProcessor underTest = new RestTemplateBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new RestTemplateBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.we
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
@ -17,6 +18,7 @@ class SpringWebInstrumentationAutoConfigurationTest {
|
||||||
private final ApplicationContextRunner contextRunner =
|
private final ApplicationContextRunner contextRunner =
|
||||||
new ApplicationContextRunner()
|
new ApplicationContextRunner()
|
||||||
.withBean(OpenTelemetry.class, OpenTelemetry::noop)
|
.withBean(OpenTelemetry.class, OpenTelemetry::noop)
|
||||||
|
.withBean(OpenTelemetrySupplier.class, () -> OpenTelemetry::noop)
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(SpringWebInstrumentationAutoConfiguration.class));
|
AutoConfigurations.of(SpringWebInstrumentationAutoConfiguration.class));
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.we
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OpenTelemetrySupplier;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
@ -17,6 +18,7 @@ class SpringWebfluxInstrumentationAutoConfigurationTest {
|
||||||
private final ApplicationContextRunner contextRunner =
|
private final ApplicationContextRunner contextRunner =
|
||||||
new ApplicationContextRunner()
|
new ApplicationContextRunner()
|
||||||
.withBean(OpenTelemetry.class, OpenTelemetry::noop)
|
.withBean(OpenTelemetry.class, OpenTelemetry::noop)
|
||||||
|
.withBean(OpenTelemetrySupplier.class, () -> OpenTelemetry::noop)
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(SpringWebfluxInstrumentationAutoConfiguration.class));
|
AutoConfigurations.of(SpringWebfluxInstrumentationAutoConfiguration.class));
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class WebClientBeanPostProcessorTest {
|
||||||
@DisplayName(
|
@DisplayName(
|
||||||
"when processed bean is NOT of type WebClient or WebClientBuilder should return Object")
|
"when processed bean is NOT of type WebClient or WebClientBuilder should return Object")
|
||||||
void returnsObject() {
|
void returnsObject() {
|
||||||
BeanPostProcessor underTest = new WebClientBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new WebClientBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
assertThat(underTest.postProcessAfterInitialization(new Object(), "testObject"))
|
assertThat(underTest.postProcessAfterInitialization(new Object(), "testObject"))
|
||||||
.isExactlyInstanceOf(Object.class);
|
.isExactlyInstanceOf(Object.class);
|
||||||
|
@ -29,7 +29,7 @@ class WebClientBeanPostProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("when processed bean is of type WebClient should return WebClient")
|
@DisplayName("when processed bean is of type WebClient should return WebClient")
|
||||||
void returnsWebClient() {
|
void returnsWebClient() {
|
||||||
BeanPostProcessor underTest = new WebClientBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new WebClientBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
assertThat(underTest.postProcessAfterInitialization(WebClient.create(), "testWebClient"))
|
assertThat(underTest.postProcessAfterInitialization(WebClient.create(), "testWebClient"))
|
||||||
.isInstanceOf(WebClient.class);
|
.isInstanceOf(WebClient.class);
|
||||||
|
@ -38,7 +38,7 @@ class WebClientBeanPostProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("when processed bean is of type WebClientBuilder should return WebClientBuilder")
|
@DisplayName("when processed bean is of type WebClientBuilder should return WebClientBuilder")
|
||||||
void returnsWebClientBuilder() {
|
void returnsWebClientBuilder() {
|
||||||
BeanPostProcessor underTest = new WebClientBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new WebClientBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
underTest.postProcessAfterInitialization(WebClient.builder(), "testWebClientBuilder"))
|
underTest.postProcessAfterInitialization(WebClient.builder(), "testWebClientBuilder"))
|
||||||
|
@ -48,7 +48,7 @@ class WebClientBeanPostProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("when processed bean is of type WebClient should add exchange filter to WebClient")
|
@DisplayName("when processed bean is of type WebClient should add exchange filter to WebClient")
|
||||||
void addsExchangeFilterWebClient() {
|
void addsExchangeFilterWebClient() {
|
||||||
BeanPostProcessor underTest = new WebClientBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new WebClientBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
WebClient webClient = WebClient.create();
|
WebClient webClient = WebClient.create();
|
||||||
Object processedWebClient =
|
Object processedWebClient =
|
||||||
|
@ -70,7 +70,7 @@ class WebClientBeanPostProcessorTest {
|
||||||
@DisplayName(
|
@DisplayName(
|
||||||
"when processed bean is of type WebClientBuilder should add ONE exchange filter to WebClientBuilder")
|
"when processed bean is of type WebClientBuilder should add ONE exchange filter to WebClientBuilder")
|
||||||
void addsExchangeFilterWebClientBuilder() {
|
void addsExchangeFilterWebClientBuilder() {
|
||||||
BeanPostProcessor underTest = new WebClientBeanPostProcessor(OpenTelemetry.noop());
|
BeanPostProcessor underTest = new WebClientBeanPostProcessor(() -> OpenTelemetry.noop());
|
||||||
|
|
||||||
WebClient.Builder webClientBuilder = WebClient.builder();
|
WebClient.Builder webClientBuilder = WebClient.builder();
|
||||||
underTest.postProcessAfterInitialization(webClientBuilder, "testWebClientBuilder");
|
underTest.postProcessAfterInitialization(webClientBuilder, "testWebClientBuilder");
|
||||||
|
|
Loading…
Reference in New Issue