Skip to content

Commit fc9712c

Browse files
committed
extract condition
1 parent 4f1d443 commit fc9712c

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig;
1313
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
1414
import io.opentelemetry.instrumentation.sdk.DeclarativeConfigPropertiesBridge;
15+
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.DeclarativeConfigDisabled;
16+
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.DeclarativeConfigEnabled;
1517
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OtelMapConverter;
1618
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled;
1719
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.ConfigPropertiesBridge;
@@ -88,7 +90,7 @@ public ResourceProvider otelDistroVersionResourceProvider() {
8890
OtelResourceProperties.class,
8991
OtelSpringProperties.class
9092
})
91-
@ConditionalOnProperty(name = "otel.file_format", matchIfMissing = true, havingValue = "never")
93+
@Conditional(DeclarativeConfigDisabled.class)
9294
static class PropertiesConfig {
9395

9496
@Bean
@@ -147,7 +149,7 @@ public ConfigProperties otelProperties(
147149
}
148150

149151
@Configuration
150-
@ConditionalOnProperty(name = "otel.file_format")
152+
@Conditional(DeclarativeConfigEnabled.class)
151153
static class EmbeddedConfigFileConfig {
152154

153155
@Bean
@@ -226,7 +228,7 @@ public InstrumentationConfig instrumentationConfig(ConfigProperties properties)
226228
}
227229

228230
@Configuration
229-
@ConditionalOnProperty(name = "otel.file_format", matchIfMissing = true, havingValue = "never")
231+
@Conditional(DeclarativeConfigDisabled.class)
230232
static class PropertiesConfig {
231233
/**
232234
* Is only added so that we have the same converters as with active OpenTelemetry SDK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.spring.autoconfigure.internal;
7+
8+
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
10+
11+
/**
12+
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
13+
* any time.
14+
*/
15+
public class DeclarativeConfigDisabled extends AnyNestedCondition {
16+
public DeclarativeConfigDisabled() {
17+
super(ConfigurationPhase.PARSE_CONFIGURATION);
18+
}
19+
20+
@ConditionalOnProperty(name = "otel.file_format", matchIfMissing = true, havingValue = "never")
21+
static class Disabled {}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.spring.autoconfigure.internal;
7+
8+
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
10+
11+
/**
12+
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
13+
* any time.
14+
*/
15+
public class DeclarativeConfigEnabled extends AnyNestedCondition {
16+
public DeclarativeConfigEnabled() {
17+
super(ConfigurationPhase.PARSE_CONFIGURATION);
18+
}
19+
20+
@ConditionalOnProperty(name = "otel.file_format")
21+
static class Enabled {}
22+
}

0 commit comments

Comments
 (0)