Skip to content

Commit a9cecaa

Browse files
authored
ref(grouping): Do preliminary typing work for enhancements (#87369)
As a first step towards adding types to the enhancements code, this makes a handful of code changes which will be necessary once types are added to all of the enhancements methods, which will happen in #87370.
1 parent 9dd7970 commit a9cecaa

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

src/sentry/grouping/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _get_enhancements(self, project: Project) -> str:
108108

109109
try:
110110
enhancements = Enhancements.from_config_string(
111-
project_enhancements, bases=[enhancements_base]
111+
project_enhancements, bases=[enhancements_base] if enhancements_base else []
112112
).dumps()
113113
except InvalidEnhancerConfig:
114114
enhancements = get_default_enhancements()
@@ -174,7 +174,7 @@ def get_default_enhancements(config_id: str | None = None) -> str:
174174
base: str | None = DEFAULT_GROUPING_ENHANCEMENTS_BASE
175175
if config_id is not None:
176176
base = CONFIGURATIONS[config_id].enhancements_base
177-
return Enhancements.from_config_string("", bases=[base]).dumps()
177+
return Enhancements.from_config_string("", bases=[base] if base else []).dumps()
178178

179179

180180
def get_projects_default_fingerprinting_bases(

src/sentry/grouping/enhancer/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def parse_rust_enhancements(
8282
raise InvalidEnhancerConfig(str(e))
8383

8484

85+
# TODO: Convert this into a typeddict in ophio
8586
RustExceptionData = dict[str, bytes | None]
8687

8788

@@ -97,7 +98,12 @@ def make_rust_exception_data(
9798
for key, value in e.items():
9899
if isinstance(value, str):
99100
e[key] = value.encode("utf-8")
100-
return e
101+
102+
return RustExceptionData(
103+
ty=e["ty"],
104+
value=e["value"],
105+
mechanism=e["mechanism"],
106+
)
101107

102108

103109
def is_valid_profiling_matcher(matchers: list[str]) -> bool:
@@ -155,7 +161,8 @@ def apply_category_and_updated_in_app_to_frames(
155161
also be persisted in the saved event, so they can be used in the UI and when determining
156162
things like suspect commits and suggested assignees.
157163
"""
158-
match_frames = [create_match_frame(frame, platform) for frame in frames]
164+
# TODO: Fix this type to list[MatchFrame] once it's fixed in ophio
165+
match_frames: list[Any] = [create_match_frame(frame, platform) for frame in frames]
159166

160167
category_and_in_app_results = self.rust_enhancements.apply_modifications_to_frames(
161168
match_frames, make_rust_exception_data(exception_data)
@@ -183,7 +190,8 @@ def assemble_stacktrace_component(
183190
184191
This also handles cases where the entire stacktrace should be discarded.
185192
"""
186-
match_frames = [create_match_frame(frame, platform) for frame in frames]
193+
# TODO: Fix this type to list[MatchFrame] once it's fixed in ophio
194+
match_frames: list[Any] = [create_match_frame(frame, platform) for frame in frames]
187195

188196
rust_frame_components = [RustComponent(contributes=c.contributes) for c in frame_components]
189197

src/sentry/grouping/enhancer/actions.py

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def _from_config_structure(cls, val, version: int):
6363
flag, range_direction = REVERSE_ACTION_FLAGS[val >> ACTION_BITSIZE]
6464
return FlagAction(ACTIONS[val & 0xF], flag, range_direction)
6565

66+
def _to_config_structure(self, version: int) -> int | list[str | int]:
67+
raise NotImplementedError()
68+
6669

6770
class FlagAction(EnhancementAction):
6871
"""

src/sentry/grouping/enhancer/matchers.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,28 @@ def create_match_frame(frame_data: dict, platform: str | None) -> dict:
105105

106106

107107
class EnhancementMatch:
108+
key: str
109+
pattern: str
110+
108111
def matches_frame(self, frames, idx, exception_data, cache):
109112
raise NotImplementedError()
110113

114+
@property
115+
def description(self) -> str:
116+
raise NotImplementedError()
117+
111118
def _to_config_structure(self, version):
112119
raise NotImplementedError()
113120

114121
@staticmethod
115122
def _from_config_structure(config_structure, version):
116123
val = config_structure
117124
if val.startswith("|[") and val.endswith("]"):
118-
return CalleeMatch(EnhancementMatch._from_config_structure(val[2:-1], version))
125+
frame_match: Any = EnhancementMatch._from_config_structure(val[2:-1], version)
126+
return CalleeMatch(frame_match)
119127
if val.startswith("[") and val.endswith("]|"):
120-
return CallerMatch(EnhancementMatch._from_config_structure(val[1:-2], version))
128+
frame_match = EnhancementMatch._from_config_structure(val[1:-2], version)
129+
return CallerMatch(frame_match)
121130

122131
if val.startswith("!"):
123132
negated = True
@@ -250,6 +259,9 @@ def __init__(self, key, pattern, negated=False):
250259
self._encoded_pattern = pattern.lower().encode("utf-8")
251260

252261
def _positive_frame_match(self, match_frame, exception_data, cache):
262+
if not self.field: # Shouldn't happen, but it keeps mypy happy
263+
return False
264+
253265
value = match_frame[self.field]
254266
if value is None:
255267
return False
@@ -289,6 +301,9 @@ def _positive_frame_match(self, match_frame, exception_data, cache):
289301

290302
class FrameFieldMatch(FrameMatch):
291303
def _positive_frame_match(self, match_frame, exception_data, cache):
304+
if not self.field: # Shouldn't happen, but it keeps mypy happy
305+
return False
306+
292307
value = match_frame[self.field]
293308
if value is None:
294309
return False

src/sentry/utils/glob.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
def glob_match(
5-
value: str | None,
6-
pat: str,
5+
value: str | bytes | None,
6+
pat: str | bytes,
77
doublestar: bool = False,
88
ignorecase: bool = False,
99
path_normalize: bool = False,

0 commit comments

Comments
 (0)