62
62
"""
63
63
64
64
from contextlib import contextmanager
65
- import typing
65
+ from typing import Callable
66
+ from typing import Dict
67
+ from typing import Iterator
68
+ from typing import Optional
69
+ from typing import Type
70
+ from typing import Union
66
71
67
72
from opentelemetry import loader
68
73
from opentelemetry import types
69
74
70
75
# TODO: quarantine
71
- ParentSpan = typing . Optional [typing . Union ['Span' , 'SpanContext' ]]
76
+ ParentSpan = Optional [Union ['Span' , 'SpanContext' ]]
72
77
73
78
74
79
class Span :
@@ -155,7 +160,7 @@ def get_default(cls) -> 'TraceOptions':
155
160
DEFAULT_TRACE_OPTIONS = TraceOptions .get_default ()
156
161
157
162
158
- class TraceState (typing . Dict [str , str ]):
163
+ class TraceState (Dict [str , str ]):
159
164
"""A list of key-value pairs representing vendor-specific trace info.
160
165
161
166
Keys and values are strings of up to 256 printable US-ASCII characters.
@@ -278,7 +283,7 @@ def get_current_span(self) -> 'Span':
278
283
def start_span (self ,
279
284
name : str ,
280
285
parent : ParentSpan = CURRENT_SPAN
281
- ) -> typing . Iterator ['Span' ]:
286
+ ) -> Iterator ['Span' ]:
282
287
"""Context manager for span creation.
283
288
284
289
Create a new span. Start the span and set it as the current span in
@@ -362,7 +367,7 @@ def create_span(self,
362
367
return INVALID_SPAN
363
368
364
369
@contextmanager # type: ignore
365
- def use_span (self , span : 'Span' ) -> typing . Iterator [None ]:
370
+ def use_span (self , span : 'Span' ) -> Iterator [None ]:
366
371
"""Context manager for controlling a span's lifetime.
367
372
368
373
Start the given span and set it as the current span in this tracer's
@@ -378,9 +383,10 @@ def use_span(self, span: 'Span') -> typing.Iterator[None]:
378
383
yield
379
384
380
385
381
- _TRACER : typing .Optional [Tracer ] = None
382
- _TRACER_FACTORY : typing .Optional [
383
- typing .Callable [[typing .Type [Tracer ]], typing .Optional [Tracer ]]] = None
386
+ FactoryType = Callable [[Type [Tracer ]], Optional [Tracer ]]
387
+
388
+ _TRACER = None # type: Optional[Tracer]
389
+ _TRACER_FACTORY = None # type: Optional[FactoryType]
384
390
385
391
386
392
def tracer () -> Tracer :
@@ -398,10 +404,7 @@ def tracer() -> Tracer:
398
404
return _TRACER
399
405
400
406
401
- def set_preferred_tracer_implementation (
402
- factory : typing .Callable [
403
- [typing .Type [Tracer ]], typing .Optional [Tracer ]]
404
- ) -> None :
407
+ def set_preferred_tracer_implementation (factory : FactoryType ) -> None :
405
408
"""Set the factory to be used to create the tracer.
406
409
407
410
See :mod:`opentelemetry.loader` for details.
0 commit comments