Skip to content

Commit

Permalink
Polish "Provide auto configuration for OpenTelemetry Logs"
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jun 28, 2024
1 parent 2d6f248 commit cfa0571
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.sdk.logs.LogRecordProcessor;
Expand All @@ -32,26 +32,25 @@
import org.springframework.context.annotation.Bean;

/**
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry Logs.
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry logging.
*
* @author Toshiaki Maki
* @since 3.4.0
*/
@AutoConfiguration("openTelemetryLogsAutoConfiguration")
@AutoConfiguration
@ConditionalOnClass({ SdkLoggerProvider.class, OpenTelemetry.class })
public class OpenTelemetryAutoConfiguration {
public class OpenTelemetryLoggingAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public BatchLogRecordProcessor batchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
BatchLogRecordProcessor batchLogRecordProcessor(ObjectProvider<LogRecordExporter> logRecordExporters) {
return BatchLogRecordProcessor.builder(LogRecordExporter.composite(logRecordExporters.orderedStream().toList()))
.build();
}

@Bean
@ConditionalOnMissingBean
public SdkLoggerProvider otelSdkLoggerProvider(Resource resource,
ObjectProvider<LogRecordProcessor> logRecordProcessors,
SdkLoggerProvider otelSdkLoggerProvider(Resource resource, ObjectProvider<LogRecordProcessor> logRecordProcessors,
ObjectProvider<SdkLoggerProviderBuilderCustomizer> customizers) {
SdkLoggerProviderBuilder builder = SdkLoggerProvider.builder().setResource(resource);
logRecordProcessors.orderedStream().forEach(builder::addLogRecordProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;

import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs.otlp;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter;
Expand All @@ -27,15 +27,15 @@
import org.springframework.context.annotation.Import;

/**
* {@link EnableAutoConfiguration Auto-configuration} for OTLP Logs.
* {@link EnableAutoConfiguration Auto-configuration} for OTLP logging.
*
* @author Toshiaki Maki
* @since 3.4.0
*/
@AutoConfiguration
@ConditionalOnClass({ SdkLoggerProvider.class, OpenTelemetry.class, OtlpHttpLogRecordExporter.class })
@EnableConfigurationProperties(OtlpProperties.class)
@Import({ OtlpLogsConfigurations.ConnectionDetails.class, OtlpLogsConfigurations.Exporters.class })
public class OtlpLogsAutoConfiguration {
@EnableConfigurationProperties(OtlpLoggingProperties.class)
@Import({ OtlpLoggingConfigurations.ConnectionDetails.class, OtlpLoggingConfigurations.Exporters.class })
public class OtlpLoggingAutoConfiguration {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs.otlp;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;

import java.util.Locale;

Expand All @@ -28,36 +28,38 @@
import org.springframework.context.annotation.Configuration;

/**
* Configurations imported by {@link OtlpLogsAutoConfiguration}.
* Configurations imported by {@link OtlpLoggingAutoConfiguration}.
*
* @author Toshiaki Maki
* @since 3.4.0
*/
public class OtlpLogsConfigurations {
final class OtlpLoggingConfigurations {

private OtlpLoggingConfigurations() {
}

@Configuration(proxyBeanMethods = false)
static class ConnectionDetails {

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "management.otlp.logs", name = "endpoint")
OtlpLogsConnectionDetails otlpLogsConnectionDetails(OtlpProperties properties) {
return new PropertiesOtlpLogsConnectionDetails(properties);
@ConditionalOnProperty(prefix = "management.otlp.logging", name = "endpoint")
OtlpLoggingConnectionDetails otlpLogsConnectionDetails(OtlpLoggingProperties properties) {
return new PropertiesOtlpLoggingConnectionDetails(properties);
}

/**
* Adapts {@link OtlpProperties} to {@link OtlpLogsConnectionDetails}.
* Adapts {@link OtlpLoggingProperties} to {@link OtlpLoggingConnectionDetails}.
*/
static class PropertiesOtlpLogsConnectionDetails implements OtlpLogsConnectionDetails {
static class PropertiesOtlpLoggingConnectionDetails implements OtlpLoggingConnectionDetails {

private final OtlpProperties properties;
private final OtlpLoggingProperties properties;

PropertiesOtlpLogsConnectionDetails(OtlpProperties properties) {
PropertiesOtlpLoggingConnectionDetails(OtlpLoggingProperties properties) {
this.properties = properties;
}

@Override
public String getUrl() {
public String getEndpoint() {
return this.properties.getEndpoint();
}

Expand All @@ -70,12 +72,12 @@ static class Exporters {

@ConditionalOnMissingBean(value = OtlpHttpLogRecordExporter.class,
type = "io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter")
@ConditionalOnBean(OtlpLogsConnectionDetails.class)
@ConditionalOnBean(OtlpLoggingConnectionDetails.class)
@Bean
OtlpHttpLogRecordExporter otlpHttpLogRecordExporter(OtlpProperties properties,
OtlpLogsConnectionDetails connectionDetails) {
OtlpHttpLogRecordExporter otlpHttpLogRecordExporter(OtlpLoggingProperties properties,
OtlpLoggingConnectionDetails connectionDetails) {
OtlpHttpLogRecordExporterBuilder builder = OtlpHttpLogRecordExporter.builder()
.setEndpoint(connectionDetails.getUrl())
.setEndpoint(connectionDetails.getEndpoint())
.setCompression(properties.getCompression().name().toLowerCase(Locale.US))
.setTimeout(properties.getTimeout());
properties.getHeaders().forEach(builder::addHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs.otlp;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;

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

/**
* Details required to establish a connection to an OpenTelemetry logs service.
* Details required to establish a connection to an OpenTelemetry logging service.
*
* @author Toshiaki Maki
* @since 3.4.0
*/
public interface OtlpLogsConnectionDetails extends ConnectionDetails {
public interface OtlpLoggingConnectionDetails extends ConnectionDetails {

/**
* Address to where logs will be published.
* @return the address to where logs will be published
*/
String getUrl();
String getEndpoint();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs.otlp;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;

import java.time.Duration;
import java.util.HashMap;
Expand All @@ -28,8 +28,8 @@
* @author Jonatan Ivanov
* @since 3.4.0
*/
@ConfigurationProperties("management.otlp.logs")
public class OtlpProperties {
@ConfigurationProperties("management.otlp.logging")
public class OtlpLoggingProperties {

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

public String getEndpoint() {
return this.endpoint;
Expand Down Expand Up @@ -82,10 +82,6 @@ public Map<String, String> getHeaders() {
return this.headers;
}

public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

public enum Compression {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/

/**
* Auto-configuration for OpenTelemetry logs with OTLP.
* Auto-configuration for OpenTelemetry logging with OTLP.
*/
package org.springframework.boot.actuate.autoconfigure.logs.otlp;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/

/**
* Auto-configuration for OpenTelemetry Logs.
* Auto-configuration for OpenTelemetry logging.
*/
package org.springframework.boot.actuate.autoconfigure.logs;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ org.springframework.boot.actuate.autoconfigure.ldap.LdapHealthContributorAutoCon
org.springframework.boot.actuate.autoconfigure.liquibase.LiquibaseEndpointAutoConfiguration
org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointAutoConfiguration
org.springframework.boot.actuate.autoconfigure.logging.LoggersEndpointAutoConfiguration
org.springframework.boot.actuate.autoconfigure.logs.OpenTelemetryAutoConfiguration
org.springframework.boot.actuate.autoconfigure.logs.otlp.OtlpLogsAutoConfiguration
org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.OpenTelemetryLoggingAutoConfiguration
org.springframework.boot.actuate.autoconfigure.logging.opentelemetry.otlp.OtlpLoggingAutoConfiguration
org.springframework.boot.actuate.autoconfigure.mail.MailHealthContributorAutoConfiguration
org.springframework.boot.actuate.autoconfigure.management.HeapDumpWebEndpointAutoConfiguration
org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.logs;
package org.springframework.boot.actuate.autoconfigure.logging.opentelemetry;

import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -41,18 +41,18 @@
import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link OpenTelemetryAutoConfiguration}.
* Tests for {@link OpenTelemetryLoggingAutoConfiguration}.
*
* @author Toshiaki Maki
*/
class OpenTelemetryAutoConfigurationTests {
class OpenTelemetryLoggingAutoConfigurationTests {

private final ApplicationContextRunner contextRunner;

OpenTelemetryAutoConfigurationTests() {
OpenTelemetryLoggingAutoConfigurationTests() {
this.contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(
org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryAutoConfiguration.class,
OpenTelemetryAutoConfiguration.class));
OpenTelemetryLoggingAutoConfiguration.class));
}

@Test
Expand Down
Loading

0 comments on commit cfa0571

Please sign in to comment.