From 5fb82c5b661fc0dc6cbda09596a087ba9dcfe2fd Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 11 Apr 2024 13:13:30 +0200 Subject: [PATCH] review improvements --- .../web/RestTemplateBeanPostProcessor.java | 2 +- ...eptor.java => RestTemplateInstrumentation.java} | 4 ++-- .../SpringWebInstrumentationAutoConfiguration.java | 2 +- .../smoketest/OtelSpringStarterSmokeTest.java | 14 ++++---------- 4 files changed, 8 insertions(+), 14 deletions(-) rename instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/{RestTemplateInterceptor.java => RestTemplateInstrumentation.java} (93%) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateBeanPostProcessor.java index e2069bab93b0..43d0c52bac38 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateBeanPostProcessor.java @@ -24,7 +24,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) { return bean; } - return RestTemplateInterceptor.addIfNotPresent( + return RestTemplateInstrumentation.addIfNotPresent( (RestTemplate) bean, openTelemetryProvider.getObject()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInterceptor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java similarity index 93% rename from instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInterceptor.java rename to instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java index 019dc3f9e1b9..58c266f09e8c 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInterceptor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java @@ -12,9 +12,9 @@ import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.web.client.RestTemplate; -class RestTemplateInterceptor { +class RestTemplateInstrumentation { - private RestTemplateInterceptor() {} + private RestTemplateInstrumentation() {} @CanIgnoreReturnValue static RestTemplate addIfNotPresent(RestTemplate restTemplate, OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfiguration.java index b1063d8ad54c..f3f5e12847d8 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfiguration.java @@ -41,6 +41,6 @@ static RestTemplateBeanPostProcessor otelRestTemplateBeanPostProcessor( static RestTemplateCustomizer otelRestTemplateCustomizer( ObjectProvider openTelemetryProvider) { return restTemplate -> - RestTemplateInterceptor.addIfNotPresent(restTemplate, openTelemetryProvider.getObject()); + RestTemplateInstrumentation.addIfNotPresent(restTemplate, openTelemetryProvider.getObject()); } } diff --git a/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java index fbcd6aa99d48..e79d7ccab598 100644 --- a/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java @@ -45,7 +45,6 @@ import org.awaitility.core.ConditionEvaluationLogger; import org.awaitility.core.EvaluatedCondition; import org.awaitility.core.TimeoutEvent; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; @@ -81,11 +80,11 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class OtelSpringStarterSmokeTest { - public static final InMemoryMetricExporter METRIC_EXPORTER = + private static final InMemoryMetricExporter METRIC_EXPORTER = InMemoryMetricExporter.create(AggregationTemporality.DELTA); private static final InMemoryLogRecordExporter LOG_RECORD_EXPORTER = InMemoryLogRecordExporter.create(); - public static final InMemorySpanExporter SPAN_EXPORTER = InMemorySpanExporter.create(); + private static final InMemorySpanExporter SPAN_EXPORTER = InMemorySpanExporter.create(); private static final Logger logger = LoggerFactory.getLogger(OtelSpringStarterSmokeTest.class); @Autowired private TestRestTemplate testRestTemplate; @@ -168,12 +167,7 @@ AutoConfigurationCustomizerProvider propagatorCustomizer() { } } - @AfterEach - void tearDown() { - reset(); - } - - private static void reset() { + private static void resetExporters() { SPAN_EXPORTER.reset(); METRIC_EXPORTER.reset(); LOG_RECORD_EXPORTER.reset(); @@ -259,7 +253,7 @@ void shouldSendTelemetry() { @Test @org.junit.jupiter.api.Order(2) void restTemplateClient() { - reset(); // ignore the telemetry from application startup + resetExporters(); // ignore the telemetry from application startup testRestTemplate.getForObject(OtelSpringStarterSmokeTestController.REST_TEMPLATE, String.class);