Skip to content

Commit b085d42

Browse files
committed
Only filter by app & title keys by default
Matching against url, editor payload keys, etc could be problematic. The existing rules are written against these two fields, as far as I can tell.
1 parent 8aaa353 commit b085d42

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

aw_transform/classify.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Rule:
1515
ignore_case: bool
1616

1717
def __init__(self, rules: Dict[str, Any]):
18-
self.select_keys = rules.get("select_keys", None)
18+
self.select_keys = rules.get("select_keys", ["app", "title"])
1919
self.ignore_case = rules.get("ignore_case", False)
2020

2121
# NOTE: Also checks that the regex isn't an empty string (which would erroneously match everything)
@@ -29,10 +29,15 @@ def __init__(self, rules: Dict[str, Any]):
2929
)
3030

3131
def match(self, e: Event) -> bool:
32-
if self.select_keys:
33-
values = [e.data.get(key, None) for key in self.select_keys]
34-
else:
32+
# `data` contains keys like 'app', 'title'
33+
# by default, the rule regex is matched against all values
34+
35+
if self.select_keys == 'all'
3536
values = list(e.data.values())
37+
elif self.select_keys:
38+
values = [e.data.get(key, None) for key in self.select_keys]
39+
40+
# although there is a `type` field on the rule name, right now the only valid type is regex
3641
if self.regex:
3742
for val in values:
3843
if isinstance(val, str) and self.regex.search(val):
@@ -45,6 +50,7 @@ def categorize(events: List[Event], classes: List[Tuple[Category, Rule]]):
4550

4651

4752
def _categorize_one(e: Event, classes: List[Tuple[Category, Rule]]) -> Event:
53+
# TODO can we add a color here too? why is color rendered on the frontend?
4854
e.data["$category"] = _pick_category(
4955
[_cls for _cls, rule in classes if rule.match(e)]
5056
)

0 commit comments

Comments
 (0)