Skip to content

Commit 396aad9

Browse files
authored
celery: remove deprecated import of ContextManager from typing (#3145)
* celery: remove deprecated import of ContextManager from typing Signed-off-by: emdneto <[email protected]> * add type checking Signed-off-by: emdneto <[email protected]> * ruff Signed-off-by: emdneto <[email protected]> --------- Signed-off-by: emdneto <[email protected]>
1 parent 375eb6f commit 396aad9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import logging
16-
from typing import ContextManager, Optional, Tuple
18+
from typing import TYPE_CHECKING, Optional, Tuple
1719

1820
from celery import registry # pylint: disable=no-name-in-module
1921
from celery.app.task import Task
2022

2123
from opentelemetry.semconv.trace import SpanAttributes
2224
from opentelemetry.trace import Span
2325

26+
if TYPE_CHECKING:
27+
from contextlib import AbstractContextManager
28+
2429
logger = logging.getLogger(__name__)
2530

2631
# Celery Context key
@@ -123,7 +128,7 @@ def attach_context(
123128
task: Optional[Task],
124129
task_id: str,
125130
span: Span,
126-
activation: ContextManager[Span],
131+
activation: AbstractContextManager[Span],
127132
token: Optional[object],
128133
is_publish: bool = False,
129134
) -> None:
@@ -171,7 +176,7 @@ def detach_context(task, task_id, is_publish=False) -> None:
171176

172177
def retrieve_context(
173178
task, task_id, is_publish=False
174-
) -> Optional[Tuple[Span, ContextManager[Span], Optional[object]]]:
179+
) -> Optional[Tuple[Span, AbstractContextManager[Span], Optional[object]]]:
175180
"""Helper to retrieve an active `Span`, `ContextManager` and context token
176181
stored in a `Task` instance
177182
"""

instrumentation/opentelemetry-instrumentation-celery/test-requirements-1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
amqp==5.2.0
22
asgiref==3.8.1
3-
billiard==4.2.0
3+
billiard==4.2.1
44
celery==5.3.6
55
click==8.1.7
66
click-didyoumean==0.3.0

0 commit comments

Comments
 (0)