Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3882](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3882))
- `opentelemetry-instrumentation-aiohttp-server`: delay initialization of tracer, meter and excluded urls to instrumentation for testability
([#3836](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3836))
- Replace Python 3.14-deprecated `asyncio.iscoroutinefunction` with `inspect.iscoroutinefunction`.
([#3880](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3880))

## Version 1.38.0/0.59b0 (2025-10-16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def produce():

from __future__ import annotations

from asyncio import iscoroutinefunction
from inspect import iscoroutinefunction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks something, could you please take a look at the failing tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I’ll fix!

from typing import TYPE_CHECKING, Collection

import aiokafka
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,21 @@ async def async_consume_hook(span, *_) -> None:
async def test_getone_consume_hook(self) -> None:
async_consume_hook_mock = mock.AsyncMock()

def is_async_consume_hook_mock(obj: Any) -> bool:
return obj is async_consume_hook_mock

AIOKafkaInstrumentor().uninstrument()
AIOKafkaInstrumentor().instrument(
tracer_provider=self.tracer_provider,
async_consume_hook=async_consume_hook_mock,
)

# mock.patch is a hack for Python 3.9 see https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3880
with mock.patch(
"opentelemetry.instrumentation.aiokafka.iscoroutinefunction"
) as iscoro:
iscoro.side_effect = is_async_consume_hook_mock

AIOKafkaInstrumentor().instrument(
tracer_provider=self.tracer_provider,
async_consume_hook=async_consume_hook_mock,
)

consumer = await self.consumer_factory()
self.addAsyncCleanup(consumer.stop)
Expand Down Expand Up @@ -448,11 +458,20 @@ async def test_send_baggage(self) -> None:
async def test_send_produce_hook(self) -> None:
async_produce_hook_mock = mock.AsyncMock()

def is_async_produce_hook_mock(obj: Any) -> bool:
return obj is async_produce_hook_mock

AIOKafkaInstrumentor().uninstrument()
AIOKafkaInstrumentor().instrument(
tracer_provider=self.tracer_provider,
async_produce_hook=async_produce_hook_mock,
)
# mock.patch is a hack for Python 3.9 see https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3880
with mock.patch(
"opentelemetry.instrumentation.aiokafka.iscoroutinefunction"
) as iscoro:
iscoro.side_effect = is_async_produce_hook_mock

AIOKafkaInstrumentor().instrument(
tracer_provider=self.tracer_provider,
async_produce_hook=async_produce_hook_mock,
)

producer = await self.producer_factory()
self.addAsyncCleanup(producer.stop)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio
import inspect
import typing
from collections.abc import Coroutine

Expand Down Expand Up @@ -197,7 +197,7 @@ async def __aenter__(self):

async def __aexit__(self, exc_type, exc, t_b):
try:
if asyncio.iscoroutinefunction(self._obj.close):
if inspect.iscoroutinefunction(self._obj.close):
await self._obj.close()
else:
self._obj.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ async def async_response_hook(span, request, response):

import logging
import typing
from asyncio import iscoroutinefunction
from functools import partial
from inspect import iscoroutinefunction
from timeit import default_timer
from types import TracebackType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import abc
import asyncio
import inspect
import typing
from unittest import mock

Expand Down Expand Up @@ -1086,7 +1087,7 @@ def test_custom_tracer_provider(self):
def test_response_hook(self):
response_hook_key = (
"async_response_hook"
if asyncio.iscoroutinefunction(self.response_hook)
if inspect.iscoroutinefunction(self.response_hook)
else "response_hook"
)
response_hook_kwargs = {response_hook_key: self.response_hook}
Expand Down Expand Up @@ -1133,7 +1134,7 @@ def test_response_hook_sync_async_kwargs(self):
def test_request_hook(self):
request_hook_key = (
"async_request_hook"
if asyncio.iscoroutinefunction(self.request_hook)
if inspect.iscoroutinefunction(self.request_hook)
else "request_hook"
)
request_hook_kwargs = {request_hook_key: self.request_hook}
Expand Down