open-telemetry / open-telemetry/opentelemetry-python-contrib

`aio` interceptor fails because `grpc.aio.Metadata` doesn't correctly implement `abc.Mapping`

Open
#2,373 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.