Skip to content

Commit 923098b

Browse files
authored
declarative config filtering resource attributes should include by default. (#8177)
1 parent c383dc5 commit 923098b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ private static Predicate<String> detectorAttributeFilter(
9393
if (included == null && excluded == null) {
9494
return ResourceFactory::matchAll;
9595
}
96+
// when "included" is omitted in configuration, we get an empty list
97+
// in this context it should be interpreted as "include everything"
98+
if (included != null && included.isEmpty()) {
99+
included = null;
100+
}
96101
return IncludeExcludePredicate.createPatternMatching(included, excluded);
97102
}
98103
}

sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceFactoryTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,16 @@ private static Stream<Arguments> createWithDetectorsArgs() {
141141
Arguments.of(
142142
Collections.singletonList("*o*"),
143143
Collections.singletonList("order"),
144-
Resource.getDefault().toBuilder().put("color", "red").build()));
144+
Resource.getDefault().toBuilder().put("color", "red").build()),
145+
// empty or missing include should be treated as include all
146+
Arguments.of(
147+
Collections.emptyList(),
148+
Collections.singletonList("order"),
149+
Resource.getDefault().toBuilder().put("color", "red").put("shape", "square").build()),
150+
Arguments.of(
151+
null,
152+
Collections.singletonList("order"),
153+
Resource.getDefault().toBuilder().put("color", "red").put("shape", "square").build()));
145154
}
146155

147156
@ParameterizedTest

sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/IncludeExcludePredicateTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static java.util.Collections.singletonList;
1010
import static org.assertj.core.api.Assertions.assertThat;
1111

12+
import java.util.Collections;
1213
import java.util.function.Predicate;
1314
import java.util.stream.Stream;
1415
import org.junit.jupiter.params.ParameterizedTest;
@@ -25,6 +26,8 @@ class IncludeExcludePredicateTest {
2526
IncludeExcludePredicate.createExactMatching(singletonList("foo"), singletonList("bar"));
2627
private static final Predicate<String> EXACT_MULTI =
2728
IncludeExcludePredicate.createExactMatching(asList("foo", "fooo"), asList("bar", "barr"));
29+
public static final Predicate<String> EXACT_INCLUDE_NONE =
30+
IncludeExcludePredicate.createExactMatching(Collections.emptyList(), null);
2831

2932
private static final Predicate<String> PATTERN_INCLUDE =
3033
IncludeExcludePredicate.createPatternMatching(singletonList("f?o"), null);
@@ -34,6 +37,8 @@ class IncludeExcludePredicateTest {
3437
IncludeExcludePredicate.createPatternMatching(singletonList("f?o"), singletonList("b?r"));
3538
private static final Predicate<String> PATTERN_MULTI =
3639
IncludeExcludePredicate.createPatternMatching(asList("f?o", "f?oo"), asList("b?r", "b?rr"));
40+
public static final Predicate<String> PATTERN_INCLUDE_NONE =
41+
IncludeExcludePredicate.createPatternMatching(Collections.emptyList(), null);
3742

3843
@ParameterizedTest
3944
@MethodSource("testArgs")
@@ -70,6 +75,8 @@ private static Stream<Arguments> testArgs() {
7075
Arguments.of(EXACT_MULTI, "bar", false),
7176
Arguments.of(EXACT_MULTI, "barr", false),
7277
Arguments.of(EXACT_MULTI, "baz", false),
78+
// include none
79+
Arguments.of(EXACT_INCLUDE_NONE, "foo", false),
7380
// pattern matching
7481
// include only
7582
Arguments.of(PATTERN_INCLUDE, "foo", true),
@@ -99,7 +106,9 @@ private static Stream<Arguments> testArgs() {
99106
Arguments.of(PATTERN_MULTI, "bAr", false),
100107
Arguments.of(PATTERN_MULTI, "barr", false),
101108
Arguments.of(PATTERN_MULTI, "bArr", false),
102-
Arguments.of(PATTERN_MULTI, "baz", false));
109+
Arguments.of(PATTERN_MULTI, "baz", false),
110+
// include none
111+
Arguments.of(PATTERN_INCLUDE_NONE, "foo", false));
103112
}
104113

105114
@ParameterizedTest

0 commit comments

Comments
 (0)