26
26
from opentelemetry .sdk import util
27
27
from opentelemetry .sdk .util import BoundedDict , BoundedList
28
28
from opentelemetry .trace import sampling
29
- from opentelemetry .trace .status import Status , StatusCanonicalCode , StatusError
29
+ from opentelemetry .trace .status import Status , StatusCanonicalCode
30
30
from opentelemetry .util import time_ns , types
31
31
32
32
logger = logging .getLogger (__name__ )
@@ -136,7 +136,7 @@ def __init__(
136
136
links : Sequence [trace_api .Link ] = (),
137
137
kind : trace_api .SpanKind = trace_api .SpanKind .INTERNAL ,
138
138
span_processor : SpanProcessor = SpanProcessor (),
139
- auto_update_status : bool = True ,
139
+ set_status_on_exception : bool = True ,
140
140
) -> None :
141
141
142
142
self .name = name
@@ -146,7 +146,7 @@ def __init__(
146
146
self .trace_config = trace_config
147
147
self .resource = resource
148
148
self .kind = kind
149
- self ._auto_update_status = auto_update_status
149
+ self ._set_status_on_exception = set_status_on_exception
150
150
151
151
self .span_processor = span_processor
152
152
self .status = None
@@ -261,11 +261,11 @@ def end(self, end_time: int = None) -> None:
261
261
logger .warning ("Calling end() on an ended span." )
262
262
return
263
263
264
- self .span_processor .on_end (self )
265
-
266
264
if self .status is None :
267
265
self .set_status (Status (canonical_code = StatusCanonicalCode .OK ))
268
266
267
+ self .span_processor .on_end (self )
268
+
269
269
def update_name (self , name : str ) -> None :
270
270
with self ._lock :
271
271
has_ended = self .end_time is not None
@@ -293,26 +293,18 @@ def __exit__(
293
293
) -> None :
294
294
"""Ends context manager and calls `end` on the `Span`."""
295
295
296
- if self .status is None and self ._auto_update_status :
297
- if exc_val is not None :
298
-
299
- if isinstance (exc_val , StatusError ):
300
- self .set_status (
301
- Status (
302
- canonical_code = exc_val .canonical_code ,
303
- description = exc_val .description ,
304
- )
305
- )
306
-
307
- else :
308
- self .set_status (
309
- Status (
310
- canonical_code = StatusCanonicalCode .UNKNOWN ,
311
- description = "{}: {}" .format (
312
- exc_type .__name__ , exc_val
313
- ),
314
- )
315
- )
296
+ if (
297
+ self .status is None
298
+ and self ._set_status_on_exception
299
+ and exc_val is not None
300
+ ):
301
+
302
+ self .set_status (
303
+ Status (
304
+ canonical_code = StatusCanonicalCode .UNKNOWN ,
305
+ description = "{}: {}" .format (exc_type .__name__ , exc_val ),
306
+ )
307
+ )
316
308
317
309
super ().__exit__ (exc_type , exc_val , exc_tb )
318
310
@@ -383,7 +375,7 @@ def start_span( # pylint: disable=too-many-locals
383
375
attributes : Optional [types .Attributes ] = None ,
384
376
links : Sequence [trace_api .Link ] = (),
385
377
start_time : Optional [int ] = None ,
386
- auto_update_status : bool = True ,
378
+ set_status_on_exception : bool = True ,
387
379
) -> "Span" :
388
380
"""See `opentelemetry.trace.Tracer.start_span`."""
389
381
@@ -443,7 +435,7 @@ def start_span( # pylint: disable=too-many-locals
443
435
span_processor = self ._active_span_processor ,
444
436
kind = kind ,
445
437
links = links ,
446
- auto_update_status = auto_update_status ,
438
+ set_status_on_exception = set_status_on_exception ,
447
439
)
448
440
span .start (start_time = start_time )
449
441
else :
0 commit comments