Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7541460
ref(integrations): route HTTP header filtering through data collectio…
ericapisani Jul 8, 2026
5e9f610
Merge branch 'master' into py-2584-update-wsgi-filter-headers
ericapisani Jul 9, 2026
a590c8e
Make changes to adjust to the data collection option being within the…
ericapisani Jul 9, 2026
16ed0c8
fix test
ericapisani Jul 9, 2026
486f0bc
make sure host header is not filtered when being added to the url
ericapisani Jul 9, 2026
7d14a81
add test coverage for edge case around host header being dropped but …
ericapisani Jul 9, 2026
bb98334
add aws lambda test coverage
ericapisani Jul 9, 2026
61d1618
fix(aws-lambda): Remove vendored deps from new embedded-sdk test fixt…
ericapisani Jul 9, 2026
951c408
add test coverage within the wsgi test file
ericapisani Jul 9, 2026
a19be39
feat(integrations): apply data_collection cookie filtering to wsgi, s…
ericapisani Jul 10, 2026
620e222
fix(integrations): omit cookies field when data_collection cookies mo…
ericapisani Jul 10, 2026
ec6f520
update tornado test
ericapisani Jul 10, 2026
4dd3ba6
ref(integrations): route HTTP header filtering through data collectio…
ericapisani Jul 8, 2026
d0bae90
Make changes to adjust to the data collection option being within the…
ericapisani Jul 9, 2026
a6c4688
fix test
ericapisani Jul 9, 2026
d7b378b
make sure host header is not filtered when being added to the url
ericapisani Jul 9, 2026
52c2da1
add test coverage for edge case around host header being dropped but …
ericapisani Jul 9, 2026
aa645d7
add aws lambda test coverage
ericapisani Jul 9, 2026
8b6e3ad
fix(aws-lambda): Remove vendored deps from new embedded-sdk test fixt…
ericapisani Jul 9, 2026
d717172
add test coverage within the wsgi test file
ericapisani Jul 9, 2026
c7f590f
Merge branch 'py-2584-update-wsgi-filter-headers' of github.com:getse…
ericapisani Jul 14, 2026
293a291
feat(integrations): apply data_collection cookie filtering to wsgi, s…
ericapisani Jul 10, 2026
530e83c
fix(integrations): omit cookies field when data_collection cookies mo…
ericapisani Jul 10, 2026
326d796
update tornado test
ericapisani Jul 10, 2026
e9f0e20
Merge branch 'master' into py-2584-update-wsgi-filter-headers
ericapisani Jul 15, 2026
48f7c7b
Merge branch 'py-2581-cookies' of github.com:getsentry/sentry-python …
ericapisani Jul 15, 2026
621d79b
Merge branch 'py-2584-update-wsgi-filter-headers' into py-2581-cookies
ericapisani Jul 15, 2026
3d7bddb
test(aiohttp): Expect single span in streaming passthrough test
ericapisani Jul 15, 2026
fad2292
Merge branch 'py-2584-update-wsgi-filter-headers' into py-2581-cookies
ericapisani Jul 15, 2026
40d9f38
feat(wsgi): Apply data_collection filtering to URL query strings
ericapisani Jul 15, 2026
e6e7148
Merge branch 'py-2581-cookies' into py-2583-query-parameters
ericapisani Jul 15, 2026
1f9bce7
lint
ericapisani Jul 15, 2026
fad0c9a
Do not encode what is added to event/span attributes in order to conf…
ericapisani Jul 16, 2026
21cf40b
feat(asgi): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
3f0bc2a
lint
ericapisani Jul 16, 2026
eee4ea2
feat(aiohttp): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
3b17dd3
feat(tornado): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
96e0ac0
test(tornado): Use literal [Filtered] in query param expectations
ericapisani Jul 16, 2026
c3baf08
feat(sanic): Apply data_collection filtering to URL query strings
ericapisani Jul 17, 2026
ea22fc5
feat(quart): Apply data_collection filtering to URL query strings
ericapisani Jul 17, 2026
14652a9
feat(gcp): Apply data_collection filtering to URL query strings
ericapisani Jul 17, 2026
57ef596
feat(aws): Apply data_collection filtering to URL query strings
ericapisani Jul 17, 2026
6918529
lint
ericapisani Jul 17, 2026
0f58e13
feat(asgi): Gate client IP/user info behind data_collection config
ericapisani Jul 17, 2026
8c9f43d
Add starlette tests, fix potential unbound error
ericapisani Jul 20, 2026
a0bab66
fixes
ericapisani Jul 20, 2026
2ee7a87
eat(wsgi): Gate client IP/user info behind data_collection config
ericapisani Jul 21, 2026
18f8b31
wrong elif condition
ericapisani Jul 21, 2026
3854da7
set event scrubber to none
ericapisani Jul 21, 2026
7b85305
feat(flask): Gate user identity behind data_collection config
ericapisani Jul 21, 2026
066b45c
Merge branch 'master' into py-2583-query-params-sanic
ericapisani Jul 22, 2026
b4f5f65
.
ericapisani Jul 22, 2026
443b013
Merge branch 'py-2583-query-params-sanic' into py-2583-query-params-q…
ericapisani Jul 22, 2026
d0f22c5
.
ericapisani Jul 22, 2026
80e92f7
Merge branch 'py-2583-query-params-quart' into py-2583-gcp-query-params
ericapisani Jul 22, 2026
cf3ce53
.
ericapisani Jul 22, 2026
be03268
.
ericapisani Jul 22, 2026
c1c6ed6
Merge branch 'master' into py-2583-query-params-quart
ericapisani Jul 22, 2026
9e3d227
Merge branch 'py-2583-query-params-quart' into py-2583-gcp-query-params
ericapisani Jul 22, 2026
ed13f35
Merge branch 'py-2583-gcp-query-params' into py-2583-query-params-aws
ericapisani Jul 22, 2026
88784b0
.
ericapisani Jul 22, 2026
c0860c9
Merge branch 'py-2583-query-params-aws' into py-2586-gate-user-data
ericapisani Jul 22, 2026
997321c
Merge branch 'py-2586-gate-user-data' into py-2586-gate_user_data_wsgi
ericapisani Jul 22, 2026
cf79c37
Merge branch 'py-2586-gate_user_data_wsgi' into py-2586-flask
ericapisani Jul 22, 2026
7d15408
Merge branch 'master' into py-2586-flask
ericapisani Jul 22, 2026
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
19 changes: 16 additions & 3 deletions sentry_sdk/integrations/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
has_data_collection_enabled,
package_version,
)

Expand Down Expand Up @@ -142,7 +143,8 @@ def _set_transaction_name_and_source(


def _request_started(app: "Flask", **kwargs: "Any") -> None:
integration = sentry_sdk.get_client().get_integration(FlaskIntegration)
client = sentry_sdk.get_client()
integration = client.get_integration(FlaskIntegration)
if integration is None:
return

Expand All @@ -156,7 +158,13 @@ def _request_started(app: "Flask", **kwargs: "Any") -> None:

scope = sentry_sdk.get_isolation_scope()

if should_send_default_pii():
if has_data_collection_enabled(client.options):
if client.options["data_collection"]["user_info"]:
with capture_internal_exceptions():
user_properties = _get_flask_user_properties()
if user_properties:
scope.set_user(user_properties)
elif should_send_default_pii():
with capture_internal_exceptions():
user_properties = _get_flask_user_properties()
if user_properties:
Expand Down Expand Up @@ -208,7 +216,12 @@ def inner(event: "Event", hint: "dict[str, Any]") -> "Event":
with capture_internal_exceptions():
FlaskRequestExtractor(request).extract_into_event(event)

if should_send_default_pii():
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():
_add_user_to_event(event)
elif should_send_default_pii():
with capture_internal_exceptions():
_add_user_to_event(event)

Expand Down
7 changes: 6 additions & 1 deletion sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
event_from_exception,
exc_info_from_error,
format_attribute,
has_data_collection_enabled,
has_logs_enabled,
has_metrics_enabled,
logger,
Expand Down Expand Up @@ -1775,7 +1776,11 @@ def _apply_user_attributes_to_telemetry(
else:
attributes = telemetry._attributes

if not should_send_default_pii() or self._user is None:
client_options = sentry_sdk.get_client().options
if has_data_collection_enabled(client_options):
if not client_options["data_collection"]["user_info"] or self._user is None:
return
elif not should_send_default_pii() or self._user is None:
return

for attribute_name, user_attribute in (
Expand Down
102 changes: 102 additions & 0 deletions tests/integrations/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,3 +1521,105 @@ def crash():
(event,) = events

assert "ip_address" not in event.get("user", {})


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

class User:
is_authenticated = is_active = True
is_anonymous = False
email = "user@example.com"
username = "testuser"

def get_id(self):
return "42"

@login_manager.user_loader
def load_user(user_id):
return User()

@app.route("/login")
def login():
login_user(User())
return "ok"

@app.route("/crash")
def crash():
1 / 0

events = capture_events()

client = app.test_client()
assert client.get("/login").status_code == 200
with pytest.raises(ZeroDivisionError):
client.get("/crash")

(event,) = events

if expect_user:
assert event["user"]["id"] == "42"
assert event["user"]["email"] == "user@example.com"
assert event["user"]["username"] == "testuser"
else:
user = event.get("user", {})
assert "id" not in user
assert "email" not in user
assert "username" not in user


@pytest.mark.parametrize("init_kwargs, expect_user", USER_INFO_INIT_KWARGS)
def test_flask_login_user_identity_span_attributes_data_collection(
sentry_init, app, capture_items, init_kwargs, expect_user
):
init_kwargs = dict(init_kwargs)
experiments = init_kwargs.pop("_experiments", {})

sentry_init(
integrations=[flask_sentry.FlaskIntegration()],
traces_sample_rate=1.0,
trace_lifecycle="stream",
_experiments=experiments,
**init_kwargs,
)

class User:
is_authenticated = is_active = True
is_anonymous = False
email = "user@example.com"
username = "testuser"

def get_id(self):
return "42"

@login_manager.user_loader
def load_user(user_id):
return User()

@app.route("/login")
def login():
login_user(User())
return "ok"

items = capture_items("span")

client = app.test_client()
assert client.get("/login").status_code == 200
assert client.get("/message").status_code == 200

sentry_sdk.flush()

spans = [item.payload for item in items if item.type == "span"]
segment = next(s for s in spans if s["name"] == "hi")

if expect_user:
assert segment["attributes"]["user.id"] == "42"
assert segment["attributes"]["user.email"] == "user@example.com"
assert segment["attributes"]["user.name"] == "testuser"
else:
assert "user.id" not in segment.get("attributes", {})
assert "user.email" not in segment.get("attributes", {})
assert "user.name" not in segment.get("attributes", {})
Loading