Skip to content

Commit fe6a321

Browse files
committed
fix include by default
1 parent fd5eac6 commit fe6a321

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/IncludeExcludePredicate.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static java.util.stream.Collectors.joining;
1010

1111
import java.util.Collection;
12+
import java.util.Collections;
1213
import java.util.LinkedHashSet;
1314
import java.util.Set;
1415
import java.util.StringJoiner;
@@ -29,28 +30,29 @@
2930
public final class IncludeExcludePredicate implements Predicate<String> {
3031

3132
private final boolean globMatchingEnabled;
32-
@Nullable private final Set<String> included;
33-
@Nullable private final Set<String> excluded;
33+
private final Set<String> included;
34+
private final Set<String> excluded;
3435
private final Predicate<String> predicate;
3536

3637
private IncludeExcludePredicate(
3738
@Nullable Collection<String> included,
3839
@Nullable Collection<String> excluded,
3940
boolean globMatchingEnabled) {
4041
this.globMatchingEnabled = globMatchingEnabled;
41-
this.included = included == null ? null : new LinkedHashSet<>(included);
42-
this.excluded = excluded == null ? null : new LinkedHashSet<>(excluded);
43-
if (this.included != null && this.excluded != null) {
44-
this.predicate =
45-
includedPredicate(this.included, globMatchingEnabled)
46-
.and(excludedPredicate(this.excluded, globMatchingEnabled));
47-
} else if (this.included == null && this.excluded != null) {
42+
this.included = included == null ? Collections.emptySet() : new LinkedHashSet<>(included);
43+
this.excluded = excluded == null ? Collections.emptySet() : new LinkedHashSet<>(excluded);
44+
if (this.included.isEmpty() && this.excluded.isEmpty()) {
45+
throw new IllegalArgumentException(
46+
"At least one of include or exclude patterns must not be null or empty");
47+
}
48+
if (this.included.isEmpty()) {
4849
this.predicate = excludedPredicate(this.excluded, globMatchingEnabled);
49-
} else if (this.excluded == null && this.included != null) {
50+
} else if (this.excluded.isEmpty()) {
5051
this.predicate = includedPredicate(this.included, globMatchingEnabled);
5152
} else {
52-
throw new IllegalArgumentException(
53-
"At least one of includedPatterns or excludedPatterns must not be null");
53+
this.predicate =
54+
includedPredicate(this.included, globMatchingEnabled)
55+
.and(excludedPredicate(this.excluded, globMatchingEnabled));
5456
}
5557
}
5658

@@ -85,10 +87,10 @@ public boolean test(String s) {
8587
public String toString() {
8688
StringJoiner joiner = new StringJoiner(", ", "IncludeExcludePredicate{", "}");
8789
joiner.add("globMatchingEnabled=" + globMatchingEnabled);
88-
if (included != null) {
90+
if (!included.isEmpty()) {
8991
joiner.add("included=" + included.stream().collect(joining(", ", "[", "]")));
9092
}
91-
if (excluded != null) {
93+
if (!excluded.isEmpty()) {
9294
joiner.add("excluded=" + excluded.stream().collect(joining(", ", "[", "]")));
9395
}
9496
return joiner.toString();

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

Lines changed: 2 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;
@@ -20,7 +21,7 @@ class IncludeExcludePredicateTest {
2021
private static final Predicate<String> EXACT_INCLUDE =
2122
IncludeExcludePredicate.createExactMatching(singletonList("foo"), null);
2223
private static final Predicate<String> EXACT_EXCLUDE =
23-
IncludeExcludePredicate.createExactMatching(null, singletonList("bar"));
24+
IncludeExcludePredicate.createExactMatching(Collections.emptyList(), singletonList("bar"));
2425
private static final Predicate<String> EXACT_INCLUDE_AND_EXCLUDE =
2526
IncludeExcludePredicate.createExactMatching(singletonList("foo"), singletonList("bar"));
2627
private static final Predicate<String> EXACT_MULTI =

0 commit comments

Comments
 (0)