Fix/aiokafka 0.13 compatibility#4379
Merged
xrmx merged 8 commits intoopen-telemetry:mainfrom Apr 3, 2026
Merged
Conversation
yonathan-wolloch-lendbuzz
approved these changes
Mar 31, 2026
Contributor
|
Thank you for this fix! I'm a bit concerned that regular testing didn't catch this, I guess because they run on aiokafka==0.11.0. A bit brittle, but what do others (@open-telemetry/opentelemetry-python-contrib-approvers) think of adjusting the test coverage like the sqlalchemy instrumentor does? The tox.ini points to multiple test-requirements files, e.g. -1 and 2. |
xrmx
reviewed
Apr 1, 2026
6596afd to
7f87154
Compare
8cc9693 to
7f87154
Compare
9faa9e0 to
65276c3
Compare
xrmx
approved these changes
Apr 2, 2026
xrmx
reviewed
Apr 2, 2026
tammy-baylis-swi
approved these changes
Apr 2, 2026
Contributor
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Lgtm too! Thank you
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_extract_send_partition()in the aiokafka instrumentation callsinstance._serialize(topic, key, value)to serialize the key and value before partition assignment. In aiokafka 0.13, the internal_serializemethod changed its signature from(self, topic, key, value)to(self, key, value, headers), causing the arguments to shift:topic(a string) is passed wherekeyis expectedkey(oftenNone) is passed wherevalueis expectedvalue(the actual payload) is passed whereheadersis expectedThis causes custom serializers to receive wrong arguments. For example, a value serializer expecting a Pydantic model receives
Noneinstead, producing:The fix replaces the
_serialize()call with direct calls to_key_serializerand_value_serializer, which are stable across aiokafka versions:api_version parameter has been removed from producer client in aiokafka 0.13
link
Fixes #4378
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
test_kafka_properties_extractornow mocks_key_serializer/_value_serializerinstead of the removed_serializecall)test_extract_send_partition_with_custom_serializers) that verifies the value serializer receives the actual value and the key serializer receives the actual key. this test fails on main and passes with the fixtox -e py3-test-instrumentation-aiokafkaDoes This PR Require a Core Repo Change?
Checklist: