diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index 9a3bfb9b99..433a7c17c6 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -166,7 +166,8 @@ def _sentry_execute(self, task, timestamp=None): source=TRANSACTION_SOURCE_TASK, origin=HueyIntegration.origin, ) as transaction: + return_value = old_execute(self, task, timestamp) transaction.set_status(SPANSTATUS.OK) - return old_execute(self, task, timestamp) + return return_value Huey._execute = _sentry_execute diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index aba7d4f49d..2bc3c9b8a7 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -1541,13 +1541,17 @@ def set_attribute(self, key, value): def set_status(self, status): # type: (str) -> None if status == SPANSTATUS.OK: - otel_status = StatusCode.OK - otel_description = None + # Do not set status if it's already set. + # We would override an error status with OK. + if self._otel_span.status.status_code == StatusCode.UNSET: + self._otel_span.set_status(StatusCode.OK, None) else: - otel_status = StatusCode.ERROR - otel_description = status + # OpenTelemetry does not allow setting and error status + # if the span is already set to OK + if self._otel_span.status.status_code == StatusCode.OK: + return - self._otel_span.set_status(otel_status, otel_description) + self._otel_span.set_status(StatusCode.ERROR, status) def set_measurement(self, name, value, unit=""): # type: (str, float, MeasurementUnit) -> None