Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4361](https://github.com/open-telemetry/opentelemetry-python/pull/4361))
- semantic-conventions: Bump to 1.30.0
([#4337](https://github.com/open-telemetry/opentelemetry-python/pull/4397))
- Make `trace_api.use_span()` record `BaseException` as well as `Exception`
([#4406](https://github.com/open-telemetry/opentelemetry-python/pull/4406))

## Version 1.29.0/0.50b0 (2024-12-11)

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