Skip to content

Commit c4f2a2a

Browse files
authored
Fix Huey tests to work with POTel (#3843)
1 parent 1dbcdd4 commit c4f2a2a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

sentry_sdk/integrations/huey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _sentry_execute(self, task, timestamp=None):
162162

163163
sentry_headers = task.kwargs.pop("sentry_headers", {})
164164
with sentry_sdk.continue_trace(sentry_headers):
165-
with sentry_sdk.start_transaction(
165+
with sentry_sdk.start_span(
166166
name=task.name,
167167
op=OP.QUEUE_TASK_HUEY,
168168
source=TRANSACTION_SOURCE_TASK,

sentry_sdk/tracing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,12 @@ def __exit__(self, ty, value, tb):
13131313
if value is not None:
13141314
self.set_status(SPANSTATUS.INTERNAL_ERROR)
13151315
else:
1316-
self.set_status(SPANSTATUS.OK)
1316+
status_unset = (
1317+
hasattr(self._otel_span, "status")
1318+
and self._otel_span.status.status_code == StatusCode.UNSET
1319+
)
1320+
if status_unset:
1321+
self.set_status(SPANSTATUS.OK)
13171322

13181323
self.finish()
13191324
context.detach(self._ctx_token)

tests/integrations/huey/test_huey.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from decimal import DivisionByZero
33

4-
from sentry_sdk import start_transaction
4+
import sentry_sdk
55
from sentry_sdk.integrations.huey import HueyIntegration
66
from sentry_sdk.utils import parse_version
77

@@ -160,7 +160,7 @@ def dummy_task():
160160

161161
events = capture_events()
162162

163-
with start_transaction() as transaction:
163+
with sentry_sdk.start_span() as transaction:
164164
dummy_task()
165165

166166
(event,) = events
@@ -182,7 +182,7 @@ def test_huey_propagate_trace(init_huey, capture_events):
182182
def propagated_trace_task():
183183
pass
184184

185-
with start_transaction() as outer_transaction:
185+
with sentry_sdk.start_span() as outer_transaction:
186186
execute_huey_task(huey, propagated_trace_task)
187187

188188
assert (
@@ -200,7 +200,7 @@ def dummy_task():
200200

201201
events = capture_events()
202202

203-
with start_transaction():
203+
with sentry_sdk.start_span():
204204
dummy_task()
205205

206206
(event,) = events

0 commit comments

Comments
 (0)