Skip to content

Commit 18d719d

Browse files
committed
split pr
1 parent 3fd7b6f commit 18d719d

File tree

16 files changed

+42
-51
lines changed

16 files changed

+42
-51
lines changed

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ SpanSuppressor buildSpanSuppressor() {
376376
openTelemetry, "common", "experimental", "span_suppression_strategy")
377377
.orElse(null)
378378
: ConfigPropertiesUtil.getString(
379-
"otel.instrumentation.experimental.span-suppression-strategy")
380-
.orElse(null);
379+
"otel.instrumentation.experimental.span-suppression-strategy");
381380
return new SpanSuppressors.ByContextKey(
382381
SpanSuppressionStrategy.fromConfig(value).create(getSpanKeysFromAttributesExtractors()));
383382
}

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ConfigPropertiesUtil.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.api.internal;
77

88
import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;
9+
import static java.util.Collections.emptyList;
910

1011
import io.opentelemetry.api.OpenTelemetry;
1112
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
@@ -97,18 +98,6 @@ public static String getString(String propertyName) {
9798
return System.getenv(toEnvVarName(propertyName));
9899
}
99100

100-
/**
101-
* Returns the string value of the given property name from system properties and environment
102-
* variables.
103-
*
104-
* <p>It's recommended to use {@link #getString(OpenTelemetry, String...)} instead to support
105-
* Declarative Config.
106-
*/
107-
public static String getString(String propertyName, String defaultValue) {
108-
String strValue = getString(propertyName);
109-
return strValue == null ? defaultValue : strValue;
110-
}
111-
112101
/**
113102
* Returns the string value of the given property name from Declarative Config if available,
114103
* otherwise falls back to system properties and environment variables.
@@ -125,12 +114,14 @@ public static Optional<String> getString(OpenTelemetry openTelemetry, String...
125114
* Returns the list of strings value of the given property name from Declarative Config if
126115
* available, otherwise falls back to system properties and environment variables.
127116
*/
128-
public static List<String> getList(String propertyName, List<String> defaultValue) {
129-
String value = getString(propertyName);
130-
if (value == null) {
131-
return defaultValue;
117+
public static List<String> getList(OpenTelemetry openTelemetry, String... propertyName) {
118+
DeclarativeConfigProperties node = getDeclarativeConfigNode(openTelemetry, propertyName);
119+
if (node != null) {
120+
return node.getScalarList(leaf(propertyName), String.class, emptyList());
132121
}
133-
return filterBlanksAndNulls(value.split(","));
122+
return Optional.ofNullable(getString(toSystemProperty(propertyName)))
123+
.map(value -> filterBlanksAndNulls(value.split(",")))
124+
.orElse(emptyList());
134125
}
135126

136127
/** Returns true if the given OpenTelemetry instance supports Declarative Config. */

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ContextPropagationDebug.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,13 @@ public final class ContextPropagationDebug {
3232
private static final boolean FAIL_ON_CONTEXT_LEAK;
3333

3434
static {
35-
boolean agentDebugEnabled =
36-
ConfigPropertiesUtil.getBoolean("otel.javaagent.debug").orElse(false);
35+
boolean agentDebugEnabled = ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false);
3736

3837
THREAD_PROPAGATION_DEBUGGER =
3938
ConfigPropertiesUtil.getBoolean(
40-
"otel.javaagent.experimental.thread-propagation-debugger.enabled")
41-
.orElse(agentDebugEnabled);
39+
"otel.javaagent.experimental.thread-propagation-debugger.enabled", agentDebugEnabled);
4240
FAIL_ON_CONTEXT_LEAK =
43-
ConfigPropertiesUtil.getBoolean("otel.javaagent.testing.fail-on-context-leak")
44-
.orElse(false);
41+
ConfigPropertiesUtil.getBoolean("otel.javaagent.testing.fail-on-context-leak", false);
4542
}
4643

4744
// context to which debug locations were added

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class SemconvStability {
3131
boolean oldCode = true;
3232
boolean stableCode = false;
3333

34-
String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in").orElse(null);
34+
String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in");
3535
if (value != null) {
3636
Set<String> values = new HashSet<>(asList(value.split(",")));
3737

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SupportabilityMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class SupportabilityMetrics {
3030

3131
private static final SupportabilityMetrics INSTANCE =
3232
new SupportabilityMetrics(
33-
ConfigPropertiesUtil.getBoolean("otel.javaagent.debug").orElse(false), logger::fine)
33+
ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false), logger::fine)
3434
.start();
3535

3636
public static SupportabilityMetrics instance() {

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/SpanSuppressionStrategyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ private static Stream<Arguments> configArgs() {
4545
Arguments.of("Span-Kind", SpanSuppressionStrategy.SPAN_KIND),
4646
Arguments.of("semconv", SpanSuppressionStrategy.SEMCONV),
4747
Arguments.of("SemConv", SpanSuppressionStrategy.SEMCONV),
48-
Arguments.of("asdfasdfasdf", SpanSuppressionStrategy.SEMCONV));
48+
Arguments.of("asdfasdfasdf", SpanSuppressionStrategy.SEMCONV),
49+
Arguments.of(null, SpanSuppressionStrategy.SEMCONV));
4950
}
5051

5152
@ParameterizedTest

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/internal/ConfigPropertiesUtilTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class ConfigPropertiesUtilTest {
3232
@SetSystemProperty(key = "test.property.string", value = "sys")
3333
@Test
3434
void getString_systemProperty() {
35-
assertThat(ConfigPropertiesUtil.getString("test.property.string")).hasValue("sys");
35+
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isEqualTo("sys");
3636
}
3737

3838
@SetEnvironmentVariable(key = "TEST_PROPERTY_STRING", value = "env")
3939
@Test
4040
void getString_environmentVariable() {
41-
assertThat(ConfigPropertiesUtil.getString("test.property.string")).hasValue("env");
41+
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isEqualTo("env");
4242
}
4343

4444
@Test
4545
void getString_none() {
46-
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isEmpty();
46+
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isNull();
4747
}
4848

4949
@SetEnvironmentVariable(key = "OTEL_INSTRUMENTATION_TEST_PROPERTY_STRING", value = "env_value")
@@ -92,24 +92,24 @@ void getString_declarativeConfig(Object property, String expected) {
9292
@SetSystemProperty(key = "test.property.int", value = "42")
9393
@Test
9494
void getInt_systemProperty() {
95-
assertThat(ConfigPropertiesUtil.getInt("test.property.int")).hasValue(42);
95+
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(42);
9696
}
9797

9898
@SetEnvironmentVariable(key = "TEST_PROPERTY_INT", value = "12")
9999
@Test
100100
void getInt_environmentVariable() {
101-
assertThat(ConfigPropertiesUtil.getInt("test.property.int")).hasValue(12);
101+
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(12);
102102
}
103103

104104
@Test
105105
void getInt_none() {
106-
assertThat(ConfigPropertiesUtil.getInt("test.property.int")).isEmpty();
106+
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(-1);
107107
}
108108

109109
@SetSystemProperty(key = "test.property.int", value = "not a number")
110110
@Test
111111
void getInt_invalidNumber() {
112-
assertThat(ConfigPropertiesUtil.getInt("test.property.int")).isEmpty();
112+
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(-1);
113113
}
114114

115115
@SetEnvironmentVariable(key = "OTEL_INSTRUMENTATION_TEST_PROPERTY_BOOLEAN", value = "false")
@@ -131,9 +131,7 @@ void getBoolean_none() {
131131
}
132132

133133
private static void assertBoolean(boolean expected) {
134-
assertThat(
135-
ConfigPropertiesUtil.getBoolean("otel.instrumentation.test.property.boolean")
136-
.orElse(false))
134+
assertThat(ConfigPropertiesUtil.getBoolean("otel.instrumentation.test.property.boolean", false))
137135
.isEqualTo(expected);
138136
assertThat(
139137
ConfigPropertiesUtil.getBoolean(OpenTelemetry.noop(), "test", "property", "boolean")

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ public abstract class AbstractAws2ClientCoreTest {
9898

9999
protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder();
100100

101-
protected static boolean isSqsAttributeInjectionEnabled() {
101+
protected boolean isSqsAttributeInjectionEnabled() {
102102
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
103103
return ConfigPropertiesUtil.getBoolean(
104+
getTesting().getOpenTelemetry(),
104105
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging")
105106
.orElse(false);
106107
}

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientRecordHttpErrorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ private static void cleanResponses() {
126126
public boolean isRecordIndividualHttpErrorEnabled() {
127127
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
128128
return ConfigPropertiesUtil.getBoolean(
129+
getTesting().getOpenTelemetry(),
129130
"otel.instrumentation.aws-sdk.experimental-record-individual-http-error")
130131
.orElse(false);
131132
}

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsBaseTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ protected void configureSdkClient(SqsAsyncClientBuilder builder) throws URISynta
132132
protected boolean isSqsAttributeInjectionEnabled() {
133133
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
134134
return ConfigPropertiesUtil.getBoolean(
135+
getTesting().getOpenTelemetry(),
135136
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging")
136137
.orElse(false);
137138
}

0 commit comments

Comments
 (0)