Skip to content

Commit bc3bcd6

Browse files
committed
Polish "Added documentation for configuring OpenTelemetry SDK logs"
See gh-41825
1 parent 4261ed9 commit bc3bcd6

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

spring-boot-project/spring-boot-docs/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ dependencies {
8383
implementation("io.micrometer:micrometer-tracing")
8484
implementation("io.micrometer:micrometer-registry-graphite")
8585
implementation("io.micrometer:micrometer-registry-jmx")
86+
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0")
8687
implementation("io.projectreactor.netty:reactor-netty-http")
8788
implementation("io.undertow:undertow-core")
8889
implementation("jakarta.annotation:jakarta.annotation-api")

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc

+9-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ TIP: To "`reset`" the specific level of the logger (and use the default configur
3636

3737
[[actuator.loggers.opentelemetry]]
3838
== OpenTelemetry
39-
By default, the OpenTelemetry SDK logs are not configured. You can provide the location of the OpenTelemetry logs endpoint to configure it:
39+
By default, logging via OpenTelemetry is not configured.
40+
You have to provide the location of the OpenTelemetry logs endpoint to configure it:
4041

4142
[configprops,yaml]
4243
----
@@ -46,8 +47,12 @@ management:
4647
endpoint: "https://otlp.example.com:4318/v1/logs"
4748
----
4849

49-
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]
50+
NOTE: The OpenTelemetry Logback appender and Log4j appender are not part of Spring Boot.
51+
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].
5052

51-
TIP: Ensure that you add the appender to your `logback.xml` or `logback-spring.xml` (or the equivalent configuration file for Log4j).
53+
TIP: You have to configure the appender in your `logback-spring.xml` or `log4j2-spring.xml` configuration to get OpenTelemetry logging working.
5254

53-
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`.
55+
The `OpenTelemetryAppender` for both Logback and Log4j requires access to an `OpenTelemetry` instance to function properly.
56+
This instance must be set programmatically during application startup, which can be done like this:
57+
58+
include-code::OpenTelemetryAppenderInitializer[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2024 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.docs.actuator.loggers.opentelemetry;
18+
19+
import io.opentelemetry.api.OpenTelemetry;
20+
import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender;
21+
22+
import org.springframework.beans.factory.InitializingBean;
23+
import org.springframework.stereotype.Component;
24+
25+
@Component
26+
class OpenTelemetryAppenderInitializer implements InitializingBean {
27+
28+
private final OpenTelemetry openTelemetry;
29+
30+
OpenTelemetryAppenderInitializer(OpenTelemetry openTelemetry) {
31+
this.openTelemetry = openTelemetry;
32+
}
33+
34+
@Override
35+
public void afterPropertiesSet() {
36+
OpenTelemetryAppender.install(this.openTelemetry);
37+
}
38+
39+
}

spring-boot-project/spring-boot-parent/build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ bom {
159159
]
160160
}
161161
}
162+
library("OpenTelemetry Logback Appender", "2.7.0-alpha") {
163+
group("io.opentelemetry.instrumentation") {
164+
modules = [
165+
"opentelemetry-logback-appender-1.0"
166+
]
167+
}
168+
}
162169
library("Plexus Build API", "0.0.7") {
163170
group("org.sonatype.plexus") {
164171
modules = [

0 commit comments

Comments
 (0)