Skip to content

Commit 2421f02

Browse files
committed
Extract OpenTelemetryLoggingAutoConfiguration
This auto-configuration configures OpenTelemetry logging. The existing OpenTelemetrySdkAutoConfiguration now only configures the OpenTelemetry SDK, but no individual subsystems (logging, metrics, tracing). Closes gh-47963
1 parent da8aedb commit 2421f02

23 files changed

+361
-235
lines changed

module/spring-boot-opentelemetry/src/dockerTest/java/org/springframework/boot/opentelemetry/docker/compose/GrafanaOtlpLoggingDockerComposeConnectionDetailsFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.springframework.boot.opentelemetry.docker.compose;
1818

1919
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
20-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingConnectionDetails;
21-
import org.springframework.boot.opentelemetry.autoconfigure.logging.Transport;
20+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingConnectionDetails;
21+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.Transport;
2222
import org.springframework.boot.testsupport.container.TestImage;
2323

2424
import static org.assertj.core.api.Assertions.assertThat;

module/spring-boot-opentelemetry/src/dockerTest/java/org/springframework/boot/opentelemetry/docker/compose/OtelCollectorOtlpLoggingDockerComposeConnectionDetailsFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.springframework.boot.opentelemetry.docker.compose;
1818

1919
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
20-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingConnectionDetails;
21-
import org.springframework.boot.opentelemetry.autoconfigure.logging.Transport;
20+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingConnectionDetails;
21+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.Transport;
2222
import org.springframework.boot.testsupport.container.TestImage;
2323

2424
import static org.assertj.core.api.Assertions.assertThat;

module/spring-boot-opentelemetry/src/dockerTest/java/org/springframework/boot/opentelemetry/testcontainers/GrafanaOtlpLoggingContainerConnectionDetailsFactoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
26-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingAutoConfiguration;
27-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingConnectionDetails;
28-
import org.springframework.boot.opentelemetry.autoconfigure.logging.Transport;
26+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingAutoConfiguration;
27+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingConnectionDetails;
28+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.Transport;
2929
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
3030
import org.springframework.boot.testsupport.container.TestImage;
3131
import org.springframework.context.annotation.Configuration;

module/spring-boot-opentelemetry/src/dockerTest/java/org/springframework/boot/opentelemetry/testcontainers/OtelCollectorOltpLoggingContainerConnectionDetailsFactoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
26-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingAutoConfiguration;
27-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingConnectionDetails;
28-
import org.springframework.boot.opentelemetry.autoconfigure.logging.Transport;
26+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingAutoConfiguration;
27+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingConnectionDetails;
28+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.Transport;
2929
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
3030
import org.springframework.boot.testsupport.container.TestImage;
3131
import org.springframework.context.annotation.Configuration;

module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/OpenTelemetrySdkAutoConfiguration.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
import io.opentelemetry.context.propagation.ContextPropagators;
2121
import io.opentelemetry.sdk.OpenTelemetrySdk;
2222
import io.opentelemetry.sdk.OpenTelemetrySdkBuilder;
23-
import io.opentelemetry.sdk.logs.LogRecordProcessor;
2423
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
25-
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
26-
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
27-
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
2824
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
2925
import io.opentelemetry.sdk.resources.Resource;
3026
import io.opentelemetry.sdk.resources.ResourceBuilder;
@@ -37,7 +33,6 @@
3733
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3834
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3935
import org.springframework.context.annotation.Bean;
40-
import org.springframework.context.annotation.Configuration;
4136
import org.springframework.core.env.Environment;
4237

4338
/**
@@ -80,30 +75,4 @@ private Resource toResource(Environment environment, OpenTelemetryProperties pro
8075
return builder.build();
8176
}
8277

83-
@Configuration(proxyBeanMethods = false)
84-
@ConditionalOnClass(SdkLoggerProvider.class)
85-
static class LoggerConfiguration {
86-
87-
@Bean
88-
@ConditionalOnMissingBean
89-
BatchLogRecordProcessor openTelemetryBatchLogRecordProcessor(
90-
ObjectProvider<LogRecordExporter> logRecordExporters) {
91-
LogRecordExporter exporter = LogRecordExporter.composite(logRecordExporters.orderedStream().toList());
92-
return BatchLogRecordProcessor.builder(exporter).build();
93-
}
94-
95-
@Bean
96-
@ConditionalOnMissingBean
97-
SdkLoggerProvider openTelemetrySdkLoggerProvider(Resource openTelemetryResource,
98-
ObjectProvider<LogRecordProcessor> logRecordProcessors,
99-
ObjectProvider<SdkLoggerProviderBuilderCustomizer> customizers) {
100-
SdkLoggerProviderBuilder builder = SdkLoggerProvider.builder();
101-
builder.setResource(openTelemetryResource);
102-
logRecordProcessors.orderedStream().forEach(builder::addLogRecordProcessor);
103-
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
104-
return builder.build();
105-
}
106-
107-
}
108-
10978
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.opentelemetry.autoconfigure.logging;
18+
19+
import io.opentelemetry.sdk.logs.LogRecordProcessor;
20+
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
21+
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
22+
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
23+
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
24+
import io.opentelemetry.sdk.resources.Resource;
25+
26+
import org.springframework.beans.factory.ObjectProvider;
27+
import org.springframework.boot.autoconfigure.AutoConfiguration;
28+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
29+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
30+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
32+
import org.springframework.boot.opentelemetry.autoconfigure.OpenTelemetrySdkAutoConfiguration;
33+
import org.springframework.context.annotation.Bean;
34+
35+
/**
36+
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry logging.
37+
*
38+
* @author Moritz Halbritter
39+
* @since 4.0.0
40+
*/
41+
@AutoConfiguration(after = OpenTelemetrySdkAutoConfiguration.class)
42+
@ConditionalOnClass(SdkLoggerProvider.class)
43+
public final class OpenTelemetryLoggingAutoConfiguration {
44+
45+
OpenTelemetryLoggingAutoConfiguration() {
46+
}
47+
48+
@Bean
49+
@ConditionalOnMissingBean
50+
BatchLogRecordProcessor openTelemetryBatchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
51+
LogRecordExporter exporter = LogRecordExporter.composite(logRecordExporters.orderedStream().toList());
52+
return BatchLogRecordProcessor.builder(exporter).build();
53+
}
54+
55+
@Bean
56+
@ConditionalOnMissingBean
57+
@ConditionalOnBean(Resource.class)
58+
SdkLoggerProvider openTelemetrySdkLoggerProvider(Resource openTelemetryResource,
59+
ObjectProvider<LogRecordProcessor> logRecordProcessors,
60+
ObjectProvider<SdkLoggerProviderBuilderCustomizer> customizers) {
61+
SdkLoggerProviderBuilder builder = SdkLoggerProvider.builder();
62+
builder.setResource(openTelemetryResource);
63+
logRecordProcessors.orderedStream().forEach(builder::addLogRecordProcessor);
64+
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
65+
return builder.build();
66+
}
67+
68+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.opentelemetry.autoconfigure;
17+
package org.springframework.boot.opentelemetry.autoconfigure.logging;
1818

1919
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
2020
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.opentelemetry.autoconfigure.logging;
17+
package org.springframework.boot.opentelemetry.autoconfigure.logging.otlp;
1818

1919
import io.opentelemetry.api.OpenTelemetry;
2020
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
@@ -24,8 +24,8 @@
2424
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2626
import org.springframework.boot.context.properties.EnableConfigurationProperties;
27-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingConfigurations.ConnectionDetails;
28-
import org.springframework.boot.opentelemetry.autoconfigure.logging.OtlpLoggingConfigurations.Exporters;
27+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingConfigurations.ConnectionDetails;
28+
import org.springframework.boot.opentelemetry.autoconfigure.logging.otlp.OtlpLoggingConfigurations.Exporters;
2929
import org.springframework.context.annotation.Import;
3030

3131
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.opentelemetry.autoconfigure.logging;
17+
package org.springframework.boot.opentelemetry.autoconfigure.logging.otlp;
1818

1919
import java.util.Locale;
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.opentelemetry.autoconfigure.logging;
17+
package org.springframework.boot.opentelemetry.autoconfigure.logging.otlp;
1818

1919
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
2020

0 commit comments

Comments
 (0)