Skip to content
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

Make app.in_foreground searchable #43964

Merged
merged 9 commits into from
Feb 6, 2023
12 changes: 12 additions & 0 deletions src/sentry/rules/conditions/event_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"stacktrace.filename": Columns.STACK_FILENAME,
"stacktrace.abs_path": Columns.STACK_ABS_PATH,
"stacktrace.package": Columns.STACK_PACKAGE,
"app.in_foreground": Columns.APP_IN_FOREGROUND,
}


Expand Down Expand Up @@ -184,6 +185,17 @@ def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[str]:
if device is None:
device = []
return [device.get(path[1])]

elif path[0] == "app":
if path[1] in ("in_foreground"):
contexts = event.data["contexts"]
response = contexts.get("app")
if response is None:
response = {}
return [response.get(path[1])]

return []

return []

def render_label(self) -> str:
Expand Down
8 changes: 8 additions & 0 deletions src/sentry/snuba/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@ class Columns(Enum):
issue_platform_name="contexts.value",
alias="contexts.value",
)
APP_IN_FOREGROUND = Column(
group_name="events.contexts[app.in_foreground]",
event_name="contexts[app.in_foreground]",
transaction_name="contexts[app.in_foreground]",
discover_name="contexts[app.in_foreground]",
issue_platform_name="contexts[app.in_foreground]",
alias="app.in_foreground",
)
# Transactions specific columns
TRANSACTION_OP = Column(
group_name=None,
Expand Down
15 changes: 15 additions & 0 deletions tests/sentry/rules/conditions/test_event_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def get_event(self, **kwargs):
"screen_dpi": 123,
"screen_density": 2.5,
},
"app": {
"in_foreground": True,
},
},
}
data.update(kwargs)
Expand Down Expand Up @@ -727,3 +730,15 @@ def test_device_screen_density(self):
}
)
self.assertDoesNotPass(rule, event)

def test_app_in_foreground(self):
event = self.get_event()
rule = self.get_rule(
data={"match": MatchType.EQUAL, "attribute": "app.in_foreground", "value": "True"}
)
self.assertPasses(rule, event)

rule = self.get_rule(
data={"match": MatchType.EQUAL, "attribute": "app.in_foreground", "value": "False"}
)
self.assertDoesNotPass(rule, event)