Skip to content

Commit f16f059

Browse files
hasierjames-emerton
authored andcommittedJan 19, 2023
Fix ASGIGetter keys to fetch from actual carrier headers (open-telemetry#1435)
1 parent bc26d97 commit f16f059

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
 

Diff for: ‎instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def get(
260260
return decoded
261261

262262
def keys(self, carrier: dict) -> typing.List[str]:
263-
return [_key.decode("utf8") for (_key, _value) in carrier]
263+
headers = carrier.get("headers") or []
264+
return [_key.decode("utf8") for (_key, _value) in headers]
264265

265266

266267
asgi_getter = ASGIGetter()

Diff for: ‎instrumentation/opentelemetry-instrumentation-asgi/tests/test_getter.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818

1919

2020
class TestASGIGetter(TestCase):
21-
def test_get_none(self):
21+
def test_get_none_empty_carrier(self):
2222
getter = ASGIGetter()
2323
carrier = {}
2424
val = getter.get(carrier, "test")
2525
self.assertIsNone(val)
2626

27+
def test_get_none_empty_headers(self):
28+
getter = ASGIGetter()
29+
carrier = {"headers": []}
30+
val = getter.get(carrier, "test")
31+
self.assertIsNone(val)
32+
2733
def test_get_(self):
2834
getter = ASGIGetter()
2935
carrier = {"headers": [(b"test-key", b"val")]}
@@ -44,7 +50,22 @@ def test_get_(self):
4450
"Should be case insensitive",
4551
)
4652

47-
def test_keys(self):
53+
def test_keys_empty_carrier(self):
4854
getter = ASGIGetter()
4955
keys = getter.keys({})
5056
self.assertEqual(keys, [])
57+
58+
def test_keys_empty_headers(self):
59+
getter = ASGIGetter()
60+
keys = getter.keys({"headers": []})
61+
self.assertEqual(keys, [])
62+
63+
def test_keys(self):
64+
getter = ASGIGetter()
65+
carrier = {"headers": [(b"test-key", b"val")]}
66+
expected_val = ["test-key"]
67+
self.assertEqual(
68+
getter.keys(carrier),
69+
expected_val,
70+
"Should be equal",
71+
)

0 commit comments

Comments
 (0)
Please sign in to comment.