From bbb1b9468008745141c0344a6320d77f02c165b1 Mon Sep 17 00:00:00 2001 From: emdneto <9735060+emdneto@users.noreply.github.com> Date: Sat, 21 Dec 2024 14:44:46 -0300 Subject: [PATCH 1/3] celery: remove deprecated import of ContextManager from typing Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --- .../src/opentelemetry/instrumentation/celery/utils.py | 9 ++++++--- .../test-requirements-1.txt | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index 6af310df5a..4b710972f8 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -12,8 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging -from typing import ContextManager, Optional, Tuple +from contextlib import AbstractContextManager +from typing import Optional, Tuple from celery import registry # pylint: disable=no-name-in-module from celery.app.task import Task @@ -123,7 +126,7 @@ def attach_context( task: Optional[Task], task_id: str, span: Span, - activation: ContextManager[Span], + activation: AbstractContextManager[Span], token: Optional[object], is_publish: bool = False, ) -> None: @@ -171,7 +174,7 @@ def detach_context(task, task_id, is_publish=False) -> None: def retrieve_context( task, task_id, is_publish=False -) -> Optional[Tuple[Span, ContextManager[Span], Optional[object]]]: +) -> Optional[Tuple[Span, AbstractContextManager[Span], Optional[object]]]: """Helper to retrieve an active `Span`, `ContextManager` and context token stored in a `Task` instance """ diff --git a/instrumentation/opentelemetry-instrumentation-celery/test-requirements-1.txt b/instrumentation/opentelemetry-instrumentation-celery/test-requirements-1.txt index 5ef9e5750a..4d3afc74e4 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/test-requirements-1.txt +++ b/instrumentation/opentelemetry-instrumentation-celery/test-requirements-1.txt @@ -1,6 +1,6 @@ amqp==5.2.0 asgiref==3.8.1 -billiard==4.2.0 +billiard==4.2.1 celery==5.3.6 click==8.1.7 click-didyoumean==0.3.0 From 3e1bf8ff0b3504eea943706bbccc4b72a32d3e7a Mon Sep 17 00:00:00 2001 From: emdneto <9735060+emdneto@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:41:25 -0300 Subject: [PATCH 2/3] add type checking Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --- .../src/opentelemetry/instrumentation/celery/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index 4b710972f8..b17d24f243 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -15,8 +15,7 @@ from __future__ import annotations import logging -from contextlib import AbstractContextManager -from typing import Optional, Tuple +from typing import Optional, Tuple, TYPE_CHECKING from celery import registry # pylint: disable=no-name-in-module from celery.app.task import Task @@ -24,6 +23,9 @@ from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import Span +if TYPE_CHECKING: + from contextlib import AbstractContextManager + logger = logging.getLogger(__name__) # Celery Context key From 4add28e96eecbb72757b705de06b60951e370c4f Mon Sep 17 00:00:00 2001 From: emdneto <9735060+emdneto@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:42:15 -0300 Subject: [PATCH 3/3] ruff Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --- .../src/opentelemetry/instrumentation/celery/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index b17d24f243..d7ca77af8a 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -15,7 +15,7 @@ from __future__ import annotations import logging -from typing import Optional, Tuple, TYPE_CHECKING +from typing import TYPE_CHECKING, Optional, Tuple from celery import registry # pylint: disable=no-name-in-module from celery.app.task import Task