diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3Propagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3Propagator.java index 976670b214b..fb77ce0d2e8 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3Propagator.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3Propagator.java @@ -12,8 +12,6 @@ import io.opentelemetry.context.propagation.TextMapSetter; import java.util.Collection; import java.util.Optional; -import java.util.function.Supplier; -import java.util.stream.Stream; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -113,15 +111,11 @@ public void inject(Context context, @Nullable C carrier, TextMapSetter se @Override public Context extract(Context context, @Nullable C carrier, TextMapGetter getter) { - return Stream.>>of( - () -> singleHeaderExtractor.extract(context, carrier, getter), - () -> multipleHeadersExtractor.extract(context, carrier, getter), - () -> Optional.of(context)) - .map(Supplier::get) - .filter(Optional::isPresent) - .map(Optional::get) - .findFirst() - .get(); + Optional ctx = singleHeaderExtractor.extract(context, carrier, getter); + if (ctx.isPresent()) { + return ctx.get(); + } + return multipleHeadersExtractor.extract(context, carrier, getter).orElse(context); } @Override