Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions sentry_sdk/integrations/rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.scope import Scope
from sentry_sdk.traces import SegmentNameSource
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
capture_internal_exceptions,
event_from_exception,
format_timestamp,
has_data_collection_enabled,
parse_version,
)

Expand Down Expand Up @@ -161,16 +159,9 @@ def event_processor(event: "Event", hint: "dict[str, Any]") -> "Event":
}

client_options = sentry_sdk.get_client().options
if has_data_collection_enabled(client_options):
if client_options["data_collection"]["queues"]:
rq_job["args"] = job.args
rq_job["kwargs"] = job.kwargs
elif should_send_default_pii():
if client_options["data_collection"]["queues"]:
rq_job["args"] = job.args
rq_job["kwargs"] = job.kwargs
else:
rq_job["args"] = SENSITIVE_DATA_SUBSTITUTE
rq_job["kwargs"] = SENSITIVE_DATA_SUBSTITUTE

if job.enqueued_at:
rq_job["enqueued_at"] = format_timestamp(job.enqueued_at)
Expand Down
39 changes: 18 additions & 21 deletions tests/integrations/rq/test_rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import sentry_sdk
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.rq import RqIntegration
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE, parse_version
from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES_LEGACY
from sentry_sdk.utils import parse_version
from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -47,15 +47,13 @@ def do_trick(dog, trick):
return "{}, can you {}? Good dog!".format(dog, trick)


@pytest.mark.parametrize("send_default_pii", [True, False])
def test_basic(
sentry_init,
capture_items,
send_default_pii,
):
sentry_init(
integrations=[RqIntegration()],
send_default_pii=send_default_pii,
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand All @@ -73,12 +71,8 @@ def test_basic(
assert exception["stacktrace"]["frames"][-1]["vars"]["foo"] == "42"

extra = event["extra"]["rq-job"]
if send_default_pii:
assert extra["args"] == []
assert extra["kwargs"] == {"foo": 42}
else:
assert extra["args"] == SENSITIVE_DATA_SUBSTITUTE
assert extra["kwargs"] == SENSITIVE_DATA_SUBSTITUTE
assert extra["args"] == []
assert extra["kwargs"] == {"foo": 42}
assert extra["description"] == "tests.integrations.rq.test_rq.crashing_job(foo=42)"
assert extra["func"] == "tests.integrations.rq.test_rq.crashing_job"
assert "job_id" in extra
Expand All @@ -90,19 +84,19 @@ def test_basic(


@pytest.mark.parametrize(
"init_kwargs,expected_args,expected_kwargs",
DATA_COLLECTION_QUEUES_CASES_LEGACY,
"data_collection,expected_args,expected_kwargs",
DATA_COLLECTION_QUEUES_CASES,
)
def test_job_args_kwargs_data_collection(
sentry_init,
capture_items,
init_kwargs,
data_collection,
expected_args,
expected_kwargs,
):
sentry_init(
integrations=[RqIntegration()],
**init_kwargs,
data_collection=data_collection,
)

queue = rq.Queue(connection=FakeRedis())
Expand Down Expand Up @@ -130,6 +124,7 @@ def test_transport_shutdown(
):
sentry_init(
integrations=[RqIntegration()],
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand All @@ -147,16 +142,14 @@ def test_transport_shutdown(
assert exception["type"] == "ZeroDivisionError"


@pytest.mark.parametrize("send_default_pii", [True, False])
def test_worker_span_with_error(
sentry_init,
capture_items,
send_default_pii,
):
sentry_init(
integrations=[RqIntegration()],
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand Down Expand Up @@ -201,6 +194,7 @@ def test_error_has_trace_context_if_tracing_disabled(
):
sentry_init(
integrations=[RqIntegration()],
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand All @@ -222,6 +216,7 @@ def test_tracing_enabled(
sentry_init(
integrations=[RqIntegration()],
traces_sample_rate=1.0,
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand Down Expand Up @@ -262,6 +257,7 @@ def test_tracing_disabled(
):
sentry_init(
integrations=[RqIntegration()],
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand All @@ -276,16 +272,14 @@ def test_tracing_disabled(
assert error_event["contexts"]["trace"]["trace_id"]


@pytest.mark.parametrize("send_default_pii", [True, False])
def test_worker_span_no_error(
sentry_init,
capture_items,
send_default_pii,
):
sentry_init(
integrations=[RqIntegration()],
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand Down Expand Up @@ -315,6 +309,7 @@ def test_traces_sampler_gets_correct_values_in_sampling_context(
sentry_init(
integrations=[RqIntegration()],
traces_sampler=traces_sampler,
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand Down Expand Up @@ -350,6 +345,7 @@ def test_job_with_retries(
):
sentry_init(
integrations=[RqIntegration()],
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand All @@ -370,6 +366,7 @@ def test_span_origin(
sentry_init(
integrations=[RqIntegration()],
traces_sample_rate=1.0,
data_collection={},
)

queue = rq.Queue(connection=FakeRedis())
Expand Down
Loading