Skip to content

Commit 13451ec

Browse files
committed
chore(celery): refine utility helper typing
Assisted-by: GPT-5.4
1 parent b0cc7f7 commit 13451ec

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
@@ -5,7 +5,7 @@
55

66
import logging
77
from collections.abc import Mapping
8-
from typing import TYPE_CHECKING, Any, Optional, Tuple, cast
8+
from typing import TYPE_CHECKING, Any, Optional, Protocol, cast
99

1010
from celery import registry # pylint: disable=no-name-in-module
1111
from celery.app.task import Task
@@ -19,8 +19,14 @@
1919
if TYPE_CHECKING:
2020
from contextlib import AbstractContextManager
2121

22-
ContextTuple = Tuple[Span, "AbstractContextManager[Span]", Optional[object]]
23-
ContextDict = dict[tuple[str, bool], ContextTuple]
22+
ContextKey = tuple[str, bool]
23+
ContextTuple = tuple[Span, "AbstractContextManager[Span]", object | None]
24+
ContextDict = dict[ContextKey, ContextTuple]
25+
26+
27+
class ContextCarrier(Protocol):
28+
def get(self, key: str, default: Any = None) -> Any: ...
29+
2430

2531
logger = logging.getLogger(__name__)
2632

@@ -54,7 +60,7 @@
5460
# pylint:disable=too-many-branches
5561
def set_attributes_from_context(
5662
span: Span,
57-
context: Mapping[str, Any],
63+
context: ContextCarrier,
5864
) -> None:
5965
"""Helper to extract meta values from a Celery Context"""
6066
if not span.is_recording():

0 commit comments

Comments
 (0)