This pull request introduces auto-configuration for SdkLoggerProvider and OtlpHttpLogRecordExporter (closes https://github.com/spring-projects/spring-boot/issues/37355). The implementation basically follows the approach used for Tracing, excluding gRPC. Instrumentation settings via logback or log4j are out of the scope of this PR because the library is still in alpha version.

There was a consideration to place the package under the existing org.springframework.boot.actuate.autoconfigure.opentelemetry or org.springframework.boot.actuate.autoconfigure.logging. However, a new package org.springframework.boot.actuate.autoconfigure.logs has been created for this auto-configuration. This may need to be changed.

With this auto-configuration, users can configure the Logback Appender to send logs via OLTP as follows:

<!-- logback-spring.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
    <appender name="OPEN_TELEMETRY"
              class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
        <captureExperimentalAttributes>true</captureExperimentalAttributes>
        <captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
    </appender>
    <root level="INFO">
        <appender-ref ref="OPEN_TELEMETRY"/>
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>
@Bean
public ApplicationListener<ApplicationReadyEvent> logbackOtelAppenderInitializer(OpenTelemetry openTelemetry) {
    return event -> OpenTelemetryAppender.install(openTelemetry);
}
management.otlp.logs.endpoint=http://localhost:4318/v1/logs
management.otlp.logs.headers.authorization=Bearer changeme
management.otlp.logs.compression=gzip
management.otlp.logs.timeout=10s

Additionally, to ensure the functionality of this pull request, an experimental project was created and tested, which also includes auto-configuration for the Logback Appender: https://github.com/making/otel-logs-autoconfigure

Comment From: mhalbritter

Thanks a lot!