diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/OpenTelemetryAppenderInitializer.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/OpenTelemetryAppenderInitializer.kt new file mode 100644 index 000000000000..d393896a1151 --- /dev/null +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/loggers/opentelemetry/OpenTelemetryAppenderInitializer.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2012-present 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( + private val openTelemetry: OpenTelemetry +) : InitializingBean { + + override fun afterPropertiesSet() = OpenTelemetryAppender.install(openTelemetry) + +} diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/observability/MyCustomObservation.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/observability/MyCustomObservation.kt new file mode 100644 index 000000000000..03ffba58417e --- /dev/null +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/observability/MyCustomObservation.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2012-present 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.observability + +import io.micrometer.observation.Observation +import io.micrometer.observation.ObservationRegistry; + +import org.springframework.stereotype.Component + +@Component +class MyCustomObservation(private val observationRegistry: ObservationRegistry) { + + fun doSomething() { + Observation.createNotStarted("doSomething", observationRegistry) + .lowCardinalityKeyValue("locale", "en-US") + .highCardinalityKeyValue("userId", "42") + .observe { + // Execute business logic here + } + } +} diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/observability/preventingobservations/MyObservationPredicate.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/observability/preventingobservations/MyObservationPredicate.kt new file mode 100644 index 000000000000..60eea6b0bd61 --- /dev/null +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/observability/preventingobservations/MyObservationPredicate.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2012-present 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.observability.preventingobservations + +import io.micrometer.observation.Observation.Context +import io.micrometer.observation.ObservationPredicate +import org.springframework.stereotype.Component + +@Component +class MyObservationPredicate : ObservationPredicate { + + override fun test(name: String, context: Context): Boolean { + return !name.contains("denied") + } +}