From ab8e760c8e49192965afea377f438b9fe5f70776 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Thu, 10 Oct 2024 15:34:52 +0200 Subject: [PATCH] Set internal_error span status on span context manager exit --- sentry_sdk/tracing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 2e560ff3d7..112ad2bdc4 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -1273,8 +1273,10 @@ def __enter__(self): def __exit__(self, ty, value, tb): # type: (Optional[Any], Optional[Any], Optional[Any]) -> None + if value is not None: + self.set_status(SPANSTATUS.INTERNAL_ERROR) + self.finish() - # XXX set status to error if unset and an exception occurred? context.detach(self._ctx_token) def _get_attribute(self, name):