From 396aad9c24adc4a6501e9b51e48aaa5e96c72096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C3=ADdio=20Neto?= <9735060+emdneto@users.noreply.github.com> Date: Tue, 24 Dec 2024 10:55:33 -0300 Subject: [PATCH] celery: remove deprecated import of ContextManager from typing (#3145) * celery: remove deprecated import of ContextManager from typing Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> * add type checking Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> * ruff Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --------- Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --- .../src/opentelemetry/instrumentation/celery/utils.py | 11 ++++++++--- .../test-requirements-1.txt | 2 +- 2 files changed, 9 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 6af310df5..d7ca77af8 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,10 @@ # 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 typing import TYPE_CHECKING, Optional, Tuple from celery import registry # pylint: disable=no-name-in-module from celery.app.task import Task @@ -21,6 +23,9 @@ from celery.app.task import Task 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 @@ -123,7 +128,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 +176,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 5ef9e5750..4d3afc74e 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