Skip to content

Commit 90235dc

Browse files
authored
Merge branch 'main' into main
2 parents 281ad80 + 3acc474 commit 90235dc

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#3798](https://github.com/open-telemetry/opentelemetry-python/pull/3798))
1818
- Fix otlp exporter to export log_record.observed_timestamp
1919
([#3785](https://github.com/open-telemetry/opentelemetry-python/pull/3785))
20+
- Add capture the fully qualified type name for raised exceptions in spans
21+
([#3837](https://github.com/open-telemetry/opentelemetry-python/pull/3837))
2022

2123
## Version 1.24.0/0.45b0 (2024-03-28)
2224

opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,15 @@ def record_exception(
995995
type(exception), value=exception, tb=exception.__traceback__
996996
)
997997
)
998+
module = type(exception).__module__
999+
qualname = type(exception).__qualname__
1000+
exception_type = (
1001+
f"{module}.{qualname}"
1002+
if module and module != "builtins"
1003+
else qualname
1004+
)
9981005
_attributes: MutableMapping[str, types.AttributeValue] = {
999-
"exception.type": exception.__class__.__name__,
1006+
"exception.type": exception_type,
10001007
"exception.message": str(exception),
10011008
"exception.stacktrace": stacktrace,
10021009
"exception.escaped": str(escaped),

opentelemetry-sdk/tests/trace/test_trace.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ def test_events(self):
636636
self.assertEqual(span.events, tuple(events))
637637

638638

639+
class DummyError(Exception):
640+
pass
641+
642+
639643
class TestSpan(unittest.TestCase):
640644
# pylint: disable=too-many-public-methods
641645

@@ -1144,6 +1148,25 @@ def error_status_test(context):
11441148
.start_as_current_span("root")
11451149
)
11461150

1151+
def test_record_exception_fqn(self):
1152+
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
1153+
exception = DummyError("error")
1154+
exception_type = "tests.trace.test_trace.DummyError"
1155+
span.record_exception(exception)
1156+
exception_event = span.events[0]
1157+
self.assertEqual("exception", exception_event.name)
1158+
self.assertEqual(
1159+
"error", exception_event.attributes["exception.message"]
1160+
)
1161+
self.assertEqual(
1162+
exception_type,
1163+
exception_event.attributes["exception.type"],
1164+
)
1165+
self.assertIn(
1166+
"DummyError: error",
1167+
exception_event.attributes["exception.stacktrace"],
1168+
)
1169+
11471170
def test_record_exception(self):
11481171
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
11491172
try:

0 commit comments

Comments
 (0)