diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SpanFilterBuilder.java b/splunk-otel-android/src/main/java/com/splunk/rum/SpanFilterBuilder.java index 5c08c1ed..d4682f19 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SpanFilterBuilder.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SpanFilterBuilder.java @@ -19,19 +19,21 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.rum.internal.export.SpanDataModifier; import io.opentelemetry.sdk.trace.export.SpanExporter; -import java.util.HashMap; -import java.util.Map; import java.util.function.Function; import java.util.function.Predicate; /** Delegating wrapper around otel SpanDataModifier. */ public final class SpanFilterBuilder { - // TODO: Use pure upstream mechanism for this - private Predicate rejectSpanNamesPredicate = spanName -> false; - private final Map, Predicate> rejectSpanAttributesPredicates = - new HashMap<>(); - private final Map, Function> spanAttributeReplacements = new HashMap<>(); + private final SpanDataModifier spanDataModifier; + + public SpanFilterBuilder(SpanExporter exporter) { + this(SpanDataModifier.builder(exporter)); + } + + public SpanFilterBuilder(SpanDataModifier spanDataModifier) { + this.spanDataModifier = spanDataModifier; + } /** * Remove matching spans from the exporter pipeline. @@ -43,7 +45,8 @@ public final class SpanFilterBuilder { * @return {@code this}. */ public SpanFilterBuilder rejectSpansByName(Predicate spanNamePredicate) { - this.rejectSpanNamesPredicate = rejectSpanNamesPredicate.or(spanNamePredicate); + // TODO: Use pure upstream mechanism for this + spanDataModifier.rejectSpansByName(spanNamePredicate); return this; } @@ -60,12 +63,7 @@ public SpanFilterBuilder rejectSpansByName(Predicate spanNamePredicate) */ public SpanFilterBuilder rejectSpansByAttributeValue( AttributeKey attributeKey, Predicate attributeValuePredicate) { - rejectSpanAttributesPredicates.compute( - attributeKey, - (k, oldValue) -> - oldValue == null - ? attributeValuePredicate - : ((Predicate) oldValue).or(attributeValuePredicate)); + spanDataModifier.rejectSpansByAttributeValue(attributeKey, attributeValuePredicate); return this; } @@ -115,31 +113,11 @@ public SpanFilterBuilder removeSpanAttribute( */ public SpanFilterBuilder replaceSpanAttribute( AttributeKey attributeKey, Function attributeValueModifier) { - spanAttributeReplacements.compute( - attributeKey, - (k, oldValue) -> - oldValue == null - ? attributeValueModifier - : ((Function) oldValue).andThen(attributeValueModifier)); + spanDataModifier.replaceSpanAttribute(attributeKey, attributeValueModifier); return this; } - SpanExporter build(SpanExporter exporter) { - SpanDataModifier builder = - SpanDataModifier.builder(exporter).rejectSpansByName(rejectSpanNamesPredicate); - spanAttributeReplacements.forEach( - (attributeKey, function) -> { - AttributeKey key = (AttributeKey) attributeKey; - Function fn = - (Function) function; - builder.replaceSpanAttribute(key, fn); - }); - rejectSpanAttributesPredicates.forEach( - ((attributeKey, predicate) -> { - AttributeKey kk = (AttributeKey) attributeKey; - Predicate vv = (Predicate) predicate; - builder.rejectSpansByAttributeValue(kk, vv); - })); - return builder.build(); + SpanExporter build() { + return spanDataModifier.build(); } } diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java index 1b826a1e..532e3e57 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java @@ -43,7 +43,7 @@ public final class SplunkRumBuilder { Duration slowRenderingDetectionPollInterval = DEFAULT_SLOW_RENDERING_DETECTION_POLL_INTERVAL; Attributes globalAttributes = Attributes.empty(); @Nullable String deploymentEnvironment; - private final SpanFilterBuilder spanFilterBuilder = new SpanFilterBuilder(); + private Consumer spanFilterConfigurer = x -> {}; int maxUsageMegabytes = DEFAULT_MAX_STORAGE_USE_MB; boolean sessionBasedSamplerEnabled = false; double sessionBasedSamplerRatio = 1.0; @@ -242,7 +242,7 @@ public SplunkRumBuilder setDeploymentEnvironment(String environment) { * @return {@code this} */ public SplunkRumBuilder filterSpans(Consumer configurer) { - configurer.accept(spanFilterBuilder); + this.spanFilterConfigurer = configurer; return this; } @@ -320,7 +320,9 @@ ConfigFlags getConfigFlags() { } SpanExporter decorateWithSpanFilter(SpanExporter exporter) { - return spanFilterBuilder.build(exporter); + SpanFilterBuilder spanFilterBuilder = new SpanFilterBuilder(exporter); + this.spanFilterConfigurer.accept(spanFilterBuilder); + return spanFilterBuilder.build(); } boolean isDebugEnabled() {