Skip to content

Commit

Permalink
Fix Huey tests to work with POTel (#3843)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker authored Dec 4, 2024
1 parent 1dbcdd4 commit c4f2a2a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _sentry_execute(self, task, timestamp=None):

sentry_headers = task.kwargs.pop("sentry_headers", {})
with sentry_sdk.continue_trace(sentry_headers):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
name=task.name,
op=OP.QUEUE_TASK_HUEY,
source=TRANSACTION_SOURCE_TASK,
Expand Down
7 changes: 6 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,12 @@ def __exit__(self, ty, value, tb):
if value is not None:
self.set_status(SPANSTATUS.INTERNAL_ERROR)
else:
self.set_status(SPANSTATUS.OK)
status_unset = (
hasattr(self._otel_span, "status")
and self._otel_span.status.status_code == StatusCode.UNSET
)
if status_unset:
self.set_status(SPANSTATUS.OK)

self.finish()
context.detach(self._ctx_token)
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/huey/test_huey.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from decimal import DivisionByZero

from sentry_sdk import start_transaction
import sentry_sdk
from sentry_sdk.integrations.huey import HueyIntegration
from sentry_sdk.utils import parse_version

Expand Down Expand Up @@ -160,7 +160,7 @@ def dummy_task():

events = capture_events()

with start_transaction() as transaction:
with sentry_sdk.start_span() as transaction:
dummy_task()

(event,) = events
Expand All @@ -182,7 +182,7 @@ def test_huey_propagate_trace(init_huey, capture_events):
def propagated_trace_task():
pass

with start_transaction() as outer_transaction:
with sentry_sdk.start_span() as outer_transaction:
execute_huey_task(huey, propagated_trace_task)

assert (
Expand All @@ -200,7 +200,7 @@ def dummy_task():

events = capture_events()

with start_transaction():
with sentry_sdk.start_span():
dummy_task()

(event,) = events
Expand Down

0 comments on commit c4f2a2a

Please sign in to comment.