-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Kafka producer headers to be dict or list #1655
Conversation
Thank you for your contribution. |
instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py
Outdated
Show resolved
Hide resolved
instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py
Show resolved
Hide resolved
Please add a changelog entry |
@shalevr thanks for reviewing!
Since the KafkaContextGetter is being used on |
df89ae0
to
92001b1
Compare
@srikanthccv I saw that you had approved the PR which then ran the workflows, but I had to make a change based on the lint output. I made that change and force pushed. Can you approve running the workflows on this again? |
@srikanthccv @shalevr thanks for rebasing with the latest main commits. Do you think we can now merge this PR? |
It will be merged after it gets approvals, especially from the codeowner for the fixes. |
regarding this: The issue was only with the KafkaContextSetter.set, since it was being called on headers which is passed by the user and could be a dict or list. And KafkaContextGetter.get is only being called on the output of record.headers() which always returns a list of tuples, hence doesn’t need to check for a dict. But for consistency and to allow future use of this method on a dict and list, I’ve updated the get and keys method on KafkaContextGetter as well to handle both, a dict and list |
@srikanthccv okay thanks, who are the codeowners and can they be added to this PR’s reviewers list too? @shalevr since you first reviewed I've added a new commit, can you re-review to see if my changes/comments address your previous review comments? thanks |
No sure why actions didn't assign this author https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/.github/component_owners.yml#L27. |
@oxeye-dorkolog, @dorkolog another ping |
* Allow Kafka producer headers to be dict or list * modify kafka context getter helper methods to work on dict and list --------- Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Description
Fixes #1364
The package confluent-kafka has a class
Producer
, with a methodproduce
, which accepts headers as one of the parameters, and thisheaders
parameter can be a list or a dict. (Ref: https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#confluent_kafka.Producer.produce)However, passing a dictionary of headers to Producer when using opentelemetry-instrumentation-confluent-kafka doesn't work, because the KafkaContextSetter's set method tries to append the headers assuming the carrier is a list.
This PR checks the carrier type, and appends the
(key, value)
tuple in case of a list, or adds thekey:value
to the dict in case the carrier is a dict.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
append
on a dict. With the changes in this PR it appends the header in case of a list, or adds the header to the existing dict as expected.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.