diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 7f305dcc0d9..f7d471a78f3 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -524,7 +524,7 @@ def use_span( ) ) - raise + raise finally: if end_on_exit: diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 188c019acc1..9592d9a15ed 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -679,6 +679,32 @@ def error_status_test(context): .start_as_current_span("root") ) + def test_override_error_status(self): + def error_status_test(context): + with self.assertRaises(AssertionError): + with context as root: + root.set_status( + trace_api.status.Status( + StatusCanonicalCode.UNAVAILABLE, + "Error: Unavailable", + ) + ) + raise AssertionError("unknown") + + self.assertIs( + root.status.canonical_code, StatusCanonicalCode.UNAVAILABLE + ) + self.assertEqual(root.status.description, "Error: Unavailable") + + error_status_test( + trace.TracerProvider().get_tracer(__name__).start_span("root") + ) + error_status_test( + trace.TracerProvider() + .get_tracer(__name__) + .start_as_current_span("root") + ) + def span_event_start_fmt(span_processor_name, span_name): return span_processor_name + ":" + span_name + ":start"