Repository: open-telemetry/opentelemetry-python-contrib

Issue:
WSGI Carrier Getter always returns an empty list as keys
**Describe your environment**
Not relevant.

**Steps to reproduce**
1. Call the method: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/f8e51c488da1f5ab628ba4f5bf25e65638974c44/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py#L91

**What is the expected behavior?**
I would expect all the keys from the provided carrier returned.

**What is the actual behavior?**
No matter of the carrier contents an empty list is returned.

**Additional context**
Due to this behavior other extensions from this repository might not work as expected.
For example [OT Trace Propagator](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/f8e51c488da1f5ab628ba4f5bf25e65638974c44/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py#L92) cannot extract baggage information from the carrier, because empty list is always returned.



Discussion:

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py
--- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py
+++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py
@@ -66,6 +66,8 @@ def hello():
 from opentelemetry.trace.status import Status, StatusCode
 
 _HTTP_VERSION_PREFIX = "HTTP/"
+_CARRIER_KEY_PREFIX = "HTTP_"
+_CARRIER_KEY_PREFIX_LEN = len(_CARRIER_KEY_PREFIX)
 
 
 class CarrierGetter(DictGetter):
@@ -89,7 +91,11 @@ def get(
         return None
 
     def keys(self, carrier):
-        return []
+        return [
+            key[_CARRIER_KEY_PREFIX_LEN:].lower().replace("_", "-")
+            for key in carrier
+            if key.startswith(_CARRIER_KEY_PREFIX)
+        ]
 
 
 carrier_getter = CarrierGetter()


Test patch:
diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_getter.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_getter.py
--- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_getter.py
+++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_getter.py
@@ -22,15 +22,30 @@ def test_get_none(self):
         getter = CarrierGetter()
         carrier = {}
         val = getter.get(carrier, "test")
+
         self.assertIsNone(val)
 
-    def test_get_(self):
+    def test_get(self):
         getter = CarrierGetter()
         carrier = {"HTTP_TEST_KEY": "val"}
         val = getter.get(carrier, "test-key")
+
         self.assertEqual(val, ["val"])
 
     def test_keys(self):
+        getter = CarrierGetter()
+        keys = getter.keys(
+            {
+                "HTTP_TEST_KEY": "val",
+                "HTTP_OTHER_KEY": 42,
+                "NON_HTTP_KEY": "val",
+            }
+        )
+
+        self.assertEqual(keys, ["test-key", "other-key"])
+
+    def test_keys_empty(self):
         getter = CarrierGetter()
         keys = getter.keys({})
+
         self.assertEqual(keys, [])