From 0cc8d1fc3863771812a8c70fb58913a8c815b79b Mon Sep 17 00:00:00 2001 From: famaridon Date: Mon, 12 Aug 2024 09:59:26 +0200 Subject: [PATCH 1/4] Added documentation for configuring OpenTelemetry SDK logs. --- .../modules/reference/pages/actuator/loggers.adoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc index 3c6e0534acd9..acdeb701d034 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc @@ -31,3 +31,16 @@ To configure a given logger, `POST` a partial entity to the resource's URI, as t ---- 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`. + +== OpenTelemetry +By default, the OpenTelemetry SDK logs are not configured. You can provide the location of the OpenTelemetry logs endpoint to configure it: + +[source,yaml] +---- +management: + otlp: + logging: + endpoint: "https://otlp.example.com:4318/v1/logs" +---- + +Note: The OpenTelemetry Logback appender and Log4j appender are not part of Spring Boot. You have to provide and configure them yourself. For more details, https://github.com/spring-projects/spring-boot/pull/40961[see this pull request]. From dcc65f5f834ba74eb967f70074efbc8d845f318b Mon Sep 17 00:00:00 2001 From: famaridon Date: Thu, 29 Aug 2024 14:26:56 +0200 Subject: [PATCH 2/4] pull request fix --- .../modules/reference/pages/actuator/loggers.adoc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc index acdeb701d034..47e010214a97 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc @@ -32,10 +32,13 @@ To configure a given logger, `POST` a partial entity to the resource's URI, as t 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`. + + +[[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: -[source,yaml] +[configprops,yaml] ---- management: otlp: @@ -43,4 +46,11 @@ management: endpoint: "https://otlp.example.com:4318/v1/logs" ---- -Note: The OpenTelemetry Logback appender and Log4j appender are not part of Spring Boot. You have to provide and configure them yourself. For more details, https://github.com/spring-projects/spring-boot/pull/40961[see this pull request]. +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] + +You have to add the appender to your logback-spring.xml or log4j-spring.xml. + +In order to function, OpenTelemetryAppender needs access to an OpenTelemetry instance. This must be set programmatically during application startup as follows: + +include-code::opentelemetry/OpentelemetryLoggerConfiguration[] + From c3ebcb4418e061c41f891af8e6bc3f4d84cdb341 Mon Sep 17 00:00:00 2001 From: famaridon Date: Thu, 29 Aug 2024 14:55:38 +0200 Subject: [PATCH 3/4] add opentelemetry logger appeder link to Opentelemetry sdk sample --- .../reference/pages/actuator/loggers.adoc | 2 +- .../OpentelemetryLoggerConfiguration.java | 34 +++++++++++++++++++ .../OpentelemetryLoggerConfiguration.kt | 34 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc index 47e010214a97..e7d82bd4a2bf 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc @@ -52,5 +52,5 @@ You have to add the appender to your logback-spring.xml or log4j-spring.xml. In order to function, OpenTelemetryAppender needs access to an OpenTelemetry instance. This must be set programmatically during application startup as follows: -include-code::opentelemetry/OpentelemetryLoggerConfiguration[] +include-code::logback/OpentelemetryLoggerConfiguration[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java new file mode 100644 index 000000000000..d6038b23e3b2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2022 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.logback; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender; + +@Configuration +public class OpentelemetryLoggerConfiguration { + + @Bean + public ApplicationListener logbackOtelAppenderInitializer(OpenTelemetry openTelemetry) { + return event -> OpenTelemetryAppender.install(openTelemetry); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt new file mode 100644 index 000000000000..d4ca9ac0f8ad --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2022 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.logback + +import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.context.ApplicationListener +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender + +@Configuration +class OpentelemetryLoggerConfiguration { + + @Bean + fun logbackOtelAppenderInitializer(openTelemetry: OpenTelemetry): ApplicationListener { + return ApplicationListener { OpenTelemetryAppender.install(openTelemetry) } + } +} \ No newline at end of file From b4e1f060eea640d099c9324a55691a3719c829b7 Mon Sep 17 00:00:00 2001 From: famaridon Date: Fri, 30 Aug 2024 13:35:38 +0000 Subject: [PATCH 4/4] remove sample code OpenTelemetryAppender s not in spring boot classpath. Replace by tips --- .../reference/pages/actuator/loggers.adoc | 7 ++-- .../OpentelemetryLoggerConfiguration.java | 34 ------------------- .../OpentelemetryLoggerConfiguration.kt | 34 ------------------- 3 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java delete mode 100644 spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc index e7d82bd4a2bf..8567b9c6730c 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/loggers.adoc @@ -48,9 +48,6 @@ management: 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] -You have to add the appender to your logback-spring.xml or log4j-spring.xml. - -In order to function, OpenTelemetryAppender needs access to an OpenTelemetry instance. This must be set programmatically during application startup as follows: - -include-code::logback/OpentelemetryLoggerConfiguration[] +TIP: Ensure that you add the appender to your `logback.xml` or `logback-spring.xml` (or the equivalent configuration file for Log4j). +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`. diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java deleted file mode 100644 index d6038b23e3b2..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2022 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.logback; - -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender; - -@Configuration -public class OpentelemetryLoggerConfiguration { - - @Bean - public ApplicationListener logbackOtelAppenderInitializer(OpenTelemetry openTelemetry) { - return event -> OpenTelemetryAppender.install(openTelemetry); - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt deleted file mode 100644 index d4ca9ac0f8ad..000000000000 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/logback/OpentelemetryLoggerConfiguration.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2022 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.logback - -import org.springframework.boot.context.event.ApplicationReadyEvent -import org.springframework.context.ApplicationListener -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -import io.opentelemetry.api.OpenTelemetry -import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender - -@Configuration -class OpentelemetryLoggerConfiguration { - - @Bean - fun logbackOtelAppenderInitializer(openTelemetry: OpenTelemetry): ApplicationListener { - return ApplicationListener { OpenTelemetryAppender.install(openTelemetry) } - } -} \ No newline at end of file