Skip to content

Commit 650d74a

Browse files
c298leearmenzg
authored andcommitted
ref(replay): Rage click clicked element name (#70493)
Since we now use react component names in the selector path, we should modify clicked element to provide more specific info such as class, role etc. This prevents giving the react component name twice and would give more info for debugging since react component names aren't very specific Before: <img width="845" alt="image" src="https://github.com/getsentry/sentry/assets/55311782/87b6c8cd-1b29-40bb-b448-715595cb255b">
1 parent 91bd6e0 commit 650d74a

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

src/sentry/replays/usecases/ingest/issue_creation.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def report_rage_click_issue_with_replay_event(
3232
timestamp_utc = date.replace(tzinfo=datetime.UTC)
3333

3434
selector = selector
35-
clicked_element = selector.split(" > ")[-1]
35+
clicked_element = _make_clicked_element(node)
3636
component_name = component_name
3737
evidence = [
3838
IssueEvidence(name="Clicked Element", value=clicked_element, important=False),
@@ -110,3 +110,27 @@ def _make_tags(replay_id, url, replay_event):
110110
tags.update(replay_event["tags"])
111111

112112
return tags
113+
114+
115+
def _make_clicked_element(node):
116+
element = node.get("tagName", "")
117+
if "attributes" in node:
118+
for key, value in node["attributes"].items():
119+
if key == "id":
120+
element += f"#{value}"
121+
elif key == "class":
122+
element = element + "." + ".".join(value.split(" "))
123+
elif key == "role":
124+
element += f'[role="{value}"]'
125+
elif key == "alt":
126+
element += f'[alt="{value}"]'
127+
elif key == "data-test-id" or key == "data-testid":
128+
element += f'[data-test-id="{value}"]'
129+
elif key == "aria-label":
130+
element += f'[aria="{value}"]'
131+
elif key == "title":
132+
element += f'[title="{value}"]'
133+
elif key == "data-sentry-component":
134+
element += f'[data-sentry-component="{value}"]'
135+
136+
return element

tests/sentry/replays/unit/test_issue_creation.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,66 @@ def test_report_rage_click_issue_with_replay_event(mock_new_issue_occurrence, de
2323
report_rage_click_issue_with_replay_event(
2424
project_id=default_project.id,
2525
replay_id=replay_id,
26-
selector="div.xyz > a",
26+
selector="div.xyz > SmartSearchBar",
2727
timestamp=seq1_timestamp.timestamp(),
2828
url="https://www.sentry.io",
29-
node={"tagName": "a"},
29+
node={
30+
"tagName": "a",
31+
"attributes": {
32+
"id": "id",
33+
"class": "class1 class2",
34+
"role": "button",
35+
"aria-label": "test",
36+
"alt": "1",
37+
"data-testid": "2",
38+
"title": "3",
39+
"data-sentry-component": "SignUpForm",
40+
},
41+
},
3042
component_name="SmartSearchBar",
3143
replay_event=mock_replay_event(),
3244
)
3345
issue_occurence_call = mock_new_issue_occurrence.call_args[1]
3446
assert issue_occurence_call["culprit"] == "https://www.sentry.io"
3547
assert issue_occurence_call["environment"] == "production"
36-
assert issue_occurence_call["fingerprint"] == ["div.xyz > a"]
48+
assert issue_occurence_call["fingerprint"] == ["div.xyz > SmartSearchBar"]
3749
assert issue_occurence_call["issue_type"].type_id == 5002
3850
assert issue_occurence_call["level"] == "error"
3951
assert issue_occurence_call["platform"] == "javascript"
4052
assert issue_occurence_call["project_id"] == default_project.id
41-
assert issue_occurence_call["subtitle"] == "div.xyz > a"
53+
assert issue_occurence_call["subtitle"] == "div.xyz > SmartSearchBar"
4254
assert issue_occurence_call["title"] == "Rage Click"
4355
assert issue_occurence_call["evidence_data"] == {
44-
"node": {"tagName": "a"},
45-
"selector": "div.xyz > a",
56+
"node": {
57+
"tagName": "a",
58+
"attributes": {
59+
"id": "id",
60+
"class": "class1 class2",
61+
"role": "button",
62+
"aria-label": "test",
63+
"alt": "1",
64+
"data-testid": "2",
65+
"title": "3",
66+
"data-sentry-component": "SignUpForm",
67+
},
68+
},
69+
"selector": "div.xyz > SmartSearchBar",
4670
"component_name": "SmartSearchBar",
4771
}
4872

4973
assert (
5074
issue_occurence_call["evidence_display"][0].to_dict()
51-
== IssueEvidence(name="Clicked Element", value="a", important=False).to_dict()
75+
== IssueEvidence(
76+
name="Clicked Element",
77+
value='a#id.class1.class2[role="button"][aria="test"][alt="1"][data-test-id="2"][title="3"][data-sentry-component="SignUpForm"]',
78+
important=False,
79+
).to_dict()
5280
)
5381
assert (
5482
issue_occurence_call["evidence_display"][1].to_dict()
55-
== IssueEvidence(name="Selector Path", value="div.xyz > a", important=False).to_dict()
83+
== IssueEvidence(
84+
name="Selector Path", value="div.xyz > SmartSearchBar", important=False
85+
).to_dict()
5686
)
5787
assert (
5888
issue_occurence_call["evidence_display"][2].to_dict()

0 commit comments

Comments
 (0)