Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4302](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4302))
- `opentelemetry-instrumentation-grpc`: Fix bidirectional streaming RPCs raising `AttributeError: 'generator' object has no attribute 'add_done_callback'`
([#4259](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4259))
- `opentelemetry-instrumentation-aiokafka`: Fix compatibility with aiokafka 0.13 by calling
`_key_serializer`/`_value_serializer` directly instead of the internal `_serialize` method
whose signature changed in 0.13 from `(topic, key, value)` to `(key, value, headers)`
Comment thread
xrmx marked this conversation as resolved.

### Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,17 @@ async def _extract_send_partition(
key = _extract_send_key(args, kwargs)
value = _extract_send_value(args, kwargs)
partition = _extract_argument("partition", 3, None, args, kwargs)
key_bytes, value_bytes = cast(
"tuple[bytes | None, bytes | None]",
instance._serialize(topic, key, value), # type: ignore[reportUnknownMemberType]
key_bytes = cast(
"bytes | None",
instance._key_serializer(key) # type: ignore[reportUnknownMemberType]
if instance._key_serializer # type: ignore[reportUnknownMemberType]
else key,
)
value_bytes = cast(
"bytes | None",
instance._value_serializer(value) # type: ignore[reportUnknownMemberType]
if instance._value_serializer # type: ignore[reportUnknownMemberType]
else value,
)
valid_types = (bytes, bytearray, memoryview, type(None))
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aiokafka==0.11.0
aiokafka==0.13.0; python_version >= "3.10"
aiokafka==0.12.0; python_version < "3.10"
pytest==7.4.4
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-aiokafka
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

from __future__ import annotations

import sys
import uuid
from typing import Any, Sequence, cast
from unittest import IsolatedAsyncioTestCase, TestCase, mock
from unittest import IsolatedAsyncioTestCase, TestCase, mock, skipIf

import aiokafka
from aiokafka import (
Expand Down Expand Up @@ -63,6 +64,10 @@ def test_instrument_api(self) -> None:
)


@skipIf(
sys.version_info < (3, 10),
Comment thread
xrmx marked this conversation as resolved.
"aiokafka >= 0.13 requires Python 3.10+",
)
class TestAIOKafkaInstrumentation(TestBase, IsolatedAsyncioTestCase):
@staticmethod
def consumer_record_factory(
Expand Down Expand Up @@ -126,7 +131,7 @@ async def consumer_factory(**consumer_kwargs: Any) -> AIOKafkaConsumer:

@staticmethod
async def producer_factory() -> AIOKafkaProducer:
producer = AIOKafkaProducer(api_version="1.0")
Comment thread
dorlib marked this conversation as resolved.
producer = AIOKafkaProducer()

producer.client._wait_on_metadata = mock.AsyncMock()
producer.client.bootstrap = mock.AsyncMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ async def test_create_consumer_span(

async def test_kafka_properties_extractor(self):
aiokafka_instance_mock = mock.Mock()
aiokafka_instance_mock._serialize.return_value = None, None
aiokafka_instance_mock._key_serializer = None
aiokafka_instance_mock._value_serializer = None
aiokafka_instance_mock._partition.return_value = "partition"
aiokafka_instance_mock.client._wait_on_metadata = mock.AsyncMock()
assert (
Expand Down
Loading