Skip to content

Commit a90265f

Browse files
committed
fix(aiokafka): call serializers directly instead of _serialize
1 parent cf17596 commit a90265f

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-aiokafka

instrumentation/opentelemetry-instrumentation-aiokafka/src/opentelemetry/instrumentation/aiokafka/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,17 @@ async def _extract_send_partition(
162162
key = _extract_send_key(args, kwargs)
163163
value = _extract_send_value(args, kwargs)
164164
partition = _extract_argument("partition", 3, None, args, kwargs)
165-
key_bytes, value_bytes = cast(
166-
"tuple[bytes | None, bytes | None]",
167-
instance._serialize(topic, key, value), # type: ignore[reportUnknownMemberType]
165+
key_bytes = cast(
166+
"bytes | None",
167+
instance._key_serializer(key) # type: ignore[reportUnknownMemberType]
168+
if instance._key_serializer # type: ignore[reportUnknownMemberType]
169+
else key,
170+
)
171+
value_bytes = cast(
172+
"bytes | None",
173+
instance._value_serializer(value) # type: ignore[reportUnknownMemberType]
174+
if instance._value_serializer # type: ignore[reportUnknownMemberType]
175+
else value,
168176
)
169177
valid_types = (bytes, bytearray, memoryview, type(None))
170178
if (

instrumentation/opentelemetry-instrumentation-aiokafka/tests/test_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ async def test_create_consumer_span(
370370

371371
async def test_kafka_properties_extractor(self):
372372
aiokafka_instance_mock = mock.Mock()
373-
aiokafka_instance_mock._serialize.return_value = None, None
373+
aiokafka_instance_mock._key_serializer = None
374+
aiokafka_instance_mock._value_serializer = None
374375
aiokafka_instance_mock._partition.return_value = "partition"
375376
aiokafka_instance_mock.client._wait_on_metadata = mock.AsyncMock()
376377
assert (

0 commit comments

Comments
 (0)