@@ -246,82 +246,111 @@ def __init__(
246
246
span_processor : SpanProcessor = SpanProcessor (),
247
247
) -> None :
248
248
249
- self .name = name
250
- self .context = context
251
- self .parent = parent
252
- self .sampler = sampler
253
- self .trace_config = trace_config
254
- self .resource = resource
255
- self .attributes = attributes
256
- self .events = events
257
- self .links = links
258
- self .span_processor = span_processor
249
+ self ._name = name
250
+ self ._context = context
251
+ self ._parent = parent
252
+ self ._sampler = sampler
253
+ self ._trace_config = trace_config
254
+ self ._resource = resource
255
+ self ._attributes = attributes
256
+ self ._events = events
257
+ self ._links = links
258
+ self ._span_processor = span_processor
259
259
260
260
if attributes is None :
261
- self .attributes = Span .empty_attributes
261
+ self ._attributes = Span .empty_attributes
262
262
else :
263
- self .attributes = BoundedDict .from_map (
263
+ self ._attributes = BoundedDict .from_map (
264
264
MAX_NUM_ATTRIBUTES , attributes
265
265
)
266
266
267
267
if events is None :
268
- self .events = Span .empty_events
268
+ self ._events = Span .empty_events
269
269
else :
270
- self .events = BoundedList .from_seq (MAX_NUM_EVENTS , events )
270
+ self ._events = BoundedList .from_seq (MAX_NUM_EVENTS , events )
271
271
272
272
if links is None :
273
- self .links = Span .empty_links
273
+ self ._links = Span .empty_links
274
274
else :
275
- self .links = BoundedList .from_seq (MAX_NUM_LINKS , links )
275
+ self ._links = BoundedList .from_seq (MAX_NUM_LINKS , links )
276
276
277
- self .end_time = None
278
- self .start_time = None
277
+ self ._end_time = None
278
+ self ._start_time = None
279
279
280
280
def __repr__ (self ):
281
281
return '{}(name="{}")' .format (type (self ).__name__ , self .name )
282
282
283
283
def get_context (self ):
284
- return self .context
284
+ return self ._context
285
285
286
286
def set_attribute (
287
287
self : "Span" , key : str , value : types .AttributeValue
288
288
) -> None :
289
- if self .attributes is Span .empty_attributes :
290
- self .attributes = BoundedDict (MAX_NUM_ATTRIBUTES )
291
- self .attributes [key ] = value
289
+ if self ._attributes is Span .empty_attributes :
290
+ self ._attributes = BoundedDict (MAX_NUM_ATTRIBUTES )
291
+ self ._attributes [key ] = value
292
292
293
293
def add_event (
294
294
self : "Span" , name : str , attributes : types .Attributes = None
295
295
) -> None :
296
- if self .events is Span .empty_events :
297
- self .events = BoundedList (MAX_NUM_EVENTS )
296
+ if self ._events is Span .empty_events :
297
+ self ._events = BoundedList (MAX_NUM_EVENTS )
298
298
if attributes is None :
299
299
attributes = Span .empty_attributes
300
- self .events .append (Event (name , attributes ))
300
+ self ._events .append (Event (name , attributes ))
301
301
302
302
def add_link (
303
303
self : "Span" ,
304
304
link_target_context : "trace_api.SpanContext" ,
305
305
attributes : types .Attributes = None ,
306
306
) -> None :
307
- if self .links is Span .empty_links :
308
- self .links = BoundedList (MAX_NUM_LINKS )
307
+ if self ._links is Span .empty_links :
308
+ self ._links = BoundedList (MAX_NUM_LINKS )
309
309
if attributes is None :
310
310
attributes = Span .empty_attributes
311
- self .links .append (Link (link_target_context , attributes ))
311
+ self ._links .append (Link (link_target_context , attributes ))
312
312
313
313
def start (self ):
314
- if self .start_time is None :
315
- self .start_time = util .time_ns ()
316
- self .span_processor .on_start (self )
314
+ if self ._start_time is None :
315
+ self ._start_time = util .time_ns ()
316
+ self ._span_processor .on_start (self )
317
317
318
318
def end (self ):
319
- if self .end_time is None :
320
- self .end_time = util .time_ns ()
321
- self .span_processor .on_end (self )
319
+ if self ._end_time is None :
320
+ self ._end_time = util .time_ns ()
321
+ self ._span_processor .on_end (self )
322
322
323
323
def update_name (self , name : str ) -> None :
324
- self .name = name
324
+ self ._name = name
325
+
326
+ # accessors
327
+ @property
328
+ def events (self ) -> Event :
329
+ return self ._events
330
+
331
+ @property
332
+ def attributes (self ) -> types .Attributes :
333
+ return self ._attributes
334
+
335
+ @property
336
+ def links (self ) -> Link :
337
+ return self ._links
338
+
339
+ @property
340
+ def name (self ) -> str :
341
+ return self ._name
342
+
343
+ @property
344
+ def start_time (self ) -> int :
345
+ return self ._start_time
346
+
347
+ @property
348
+ def end_time (self ) -> int :
349
+ return self ._end_time
350
+
351
+ @property
352
+ def parent (self ) -> trace_api .ParentSpan :
353
+ return self ._parent
325
354
326
355
327
356
def generate_span_id ():
0 commit comments