Skip to content

Commit 2f9acf3

Browse files
committed
string
1 parent d6fa683 commit 2f9acf3

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
4949

5050
private static final Logger logger = Logger.getLogger(InstrumenterBuilder.class.getName());
5151

52-
private static final SpanSuppressionStrategy spanSuppressionStrategy =
53-
SpanSuppressionStrategy.fromConfig(
54-
ConfigPropertiesUtil.getString(
55-
"otel.instrumentation.experimental.span-suppression-strategy"));
56-
5752
final OpenTelemetry openTelemetry;
5853
final String instrumentationName;
5954
SpanNameExtractor<? super REQUEST> spanNameExtractor;
@@ -374,7 +369,10 @@ private String getSchemaUrl() {
374369

375370
SpanSuppressor buildSpanSuppressor() {
376371
return new SpanSuppressors.ByContextKey(
377-
spanSuppressionStrategy.create(getSpanKeysFromAttributesExtractors()));
372+
SpanSuppressionStrategy.fromConfig(
373+
ConfigPropertiesUtil.getNullableString(
374+
openTelemetry, "experimental", "span_suppression_strategy"))
375+
.create(getSpanKeysFromAttributesExtractors()));
378376
}
379377

380378
private Set<SpanKey> getSpanKeysFromAttributesExtractors() {

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

Lines changed: 22 additions & 10 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.Objects.requireNonNull;
910

1011
import io.opentelemetry.api.OpenTelemetry;
1112
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
@@ -87,18 +88,29 @@ public static String getString(String propertyName) {
8788
return System.getenv(toEnvVarName(propertyName));
8889
}
8990

90-
private static String getString(String propertyName, String defaultValue) {
91-
String strValue = getString(propertyName);
92-
return strValue == null ? defaultValue : strValue;
93-
}
94-
9591
public static String getString(
9692
OpenTelemetry openTelemetry, String defaultValue, String... propertyName) {
97-
return getDeclarativeConfigOrFallback(
98-
openTelemetry,
99-
propertyName,
100-
(node, key) -> node.getString(key, defaultValue),
101-
(key) -> getString(key, defaultValue));
93+
return requireNonNull(getStringImpl(openTelemetry, defaultValue, propertyName));
94+
}
95+
96+
@Nullable
97+
public static String getStringImpl(
98+
OpenTelemetry openTelemetry, @Nullable String defaultValue, String... propertyName) {
99+
String result =
100+
getDeclarativeConfigOrFallback(
101+
openTelemetry,
102+
propertyName,
103+
(node, key) -> node.getString(key),
104+
(key) -> getString(key));
105+
if (result == null) {
106+
return defaultValue;
107+
}
108+
return result;
109+
}
110+
111+
@Nullable
112+
public static String getNullableString(OpenTelemetry openTelemetry, String... propertyName) {
113+
return getStringImpl(openTelemetry, null, propertyName);
102114
}
103115

104116
private static List<String> getList(String propertyName, List<String> defaultValue) {

0 commit comments

Comments
 (0)