From 962f1f9db226ca21d0fac788d6814e7eed9f7cf5 Mon Sep 17 00:00:00 2001 From: famaridon Date: Thu, 29 Aug 2024 14:55:38 +0200 Subject: [PATCH] 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