mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 11:31:52 +08:00
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>
This commit is contained in:
@ -12,8 +12,10 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
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 import registry # pylint: disable=no-name-in-module
|
||||||
from celery.app.task import Task
|
from celery.app.task import Task
|
||||||
@ -21,6 +23,9 @@ from celery.app.task import Task
|
|||||||
from opentelemetry.semconv.trace import SpanAttributes
|
from opentelemetry.semconv.trace import SpanAttributes
|
||||||
from opentelemetry.trace import Span
|
from opentelemetry.trace import Span
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from contextlib import AbstractContextManager
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Celery Context key
|
# Celery Context key
|
||||||
@ -123,7 +128,7 @@ def attach_context(
|
|||||||
task: Optional[Task],
|
task: Optional[Task],
|
||||||
task_id: str,
|
task_id: str,
|
||||||
span: Span,
|
span: Span,
|
||||||
activation: ContextManager[Span],
|
activation: AbstractContextManager[Span],
|
||||||
token: Optional[object],
|
token: Optional[object],
|
||||||
is_publish: bool = False,
|
is_publish: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -171,7 +176,7 @@ def detach_context(task, task_id, is_publish=False) -> None:
|
|||||||
|
|
||||||
def retrieve_context(
|
def retrieve_context(
|
||||||
task, task_id, is_publish=False
|
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
|
"""Helper to retrieve an active `Span`, `ContextManager` and context token
|
||||||
stored in a `Task` instance
|
stored in a `Task` instance
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
amqp==5.2.0
|
amqp==5.2.0
|
||||||
asgiref==3.8.1
|
asgiref==3.8.1
|
||||||
billiard==4.2.0
|
billiard==4.2.1
|
||||||
celery==5.3.6
|
celery==5.3.6
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
click-didyoumean==0.3.0
|
click-didyoumean==0.3.0
|
||||||
|
Reference in New Issue
Block a user