Skip to content

Commit 2ca0897

Browse files
committed
Relocate OpenTelemetryLoggingAutoConfiguration and SdkLoggerProviderBuilderCustomizer to an OpenTelemetry-specific package
Closes gh-44647
1 parent 62e145e commit 2ca0897

File tree

9 files changed

+190
-48
lines changed

9 files changed

+190
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,46 +16,17 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.logging;
1818

19-
import io.opentelemetry.api.OpenTelemetry;
20-
import io.opentelemetry.sdk.logs.LogRecordProcessor;
21-
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
22-
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
23-
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
24-
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
25-
import io.opentelemetry.sdk.resources.Resource;
26-
27-
import org.springframework.beans.factory.ObjectProvider;
28-
import org.springframework.boot.autoconfigure.AutoConfiguration;
2919
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
30-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
31-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
32-
import org.springframework.context.annotation.Bean;
3320

3421
/**
3522
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry logging.
3623
*
3724
* @author Toshiaki Maki
3825
* @since 3.4.0
26+
* @deprecated since 3.5.0 for removal in 4.0.0 in favor of
27+
* {@link org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.OpenTelemetryLoggingAutoConfiguration}
3928
*/
40-
@AutoConfiguration
41-
@ConditionalOnClass({ SdkLoggerProvider.class, OpenTelemetry.class })
29+
@Deprecated(since = "3.4.0", forRemoval = true)
4230
public class OpenTelemetryLoggingAutoConfiguration {
4331

44-
@Bean
45-
@ConditionalOnMissingBean
46-
BatchLogRecordProcessor batchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
47-
return BatchLogRecordProcessor.builder(LogRecordExporter.composite(logRecordExporters.orderedStream().toList()))
48-
.build();
49-
}
50-
51-
@Bean
52-
@ConditionalOnMissingBean
53-
SdkLoggerProvider otelSdkLoggerProvider(Resource resource, ObjectProvider<LogRecordProcessor> logRecordProcessors,
54-
ObjectProvider<SdkLoggerProviderBuilderCustomizer> customizers) {
55-
SdkLoggerProviderBuilder builder = SdkLoggerProvider.builder().setResource(resource);
56-
logRecordProcessors.orderedStream().forEach(builder::addLogRecordProcessor);
57-
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
58-
return builder.build();
59-
}
60-
6132
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/SdkLoggerProviderBuilderCustomizer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,11 @@
2525
*
2626
* @author Toshiaki Maki
2727
* @since 3.4.0
28+
* @deprecated since 3.5.0 for removal in 4.0.0 in favor of
29+
* {@link org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.SdkLoggerProviderBuilderCustomizer}
2830
*/
2931
@FunctionalInterface
32+
@Deprecated(since = "3.5.0", forRemoval = true)
3033
public interface SdkLoggerProviderBuilderCustomizer {
3134

3235
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2012-2025 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.actuate.autoconfigure.logging.opentelemetry;
18+
19+
import io.opentelemetry.api.OpenTelemetry;
20+
import io.opentelemetry.sdk.logs.LogRecordProcessor;
21+
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
22+
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
23+
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
24+
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
25+
import io.opentelemetry.sdk.resources.Resource;
26+
27+
import org.springframework.beans.factory.ObjectProvider;
28+
import org.springframework.boot.autoconfigure.AutoConfiguration;
29+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
30+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
32+
import org.springframework.context.annotation.Bean;
33+
34+
/**
35+
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry logging.
36+
*
37+
* @author Toshiaki Maki
38+
* @since 3.5.0
39+
*/
40+
@AutoConfiguration
41+
@ConditionalOnClass({ SdkLoggerProvider.class, OpenTelemetry.class })
42+
public class OpenTelemetryLoggingAutoConfiguration {
43+
44+
@Bean
45+
@ConditionalOnMissingBean
46+
BatchLogRecordProcessor batchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
47+
return BatchLogRecordProcessor.builder(LogRecordExporter.composite(logRecordExporters.orderedStream().toList()))
48+
.build();
49+
}
50+
51+
@Bean
52+
@ConditionalOnMissingBean
53+
@SuppressWarnings("removal")
54+
SdkLoggerProvider otelSdkLoggerProvider(Resource resource, ObjectProvider<LogRecordProcessor> logRecordProcessors,
55+
ObjectProvider<SdkLoggerProviderBuilderCustomizer> customizers,
56+
ObjectProvider<org.springframework.boot.actuate.autoconfigure.logging.SdkLoggerProviderBuilderCustomizer> deprecatedCustomizers) {
57+
SdkLoggerProviderBuilder builder = SdkLoggerProvider.builder().setResource(resource);
58+
logRecordProcessors.orderedStream().forEach(builder::addLogRecordProcessor);
59+
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
60+
deprecatedCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
61+
return builder.build();
62+
}
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-2025 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.actuate.autoconfigure.logging.opentelemetry;
18+
19+
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
20+
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
21+
22+
/**
23+
* Callback interface that can be used to customize the {@link SdkLoggerProviderBuilder}
24+
* that is used to create the auto-configured {@link SdkLoggerProvider}.
25+
*
26+
* @author Toshiaki Maki
27+
* @since 3.5.0
28+
*/
29+
@FunctionalInterface
30+
public interface SdkLoggerProviderBuilderCustomizer {
31+
32+
/**
33+
* Customize the given {@code builder}.
34+
* @param builder the builder to customize
35+
*/
36+
void customize(SdkLoggerProviderBuilder builder);
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2025 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+
/**
18+
* Auto-configuration for logging over OpenTelemetry.
19+
*/
20+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ org.springframework.boot.actuate.autoconfigure.ldap.LdapHealthContributorAutoCon
3434
org.springframework.boot.actuate.autoconfigure.liquibase.LiquibaseEndpointAutoConfiguration
3535
org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointAutoConfiguration
3636
org.springframework.boot.actuate.autoconfigure.logging.LoggersEndpointAutoConfiguration
37-
org.springframework.boot.actuate.autoconfigure.logging.OpenTelemetryLoggingAutoConfiguration
37+
org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.OpenTelemetryLoggingAutoConfiguration
3838
org.springframework.boot.actuate.autoconfigure.logging.otlp.OtlpLoggingAutoConfiguration
3939
org.springframework.boot.actuate.autoconfigure.mail.MailHealthContributorAutoConfiguration
4040
org.springframework.boot.actuate.autoconfigure.management.HeapDumpWebEndpointAutoConfiguration
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
org.springframework.boot.actuate.autoconfigure.tracing.OpenTelemetryAutoConfiguration=org.springframework.boot.actuate.autoconfigure.tracing.OpenTelemetryTracingAutoConfiguration
22
org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpAutoConfiguration=org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingAutoConfiguration
3+
org.springframework.boot.actuate.autoconfigure.logging.OpenTelemetryLoggingAutoConfiguration=org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.OpenTelemetryLoggingAutoConfiguration
Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

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

1919
import java.util.Collection;
2020
import java.util.concurrent.atomic.AtomicInteger;
@@ -45,6 +45,7 @@
4545
* Tests for {@link OpenTelemetryLoggingAutoConfiguration}.
4646
*
4747
* @author Toshiaki Maki
48+
* @author Moritz Halbritter
4849
*/
4950
class OpenTelemetryLoggingAutoConfigurationTests {
5051

@@ -120,16 +121,33 @@ void shouldAllowMultipleSdkLoggerProviderBuilderCustomizers() {
120121
});
121122
}
122123

124+
@Test
125+
@SuppressWarnings("removal")
126+
void shouldApplyDeprecatedCustomizers() {
127+
this.contextRunner.withUserConfiguration(DeprecatedSdkLoggerProviderBuilderCustomizerConfig.class)
128+
.run((context) -> {
129+
assertThat(context).hasSingleBean(SdkLoggerProvider.class);
130+
assertThat(context.getBeansOfType(
131+
org.springframework.boot.actuate.autoconfigure.logging.SdkLoggerProviderBuilderCustomizer.class))
132+
.hasSize(1);
133+
assertThat(context).hasBean("deprecatedSdkLoggerProviderBuilderCustomizer");
134+
assertThat(context
135+
.getBean("deprecatedSdkLoggerProviderBuilderCustomizer",
136+
DeprecatedNoopSdkLoggerProviderBuilderCustomizer.class)
137+
.called()).isEqualTo(1);
138+
});
139+
}
140+
123141
@Configuration(proxyBeanMethods = false)
124142
public static class CustomConfig {
125143

126144
@Bean
127-
public BatchLogRecordProcessor customBatchLogRecordProcessor() {
145+
BatchLogRecordProcessor customBatchLogRecordProcessor() {
128146
return BatchLogRecordProcessor.builder(new NoopLogRecordExporter()).build();
129147
}
130148

131149
@Bean
132-
public SdkLoggerProvider customSdkLoggerProvider() {
150+
SdkLoggerProvider customSdkLoggerProvider() {
133151
return SdkLoggerProvider.builder().build();
134152
}
135153

@@ -139,12 +157,12 @@ public SdkLoggerProvider customSdkLoggerProvider() {
139157
public static class MultipleLogRecordExportersConfig {
140158

141159
@Bean
142-
public LogRecordExporter customLogRecordExporter1() {
160+
LogRecordExporter customLogRecordExporter1() {
143161
return new NoopLogRecordExporter();
144162
}
145163

146164
@Bean
147-
public LogRecordExporter customLogRecordExporter2() {
165+
LogRecordExporter customLogRecordExporter2() {
148166
return new NoopLogRecordExporter();
149167
}
150168

@@ -154,12 +172,12 @@ public LogRecordExporter customLogRecordExporter2() {
154172
public static class MultipleLogRecordProcessorsConfig {
155173

156174
@Bean
157-
public LogRecordProcessor customLogRecordProcessor1() {
175+
LogRecordProcessor customLogRecordProcessor1() {
158176
return new NoopLogRecordProcessor();
159177
}
160178

161179
@Bean
162-
public LogRecordProcessor customLogRecordProcessor2() {
180+
LogRecordProcessor customLogRecordProcessor2() {
163181
return new NoopLogRecordProcessor();
164182
}
165183

@@ -169,17 +187,27 @@ public LogRecordProcessor customLogRecordProcessor2() {
169187
public static class MultipleSdkLoggerProviderBuilderCustomizersConfig {
170188

171189
@Bean
172-
public SdkLoggerProviderBuilderCustomizer customSdkLoggerProviderBuilderCustomizer1() {
190+
SdkLoggerProviderBuilderCustomizer customSdkLoggerProviderBuilderCustomizer1() {
173191
return new NoopSdkLoggerProviderBuilderCustomizer();
174192
}
175193

176194
@Bean
177-
public SdkLoggerProviderBuilderCustomizer customSdkLoggerProviderBuilderCustomizer2() {
195+
SdkLoggerProviderBuilderCustomizer customSdkLoggerProviderBuilderCustomizer2() {
178196
return new NoopSdkLoggerProviderBuilderCustomizer();
179197
}
180198

181199
}
182200

201+
@Configuration(proxyBeanMethods = false)
202+
public static class DeprecatedSdkLoggerProviderBuilderCustomizerConfig {
203+
204+
@Bean
205+
DeprecatedNoopSdkLoggerProviderBuilderCustomizer deprecatedSdkLoggerProviderBuilderCustomizer() {
206+
return new DeprecatedNoopSdkLoggerProviderBuilderCustomizer();
207+
}
208+
209+
}
210+
183211
static class NoopLogRecordExporter implements LogRecordExporter {
184212

185213
@Override
@@ -210,7 +238,24 @@ public void onEmit(Context context, ReadWriteLogRecord logRecord) {
210238

211239
static class NoopSdkLoggerProviderBuilderCustomizer implements SdkLoggerProviderBuilderCustomizer {
212240

213-
final AtomicInteger called = new AtomicInteger(0);
241+
private final AtomicInteger called = new AtomicInteger(0);
242+
243+
@Override
244+
public void customize(SdkLoggerProviderBuilder builder) {
245+
this.called.incrementAndGet();
246+
}
247+
248+
int called() {
249+
return this.called.get();
250+
}
251+
252+
}
253+
254+
@SuppressWarnings("removal")
255+
static class DeprecatedNoopSdkLoggerProviderBuilderCustomizer
256+
implements org.springframework.boot.actuate.autoconfigure.logging.SdkLoggerProviderBuilderCustomizer {
257+
258+
private final AtomicInteger called = new AtomicInteger(0);
214259

215260
@Override
216261
public void customize(SdkLoggerProviderBuilder builder) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.Test;
3434

35-
import org.springframework.boot.actuate.autoconfigure.logging.OpenTelemetryLoggingAutoConfiguration;
35+
import org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.OpenTelemetryLoggingAutoConfiguration;
3636
import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryAutoConfiguration;
3737
import org.springframework.boot.autoconfigure.AutoConfigurations;
3838
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

0 commit comments

Comments
 (0)