Skip to content

Commit cbadf0e

Browse files
committed
Revert partial parsing
1 parent 38486fe commit cbadf0e

2 files changed

Lines changed: 5 additions & 31 deletions

File tree

api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,19 @@ private static <C> Context extractMulti(
155155
continue;
156156
}
157157

158-
int remainingBytes = MAX_BAGGAGE_BYTES - totalBytes;
159158
totalBytes += header.length();
160-
161-
if (totalEntries >= MAX_BAGGAGE_ENTRIES) {
159+
if (totalBytes > MAX_BAGGAGE_BYTES || totalEntries >= MAX_BAGGAGE_ENTRIES) {
162160
LOGGER.fine("Baggage header exceeded W3C limits, dropping remaining entries");
163161
break;
164162
}
165163

166-
String headerToParse =
167-
totalBytes > MAX_BAGGAGE_BYTES ? header.substring(0, remainingBytes) : header;
168-
169164
try {
170-
int added =
171-
extractEntries(headerToParse, baggageBuilder, MAX_BAGGAGE_ENTRIES - totalEntries);
165+
int added = extractEntries(header, baggageBuilder, MAX_BAGGAGE_ENTRIES - totalEntries);
172166
extracted = true;
173167
totalEntries += added;
174168
} catch (RuntimeException expected) {
175169
// invalid baggage header, continue
176170
}
177-
178-
if (totalBytes > MAX_BAGGAGE_BYTES) {
179-
LOGGER.fine("Baggage header exceeded W3C limits, dropping remaining entries");
180-
break;
181-
}
182171
}
183172

184173
return extracted ? context.with(baggageBuilder.build()) : context;

api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -649,25 +649,10 @@ private static String baggageHeader(int start, int count) {
649649
@Test
650650
void extract_limit_maxBytes_exceedsLimit() {
651651
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
652-
// Single header over 8192 bytes — truncated to the byte limit; the entry within budget is
653-
// extracted with a truncated value
654-
String header = "k=" + fillChars('v', 8192); // 8194 bytes; truncated to 8192 → k=<8190 v's>
652+
// Single header over 8192 bytes — dropped entirely; partial values must not be extracted
653+
String header = "k=" + fillChars('v', 8192); // 8194 bytes
655654
Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", header), getter);
656-
assertThat(Baggage.fromContext(result).getEntryValue("k")).isEqualTo(fillChars('v', 8190));
657-
}
658-
659-
@Test
660-
void extract_limit_maxBytes_partialHeader() {
661-
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
662-
// A header where the first entry is complete within the byte budget but the second entry's
663-
// key is cut off by the truncation — only the first entry is extracted.
664-
// "k1=" (3) + 8186 'v's + "," (1) + "k2=v2" (5) = 8195 bytes;
665-
// truncated to 8192 → "k1=<8186 v's>,k2" (k2's "=" is beyond the budget)
666-
String header = "k1=" + fillChars('v', 8186) + ",k2=v2";
667-
Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", header), getter);
668-
Baggage baggage = Baggage.fromContext(result);
669-
assertThat(baggage.getEntryValue("k1")).isEqualTo(fillChars('v', 8186));
670-
assertThat(baggage.getEntryValue("k2")).isNull();
655+
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
671656
}
672657

673658
@Test

0 commit comments

Comments
 (0)