Skip to content

Commit af2a500

Browse files
committed
Change typing
1 parent 7cce48a commit af2a500

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/a2a/utils/telemetry.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ def internal_method(self):
5959
import logging
6060

6161
from collections.abc import Callable
62-
from typing import Any
62+
from typing import TYPE_CHECKING, Any
6363

6464

65+
if TYPE_CHECKING:
66+
from opentelemetry.trace import SpanKind as SpanKindType
67+
else:
68+
SpanKindType = object
69+
6570
logger = logging.getLogger(__name__)
6671

6772
try:
6873
from opentelemetry import trace
69-
from opentelemetry.trace import SpanKind as _SpanKind
70-
from opentelemetry.trace import StatusCode
74+
from opentelemetry.trace import SpanKind, StatusCode
7175

7276
except ImportError:
7377
logger.debug(
@@ -91,12 +95,9 @@ def __getattr__(self, name: str) -> '_NoOp':
9195
return self
9296

9397
trace = _NoOp()
94-
_SpanKind = _NoOp()
98+
SpanKind = _NoOp()
9599
StatusCode = _NoOp()
96100

97-
SpanKind = _SpanKind
98-
__all__ = ['SpanKind']
99-
100101
INSTRUMENTING_MODULE_NAME = 'a2a-python-sdk'
101102
INSTRUMENTING_MODULE_VERSION = '1.0.0'
102103

@@ -105,7 +106,7 @@ def trace_function( # noqa: PLR0915
105106
func: Callable | None = None,
106107
*,
107108
span_name: str | None = None,
108-
kind: SpanKind = SpanKind.INTERNAL,
109+
kind: SpanKindType = SpanKind.INTERNAL,
109110
attributes: dict[str, Any] | None = None,
110111
attribute_extractor: Callable | None = None,
111112
) -> Callable:
@@ -252,7 +253,7 @@ def sync_wrapper(*args, **kwargs) -> Any:
252253
def trace_class(
253254
include_list: list[str] | None = None,
254255
exclude_list: list[str] | None = None,
255-
kind: SpanKind = SpanKind.INTERNAL,
256+
kind: SpanKindType = SpanKind.INTERNAL,
256257
) -> Callable:
257258
"""A class decorator to automatically trace specified methods of a class.
258259

0 commit comments

Comments
 (0)