From c4f2a2a2aa98c07a77253a69dbb05a5e95832752 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 4 Dec 2024 19:37:25 +0100 Subject: [PATCH] Fix Huey tests to work with POTel (#3843) --- sentry_sdk/integrations/huey.py | 2 +- sentry_sdk/tracing.py | 7 ++++++- tests/integrations/huey/test_huey.py | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index f12c63705b..4dcff8513f 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -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, diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 6bd42983f2..6728b9b4c9 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -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) diff --git a/tests/integrations/huey/test_huey.py b/tests/integrations/huey/test_huey.py index 143a369348..bdd5c2ca10 100644 --- a/tests/integrations/huey/test_huey.py +++ b/tests/integrations/huey/test_huey.py @@ -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 @@ -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 @@ -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 ( @@ -200,7 +200,7 @@ def dummy_task(): events = capture_events() - with start_transaction(): + with sentry_sdk.start_span(): dummy_task() (event,) = events