File tree 2 files changed +37
-10
lines changed
src/opentelemetry/sdk/trace
2 files changed +37
-10
lines changed Original file line number Diff line number Diff line change @@ -538,6 +538,23 @@ def use_span(
538
538
self .source ._current_span_slot .set ( # pylint:disable=protected-access
539
539
span_snapshot
540
540
)
541
+
542
+ except Exception as error : # pylint: disable=broad-except
543
+ if (
544
+ span .status is None
545
+ and span ._set_status_on_exception # pylint:disable=protected-access # noqa
546
+ ):
547
+ span .set_status (
548
+ Status (
549
+ canonical_code = StatusCanonicalCode .UNKNOWN ,
550
+ description = "{}: {}" .format (
551
+ type (error ).__name__ , error
552
+ ),
553
+ )
554
+ )
555
+
556
+ raise
557
+
541
558
finally :
542
559
if end_on_exit :
543
560
span .end ()
Original file line number Diff line number Diff line change @@ -641,16 +641,26 @@ def test_ended_span(self):
641
641
)
642
642
643
643
def test_error_status (self ):
644
- try :
645
- with trace .TracerSource ().get_tracer (__name__ ).start_span (
646
- "root"
647
- ) as root :
648
- raise Exception ("unknown" )
649
- except Exception : # pylint: disable=broad-except
650
- pass
651
-
652
- self .assertIs (root .status .canonical_code , StatusCanonicalCode .UNKNOWN )
653
- self .assertEqual (root .status .description , "Exception: unknown" )
644
+ def error_status_test (context ):
645
+ with self .assertRaises (AssertionError ):
646
+ with context as root :
647
+ raise AssertionError ("unknown" )
648
+
649
+ self .assertIs (
650
+ root .status .canonical_code , StatusCanonicalCode .UNKNOWN
651
+ )
652
+ self .assertEqual (
653
+ root .status .description , "AssertionError: unknown"
654
+ )
655
+
656
+ error_status_test (
657
+ trace .TracerSource ().get_tracer (__name__ ).start_span ("root" )
658
+ )
659
+ error_status_test (
660
+ trace .TracerSource ()
661
+ .get_tracer (__name__ )
662
+ .start_as_current_span ("root" )
663
+ )
654
664
655
665
656
666
def span_event_start_fmt (span_processor_name , span_name ):
You can’t perform that action at this time.
0 commit comments