open-telemetry / open-telemetry/opentelemetry-python-contrib
`aio` interceptor fails because `grpc.aio.Metadata` doesn't correctly implement `abc.Mapping`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
This is related to a known grpc bug: https://github.com/grpc/grpc/issues/26498
...however, I'm opening it here because that has been opened for several years, and this package could work around the issue.
Environment
I believe this applies to any environment using the current latest Python grpc and opentelemetry-instrumentation-grpc packages.
Steps to reproduce
Perform a gRPC call using aio, with non-empty metadata and a configured interceptor (e.g. using autoinstrumentation).
To see a simple demonstration that the code in propagate_trace_in_details doesn't work, just build an example Metadata object in a Python terminal and attempt to construct an OrderedDict from it:
>>> from collections import OrderedDict
>>> from grpc.aio import Metadata
>>> m = grpc.aio.Metadata({"foo", "bar"})
>>> OrderedDict(m)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<path>/.venv/lib/python3.9/site-packages/grpc/aio/_metadata.py", line 64, in __getitem__
return self._metadata[key][0]
KeyError: ('bar', 'foo')
What is the expected behavior?
The call should succeed, and a corresponding trace span should be created.
What is the actual behavior?
There is a key error indicating that lookup of a metadata (key, value) pair failed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the propagate_trace_in_details entry point and reproduce the failure with grpc.aio.Metadata containing non-empty metadata, then construct an OrderedDict from it to observe the KeyError. The work is done when an intercepted aio gRPC call succeeds and creates the corresponding trace span.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- grpc, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100