@@ -73,10 +73,10 @@ class MultiSpanProcessor(SpanProcessor):
73
73
def __init__ (self ):
74
74
# use a tuple to avoid race conditions when adding a new span and
75
75
# iterating through it on "on_start" and "on_end".
76
- self ._span_processors = ()
76
+ self ._span_processors = () # type: typing.Tuple[SpanProcessor, ...]
77
77
self ._lock = threading .Lock ()
78
78
79
- def add_span_processor (self , span_processor : SpanProcessor ):
79
+ def add_span_processor (self , span_processor : SpanProcessor ) -> None :
80
80
"""Adds a SpanProcessor to the list handled by this instance."""
81
81
with self ._lock :
82
82
self ._span_processors = self ._span_processors + (span_processor ,)
@@ -122,11 +122,11 @@ class Span(trace_api.Span):
122
122
def __init__ (
123
123
self ,
124
124
name : str ,
125
- context : " trace_api.SpanContext" ,
125
+ context : trace_api .SpanContext ,
126
126
parent : trace_api .ParentSpan = None ,
127
- sampler = None , # TODO
128
- trace_config = None , # TODO
129
- resource = None , # TODO
127
+ sampler : None = None , # TODO
128
+ trace_config : None = None , # TODO
129
+ resource : None = None , # TODO
130
130
attributes : types .Attributes = None , # TODO
131
131
events : typing .Sequence [trace_api .Event ] = None , # TODO
132
132
links : typing .Sequence [trace_api .Link ] = None , # TODO
@@ -140,9 +140,6 @@ def __init__(
140
140
self .sampler = sampler
141
141
self .trace_config = trace_config
142
142
self .resource = resource
143
- self .attributes = attributes
144
- self .events = events
145
- self .links = links
146
143
self .kind = kind
147
144
148
145
self .span_processor = span_processor
@@ -165,8 +162,8 @@ def __init__(
165
162
else :
166
163
self .links = BoundedList .from_seq (MAX_NUM_LINKS , links )
167
164
168
- self .end_time = None
169
- self .start_time = None
165
+ self .end_time = None # type: typing.Optional[int]
166
+ self .start_time = None # type: typing.Optional[int]
170
167
171
168
def __repr__ (self ):
172
169
return '{}(name="{}", context={})' .format (
@@ -203,9 +200,13 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None:
203
200
def add_event (
204
201
self , name : str , attributes : types .Attributes = None
205
202
) -> None :
206
- if attributes is None :
207
- attributes = Span .empty_attributes
208
- self .add_lazy_event (trace_api .Event (name , util .time_ns (), attributes ))
203
+ self .add_lazy_event (
204
+ trace_api .Event (
205
+ name ,
206
+ util .time_ns (),
207
+ Span .empty_attributes if attributes is None else attributes ,
208
+ )
209
+ )
209
210
210
211
def add_lazy_event (self , event : trace_api .Event ) -> None :
211
212
with self ._lock :
@@ -226,7 +227,9 @@ def add_link(
226
227
attributes : types .Attributes = None ,
227
228
) -> None :
228
229
if attributes is None :
229
- attributes = Span .empty_attributes
230
+ attributes = (
231
+ Span .empty_attributes
232
+ ) # TODO: empty_attributes is not a Dict. Use Mapping?
230
233
self .add_lazy_link (trace_api .Link (link_target_context , attributes ))
231
234
232
235
def add_lazy_link (self , link : "trace_api.Link" ) -> None :
@@ -242,7 +245,7 @@ def add_lazy_link(self, link: "trace_api.Link") -> None:
242
245
return
243
246
self .links .append (link )
244
247
245
- def start (self , start_time : int = None ):
248
+ def start (self , start_time : typing . Optional [ int ] = None ) -> None :
246
249
with self ._lock :
247
250
if not self .is_recording_events ():
248
251
return
@@ -256,7 +259,7 @@ def start(self, start_time: int = None):
256
259
return
257
260
self .span_processor .on_start (self )
258
261
259
- def end (self , end_time : int = None ):
262
+ def end (self , end_time : int = None ) -> None :
260
263
with self ._lock :
261
264
if not self .is_recording_events ():
262
265
return
@@ -285,7 +288,7 @@ def is_recording_events(self) -> bool:
285
288
return True
286
289
287
290
288
- def generate_span_id ():
291
+ def generate_span_id () -> int :
289
292
"""Get a new random span ID.
290
293
291
294
Returns:
@@ -294,7 +297,7 @@ def generate_span_id():
294
297
return random .getrandbits (64 )
295
298
296
299
297
- def generate_trace_id ():
300
+ def generate_trace_id () -> int :
298
301
"""Get a new random trace ID.
299
302
300
303
Returns:
@@ -327,7 +330,7 @@ def start_span(
327
330
name : str ,
328
331
parent : trace_api .ParentSpan = trace_api .Tracer .CURRENT_SPAN ,
329
332
kind : trace_api .SpanKind = trace_api .SpanKind .INTERNAL ,
330
- ) -> typing .Iterator [" Span" ]:
333
+ ) -> typing .Iterator [trace_api . Span ]:
331
334
"""See `opentelemetry.trace.Tracer.start_span`."""
332
335
333
336
span = self .create_span (name , parent , kind )
@@ -370,8 +373,8 @@ def create_span(
370
373
371
374
@contextmanager
372
375
def use_span (
373
- self , span : Span , end_on_exit : bool = False
374
- ) -> typing .Iterator [Span ]:
376
+ self , span : trace_api . Span , end_on_exit : bool = False
377
+ ) -> typing .Iterator [trace_api . Span ]:
375
378
"""See `opentelemetry.trace.Tracer.use_span`."""
376
379
try :
377
380
span_snapshot = self ._current_span_slot .get ()
0 commit comments