Skip to content

Commit 158c395

Browse files
Refactor tracing annotation and export condition
- Rename @ConditionalOnEnabledTracing to @ConditionalOnEnabledTracingExport - Rename global property from management.tracing.enabled to management.tracing.export.enabled - Update additional-spring-configuration-metadata.json accordingly - Rename OnEnabledTracingCondition to OnEnabledTracingExportCondition Signed-off-by: Maziyar Bahramian <maziyar.bahramian@gmail.com>
1 parent 78bc232 commit 158c395

File tree

21 files changed

+65
-62
lines changed

21 files changed

+65
-62
lines changed

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Regardless of your classpath, tracing components which are reporting data are no
233233

234234
If you need those components as part of an integration test, annotate the test with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation].
235235

236-
If you have created your own reporting components (e.g. a custom javadoc:io.opentelemetry.sdk.trace.export.SpanExporter[] or `brave.handler.SpanHandler`) and you don't want them to be active in tests, you can use the javadoc:org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracing[format=annotation] annotation to disable them.
236+
If you have created your own reporting components (e.g. a custom javadoc:io.opentelemetry.sdk.trace.export.SpanExporter[] or `brave.handler.SpanHandler`) and you don't want them to be active in tests, you can use the javadoc:org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport[format=annotation] annotation to disable them.
237237

238238
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation], it auto-configures a no-op javadoc:io.micrometer.tracing.Tracer[].
239239
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation] annotation.

module/spring-boot-micrometer-tracing/src/main/java/org/springframework/boot/micrometer/tracing/autoconfigure/BravePropagationConfigurations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static class PropagationWithoutBaggage {
5858

5959
@Bean
6060
@ConditionalOnMissingBean(Factory.class)
61-
@ConditionalOnEnabledTracing
61+
@ConditionalOnEnabledTracingExport
6262
CompositePropagationFactory propagationFactory(TracingProperties properties) {
6363
return CompositePropagationFactory.create(properties.getPropagation());
6464
}
@@ -127,7 +127,7 @@ BaggagePropagationCustomizer remoteFieldsBaggagePropagationCustomizer() {
127127

128128
@Bean
129129
@ConditionalOnMissingBean
130-
@ConditionalOnEnabledTracing
130+
@ConditionalOnEnabledTracingExport
131131
Factory propagationFactory(BaggagePropagation.FactoryBuilder factoryBuilder) {
132132
return factoryBuilder.build();
133133
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
/**
2828
* {@link Conditional @Conditional} that checks whether tracing is enabled. It matches if
29-
* the value of the {@code management.tracing.enabled} property is {@code true} or if it
30-
* is not configured. If the {@link #value() tracing exporter name} is set, the
29+
* the value of the {@code management.tracing.export.enabled} property is {@code true} or
30+
* if it is not configured. If the {@link #value() tracing exporter name} is set, the
3131
* {@code management.<name>.tracing.export.enabled} property can be used to control the
3232
* behavior for the specific tracing exporter. In that case, the exporter specific
3333
* property takes precedence over the global property.
@@ -38,8 +38,8 @@
3838
@Retention(RetentionPolicy.RUNTIME)
3939
@Target({ ElementType.TYPE, ElementType.METHOD })
4040
@Documented
41-
@Conditional(OnEnabledTracingCondition.class)
42-
public @interface ConditionalOnEnabledTracing {
41+
@Conditional(OnEnabledTracingExportCondition.class)
42+
public @interface ConditionalOnEnabledTracingExport {
4343

4444
/**
4545
* Name of the tracing exporter.

module/spring-boot-micrometer-tracing/src/main/java/org/springframework/boot/micrometer/tracing/autoconfigure/LogCorrelationEnvironmentPostProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* {@link EnvironmentPostProcessor} to add a {@link PropertySource} to support log
3232
* correlation IDs when Micrometer Tracing is present. Adds support for the
3333
* {@value LoggingSystem#EXPECT_CORRELATION_ID_PROPERTY} property by delegating to
34-
* {@code management.tracing.enabled}.
34+
* {@code management.tracing.export.enabled}.
3535
*
3636
* @author Jonatan Ivanov
3737
* @author Phillip Webb
@@ -67,7 +67,7 @@ public String[] getPropertyNames() {
6767
@Override
6868
public @Nullable Object getProperty(String name) {
6969
if (name.equals(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY)) {
70-
return this.environment.getProperty("management.tracing.enabled", Boolean.class, Boolean.TRUE);
70+
return this.environment.getProperty("management.tracing.export.enabled", Boolean.class, Boolean.TRUE);
7171
}
7272
return null;
7373
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
* {@link SpringBootCondition} to check whether tracing is enabled.
3232
*
3333
* @author Moritz Halbritter
34-
* @see ConditionalOnEnabledTracing
34+
* @see ConditionalOnEnabledTracingExport
3535
*/
36-
class OnEnabledTracingCondition extends SpringBootCondition {
36+
class OnEnabledTracingExportCondition extends SpringBootCondition {
3737

38-
private static final String GLOBAL_PROPERTY = "management.tracing.enabled";
38+
/// management.tracing.enabled
39+
private static final String GLOBAL_PROPERTY = "management.tracing.export.enabled";
3940

4041
private static final String EXPORTER_PROPERTY = "management.%s.tracing.export.enabled";
4142

@@ -47,23 +48,23 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
4748
.getProperty(EXPORTER_PROPERTY.formatted(tracingExporter), Boolean.class);
4849
if (exporterTracingEnabled != null) {
4950
return new ConditionOutcome(exporterTracingEnabled,
50-
ConditionMessage.forCondition(ConditionalOnEnabledTracing.class)
51+
ConditionMessage.forCondition(ConditionalOnEnabledTracingExport.class)
5152
.because(EXPORTER_PROPERTY.formatted(tracingExporter) + " is " + exporterTracingEnabled));
5253
}
5354
}
5455
Boolean globalTracingEnabled = context.getEnvironment().getProperty(GLOBAL_PROPERTY, Boolean.class);
5556
if (globalTracingEnabled != null) {
5657
return new ConditionOutcome(globalTracingEnabled,
57-
ConditionMessage.forCondition(ConditionalOnEnabledTracing.class)
58+
ConditionMessage.forCondition(ConditionalOnEnabledTracingExport.class)
5859
.because(GLOBAL_PROPERTY + " is " + globalTracingEnabled));
5960
}
60-
return ConditionOutcome.match(ConditionMessage.forCondition(ConditionalOnEnabledTracing.class)
61+
return ConditionOutcome.match(ConditionMessage.forCondition(ConditionalOnEnabledTracingExport.class)
6162
.because("tracing is enabled by default"));
6263
}
6364

6465
private static @Nullable String getExporterName(AnnotatedTypeMetadata metadata) {
6566
Map<String, @Nullable Object> attributes = metadata
66-
.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName());
67+
.getAnnotationAttributes(ConditionalOnEnabledTracingExport.class.getName());
6768
if (attributes == null) {
6869
return null;
6970
}

module/spring-boot-micrometer-tracing/src/main/java/org/springframework/boot/micrometer/tracing/autoconfigure/OpenTelemetryPropagationConfigurations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OpenTelemetryPropagationConfigurations {
4747
static class PropagationWithoutBaggage {
4848

4949
@Bean
50-
@ConditionalOnEnabledTracing
50+
@ConditionalOnEnabledTracingExport
5151
TextMapPropagator textMapPropagator(TracingProperties properties) {
5252
return CompositeTextMapPropagator.create(properties.getPropagation(), null);
5353
}
@@ -69,7 +69,7 @@ static class PropagationWithBaggage {
6969
}
7070

7171
@Bean
72-
@ConditionalOnEnabledTracing
72+
@ConditionalOnEnabledTracingExport
7373
TextMapPropagator textMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurrentTraceContext) {
7474
List<String> remoteFields = this.tracingProperties.getBaggage().getRemoteFields();
7575
List<String> tagFields = this.tracingProperties.getBaggage().getTagFields();

module/spring-boot-micrometer-tracing/src/main/java/org/springframework/boot/micrometer/tracing/autoconfigure/otlp/OtlpTracingConfigurations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2929
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3030
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
31-
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracing;
31+
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport;
3232
import org.springframework.context.annotation.Bean;
3333
import org.springframework.context.annotation.Configuration;
3434
import org.springframework.util.Assert;
@@ -79,7 +79,7 @@ public String getUrl(Transport transport) {
7979
@Configuration(proxyBeanMethods = false)
8080
@ConditionalOnMissingBean({ OtlpGrpcSpanExporter.class, OtlpHttpSpanExporter.class })
8181
@ConditionalOnBean(OtlpTracingConnectionDetails.class)
82-
@ConditionalOnEnabledTracing("otlp")
82+
@ConditionalOnEnabledTracingExport("otlp")
8383
static class Exporters {
8484

8585
@Bean

module/spring-boot-micrometer-tracing/src/main/java/org/springframework/boot/micrometer/tracing/autoconfigure/zipkin/ZipkinTracingAutoConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3535
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3636
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
37-
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracing;
37+
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport;
3838
import org.springframework.boot.micrometer.tracing.autoconfigure.zipkin.ZipkinTracingAutoConfiguration.BraveConfiguration;
3939
import org.springframework.boot.micrometer.tracing.autoconfigure.zipkin.ZipkinTracingAutoConfiguration.OpenTelemetryConfiguration;
4040
import org.springframework.context.annotation.Bean;
@@ -71,7 +71,7 @@ BytesEncoder<MutableSpan> mutableSpanBytesEncoder(Encoding encoding,
7171
@Bean
7272
@ConditionalOnMissingBean
7373
@ConditionalOnBean(BytesMessageSender.class)
74-
@ConditionalOnEnabledTracing("zipkin")
74+
@ConditionalOnEnabledTracingExport("zipkin")
7575
AsyncZipkinSpanHandler asyncZipkinSpanHandler(BytesMessageSender sender,
7676
BytesEncoder<MutableSpan> mutableSpanBytesEncoder) {
7777
return AsyncZipkinSpanHandler.newBuilder(sender).build(mutableSpanBytesEncoder);
@@ -93,7 +93,7 @@ BytesEncoder<Span> spanBytesEncoder(Encoding encoding) {
9393
@Bean
9494
@ConditionalOnMissingBean
9595
@ConditionalOnBean(BytesMessageSender.class)
96-
@ConditionalOnEnabledTracing("zipkin")
96+
@ConditionalOnEnabledTracingExport("zipkin")
9797
ZipkinSpanExporter zipkinSpanExporter(BytesMessageSender sender, BytesEncoder<Span> spanBytesEncoder) {
9898
return ZipkinSpanExporter.builder().setSender(sender).setEncoder(spanBytesEncoder).build();
9999
}

module/spring-boot-micrometer-tracing/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": "Whether auto-configuration of tracing is enabled to export OTLP traces."
88
},
99
{
10-
"name": "management.tracing.enabled",
10+
"name": "management.tracing.export.enabled",
1111
"type": "java.lang.Boolean",
1212
"description": "Whether auto-configuration of tracing is enabled to export and propagate traces.",
1313
"defaultValue": true

module/spring-boot-micrometer-tracing/src/test/java/org/springframework/boot/micrometer/tracing/autoconfigure/BraveAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void compositeSpanHandlerUsesFilterPredicateAndReportersInOrder() {
350350

351351
@Test
352352
void shouldDisablePropagationIfTracingIsDisabled() {
353-
this.contextRunner.withPropertyValues("management.tracing.enabled=false").run((context) -> {
353+
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false").run((context) -> {
354354
assertThat(context).hasSingleBean(Factory.class);
355355
Factory factory = context.getBean(Factory.class);
356356
Propagation<String> propagation = factory.get();

0 commit comments

Comments
 (0)