Polish "Added documentation for configuring OpenTelemetry SDK logs"

See gh-41825
This commit is contained in:
Moritz Halbritter 2024-09-05 15:16:00 +02:00
parent 4261ed9c2b
commit bc3bcd68d6
4 changed files with 56 additions and 4 deletions

View File

@ -83,6 +83,7 @@ dependencies {
implementation("io.micrometer:micrometer-tracing")
implementation("io.micrometer:micrometer-registry-graphite")
implementation("io.micrometer:micrometer-registry-jmx")
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0")
implementation("io.projectreactor.netty:reactor-netty-http")
implementation("io.undertow:undertow-core")
implementation("jakarta.annotation:jakarta.annotation-api")

View File

@ -36,7 +36,8 @@ TIP: To "`reset`" the specific level of the logger (and use the default configur
[[actuator.loggers.opentelemetry]]
== OpenTelemetry
By default, the OpenTelemetry SDK logs are not configured. You can provide the location of the OpenTelemetry logs endpoint to configure it:
By default, logging via OpenTelemetry is not configured.
You have to provide the location of the OpenTelemetry logs endpoint to configure it:
[configprops,yaml]
----
@ -46,8 +47,12 @@ management:
endpoint: "https://otlp.example.com:4318/v1/logs"
----
NOTE: The OpenTelemetry Logback appender and Log4j appender are not part of Spring Boot, for more details, see the https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/library[OpenTelemetry Logback appender] or https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/log4j/log4j-appender-2.17/library[OpenTelemetry Log4j2 appender] in the https://github.com/open-telemetry/opentelemetry-java-instrumentation[OpenTelemetry Java instrumentation GitHub repository]
NOTE: The OpenTelemetry Logback appender and Log4j appender are not part of Spring Boot.
For more details, see the https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/library[OpenTelemetry Logback appender] or the https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/log4j/log4j-appender-2.17/library[OpenTelemetry Log4j2 appender] in the https://github.com/open-telemetry/opentelemetry-java-instrumentation[OpenTelemetry Java instrumentation GitHub repository].
TIP: Ensure that you add the appender to your `logback.xml` or `logback-spring.xml` (or the equivalent configuration file for Log4j).
TIP: You have to configure the appender in your `logback-spring.xml` or `log4j2-spring.xml` configuration to get OpenTelemetry logging working.
TIP: The `OpenTelemetryAppender` requires access to an OpenTelemetry instance to function properly. This instance must be set programmatically during application startup by using an `ApplicationListener` for the `ApplicationReadyEvent`.
The `OpenTelemetryAppender` for both Logback and Log4j requires access to an `OpenTelemetry` instance to function properly.
This instance must be set programmatically during application startup, which can be done like this:
include-code::OpenTelemetryAppenderInitializer[]

View File

@ -0,0 +1,39 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.actuator.loggers.opentelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
@Component
class OpenTelemetryAppenderInitializer implements InitializingBean {
private final OpenTelemetry openTelemetry;
OpenTelemetryAppenderInitializer(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
}
@Override
public void afterPropertiesSet() {
OpenTelemetryAppender.install(this.openTelemetry);
}
}

View File

@ -159,6 +159,13 @@ bom {
]
}
}
library("OpenTelemetry Logback Appender", "2.7.0-alpha") {
group("io.opentelemetry.instrumentation") {
modules = [
"opentelemetry-logback-appender-1.0"
]
}
}
library("Plexus Build API", "0.0.7") {
group("org.sonatype.plexus") {
modules = [