Skip to content

Commit 4e29a76

Browse files
committed
test proper exception / status code recording
1 parent 3a19941 commit 4e29a76

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,22 @@ async def _():
19291929
self.assertIsNotNone(self.request_trace_id)
19301930
self.assertEqual(self.request_trace_id, self.error_trace_id)
19311931

1932+
spans = self.memory_exporter.get_finished_spans()
1933+
1934+
self.assertEqual(len(spans), 1)
1935+
span = spans[0]
1936+
self.assertEqual(span.status.status_code, StatusCode.ERROR)
1937+
self.assertEqual(
1938+
len(span.events), 2
1939+
) # The other span is a `TypeError` from the exception handler not returning a proper response, that's expected
1940+
event = span.events[0]
1941+
self.assertEqual(event.name, "exception")
1942+
assert event.attributes is not None
1943+
self.assertEqual(
1944+
event.attributes.get(EXCEPTION_TYPE),
1945+
f"{__name__}.UnhandledException",
1946+
)
1947+
19321948
def test_error_handler_side_effects(self):
19331949
"""FastAPI default exception handlers (aka error handlers) must be executed exactly once per exception"""
19341950

0 commit comments

Comments
 (0)