Skip to content

Commit 8b1805c

Browse files
committed
Merge branch 'potel-base' into potel-base-run-all-tests
2 parents 2bc2ce1 + 706300c commit 8b1805c

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

sentry_sdk/integrations/arq.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk.integrations import DidNotEnable, Integration
66
from sentry_sdk.integrations.logging import ignore_logger
77
from sentry_sdk.scope import should_send_default_pii
8-
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_TASK
8+
from sentry_sdk.tracing import TRANSACTION_SOURCE_TASK
99
from sentry_sdk.utils import (
1010
capture_internal_exceptions,
1111
ensure_integration_enabled,
@@ -37,6 +37,8 @@
3737

3838
ARQ_CONTROL_FLOW_EXCEPTIONS = (JobExecutionFailed, Retry, RetryJob)
3939

40+
DEFAULT_TRANSACTION_NAME = "unknown arq task"
41+
4042

4143
class ArqIntegration(Integration):
4244
identifier = "arq"
@@ -101,18 +103,20 @@ async def _sentry_run_job(self, job_id, score):
101103

102104
with sentry_sdk.isolation_scope() as scope:
103105
scope._name = "arq"
106+
scope.set_transaction_name(
107+
DEFAULT_TRANSACTION_NAME, source=TRANSACTION_SOURCE_TASK,
108+
)
104109
scope.clear_breadcrumbs()
105110

106-
transaction = Transaction(
107-
name="unknown arq task",
108-
status="ok",
111+
with sentry_sdk.start_span(
109112
op=OP.QUEUE_TASK_ARQ,
113+
name=DEFAULT_TRANSACTION_NAME,
110114
source=TRANSACTION_SOURCE_TASK,
111115
origin=ArqIntegration.origin,
112-
)
113-
114-
with sentry_sdk.start_transaction(transaction):
115-
return await old_run_job(self, job_id, score)
116+
) as span:
117+
return_value = await old_run_job(self, job_id, score)
118+
span.set_status(SPANSTATUS.OK)
119+
return return_value
116120

117121
Worker.run_job = _sentry_run_job
118122

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)