Skip to content

Commit

Permalink
Do not count skipped baggage entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Aug 30, 2021
1 parent c3dfa36 commit 75b44f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ def extract(
baggage_entries = header.split(",")
total_baggage_entries = self._MAX_PAIRS
for entry in baggage_entries:
if total_baggage_entries <= 0:
return context
total_baggage_entries -= 1
if len(entry) > self._MAX_PAIR_LENGTH:
continue
try:
Expand All @@ -68,6 +65,9 @@ def extract(
urllib.parse.unquote(value).strip(),
context=context,
)
total_baggage_entries -= 1
if total_baggage_entries == 0:
break

return context

Expand Down
23 changes: 23 additions & 0 deletions opentelemetry-api/tests/baggage/test_baggage_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ def test_header_contains_pair_too_long(self):
expected = {"key1": "value1", "key3": "value3"}
self.assertEqual(self._extract(header), expected)

def test_header_max_entries_skip_invalid_entry(self):

self.assertEqual(
self._extract(
",".join(
[
f"key{index}=value{index}"
if index != 2
else (
f"key{index}="
f"value{'s' * (W3CBaggagePropagator._MAX_PAIR_LENGTH + 1)}"
)
for index in range(W3CBaggagePropagator._MAX_PAIRS + 1)
]
)
),
{
f"key{index}": f"value{index}"
for index in range(W3CBaggagePropagator._MAX_PAIRS + 1)
if index != 2
},
)

def test_inject_no_baggage_entries(self):
values = {}
output = self._inject(values)
Expand Down

0 comments on commit 75b44f7

Please sign in to comment.