Skip to content

Commit 34d9688

Browse files
committed
Set user properties on the scope using instead of
1 parent 662179a commit 34d9688

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

sentry_sdk/integrations/quart.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,22 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None:
210210
request_websocket.query_string.decode("utf-8", errors="replace"),
211211
)
212212

213-
current_user_id = _get_current_user_id_from_quart()
214-
if current_user_id:
215-
sentry_sdk.get_current_scope().set_attribute(
216-
"user.id", current_user_id
217-
)
218-
213+
user_properties = {}
219214
if len(request_websocket.access_route) >= 1:
220215
segment.set_attribute(
221216
"client.address", request_websocket.access_route[0]
222217
)
223218
segment.set_attribute(
224219
"user.ip_address", request_websocket.access_route[0]
225220
)
221+
user_properties["ip_address"] = request_websocket.access_route[0]
222+
223+
current_user_id = _get_current_user_id_from_quart()
224+
if current_user_id:
225+
user_properties["id"] = current_user_id
226+
227+
if user_properties:
228+
sentry_sdk.get_current_scope().set_user(user_properties)
226229

227230
evt_processor = _make_request_event_processor(app, request_websocket, integration)
228231
scope.add_event_processor(evt_processor)

tests/integrations/quart/test_quart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ async def login():
932932
segment = spans[1]
933933
if send_default_pii and user_id is not None:
934934
assert segment["attributes"]["user.id"] == user_id
935+
print("SEGMENT ATTRS", segment["attributes"])
935936
else:
936937
assert "user.id" not in segment.get("attributes", {})
937938

0 commit comments

Comments
 (0)