diff --git a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java index 9701214e506..150be6e4fdd 100644 --- a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java +++ b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java @@ -127,7 +127,7 @@ private static boolean baggageIsInvalid(String key, BaggageEntry baggageEntry) { * @return whether the name is valid. */ private static boolean isValidBaggageKey(String name) { - return name != null && !name.isEmpty() && StringUtils.isPrintableString(name); + return name != null && !name.trim().isEmpty() && StringUtils.isPrintableString(name); } /** diff --git a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java index 3fbf7bf5297..e775ed04f1e 100644 --- a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java @@ -448,6 +448,7 @@ void inject() { .put("\2ab\3cd", "wacky key nonprintable") .put(null, "null key") .put("nullvalue", null) + .put(" ", "key is only space") .build(); W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance(); Map carrier = new HashMap<>();