From 1f1e69905358986cef14f5dba03f9a8d1fd1de0a Mon Sep 17 00:00:00 2001 From: Dave Grochowski Date: Mon, 9 Mar 2020 13:33:28 -0400 Subject: [PATCH] Re-raise errors caught in opentelemetry.sdk.trace.Tracer.use_span() (#469) User raised exceptions were consumed by the context manager. --- .../src/opentelemetry/sdk/trace/__init__.py | 2 +- opentelemetry-sdk/tests/trace/test_trace.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 7f305dcc0d..f7d471a78f 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 188c019acc..9592d9a15e 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"