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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4444](https://github.com/open-telemetry/opentelemetry-python/pull/4444))
- Updated `tracecontext-integration-test` gitref to `d782773b2cf2fa4afd6a80a93b289d8a74ca894d`
([#4448](https://github.com/open-telemetry/opentelemetry-python/pull/4448))
- Make `trace_api.use_span()` record `BaseException` as well as `Exception`
([#4406](https://github.com/open-telemetry/opentelemetry-python/pull/4406))

## Version 1.30.0/0.51b0 (2025-02-03)

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def use_span(
finally:
context_api.detach(token)

except Exception as exc: # pylint: disable=broad-exception-caught
except BaseException as exc: # pylint: disable=broad-exception-caught
if isinstance(span, Span) and span.is_recording():
# Record the exception as an event
if record_exception:
Expand Down
12 changes: 12 additions & 0 deletions opentelemetry-api/tests/trace/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ class TestUseSpanException(Exception):

self.assertEqual(test_span.recorded_exception, exception)

def test_use_span_base_exception(self):
class TestUseSpanBaseException(BaseException):
pass

test_span = SpanTest(trace.INVALID_SPAN_CONTEXT)
exception = TestUseSpanBaseException("test exception")
with self.assertRaises(TestUseSpanBaseException):
with trace.use_span(test_span):
raise exception

self.assertEqual(test_span.recorded_exception, exception)

def test_use_span_set_status(self):
class TestUseSpanException(Exception):
pass
Expand Down