Skip to content

Commit cfa0571

Browse files
committed
Polish "Provide auto configuration for OpenTelemetry Logs"
See gh-40961
1 parent 2d6f248 commit cfa0571

File tree

12 files changed

+99
-104
lines changed

12 files changed

+99
-104
lines changed
Lines changed: 6 additions & 7 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.actuate.autoconfigure.logs;
17+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;
1818

1919
import io.opentelemetry.api.OpenTelemetry;
2020
import io.opentelemetry.sdk.logs.LogRecordProcessor;
@@ -32,26 +32,25 @@
3232
import org.springframework.context.annotation.Bean;
3333

3434
/**
35-
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry Logs.
35+
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry logging.
3636
*
3737
* @author Toshiaki Maki
3838
* @since 3.4.0
3939
*/
40-
@AutoConfiguration("openTelemetryLogsAutoConfiguration")
40+
@AutoConfiguration
4141
@ConditionalOnClass({ SdkLoggerProvider.class, OpenTelemetry.class })
42-
public class OpenTelemetryAutoConfiguration {
42+
public class OpenTelemetryLoggingAutoConfiguration {
4343

4444
@Bean
4545
@ConditionalOnMissingBean
46-
public BatchLogRecordProcessor batchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
46+
BatchLogRecordProcessor batchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
4747
return BatchLogRecordProcessor.builder(LogRecordExporter.composite(logRecordExporters.orderedStream().toList()))
4848
.build();
4949
}
5050

5151
@Bean
5252
@ConditionalOnMissingBean
53-
public SdkLoggerProvider otelSdkLoggerProvider(Resource resource,
54-
ObjectProvider<LogRecordProcessor> logRecordProcessors,
53+
SdkLoggerProvider otelSdkLoggerProvider(Resource resource, ObjectProvider<LogRecordProcessor> logRecordProcessors,
5554
ObjectProvider<SdkLoggerProviderBuilderCustomizer> customizers) {
5655
SdkLoggerProviderBuilder builder = SdkLoggerProvider.builder().setResource(resource);
5756
logRecordProcessors.orderedStream().forEach(builder::addLogRecordProcessor);
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.actuate.autoconfigure.logs;
17+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;
1818

1919
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
2020
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
Lines changed: 5 additions & 5 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.actuate.autoconfigure.logs.otlp;
17+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;
1818

1919
import io.opentelemetry.api.OpenTelemetry;
2020
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter;
@@ -27,15 +27,15 @@
2727
import org.springframework.context.annotation.Import;
2828

2929
/**
30-
* {@link EnableAutoConfiguration Auto-configuration} for OTLP Logs.
30+
* {@link EnableAutoConfiguration Auto-configuration} for OTLP logging.
3131
*
3232
* @author Toshiaki Maki
3333
* @since 3.4.0
3434
*/
3535
@AutoConfiguration
3636
@ConditionalOnClass({ SdkLoggerProvider.class, OpenTelemetry.class, OtlpHttpLogRecordExporter.class })
37-
@EnableConfigurationProperties(OtlpProperties.class)
38-
@Import({ OtlpLogsConfigurations.ConnectionDetails.class, OtlpLogsConfigurations.Exporters.class })
39-
public class OtlpLogsAutoConfiguration {
37+
@EnableConfigurationProperties(OtlpLoggingProperties.class)
38+
@Import({ OtlpLoggingConfigurations.ConnectionDetails.class, OtlpLoggingConfigurations.Exporters.class })
39+
public class OtlpLoggingAutoConfiguration {
4040

4141
}
Lines changed: 18 additions & 16 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.actuate.autoconfigure.logs.otlp;
17+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;
1818

1919
import java.util.Locale;
2020

@@ -28,36 +28,38 @@
2828
import org.springframework.context.annotation.Configuration;
2929

3030
/**
31-
* Configurations imported by {@link OtlpLogsAutoConfiguration}.
31+
* Configurations imported by {@link OtlpLoggingAutoConfiguration}.
3232
*
3333
* @author Toshiaki Maki
34-
* @since 3.4.0
3534
*/
36-
public class OtlpLogsConfigurations {
35+
final class OtlpLoggingConfigurations {
36+
37+
private OtlpLoggingConfigurations() {
38+
}
3739

3840
@Configuration(proxyBeanMethods = false)
3941
static class ConnectionDetails {
4042

4143
@Bean
4244
@ConditionalOnMissingBean
43-
@ConditionalOnProperty(prefix = "management.otlp.logs", name = "endpoint")
44-
OtlpLogsConnectionDetails otlpLogsConnectionDetails(OtlpProperties properties) {
45-
return new PropertiesOtlpLogsConnectionDetails(properties);
45+
@ConditionalOnProperty(prefix = "management.otlp.logging", name = "endpoint")
46+
OtlpLoggingConnectionDetails otlpLogsConnectionDetails(OtlpLoggingProperties properties) {
47+
return new PropertiesOtlpLoggingConnectionDetails(properties);
4648
}
4749

4850
/**
49-
* Adapts {@link OtlpProperties} to {@link OtlpLogsConnectionDetails}.
51+
* Adapts {@link OtlpLoggingProperties} to {@link OtlpLoggingConnectionDetails}.
5052
*/
51-
static class PropertiesOtlpLogsConnectionDetails implements OtlpLogsConnectionDetails {
53+
static class PropertiesOtlpLoggingConnectionDetails implements OtlpLoggingConnectionDetails {
5254

53-
private final OtlpProperties properties;
55+
private final OtlpLoggingProperties properties;
5456

55-
PropertiesOtlpLogsConnectionDetails(OtlpProperties properties) {
57+
PropertiesOtlpLoggingConnectionDetails(OtlpLoggingProperties properties) {
5658
this.properties = properties;
5759
}
5860

5961
@Override
60-
public String getUrl() {
62+
public String getEndpoint() {
6163
return this.properties.getEndpoint();
6264
}
6365

@@ -70,12 +72,12 @@ static class Exporters {
7072

7173
@ConditionalOnMissingBean(value = OtlpHttpLogRecordExporter.class,
7274
type = "io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter")
73-
@ConditionalOnBean(OtlpLogsConnectionDetails.class)
75+
@ConditionalOnBean(OtlpLoggingConnectionDetails.class)
7476
@Bean
75-
OtlpHttpLogRecordExporter otlpHttpLogRecordExporter(OtlpProperties properties,
76-
OtlpLogsConnectionDetails connectionDetails) {
77+
OtlpHttpLogRecordExporter otlpHttpLogRecordExporter(OtlpLoggingProperties properties,
78+
OtlpLoggingConnectionDetails connectionDetails) {
7779
OtlpHttpLogRecordExporterBuilder builder = OtlpHttpLogRecordExporter.builder()
78-
.setEndpoint(connectionDetails.getUrl())
80+
.setEndpoint(connectionDetails.getEndpoint())
7981
.setCompression(properties.getCompression().name().toLowerCase(Locale.US))
8082
.setTimeout(properties.getTimeout());
8183
properties.getHeaders().forEach(builder::addHeader);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

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

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

2121
/**
22-
* Details required to establish a connection to an OpenTelemetry logs service.
22+
* Details required to establish a connection to an OpenTelemetry logging service.
2323
*
2424
* @author Toshiaki Maki
2525
* @since 3.4.0
2626
*/
27-
public interface OtlpLogsConnectionDetails extends ConnectionDetails {
27+
public interface OtlpLoggingConnectionDetails extends ConnectionDetails {
2828

2929
/**
3030
* Address to where logs will be published.
3131
* @return the address to where logs will be published
3232
*/
33-
String getUrl();
33+
String getEndpoint();
3434

3535
}
Lines changed: 4 additions & 8 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.actuate.autoconfigure.logs.otlp;
17+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;
1818

1919
import java.time.Duration;
2020
import java.util.HashMap;
@@ -28,8 +28,8 @@
2828
* @author Jonatan Ivanov
2929
* @since 3.4.0
3030
*/
31-
@ConfigurationProperties("management.otlp.logs")
32-
public class OtlpProperties {
31+
@ConfigurationProperties("management.otlp.logging")
32+
public class OtlpLoggingProperties {
3333

3434
/**
3535
* URL to the OTel collector's HTTP API.
@@ -52,7 +52,7 @@ public class OtlpProperties {
5252
/**
5353
* Custom HTTP headers you want to pass to the collector, for example auth headers.
5454
*/
55-
private Map<String, String> headers = new HashMap<>();
55+
private final Map<String, String> headers = new HashMap<>();
5656

5757
public String getEndpoint() {
5858
return this.endpoint;
@@ -82,10 +82,6 @@ public Map<String, String> getHeaders() {
8282
return this.headers;
8383
}
8484

85-
public void setHeaders(Map<String, String> headers) {
86-
this.headers = headers;
87-
}
88-
8985
public enum Compression {
9086

9187
/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
*/
1616

1717
/**
18-
* Auto-configuration for OpenTelemetry logs with OTLP.
18+
* Auto-configuration for OpenTelemetry logging with OTLP.
1919
*/
20-
package org.springframework.boot.actuate.autoconfigure.logs.otlp;
20+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
*/
1616

1717
/**
18-
* Auto-configuration for OpenTelemetry Logs.
18+
* Auto-configuration for OpenTelemetry logging.
1919
*/
20-
package org.springframework.boot.actuate.autoconfigure.logs;
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ org.springframework.boot.actuate.autoconfigure.ldap.LdapHealthContributorAutoCon
3535
org.springframework.boot.actuate.autoconfigure.liquibase.LiquibaseEndpointAutoConfiguration
3636
org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointAutoConfiguration
3737
org.springframework.boot.actuate.autoconfigure.logging.LoggersEndpointAutoConfiguration
38-
org.springframework.boot.actuate.autoconfigure.logs.OpenTelemetryAutoConfiguration
39-
org.springframework.boot.actuate.autoconfigure.logs.otlp.OtlpLogsAutoConfiguration
38+
org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.OpenTelemetryLoggingAutoConfiguration
39+
org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp.OtlpLoggingAutoConfiguration
4040
org.springframework.boot.actuate.autoconfigure.mail.MailHealthContributorAutoConfiguration
4141
org.springframework.boot.actuate.autoconfigure.management.HeapDumpWebEndpointAutoConfiguration
4242
org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration
Lines changed: 5 additions & 5 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.actuate.autoconfigure.logs;
17+
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;
1818

1919
import java.util.Collection;
2020
import java.util.concurrent.atomic.AtomicInteger;
@@ -41,18 +41,18 @@
4141
import static org.assertj.core.api.Assertions.assertThat;
4242

4343
/**
44-
* Tests for {@link OpenTelemetryAutoConfiguration}.
44+
* Tests for {@link OpenTelemetryLoggingAutoConfiguration}.
4545
*
4646
* @author Toshiaki Maki
4747
*/
48-
class OpenTelemetryAutoConfigurationTests {
48+
class OpenTelemetryLoggingAutoConfigurationTests {
4949

5050
private final ApplicationContextRunner contextRunner;
5151

52-
OpenTelemetryAutoConfigurationTests() {
52+
OpenTelemetryLoggingAutoConfigurationTests() {
5353
this.contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(
5454
org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryAutoConfiguration.class,
55-
OpenTelemetryAutoConfiguration.class));
55+
OpenTelemetryLoggingAutoConfiguration.class));
5656
}
5757

5858
@Test

0 commit comments

Comments
 (0)