Skip to content

Commit 4c557a6

Browse files
authored
feat(replays): Add replay.analyzer_service_url option (#59109)
1 parent d766d66 commit 4c557a6

File tree

5 files changed

+31
-54
lines changed

5 files changed

+31
-54
lines changed

src/sentry/conf/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,8 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
17031703
"organizations:session-replay-new-event-counts": False,
17041704
# Enable the Replay Details > New timeline
17051705
"organizations:session-replay-new-timeline": False,
1706+
# Enable the accessibility issues endpoint
1707+
"organizations:session-replay-accessibility-issues": False,
17061708
# Enable the new suggested assignees feature
17071709
"organizations:streamline-targeting-context": False,
17081710
# Enable the new experimental starfish view

src/sentry/features/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
default_manager.add("organizations:session-replay-new-event-counts", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
211211
default_manager.add("organizations:session-replay-weekly-email", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
212212
default_manager.add("organizations:session-replay-new-timeline", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
213+
default_manager.add("organizations:session-replay-accessibility-issues", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
213214
default_manager.add("organizations:set-grouping-config", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
214215
default_manager.add("organizations:slack-overage-notifications", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
215216
default_manager.add("organizations:sdk-crash-detection", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)

src/sentry/options/defaults.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@
381381
default=0,
382382
flags=FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
383383
)
384+
# Replay Analyzer service.
385+
register(
386+
"replay.analyzer_service_url",
387+
default=None,
388+
flags=FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
389+
)
384390

385391
# Analytics
386392
register("analytics.backend", default="noop", flags=FLAG_NOSTORE)

src/sentry/replays/endpoints/project_replay_accessibility_issues.py

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import uuid
55
from typing import Any
66

7-
# import requests
8-
# from rest_framework.exceptions import ParseError
7+
import requests
8+
from rest_framework.exceptions import ParseError
99
from rest_framework.request import Request
1010
from rest_framework.response import Response
1111

12-
from sentry import features
12+
from sentry import features, options
1313
from sentry.api.api_owners import ApiOwner
1414
from sentry.api.api_publish_status import ApiPublishStatus
1515
from sentry.api.base import region_silo_endpoint
@@ -37,6 +37,13 @@ def get(self, request: Request, project: Project, replay_id: str) -> Response:
3737
):
3838
return Response(status=404)
3939

40+
if not features.has(
41+
"organizations:session-replay-accessibility-issues",
42+
project.organization,
43+
actor=request.user,
44+
):
45+
return Response(status=404)
46+
4047
try:
4148
replay_id = str(uuid.UUID(replay_id))
4249
except ValueError:
@@ -78,53 +85,11 @@ def get_result(self, limit, cursor=None):
7885

7986

8087
def request_accessibility_issues(filenames: list[str]) -> Any:
81-
# TODO: Remove this once the service is ready.
82-
return {
83-
"meta": {"total": 1},
84-
"data": [
85-
{
86-
"elements": [
87-
{
88-
"alternatives": [
89-
{
90-
"id": "button-has-visible-text",
91-
"message": "Element does not have inner text that is visible to screen readers",
92-
},
93-
{
94-
"id": "aria-label",
95-
"message": "aria-label attribute does not exist or is empty",
96-
},
97-
{
98-
"id": "aria-labelledby",
99-
"message": "aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty",
100-
},
101-
{
102-
"id": "non-empty-title",
103-
"message": "Element has no title attribute",
104-
},
105-
{
106-
"id": "presentational-role",
107-
"message": 'Element\'s default semantics were not overridden with role="none" or role="presentation"',
108-
},
109-
],
110-
"element": '<button class="svelte-19ke1iv">',
111-
"target": ["button:nth-child(1)"],
112-
}
113-
],
114-
"help_url": "https://dequeuniversity.com/rules/axe/4.8/button-name?application=playwright",
115-
"help": "Buttons must have discernible text",
116-
"id": "button-name",
117-
"impact": "critical",
118-
"timestamp": 1695967678108,
119-
}
120-
],
121-
}
122-
# TODO: When the service is deploy this should be the primary path.
123-
# try:
124-
# return requests.post(
125-
# "/api/0/analyze/accessibility",
126-
# json={"data": {"filenames": filenames}},
127-
# ).json()
128-
# except Exception:
129-
# logger.exception("replay accessibility analysis failed")
130-
# raise ParseError("Could not analyze accessibility issues at this time.")
88+
try:
89+
return requests.post(
90+
f"{options.get('replay.analyzer_service_url')}/api/0/analyze/accessibility",
91+
json={"data": {"filenames": filenames}},
92+
).json()
93+
except Exception:
94+
logger.exception("replay accessibility analysis failed")
95+
raise ParseError("Could not analyze accessibility issues at this time.")

tests/sentry/replays/test_project_replay_accessibility_issues.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
from sentry.testutils.cases import APITestCase, ReplaysSnubaTestCase
99
from sentry.testutils.silo import region_silo_test
1010

11-
REPLAYS_FEATURES = {"organizations:session-replay": True}
11+
REPLAYS_FEATURES = {
12+
"organizations:session-replay": True,
13+
"organizations:session-replay-accessibility-issues": True,
14+
}
1215

1316

1417
@region_silo_test(stable=True)

0 commit comments

Comments
 (0)