Skip to content

feat(replay): make user.geo fields searchable #91313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/sentry/replays/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ def _empty_uuids_lambda():
"user.email": ["user_email"],
"user.username": ["user_username"],
"user.ip": ["user_ip"],
"user.geo.city": ["user_geo_city"],
"user.geo.country_code": ["user_geo_country_code"],
"user.geo.region": ["user_geo_region"],
"user.geo.subdivision": ["user_geo_subdivision"],
"os.name": ["os_name"],
"os.version": ["os_version"],
"browser.name": ["browser_name"],
Expand Down Expand Up @@ -715,6 +719,10 @@ def _empty_uuids_lambda():
parameters=[anyIfNonZeroIP(column_name="ip_address_v4", aliased=False)],
alias="user_ip",
),
"user_geo_city": anyIf(column_name="user_geo_city"),
"user_geo_country_code": anyIf(column_name="user_geo_country_code"),
"user_geo_region": anyIf(column_name="user_geo_region"),
"user_geo_subdivision": anyIf(column_name="user_geo_subdivision"),
"os_name": anyIf(column_name="os_name"),
"os_version": anyIf(column_name="os_version"),
"browser_name": anyIf(column_name="browser_name"),
Expand Down
12 changes: 12 additions & 0 deletions src/sentry/replays/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def mock_expected_response(
"email": kwargs.pop("user_email", "username@example.com"),
"username": kwargs.pop("user_name", "username"),
"ip": kwargs.pop("user_ip", "127.0.0.1"),
"geo": {
"city": kwargs.pop("user_geo_city", "San Francisco"),
"country_code": kwargs.pop("user_geo_country_code", "USA"),
"region": kwargs.pop("user_geo_region", "United States"),
"subdivision": kwargs.pop("user_geo_subdivision", "California"),
},
},
"tags": kwargs.pop("tags", {}),
"activity": kwargs.pop("activity", 0),
Expand Down Expand Up @@ -180,6 +186,12 @@ def mock_replay(
"username": kwargs.pop("user_name", "username"),
"email": kwargs.pop("user_email", "username@example.com"),
"ip_address": kwargs.pop("ipv4", "127.0.0.1"),
"geo": {
"city": kwargs.pop("user_geo_city", "San Francisco"),
"country_code": kwargs.pop("user_geo_country_code", "USA"),
"region": kwargs.pop("user_geo_region", "United States"),
"subdivision": kwargs.pop("user_geo_subdivision", "California"),
},
},
"sdk": {
"name": kwargs.pop("sdk_name", "sentry.javascript.react"),
Expand Down
4 changes: 4 additions & 0 deletions src/sentry/replays/usecases/query/configs/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def array_string_field(column_name: str) -> StringColumnField:
"user.id": string_field("user_id"),
"user.ip_address": NullableStringColumnField("ip_address_v4", parse_ipv4, SumOfIPv4Scalar),
"user.username": string_field("user_name"),
"user.geo.city": string_field("user_geo_city"),
"user.geo.country_code": string_field("user_geo_country_code"),
"user.geo.region": string_field("user_geo_region"),
"user.geo.subdivision": string_field("user_geo_subdivision"),
"viewed_by_id": IntegerColumnField("viewed_by_id", parse_int, SumOfIntegerIdScalar),
"warning_ids": UUIDColumnField("warning_id", parse_uuid, SumOfUUIDScalar),
}
Expand Down
11 changes: 11 additions & 0 deletions tests/sentry/replays/test_organization_replay_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ def test_get_replays_user_filters(self):
"user.ip:127.0.0.1",
"user.ip:[127.0.0.1, 10.0.4.4]",
"!user.ip:[127.1.1.1, 10.0.4.4]",
'user.geo.city:"San Francisco"',
"user.geo.country_code:USA",
'user.geo.region:"United States"',
"user.geo.subdivision:California",
'user.geo.city:"San Francisco" AND user.geo.country_code:USA AND user.geo.region:"United States" AND user.geo.subdivision:California',
"sdk.name:sentry.javascript.react",
"os.name:macOS",
"os.version:15",
Expand Down Expand Up @@ -761,6 +766,12 @@ def test_get_replays_user_filters(self):
"seen_by_me:false",
"user.email:[user2@example.com]",
"!user.email:[username@example.com, user2@example.com]",
'!user.geo.city:"San Francisco"',
"!user.geo.country_code:USA",
'!user.geo.region:"United States"',
"!user.geo.subdivision:California",
'user.geo.city:"San Francisco" AND !user.geo.country_code:USA',
'!user.geo.subdivision:California OR !user.geo.region:"United States"',
]
for query in null_queries:
response = self.client.get(self.url + f"?field=id&query={query}")
Expand Down
Loading