Skip to content

Commit

Permalink
Merge branch 'potel-base' into potel-base-run-all-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker committed Nov 11, 2024
2 parents 2bc2ce1 + 706300c commit 8b1805c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
20 changes: 12 additions & 8 deletions sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_TASK
from sentry_sdk.tracing import TRANSACTION_SOURCE_TASK
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down Expand Up @@ -37,6 +37,8 @@

ARQ_CONTROL_FLOW_EXCEPTIONS = (JobExecutionFailed, Retry, RetryJob)

DEFAULT_TRANSACTION_NAME = "unknown arq task"


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

with sentry_sdk.isolation_scope() as scope:
scope._name = "arq"
scope.set_transaction_name(
DEFAULT_TRANSACTION_NAME, source=TRANSACTION_SOURCE_TASK,
)
scope.clear_breadcrumbs()

transaction = Transaction(
name="unknown arq task",
status="ok",
with sentry_sdk.start_span(
op=OP.QUEUE_TASK_ARQ,
name=DEFAULT_TRANSACTION_NAME,
source=TRANSACTION_SOURCE_TASK,
origin=ArqIntegration.origin,
)

with sentry_sdk.start_transaction(transaction):
return await old_run_job(self, job_id, score)
) as span:
return_value = await old_run_job(self, job_id, score)
span.set_status(SPANSTATUS.OK)
return return_value

Worker.run_job = _sentry_run_job

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def _sentry_execute(self, task, timestamp=None):
source=TRANSACTION_SOURCE_TASK,
origin=HueyIntegration.origin,
) as transaction:
return_value = old_execute(self, task, timestamp)
transaction.set_status(SPANSTATUS.OK)
return old_execute(self, task, timestamp)
return return_value

Huey._execute = _sentry_execute
14 changes: 9 additions & 5 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,13 +1541,17 @@ def set_attribute(self, key, value):
def set_status(self, status):
# type: (str) -> None
if status == SPANSTATUS.OK:
otel_status = StatusCode.OK
otel_description = None
# Do not set status if it's already set.
# We would override an error status with OK.
if self._otel_span.status.status_code == StatusCode.UNSET:
self._otel_span.set_status(StatusCode.OK, None)
else:
otel_status = StatusCode.ERROR
otel_description = status
# OpenTelemetry does not allow setting and error status
# if the span is already set to OK
if self._otel_span.status.status_code == StatusCode.OK:
return

self._otel_span.set_status(otel_status, otel_description)
self._otel_span.set_status(StatusCode.ERROR, status)

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

0 comments on commit 8b1805c

Please sign in to comment.