From 647006398228a3d75128fb0471ec701e93884acf Mon Sep 17 00:00:00 2001 From: Artem Ivanov Date: Fri, 15 Dec 2023 10:31:55 +0100 Subject: [PATCH] Arq integration ctx (#2600) --- sentry_sdk/integrations/arq.py | 2 +- tests/integrations/arq/test_arq.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/arq.py b/sentry_sdk/integrations/arq.py index 9997f4cac6..f46d1204c5 100644 --- a/sentry_sdk/integrations/arq.py +++ b/sentry_sdk/integrations/arq.py @@ -169,7 +169,7 @@ async def _sentry_coroutine(ctx, *args, **kwargs): # type: (Dict[Any, Any], *Any, **Any) -> Any hub = Hub.current if hub.get_integration(ArqIntegration) is None: - return await coroutine(*args, **kwargs) + return await coroutine(ctx, *args, **kwargs) hub.scope.add_event_processor( _make_event_processor({**ctx, "job_name": name}, *args, **kwargs) diff --git a/tests/integrations/arq/test_arq.py b/tests/integrations/arq/test_arq.py index 0ed9da992b..4c4bc95163 100644 --- a/tests/integrations/arq/test_arq.py +++ b/tests/integrations/arq/test_arq.py @@ -1,7 +1,7 @@ import asyncio import pytest -from sentry_sdk import start_transaction +from sentry_sdk import start_transaction, Hub from sentry_sdk.integrations.arq import ArqIntegration import arq.worker @@ -234,3 +234,21 @@ async def dummy_job(_): assert len(event["spans"]) assert event["spans"][0]["op"] == "queue.submit.arq" assert event["spans"][0]["description"] == "dummy_job" + + +@pytest.mark.asyncio +async def test_execute_job_without_integration(init_arq): + async def dummy_job(_ctx): + pass + + dummy_job.__qualname__ = dummy_job.__name__ + + pool, worker = init_arq([dummy_job]) + # remove the integration to trigger the edge case + Hub.current.client.integrations.pop("arq") + + job = await pool.enqueue_job("dummy_job") + + await worker.run_job(job.job_id, timestamp_ms()) + + assert await job.result() is None