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 e39f80b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.5.0-0.24b0...HEAD)

- Fix propagation bug caused by counting skipped entries
([#2071](https://github.com/open-telemetry/opentelemetry-python/pull/2071))

## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26


Expand Down
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 e39f80b

Please sign in to comment.