From 365b5966c9df7ee5d81600cdbdaf8cd41b6d18c8 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Mon, 15 May 2023 16:47:55 +0200 Subject: [PATCH 1/7] OTLP log export for the OpenTelemetry Spring Starter --- .../build.gradle.kts | 2 + .../OpenTelemetryAutoConfiguration.java | 34 +++++++- .../otlp/OtlpExporterProperties.java | 5 ++ .../OtlpLoggerExporterAutoConfiguration.java | 53 ++++++++++++ .../main/resources/META-INF/spring.factories | 1 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../OpenTelemetryAutoConfigurationTest.java | 10 ++- .../TraceAspectAutoConfigurationTest.java | 7 ++ ...egerSpanExporterAutoConfigurationTest.java | 7 ++ ...ngMetricExporterAutoConfigurationTest.java | 7 ++ ...gingSpanExporterAutoConfigurationTest.java | 7 ++ .../OtlpLogExporterAutoConfigurationTest.java | 80 +++++++++++++++++++ ...lpMetricExporterAutoConfigurationTest.java | 7 ++ ...OtlpSpanExporterAutoConfigurationTest.java | 7 ++ ...pkinSpanExporterAutoConfigurationTest.java | 7 ++ .../RestTemplateAutoConfigurationTest.java | 7 ++ .../WebClientAutoConfigurationTest.java | 7 ++ .../MicrometerShimAutoConfigurationTest.java | 7 ++ .../PropagationAutoConfigurationTest.java | 7 ++ .../PropagationPropertiesTest.java | 7 ++ .../OtelResourceAutoConfigurationTest.java | 7 ++ .../resources/OtelResourcePropertiesTest.java | 7 ++ .../SpringResourceConfigPropertiesTest.java | 7 ++ ...MvcFilterAutoConfigurationSpring6Test.java | 8 +- .../WebMvcFilterAutoConfigurationTest.java | 8 +- .../spring-boot-starter/build.gradle.kts | 1 + 26 files changed, 300 insertions(+), 8 deletions(-) create mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java create mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java diff --git a/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts b/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts index 68aa2dc6b99e..257e55f16bd8 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts +++ b/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts @@ -36,6 +36,7 @@ dependencies { compileOnly("io.opentelemetry:opentelemetry-extension-trace-propagators") compileOnly("io.opentelemetry.contrib:opentelemetry-aws-xray-propagator") compileOnly("io.opentelemetry:opentelemetry-exporter-logging") + compileOnly("io.opentelemetry:opentelemetry-exporter-otlp-logs") compileOnly("io.opentelemetry:opentelemetry-exporter-jaeger") compileOnly("io.opentelemetry:opentelemetry-exporter-otlp") compileOnly("io.opentelemetry:opentelemetry-exporter-zipkin") @@ -61,6 +62,7 @@ dependencies { testImplementation("io.opentelemetry:opentelemetry-extension-trace-propagators") testImplementation("io.opentelemetry.contrib:opentelemetry-aws-xray-propagator") testImplementation("io.opentelemetry:opentelemetry-exporter-logging") + testImplementation("io.opentelemetry:opentelemetry-exporter-otlp-logs") testImplementation("io.opentelemetry:opentelemetry-exporter-jaeger") testImplementation("io.opentelemetry:opentelemetry-exporter-otlp") testImplementation("io.opentelemetry:opentelemetry-exporter-zipkin") diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java index 0702bff7054f..5d0720ffc266 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java @@ -6,12 +6,17 @@ package io.opentelemetry.instrumentation.spring.autoconfigure; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringResourceConfigProperties; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; +import io.opentelemetry.sdk.logs.export.LogRecordExporter; +import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.export.MetricExporter; @@ -68,6 +73,31 @@ public SdkTracerProvider sdkTracerProvider( .build(); } + @Bean + @ConditionalOnMissingBean + public SdkLoggerProvider sdkLoggerProvider( + ObjectProvider> loggerExportersProvider, Resource otelResource) { + + SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); + loggerProviderBuilder.setResource(otelResource); + + initializeGlobalLoggerProvider(loggerExportersProvider); + + return loggerProviderBuilder.build(); + } + + private static void initializeGlobalLoggerProvider( + ObjectProvider> loggerExportersProvider) { + SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); + loggerExportersProvider.getIfAvailable(Collections::emptyList).stream() + .forEach( + loggerExporter -> + loggerProviderBuilder.addLogRecordProcessor( + SimpleLogRecordProcessor.create(loggerExporter))); + SdkLoggerProvider loggerProvider = loggerProviderBuilder.build(); + GlobalLoggerProvider.set(loggerProvider); + } + @Bean @ConditionalOnMissingBean public SdkMeterProvider sdkMeterProvider( @@ -111,13 +141,15 @@ public Resource otelResource( public OpenTelemetry openTelemetry( ObjectProvider propagatorsProvider, SdkTracerProvider tracerProvider, - SdkMeterProvider meterProvider) { + SdkMeterProvider meterProvider, + SdkLoggerProvider loggerProvider) { ContextPropagators propagators = propagatorsProvider.getIfAvailable(ContextPropagators::noop); return OpenTelemetrySdk.builder() .setTracerProvider(tracerProvider) .setMeterProvider(meterProvider) + .setLoggerProvider(loggerProvider) .setPropagators(propagators) .build(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterProperties.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterProperties.java index 5ff65baa6145..6fed282b81f6 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterProperties.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterProperties.java @@ -27,6 +27,7 @@ public final class OtlpExporterProperties { @Nullable private Duration timeout; private final SignalProperties traces = new SignalProperties(); private final SignalProperties metrics = new SignalProperties(); + private final SignalProperties logs = new SignalProperties(); public boolean isEnabled() { return enabled; @@ -62,6 +63,10 @@ public SignalProperties getMetrics() { return metrics; } + public SignalProperties getLogs() { + return logs; + } + public static class SignalProperties { private boolean enabled = true; diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java new file mode 100644 index 000000000000..3ed52b438df2 --- /dev/null +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp; + +import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; +import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder; +import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import java.time.Duration; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class) +@EnableConfigurationProperties(OtlpExporterProperties.class) +@ConditionalOnProperty( + prefix = "otel.exporter.otlp", + name = {"enabled", "logs.enabled"}, + matchIfMissing = true) +@ConditionalOnClass(OtlpGrpcLogRecordExporter.class) +public class OtlpLoggerExporterAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + @SuppressWarnings("SystemOut") + public OtlpGrpcLogRecordExporter otelOtlpGrpcLogRecordExporter( + OtlpExporterProperties properties) { + OtlpGrpcLogRecordExporterBuilder builder = OtlpGrpcLogRecordExporter.builder(); + + String endpoint = properties.getTraces().getEndpoint(); + if (endpoint == null) { + endpoint = properties.getEndpoint(); + } + if (endpoint != null) { + builder.setEndpoint(endpoint); + } + + Duration timeout = properties.getTraces().getTimeout(); + if (timeout == null) { + timeout = properties.getTimeout(); + } + if (timeout != null) { + builder.setTimeout(timeout); + } + + return builder.build(); + } +} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 229b05f41c03..2d5f5144909f 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -5,6 +5,7 @@ io.opentelemetry.instrumentation.spring.autoconfigure.exporters.jaeger.JaegerSpa io.opentelemetry.instrumentation.spring.autoconfigure.exporters.logging.LoggingSpanExporterAutoConfiguration,\ io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpMetricExporterAutoConfiguration,\ io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration,\ +io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpLoggerExporterAutoConfiguration,\ io.opentelemetry.instrumentation.spring.autoconfigure.exporters.zipkin.ZipkinSpanExporterAutoConfiguration,\ io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.resttemplate.RestTemplateAutoConfiguration,\ io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient.WebClientAutoConfiguration,\ diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index a14ed6c7e206..0e9748f20b63 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -4,6 +4,7 @@ io.opentelemetry.instrumentation.spring.autoconfigure.exporters.jaeger.JaegerSpa io.opentelemetry.instrumentation.spring.autoconfigure.exporters.logging.LoggingSpanExporterAutoConfiguration io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpMetricExporterAutoConfiguration io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration +io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpLoggerExporterAutoConfiguration io.opentelemetry.instrumentation.spring.autoconfigure.exporters.zipkin.ZipkinSpanExporterAutoConfiguration io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.resttemplate.RestTemplateAutoConfiguration io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient.WebClientAutoConfiguration diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java index e25ca7e00072..ffb6400c5303 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java @@ -10,10 +10,12 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -33,6 +35,11 @@ public OpenTelemetry customOpenTelemetry() { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName( "when Application Context contains OpenTelemetry bean should NOT initialize openTelemetry") @@ -60,7 +67,8 @@ void initializeProvidersAndOpenTelemetry() { assertThat(context) .hasBean("openTelemetry") .hasBean("sdkTracerProvider") - .hasBean("sdkMeterProvider")); + .hasBean("sdkMeterProvider") + .hasBean("sdkLoggerProvider")); } @Test diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/TraceAspectAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/TraceAspectAutoConfigurationTest.java index 3dc05203bf0a..6bd10650947b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/TraceAspectAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/TraceAspectAutoConfigurationTest.java @@ -7,7 +7,9 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -22,6 +24,11 @@ public class TraceAspectAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, TraceAspectAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when aspects are ENABLED should initialize WithSpanAspect bean") void aspectsEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/jaeger/JaegerSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/jaeger/JaegerSpanExporterAutoConfigurationTest.java index b1d0bf4492d5..78f5bfc231e7 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/jaeger/JaegerSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/jaeger/JaegerSpanExporterAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -23,6 +25,11 @@ class JaegerSpanExporterAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, JaegerSpanExporterAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when exporters are ENABLED should initialize JaegerGrpcSpanExporter bean") void exportersEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java index 5b1e8355e1ec..548d341ba15f 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.exporter.logging.LoggingMetricExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -22,6 +24,11 @@ class LoggingMetricExporterAutoConfigurationTest { OpenTelemetryAutoConfiguration.class, LoggingMetricExporterAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test void loggingEnabled() { runner diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java index 34abb3200ec2..b2aab55f94db 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -24,6 +26,11 @@ class LoggingSpanExporterAutoConfigurationTest { OpenTelemetryAutoConfiguration.class, LoggingSpanExporterAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when exporters are ENABLED should initialize LoggingSpanExporter bean") void loggingEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java new file mode 100644 index 000000000000..354c3fc686be --- /dev/null +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java @@ -0,0 +1,80 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.api.logs.GlobalLoggerProvider; +import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; +import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +class OtlpLogExporterAutoConfigurationTest { + + private final ApplicationContextRunner runner = + new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of( + OpenTelemetryAutoConfiguration.class, OtlpLoggerExporterAutoConfiguration.class)); + + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + + @Test + void otlpEnabled() { + runner + .withPropertyValues("otel.exporter.otlp.enabled=true") + .run( + context -> + assertThat( + context.getBean( + "otelOtlpGrpcLogRecordExporter", OtlpGrpcLogRecordExporter.class)) + .isNotNull()); + } + + @Test + void otlpLogsEnabled() { + runner + .withPropertyValues("otel.exporter.otlp.logs.enabled=true") + .run( + context -> + assertThat( + context.getBean( + "otelOtlpGrpcLogRecordExporter", OtlpGrpcLogRecordExporter.class)) + .isNotNull()); + } + + @Test + void otlpDisabled() { + runner + .withPropertyValues("otel.exporter.otlp.enabled=false") + .run( + context -> assertThat(context.containsBean("otelOtlpGrpcLogRecordExporter")).isFalse()); + } + + @Test + void otlpLogsDisabled() { + runner + .withPropertyValues("otel.exporter.otlp.logs.enabled=false") + .run( + context -> assertThat(context.containsBean("otelOtlpGrpcLogRecordExporter")).isFalse()); + } + + @Test + void loggerPresentByDefault() { + runner.run( + context -> + assertThat( + context.getBean( + "otelOtlpGrpcLogRecordExporter", OtlpGrpcLogRecordExporter.class)) + .isNotNull()); + } +} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java index 67b2365579f0..219572efcd0b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -21,6 +23,11 @@ class OtlpMetricExporterAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, OtlpMetricExporterAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test void otlpEnabled() { runner diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java index d606aae3adaa..d7e6d1829be2 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -23,6 +25,11 @@ class OtlpSpanExporterAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, OtlpSpanExporterAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when exporters are ENABLED should initialize OtlpGrpcSpanExporter bean") void otlpEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java index 7e6aa89a4515..3729ad53f04e 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -23,6 +25,11 @@ class ZipkinSpanExporterAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, ZipkinSpanExporterAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when exporters are ENABLED should initialize ZipkinSpanExporter bean") void exportersEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/resttemplate/RestTemplateAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/resttemplate/RestTemplateAutoConfigurationTest.java index 84224f625238..d6ca636f7db3 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/resttemplate/RestTemplateAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/resttemplate/RestTemplateAutoConfigurationTest.java @@ -7,7 +7,9 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -22,6 +24,11 @@ class RestTemplateAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, RestTemplateAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when httpclients are ENABLED should initialize RestTemplateInterceptor bean") void httpClientsEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfigurationTest.java index ea90e219014c..aaf49f8f33f1 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/httpclients/webclient/WebClientAutoConfigurationTest.java @@ -7,7 +7,9 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -22,6 +24,11 @@ class WebClientAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, WebClientAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when httpclients are ENABLED should initialize WebClientBeanPostProcessor bean") void httpClientsEnabled() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/metrics/MicrometerShimAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/metrics/MicrometerShimAutoConfigurationTest.java index 7e66044cd0db..18d40da93bc4 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/metrics/MicrometerShimAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/metrics/MicrometerShimAutoConfigurationTest.java @@ -8,8 +8,10 @@ import static org.assertj.core.api.Assertions.assertThat; import io.micrometer.core.instrument.MeterRegistry; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.micrometer.v1_5.OpenTelemetryMeterRegistry; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -23,6 +25,11 @@ class MicrometerShimAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, MicrometerShimAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test void metricsEnabled() { runner diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java index a20162cec993..00dd4c71f80f 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -22,6 +24,11 @@ class PropagationAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, PropagationAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when propagation is ENABLED should initialize PropagationAutoConfiguration bean") void shouldBeConfigured() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java index 6c746b0c92be..f835cb68be5b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java @@ -7,8 +7,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; import java.util.Arrays; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -22,6 +24,11 @@ public class PropagationPropertiesTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, PropagationAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when propagation is SET should set PropagationProperties with given propagators") void hasType() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java index 17506fffe3ed..0ab180d6faec 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java @@ -7,7 +7,9 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -20,6 +22,11 @@ public class OtelResourceAutoConfigurationTest { AutoConfigurations.of( OtelResourceAutoConfiguration.class, OpenTelemetryAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName( "when otel.springboot.resource.enabled is set to true configuration should be initialized") diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java index 2b882b5cf7ee..ec36d97b7a73 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java @@ -8,6 +8,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import io.opentelemetry.api.logs.GlobalLoggerProvider; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -19,6 +21,11 @@ public class OtelResourcePropertiesTest { .withPropertyValues("otel.springboot.resource.enabled=true") .withConfiguration(AutoConfigurations.of(OtelResourceAutoConfiguration.class)); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when attributes are SET should set OtelResourceProperties with given attributes") void hasAttributes() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceConfigPropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceConfigPropertiesTest.java index 93756ae1c4ed..96f4209c599a 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceConfigPropertiesTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceConfigPropertiesTest.java @@ -8,6 +8,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import io.opentelemetry.api.logs.GlobalLoggerProvider; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -17,6 +19,11 @@ class SpringResourceConfigPropertiesTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); + @BeforeEach + void resetGlobalLoggerProvider() { + GlobalLoggerProvider.resetForTest(); + } + @Test @DisplayName("when map is set in properties in a row it should be available in config") void shouldInitializeAttributesByMapInArow() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationSpring6Test.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationSpring6Test.java index 43a283d69145..26f8f5ea5aba 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationSpring6Test.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationSpring6Test.java @@ -8,9 +8,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assumptions.assumeTrue; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; import jakarta.servlet.Filter; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -25,9 +26,10 @@ class WebMvcFilterAutoConfigurationSpring6Test { OpenTelemetryAutoConfiguration.class, WebMvcFilterAutoConfigurationSpring6.class)); - @BeforeAll - static void setUp() { + @BeforeEach + void setUp() { assumeTrue(Boolean.getBoolean("testLatestDeps")); + GlobalLoggerProvider.resetForTest(); } @Test diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationTest.java index 0d0e9133125c..20420df04f19 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationTest.java @@ -8,9 +8,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assumptions.assumeFalse; +import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; import javax.servlet.Filter; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -24,9 +25,10 @@ class WebMvcFilterAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, WebMvcFilterAutoConfiguration.class)); - @BeforeAll - static void setUp() { + @BeforeEach + void setUp() { assumeFalse(Boolean.getBoolean("testLatestDeps")); + GlobalLoggerProvider.resetForTest(); } @Test diff --git a/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts b/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts index cd1b989913f0..5c00e886d886 100644 --- a/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts +++ b/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { api("io.opentelemetry:opentelemetry-api") api("io.opentelemetry:opentelemetry-exporter-logging") api("io.opentelemetry:opentelemetry-exporter-otlp") + api("io.opentelemetry:opentelemetry-exporter-otlp-logs") api("io.opentelemetry:opentelemetry-sdk") api(project(":instrumentation-annotations")) } From 08d5ae4c3c57bfc329dd9e831c20236a7b4c7691 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Mon, 5 Jun 2023 14:28:03 +0200 Subject: [PATCH 2/7] Update instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java Co-authored-by: Mateusz Rzeszutek --- .../exporters/otlp/OtlpLoggerExporterAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java index 3ed52b438df2..fce0c6600724 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java @@ -32,7 +32,7 @@ public OtlpGrpcLogRecordExporter otelOtlpGrpcLogRecordExporter( OtlpExporterProperties properties) { OtlpGrpcLogRecordExporterBuilder builder = OtlpGrpcLogRecordExporter.builder(); - String endpoint = properties.getTraces().getEndpoint(); + String endpoint = properties.getLogs().getEndpoint(); if (endpoint == null) { endpoint = properties.getEndpoint(); } From dfe93e9f3c0d9d2a0d7a9949f4ca5f4c5a2f882a Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Mon, 5 Jun 2023 14:28:18 +0200 Subject: [PATCH 3/7] Update instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java Co-authored-by: Mateusz Rzeszutek --- .../exporters/otlp/OtlpLoggerExporterAutoConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java index fce0c6600724..eff935bd9115 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java @@ -27,7 +27,6 @@ public class OtlpLoggerExporterAutoConfiguration { @Bean @ConditionalOnMissingBean - @SuppressWarnings("SystemOut") public OtlpGrpcLogRecordExporter otelOtlpGrpcLogRecordExporter( OtlpExporterProperties properties) { OtlpGrpcLogRecordExporterBuilder builder = OtlpGrpcLogRecordExporter.builder(); From 611659549556ccc363c1a7f037c230c6bfdd0a76 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Mon, 5 Jun 2023 14:28:41 +0200 Subject: [PATCH 4/7] Update instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java Co-authored-by: Mateusz Rzeszutek --- .../exporters/otlp/OtlpLoggerExporterAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java index eff935bd9115..02636a5a2af2 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLoggerExporterAutoConfiguration.java @@ -39,7 +39,7 @@ public OtlpGrpcLogRecordExporter otelOtlpGrpcLogRecordExporter( builder.setEndpoint(endpoint); } - Duration timeout = properties.getTraces().getTimeout(); + Duration timeout = properties.getLogs().getTimeout(); if (timeout == null) { timeout = properties.getTimeout(); } From b7ec327182f08c520db62479bac4bc854b0408a6 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Mon, 5 Jun 2023 15:10:50 +0200 Subject: [PATCH 5/7] Add other LoggerProvider tests --- .../OpenTelemetryAutoConfigurationTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java index ffb6400c5303..c98eeed7d91b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; @@ -53,7 +54,8 @@ void customOpenTelemetry() { .hasBean("customOpenTelemetry") .doesNotHaveBean("openTelemetry") .doesNotHaveBean("sdkTracerProvider") - .doesNotHaveBean("sdkMeterProvider")); + .doesNotHaveBean("sdkMeterProvider") + .doesNotHaveBean("sdkLoggerProvider")); } @Test @@ -82,6 +84,10 @@ void initializeOpenTelemetryWithCustomProviders() { () -> SdkTracerProvider.builder().build()) .withBean( "customMeterProvider", SdkMeterProvider.class, () -> SdkMeterProvider.builder().build()) + .withBean( + "customLoggerProvider", + SdkLoggerProvider.class, + () -> SdkLoggerProvider.builder().build()) .withConfiguration(AutoConfigurations.of(OpenTelemetryAutoConfiguration.class)) .run( context -> @@ -90,7 +96,9 @@ void initializeOpenTelemetryWithCustomProviders() { .hasBean("customTracerProvider") .doesNotHaveBean("sdkTracerProvider") .hasBean("customMeterProvider") - .doesNotHaveBean("sdkMeterProvider")); + .doesNotHaveBean("sdkMeterProvider") + .hasBean("customLoggerProvider") + .doesNotHaveBean("sdkLoggerProvider")); } @Test From cdd69066cc162c1a9984a9e2c1b83a3d620d4c23 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Wed, 7 Jun 2023 14:35:05 +0200 Subject: [PATCH 6/7] SdkLoggerProvider instantiated once and BatchLogRecordProcessor is used --- .../OpenTelemetryAutoConfiguration.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java index 5d0720ffc266..a965a48f1a54 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java @@ -15,8 +15,8 @@ import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; +import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor; import io.opentelemetry.sdk.logs.export.LogRecordExporter; -import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.export.MetricExporter; @@ -81,21 +81,16 @@ public SdkLoggerProvider sdkLoggerProvider( SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); loggerProviderBuilder.setResource(otelResource); - initializeGlobalLoggerProvider(loggerExportersProvider); - - return loggerProviderBuilder.build(); - } - - private static void initializeGlobalLoggerProvider( - ObjectProvider> loggerExportersProvider) { - SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); loggerExportersProvider.getIfAvailable(Collections::emptyList).stream() .forEach( loggerExporter -> loggerProviderBuilder.addLogRecordProcessor( - SimpleLogRecordProcessor.create(loggerExporter))); + BatchLogRecordProcessor.builder(loggerExporter).build())); + SdkLoggerProvider loggerProvider = loggerProviderBuilder.build(); GlobalLoggerProvider.set(loggerProvider); + + return loggerProvider; } @Bean From 7e2ba0b614e12ebadae12bcad877b49acbbf2269 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Wed, 7 Jun 2023 15:16:51 +0200 Subject: [PATCH 7/7] Fix spotless --- .../autoconfigure/OpenTelemetryAutoConfigurationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java index 67b0af1a8061..e8a4b1546276 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java @@ -12,8 +12,8 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration; -import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider;