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..d7ca77af8a 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 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 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