Skip to content

OtTracePropagator extracts an empty baggage key from an ot-baggage- header #8629

Description

@thswlsqls

Describe the bug
OtTracePropagator.extract() creates a baggage entry with an empty string key when the carrier contains a header named exactly ot-baggage- (the prefix with no key after it).

Steps to reproduce
Extract from a carrier holding a valid OT span context plus a header keyed ot-baggage-:

Map<String, String> carrier = new LinkedHashMap<>();
carrier.put("ot-tracer-traceid", "ff000000000000000000000000000041");
carrier.put("ot-tracer-spanid", "ff00000000000041");
carrier.put("ot-tracer-sampled", "1");
carrier.put("ot-baggage-", "value");

Baggage baggage =
    Baggage.fromContext(
        OtTracePropagator.getInstance().extract(Context.current(), carrier, getter));
// baggage is {=ImmutableEntry{value=value, ...}} — expected Baggage.empty()

What did you expect to see?
Baggage.empty(). The sibling JaegerPropagator.getBaggageFromHeader() skips a header that is only the uberctx- prefix, and JaegerPropagatorTest.extract_baggageOnly_withPrefix_emptyKey asserts that contract. W3CBaggagePropagator.isValidBaggageKey() also treats an empty key as invalid.

What did you see instead?
A baggage entry keyed "". OtTracePropagator.extract() line 149 only checks startsWith, so substring at line 156 yields "" and line 161 puts it. The ImmutableKeyValuePairs Javadoc makes removing empty keys the caller's responsibility. A later inject() re-emits the entry, so it keeps propagating and consumes the 64-entry budget.

What version and what artifacts are you using?
Artifacts: opentelemetry-extension-trace-propagators
Version: main @ b86f040
How did you reference these artifacts? implementation("io.opentelemetry:opentelemetry-extension-trace-propagators")

Environment
Compiler: Temurin 21
OS: N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions