Skip to content

Commit 136eac6

Browse files
committed
updated the get arguments as per the spec
1 parent 7c3a32c commit 136eac6

File tree

2 files changed

+25
-12
lines changed
  • instrumentation
    • opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi
    • opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi

2 files changed

+25
-12
lines changed

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@
3333
from opentelemetry.trace.status import Status, StatusCanonicalCode
3434

3535

36-
# pylint:disable=arguments-differ
3736
class CarrierGetter(DictGetter):
38-
def get(self, scope: dict, header_name: str) -> typing.List[str]:
39-
headers = scope.get("headers")
37+
def get(self, carrier: dict, key: str) -> typing.List[str]:
38+
"""Getter implementation to retrieve a HTTP header value from the ASGI
39+
scope.
40+
41+
Args:
42+
carrier: ASGI scope object
43+
key: header name in scope
44+
Returns:
45+
A list with a single string with the header value if it exists,
46+
else an empty list.
47+
"""
48+
headers = carrier.get("headers")
4049
return [
41-
value.decode("utf8")
42-
for (key, value) in headers
43-
if key.decode("utf8") == header_name
50+
_value.decode("utf8")
51+
for (_key, _value) in headers
52+
if _key.decode("utf8") == key
4453
]
4554

4655

instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ def hello():
6767
_HTTP_VERSION_PREFIX = "HTTP/"
6868

6969

70-
# pylint:disable=arguments-differ
7170
class CarrierGetter(DictGetter):
72-
def get(self, environ: dict, header_name: str) -> typing.List[str]:
73-
"""Retrieve a HTTP header value from the PEP3333-conforming WSGI environ.
71+
def get(self, carrier: dict, key: str) -> typing.List[str]:
72+
"""Getter implementation to retrieve a HTTP header value from the
73+
PEP3333-conforming WSGI environ
7474
75+
Args:
76+
carrier: WSGI environ object
77+
key: header name in environ object
7578
Returns:
76-
A list with a single string with the header value if it exists, else an empty list.
79+
A list with a single string with the header value if it exists,
80+
else an empty list.
7781
"""
78-
environ_key = "HTTP_" + header_name.upper().replace("-", "_")
79-
value = environ.get(environ_key)
82+
environ_key = "HTTP_" + key.upper().replace("-", "_")
83+
value = carrier.get(environ_key)
8084
if value is not None:
8185
return [value]
8286
return []

0 commit comments

Comments
 (0)