Skip to content

Commit 1624119

Browse files
committed
chore(celery): refine utility helper typing
Assisted-by: GPT-5.4
1 parent 252d6ac commit 1624119

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import logging
1818
from collections.abc import Mapping
19-
from typing import TYPE_CHECKING, Any, Optional, Tuple, cast
19+
from typing import TYPE_CHECKING, Any, Optional, Protocol, cast
2020

2121
from celery import registry # pylint: disable=no-name-in-module
2222
from celery.app.task import Task
@@ -30,8 +30,14 @@
3030
if TYPE_CHECKING:
3131
from contextlib import AbstractContextManager
3232

33-
ContextTuple = Tuple[Span, "AbstractContextManager[Span]", Optional[object]]
34-
ContextDict = dict[tuple[str, bool], ContextTuple]
33+
ContextKey = tuple[str, bool]
34+
ContextTuple = tuple[Span, "AbstractContextManager[Span]", object | None]
35+
ContextDict = dict[ContextKey, ContextTuple]
36+
37+
38+
class ContextCarrier(Protocol):
39+
def get(self, key: str, default: Any = None) -> Any: ...
40+
3541

3642
logger = logging.getLogger(__name__)
3743

@@ -65,7 +71,7 @@
6571
# pylint:disable=too-many-branches
6672
def set_attributes_from_context(
6773
span: Span,
68-
context: Mapping[str, Any],
74+
context: ContextCarrier,
6975
) -> None:
7076
"""Helper to extract meta values from a Celery Context"""
7177
if not span.is_recording():

0 commit comments

Comments
 (0)