Skip to content

Commit 109142e

Browse files
committed
Merge pull request #41825 from famaridon
* pr/41825: Polish "Added documentation for configuring OpenTelemetry SDK logs" Added documentation for configuring OpenTelemetry SDK logs Closes gh-41825
2 parents f7ba5f1 + bc3bcd6 commit 109142e

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
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

+25
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,28 @@ To configure a given logger, `POST` a partial entity to the resource's URI, as t
3131
----
3232

3333
TIP: To "`reset`" the specific level of the logger (and use the default configuration instead), you can pass a value of `null` as the `configuredLevel`.
34+
35+
36+
37+
[[actuator.loggers.opentelemetry]]
38+
== OpenTelemetry
39+
By default, logging via OpenTelemetry is not configured.
40+
You have to provide the location of the OpenTelemetry logs endpoint to configure it:
41+
42+
[configprops,yaml]
43+
----
44+
management:
45+
otlp:
46+
logging:
47+
endpoint: "https://otlp.example.com:4318/v1/logs"
48+
----
49+
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].
52+
53+
TIP: You have to configure the appender in your `logback-spring.xml` or `log4j2-spring.xml` configuration to get OpenTelemetry logging working.
54+
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)