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
26 changes: 4 additions & 22 deletions tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware, _looks_like_asgi3
from sentry_sdk.traces import SegmentNameSource
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES


@pytest.fixture
Expand Down Expand Up @@ -1029,36 +1030,17 @@ async def test_custom_transaction_name(


@pytest.mark.asyncio
@pytest.mark.parametrize(
"init_kwargs, expect_ip",
[
pytest.param(
{"data_collection": {}},
True,
id="dc_default_user_info",
),
pytest.param(
{"data_collection": {"user_info": True}},
True,
id="dc_user_info_true",
),
pytest.param(
{"data_collection": {"user_info": False}},
False,
id="dc_user_info_false",
),
],
)
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
async def test_user_ip_address_on_all_spans(
sentry_init,
capture_items,
init_kwargs,
data_collection,
expect_ip,
asgi3_app_with_span,
):
sentry_init(
traces_sample_rate=1.0,
**init_kwargs,
data_collection=data_collection,
)

app = SentryAsgiMiddleware(asgi3_app_with_span)
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/django/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sentry_sdk.integrations.django.asgi import _asgi_middleware_mixin_factory
from tests.integrations.django.myapp.asgi import channels_application
from tests.integrations.django.utils import pytest_mark_django_db_decorator
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES

try:
from django.urls import reverse
Expand Down Expand Up @@ -887,13 +887,13 @@ async def test_async_middleware_process_exception_is_awaited(
django.VERSION < (3, 0), reason="Django ASGI support shipped in 3.0"
)
@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
@pytest_mark_django_db_decorator()
async def test_user_identity_error_event_data_collection(
sentry_init, capture_events, application, init_kwargs, expect_user
sentry_init, capture_events, application, data_collection, expect_user
):
sentry_init(integrations=[DjangoIntegration()], **init_kwargs)
sentry_init(integrations=[DjangoIntegration()], data_collection=data_collection)
events = capture_events()

comm = HttpCommunicator(application, "GET", "/mylogin-with-exception")
Expand Down
30 changes: 13 additions & 17 deletions tests/integrations/django/test_data_scrubbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tests.conftest import unpack_werkzeug_response, werkzeug_set_cookie
from tests.integrations.django.myapp.wsgi import application
from tests.integrations.django.utils import pytest_mark_django_db_decorator
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES

try:
from django.urls import reverse
Expand Down Expand Up @@ -269,16 +269,14 @@ def test_empty_query_string_is_dropped_with_data_collection(

@pytest.mark.forked
@pytest_mark_django_db_decorator()
@pytest.mark.parametrize(
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
)
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
def test_user_info_span_attributes_data_collection(
sentry_init, client, capture_items, init_kwargs, expect_ip
sentry_init, client, capture_items, data_collection, expect_ip
):
sentry_init(
integrations=[DjangoIntegration()],
traces_sample_rate=1.0,
**init_kwargs,
data_collection=data_collection,
)

items = capture_items("span")
Expand All @@ -303,15 +301,15 @@ def test_user_info_span_attributes_data_collection(
@pytest.mark.forked
@pytest_mark_django_db_decorator()
@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
def test_user_identity_span_attributes_data_collection(
sentry_init, client, capture_items, init_kwargs, expect_user
sentry_init, client, capture_items, data_collection, expect_user
):
sentry_init(
integrations=[DjangoIntegration()],
traces_sample_rate=1.0,
**init_kwargs,
data_collection=data_collection,
)

unpack_werkzeug_response(client.get(reverse("mylogin")))
Expand All @@ -335,13 +333,11 @@ def test_user_identity_span_attributes_data_collection(

@pytest.mark.forked
@pytest_mark_django_db_decorator()
@pytest.mark.parametrize(
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
)
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
def test_user_info_error_event_data_collection(
sentry_init, client, capture_events, init_kwargs, expect_ip
sentry_init, client, capture_events, data_collection, expect_ip
):
sentry_init(integrations=[DjangoIntegration()], **init_kwargs)
sentry_init(integrations=[DjangoIntegration()], data_collection=data_collection)
events = capture_events()

client.get(reverse("view_exc"), environ_base={"REMOTE_ADDR": "127.0.0.1"})
Expand All @@ -359,12 +355,12 @@ def test_user_info_error_event_data_collection(
@pytest.mark.forked
@pytest_mark_django_db_decorator()
@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
def test_user_identity_error_event_data_collection(
sentry_init, client, capture_events, init_kwargs, expect_user
sentry_init, client, capture_events, data_collection, expect_user
):
sentry_init(integrations=[DjangoIntegration()], **init_kwargs)
sentry_init(integrations=[DjangoIntegration()], data_collection=data_collection)
events = capture_events()

client.get(reverse("mylogin"))
Expand Down
34 changes: 17 additions & 17 deletions tests/integrations/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES

# Query string used across the query-param filtering tests below. ``auth`` is a
# built-in sensitive term, so it is redacted by the default denylist.
Expand Down Expand Up @@ -1235,16 +1235,14 @@ def test_empty_query_string_is_dropped_with_data_collection(
assert "query_string" not in event["request"]


@pytest.mark.parametrize(
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
)
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
def test_user_info_span_attributes_data_collection(
sentry_init, app, capture_items, monkeypatch, init_kwargs, expect_ip
sentry_init, app, capture_items, monkeypatch, data_collection, expect_ip
):
sentry_init(
integrations=[flask_sentry.FlaskIntegration()],
traces_sample_rate=1.0,
**init_kwargs,
data_collection=data_collection,
)
# This test is about user IP collection, not flask_login. Disable
# flask_login so the module-level login manager does not interfere.
Expand All @@ -1268,13 +1266,13 @@ def test_user_info_span_attributes_data_collection(
assert "client.address" not in segment["attributes"]


@pytest.mark.parametrize(
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
)
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
def test_user_info_error_event_data_collection(
sentry_init, app, capture_events, monkeypatch, init_kwargs, expect_ip
sentry_init, app, capture_events, monkeypatch, data_collection, expect_ip
):
sentry_init(integrations=[flask_sentry.FlaskIntegration()], **init_kwargs)
sentry_init(
integrations=[flask_sentry.FlaskIntegration()], data_collection=data_collection
)
monkeypatch.setattr(flask_sentry, "flask_login", None)

@app.route("/crash")
Expand Down Expand Up @@ -1322,12 +1320,14 @@ def crash():


@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
def test_flask_login_user_identity_error_event_data_collection(
sentry_init, app, capture_events, init_kwargs, expect_user
sentry_init, app, capture_events, data_collection, expect_user
):
sentry_init(integrations=[flask_sentry.FlaskIntegration()], **init_kwargs)
sentry_init(
integrations=[flask_sentry.FlaskIntegration()], data_collection=data_collection
)

class User:
is_authenticated = is_active = True
Expand Down Expand Up @@ -1372,15 +1372,15 @@ def crash():


@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
def test_flask_login_user_identity_span_attributes_data_collection(
sentry_init, app, capture_items, init_kwargs, expect_user
sentry_init, app, capture_items, data_collection, expect_user
):
sentry_init(
integrations=[flask_sentry.FlaskIntegration()],
traces_sample_rate=1.0,
**init_kwargs,
data_collection=data_collection,
)

class User:
Expand Down
30 changes: 17 additions & 13 deletions tests/integrations/pyramid/test_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
from sentry_sdk.traces import SpanStatus
from tests.conftest import unpack_werkzeug_response
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES


def hi(request):
Expand Down Expand Up @@ -65,7 +65,7 @@ def inner():
def test_view_exceptions(
get_client, route, sentry_init, capture_events, capture_exceptions
):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})
events = capture_events()
exceptions = capture_exceptions()

Expand Down Expand Up @@ -133,6 +133,7 @@ def test_segment_name_and_source(
sentry_init(
integrations=[PyramidIntegration()],
traces_sample_rate=1.0,
data_collection={},
)

items = capture_items("event", "span")
Expand All @@ -157,6 +158,7 @@ def test_http_route(
sentry_init(
integrations=[PyramidIntegration()],
traces_sample_rate=1.0,
data_collection={},
)

items = capture_items("span")
Expand Down Expand Up @@ -308,7 +310,7 @@ def test_bad_request_not_captured(
):
import pyramid.httpexceptions as exc

sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})
events = capture_events()

@route("/")
Expand All @@ -329,7 +331,7 @@ def errorhandler(exc, request):
def test_errorhandler_ok(
sentry_init, pyramid_config, capture_exceptions, route, get_client
):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})
errors = capture_exceptions()

@route("/")
Expand All @@ -350,7 +352,7 @@ def errorhandler(exc, request):
def test_errorhandler_500(
sentry_init, pyramid_config, capture_exceptions, route, get_client
):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})
errors = capture_exceptions()

@route("/")
Expand All @@ -375,7 +377,7 @@ def errorhandler(exc, request):
def test_error_in_errorhandler(
sentry_init, pyramid_config, capture_events, route, get_client
):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})

@route("/")
def index(request):
Expand Down Expand Up @@ -452,7 +454,7 @@ def tween(request):


def test_tween_ok(sentry_init, pyramid_config, capture_exceptions, route, get_client):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})
errors = capture_exceptions()

@route("/")
Expand All @@ -479,6 +481,7 @@ def test_tracing_error(
sentry_init(
integrations=[PyramidIntegration()],
traces_sample_rate=1.0,
data_collection={},
)

items = capture_items("event", "span")
Expand Down Expand Up @@ -518,6 +521,7 @@ def test_span_origin(
sentry_init(
integrations=[PyramidIntegration()],
traces_sample_rate=1.0,
data_collection={},
)

items = capture_items("event", "span")
Expand All @@ -534,20 +538,20 @@ def test_span_origin(


@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
def test_span_sets_user_id_on_segment(
sentry_init,
pyramid_config,
capture_items,
get_client,
init_kwargs,
data_collection,
expect_user,
):
sentry_init(
integrations=[PyramidIntegration()],
traces_sample_rate=1.0,
**init_kwargs,
data_collection=data_collection,
)

class AuthenticationPolicy:
Expand Down Expand Up @@ -575,18 +579,18 @@ def authenticated_userid(self, request):


@pytest.mark.parametrize(
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
"data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES
)
def test_user_id_error_event_data_collection(
sentry_init,
pyramid_config,
capture_events,
route,
get_client,
init_kwargs,
data_collection,
expect_user,
):
sentry_init(integrations=[PyramidIntegration()], **init_kwargs)
sentry_init(integrations=[PyramidIntegration()], data_collection=data_collection)
events = capture_events()

class AuthenticationPolicy:
Expand Down
Loading
Loading