Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ def use_span(

except Exception as error: # pylint: disable=broad-except
if (
span.status is None
isinstance(span, Span)
and span.status is None
and span._set_status_on_exception # pylint:disable=protected-access # noqa
):
span.set_status(
Expand Down
10 changes: 10 additions & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def run_general_code(shutdown_on_exit, explicit_shutdown):
out = run_general_code(False, False)
self.assertTrue(out.startswith(b"0"))

def test_use_span_exception(self):
class TestUseSpanException(Exception):
pass

default_span = trace_api.DefaultSpan(trace_api.INVALID_SPAN_CONTEXT)
tracer = new_tracer()
with self.assertRaises(TestUseSpanException):
with tracer.use_span(default_span):
raise TestUseSpanException()


class TestTracerSampling(unittest.TestCase):
def test_default_sampler(self):
Expand Down