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
17 changes: 3 additions & 14 deletions sentry_sdk/integrations/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations._wsgi_common import RequestExtractor
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
has_data_collection_enabled,
package_version,
reraise,
)
Expand Down Expand Up @@ -92,12 +90,7 @@ def sentry_patched_call_view(

scope = sentry_sdk.get_isolation_scope()

if has_data_collection_enabled(client.options):
if client.options["data_collection"]["user_info"]:
user_id = request.authenticated_userid
if user_id:
scope.set_user({"id": user_id})
elif should_send_default_pii():
if client.options["data_collection"]["user_info"]:
user_id = request.authenticated_userid
if user_id:
scope.set_user({"id": user_id})
Expand Down Expand Up @@ -233,12 +226,8 @@ def pyramid_event_processor(event: "Event", hint: "Dict[str, Any]") -> "Event":
PyramidRequestExtractor(request).extract_into_event(event)

client_options = sentry_sdk.get_client().options
if has_data_collection_enabled(client_options):
if client_options["data_collection"]["user_info"]:
with capture_internal_exceptions():
user_info = event.setdefault("user", {})
user_info.setdefault("id", request.authenticated_userid)
elif should_send_default_pii():

if client_options["data_collection"]["user_info"]:
with capture_internal_exceptions():
user_info = event.setdefault("user", {})
user_info.setdefault("id", request.authenticated_userid)
Expand Down
15 changes: 10 additions & 5 deletions tests/integrations/pyramid/test_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def errors(request):


def test_has_context(route, get_client, sentry_init, capture_events):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})
events = capture_events()

@route("/context_message/{msg}")
Expand All @@ -110,7 +110,6 @@ def hi2(request):
"env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
"headers": {"Host": "localhost"},
"method": "GET",
"query_string": "",
"url": "http://localhost/context_message/yoo",
}
assert event["transaction"] == "hi2"
Expand Down Expand Up @@ -182,6 +181,7 @@ def test_large_json_request(
integrations=[PyramidIntegration()],
max_request_body_size="always",
max_value_length=max_value_length,
data_collection={},
)

data = {"foo": {"bar": "a" * (1034)}}
Expand Down Expand Up @@ -215,7 +215,7 @@ def index(request):

@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
def test_flask_empty_json_request(sentry_init, capture_events, route, get_client, data):
sentry_init(integrations=[PyramidIntegration()])
sentry_init(integrations=[PyramidIntegration()], data_collection={})

@route("/")
def index(request):
Expand All @@ -238,7 +238,11 @@ def index(request):
def test_json_not_truncated_if_max_request_body_size_is_always(
sentry_init, capture_events, route, get_client
):
sentry_init(integrations=[PyramidIntegration()], max_request_body_size="always")
sentry_init(
integrations=[PyramidIntegration()],
max_request_body_size="always",
data_collection={},
)

data = {
"key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10)
Expand Down Expand Up @@ -268,6 +272,7 @@ def test_files_and_form(
integrations=[PyramidIntegration()],
max_request_body_size="always",
max_value_length=max_value_length,
data_collection={},
)

data = {
Expand Down Expand Up @@ -403,11 +408,11 @@ def test_error_in_authenticated_userid(
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_init(
send_default_pii=True,
integrations=[
PyramidIntegration(),
LoggingIntegration(event_level=logging.ERROR),
],
data_collection={},
)
logger = logging.getLogger("test_pyramid")

Expand Down
Loading