66from .vendor import six
77from .compat import StringIO , stringify , iteritems , numeric_types , time_ns , is_integer
88from .constants import (
9- NUMERIC_TAGS , MANUAL_DROP_KEY , MANUAL_KEEP_KEY ,
10- VERSION_KEY , SERVICE_VERSION_KEY , SPAN_MEASURED_KEY ,
9+ NUMERIC_TAGS ,
10+ MANUAL_DROP_KEY ,
11+ MANUAL_KEEP_KEY ,
12+ VERSION_KEY ,
13+ SERVICE_VERSION_KEY ,
14+ SPAN_MEASURED_KEY ,
1115 SERVICE_KEY ,
1216)
1317from .ext import SpanTypes , errors , priority , net , http
@@ -27,33 +31,32 @@ class Span(object):
2731
2832 __slots__ = [
2933 # Public span attributes
30- ' service' ,
31- ' name' ,
32- ' resource' ,
33- ' span_id' ,
34- ' trace_id' ,
35- ' parent_id' ,
36- ' meta' ,
37- ' error' ,
38- ' metrics' ,
39- ' span_type' ,
40- ' start_ns' ,
41- ' duration_ns' ,
42- ' tracer' ,
34+ " service" ,
35+ " name" ,
36+ " resource" ,
37+ " span_id" ,
38+ " trace_id" ,
39+ " parent_id" ,
40+ " meta" ,
41+ " error" ,
42+ " metrics" ,
43+ " span_type" ,
44+ " start_ns" ,
45+ " duration_ns" ,
46+ " tracer" ,
4347 # Sampler attributes
44- ' sampled' ,
48+ " sampled" ,
4549 # Internal attributes
46- ' _context' ,
47- ' finished' ,
48- ' _parent' ,
49- ' __weakref__' ,
50+ " _context" ,
51+ " finished" ,
52+ " _parent" ,
53+ " __weakref__" ,
5054 ]
5155
5256 def __init__ (
5357 self ,
5458 tracer ,
5559 name ,
56-
5760 service = None ,
5861 resource = None ,
5962 span_type = None ,
@@ -150,14 +153,14 @@ def finish(self, finish_time=None):
150153 try :
151154 self ._context .close_span (self )
152155 except Exception :
153- log .exception (' error recording finished trace' )
156+ log .exception (" error recording finished trace" )
154157 else :
155158 # if a tracer is available to process the current context
156159 if self .tracer :
157160 try :
158161 self .tracer .record (self ._context )
159162 except Exception :
160- log .exception (' error recording finished trace' )
163+ log .exception (" error recording finished trace" )
161164
162165 def set_tag (self , key , value = None ):
163166 """Set a tag key/value pair on the span.
@@ -185,7 +188,7 @@ def set_tag(self, key, value=None):
185188
186189 # Explicitly try to convert expected integers to `int`
187190 # DEV: Some integrations parse these values from strings, but don't call `int(value)` themselves
188- INT_TYPES = (net .TARGET_PORT , )
191+ INT_TYPES = (net .TARGET_PORT ,)
189192 if key in INT_TYPES and not val_is_an_int :
190193 try :
191194 value = int (value )
@@ -272,7 +275,7 @@ def set_metric(self, key, value):
272275 try :
273276 value = int (bool (value ))
274277 except (ValueError , TypeError ):
275- log .warning (' failed to convert %r tag to an integer from %r' , key , value )
278+ log .warning (" failed to convert %r tag to an integer from %r" , key , value )
276279 return
277280
278281 # FIXME[matt] we could push this check to serialization time as well.
@@ -283,12 +286,12 @@ def set_metric(self, key, value):
283286 try :
284287 value = float (value )
285288 except (ValueError , TypeError ):
286- log .debug (' ignoring not number metric %s:%s' , key , value )
289+ log .debug (" ignoring not number metric %s:%s" , key , value )
287290 return
288291
289292 # don't allow nan or inf
290293 if math .isnan (value ) or math .isinf (value ):
291- log .debug (' ignoring not real metric %s:%s' , key , value )
294+ log .debug (" ignoring not real metric %s:%s" , key , value )
292295 return
293296
294297 if key in self .meta :
@@ -305,36 +308,36 @@ def get_metric(self, key):
305308
306309 def to_dict (self ):
307310 d = {
308- ' trace_id' : self .trace_id ,
309- ' parent_id' : self .parent_id ,
310- ' span_id' : self .span_id ,
311- ' service' : self .service ,
312- ' resource' : self .resource ,
313- ' name' : self .name ,
314- ' error' : self .error ,
311+ " trace_id" : self .trace_id ,
312+ " parent_id" : self .parent_id ,
313+ " span_id" : self .span_id ,
314+ " service" : self .service ,
315+ " resource" : self .resource ,
316+ " name" : self .name ,
317+ " error" : self .error ,
315318 }
316319
317320 # a common mistake is to set the error field to a boolean instead of an
318321 # int. let's special case that here, because it's sure to happen in
319322 # customer code.
320- err = d .get (' error' )
323+ err = d .get (" error" )
321324 if err and type (err ) == bool :
322- d [' error' ] = 1
325+ d [" error" ] = 1
323326
324327 if self .start_ns :
325- d [' start' ] = self .start_ns
328+ d [" start" ] = self .start_ns
326329
327330 if self .duration_ns :
328- d [' duration' ] = self .duration_ns
331+ d [" duration" ] = self .duration_ns
329332
330333 if self .meta :
331- d [' meta' ] = self .meta
334+ d [" meta" ] = self .meta
332335
333336 if self .metrics :
334- d [' metrics' ] = self .metrics
337+ d [" metrics" ] = self .metrics
335338
336339 if self .span_type :
337- d [' type' ] = self .span_type
340+ d [" type" ] = self .span_type
338341
339342 return d
340343
@@ -344,10 +347,10 @@ def set_traceback(self, limit=20):
344347 """
345348 (exc_type , exc_val , exc_tb ) = sys .exc_info ()
346349
347- if ( exc_type and exc_val and exc_tb ) :
350+ if exc_type and exc_val and exc_tb :
348351 self .set_exc_info (exc_type , exc_val , exc_tb )
349352 else :
350- tb = '' .join (traceback .format_stack (limit = limit + 1 )[:- 1 ])
353+ tb = "" .join (traceback .format_stack (limit = limit + 1 )[:- 1 ])
351354 self .set_tag (errors .ERROR_STACK , tb ) # FIXME[gabin] Want to replace 'error.stack' tag with 'python.stack'
352355
353356 def set_exc_info (self , exc_type , exc_val , exc_tb ):
@@ -363,7 +366,7 @@ def set_exc_info(self, exc_type, exc_val, exc_tb):
363366 tb = buff .getvalue ()
364367
365368 # readable version of type (e.g. exceptions.ZeroDivisionError)
366- exc_type_str = ' %s.%s' % (exc_type .__module__ , exc_type .__name__ )
369+ exc_type_str = " %s.%s" % (exc_type .__module__ , exc_type .__name__ )
367370
368371 self .set_tag (errors .ERROR_MSG , exc_val )
369372 self .set_tag (errors .ERROR_TYPE , exc_type_str )
@@ -379,22 +382,22 @@ def _remove_exc_info(self):
379382 def pprint (self ):
380383 """ Return a human readable version of the span. """
381384 lines = [
382- (' name' , self .name ),
383- ('id' , self .span_id ),
384- (' trace_id' , self .trace_id ),
385- (' parent_id' , self .parent_id ),
386- (' service' , self .service ),
387- (' resource' , self .resource ),
388- (' type' , self .span_type ),
389- (' start' , self .start ),
390- (' end' , '' if not self .duration else self .start + self .duration ),
391- (' duration' , ' %fs' % (self .duration or 0 )),
392- (' error' , self .error ),
393- (' tags' , '' )
385+ (" name" , self .name ),
386+ ("id" , self .span_id ),
387+ (" trace_id" , self .trace_id ),
388+ (" parent_id" , self .parent_id ),
389+ (" service" , self .service ),
390+ (" resource" , self .resource ),
391+ (" type" , self .span_type ),
392+ (" start" , self .start ),
393+ (" end" , "" if not self .duration else self .start + self .duration ),
394+ (" duration" , " %fs" % (self .duration or 0 )),
395+ (" error" , self .error ),
396+ (" tags" , "" ),
394397 ]
395398
396- lines .extend ((' ' , ' %s:%s' % kv ) for kv in sorted (self .meta .items ()))
397- return ' \n ' .join (' %10s %s' % l for l in lines )
399+ lines .extend ((" " , " %s:%s" % kv ) for kv in sorted (self .meta .items ()))
400+ return " \n " .join (" %10s %s" % line for line in lines )
398401
399402 @property
400403 def context (self ):
@@ -414,10 +417,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
414417 self .set_exc_info (exc_type , exc_val , exc_tb )
415418 self .finish ()
416419 except Exception :
417- log .exception (' error closing trace' )
420+ log .exception (" error closing trace" )
418421
419422 def __repr__ (self ):
420- return ' <Span(id=%s,trace_id=%s,parent_id=%s,name=%s)>' % (
423+ return " <Span(id=%s,trace_id=%s,parent_id=%s,name=%s)>" % (
421424 self .span_id ,
422425 self .trace_id ,
423426 self .parent_id ,
0 commit comments