Skip to content

Commit 706300c

Browse files
authored
Make it more obvious how otel allows the span status to be set (#3759)
1 parent 0f01912 commit 706300c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

sentry_sdk/integrations/huey.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def _sentry_execute(self, task, timestamp=None):
166166
source=TRANSACTION_SOURCE_TASK,
167167
origin=HueyIntegration.origin,
168168
) as transaction:
169+
return_value = old_execute(self, task, timestamp)
169170
transaction.set_status(SPANSTATUS.OK)
170-
return old_execute(self, task, timestamp)
171+
return return_value
171172

172173
Huey._execute = _sentry_execute

sentry_sdk/tracing.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,13 +1541,17 @@ def set_attribute(self, key, value):
15411541
def set_status(self, status):
15421542
# type: (str) -> None
15431543
if status == SPANSTATUS.OK:
1544-
otel_status = StatusCode.OK
1545-
otel_description = None
1544+
# Do not set status if it's already set.
1545+
# We would override an error status with OK.
1546+
if self._otel_span.status.status_code == StatusCode.UNSET:
1547+
self._otel_span.set_status(StatusCode.OK, None)
15461548
else:
1547-
otel_status = StatusCode.ERROR
1548-
otel_description = status
1549+
# OpenTelemetry does not allow setting and error status
1550+
# if the span is already set to OK
1551+
if self._otel_span.status.status_code == StatusCode.OK:
1552+
return
15491553

1550-
self._otel_span.set_status(otel_status, otel_description)
1554+
self._otel_span.set_status(StatusCode.ERROR, status)
15511555

15521556
def set_measurement(self, name, value, unit=""):
15531557
# type: (str, float, MeasurementUnit) -> None

0 commit comments

Comments
 (0)