Skip to content

Commit

Permalink
Polish "Added documentation for configuring OpenTelemetry SDK logs"
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Sep 5, 2024
1 parent 4261ed9 commit bc3bcd6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
----
Expand All @@ -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[]
Original file line number Diff line number Diff line change
@@ -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);
}

}
7 changes: 7 additions & 0 deletions spring-boot-project/spring-boot-parent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit bc3bcd6

Please sign in to comment.