Skip to content

Commit 4fc0119

Browse files
committed
Merge branch 'main' into 4.0.x
2 parents 810134d + d8fadaf commit 4fc0119

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@
4040
import org.springframework.boot.autoconfigure.AutoConfiguration;
4141
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4242
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
43+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
4344
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4445
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4546
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
@@ -159,6 +160,7 @@ TracingAwareMeterObservationHandler<Observation.Context> tracingAwareMeterObserv
159160

160161
@Configuration(proxyBeanMethods = false)
161162
@ConditionalOnClass(Advice.class)
163+
@ConditionalOnBooleanProperty("management.observations.annotations.enabled")
162164
static class ObservedAspectConfiguration {
163165

164166
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,11 +66,13 @@
6666
class ObservationAutoConfigurationTests {
6767

6868
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple())
69+
.withPropertyValues("management.observations.annotations.enabled=true")
6970
.withClassLoader(new FilteredClassLoader("io.micrometer.tracing"))
7071
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class));
7172

7273
private final ApplicationContextRunner tracingContextRunner = new ApplicationContextRunner()
7374
.with(MetricsRun.simple())
75+
.withPropertyValues("management.observations.annotations.enabled=true")
7476
.withUserConfiguration(TracerConfiguration.class)
7577
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class));
7678

@@ -141,6 +143,7 @@ void supplyMeterHandlerAndGroupingWhenMicrometerCoreAndTracingAreOnClassPath() {
141143
@Test
142144
void supplyMeterHandlerAndGroupingWhenMicrometerCoreAndTracingAreOnClassPathButThereIsNoTracer() {
143145
new ApplicationContextRunner().with(MetricsRun.simple())
146+
.withPropertyValues("management.observations.annotations.enabled=true")
144147
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class))
145148
.run((context) -> {
146149
ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class);
@@ -181,6 +184,12 @@ void allowsObservedAspectToBeDisabled() {
181184
.run((context) -> assertThat(context).doesNotHaveBean(ObservedAspect.class));
182185
}
183186

187+
@Test
188+
void allowsObservedAspectToBeDisabledWithProperty() {
189+
this.contextRunner.withPropertyValues("management.observations.annotations.enabled=false")
190+
.run((context) -> assertThat(context).doesNotHaveBean(ObservedAspect.class));
191+
}
192+
184193
@Test
185194
void allowsObservedAspectToBeCustomized() {
186195
this.contextRunner.withUserConfiguration(CustomObservedAspectConfiguration.class)

0 commit comments

Comments
 (0)