Browse Source

fix(on_demand): device model mapping (#59342)

Ogi 1 year ago
parent
commit
add14d55ef
2 changed files with 14 additions and 0 deletions
  1. 1 0
      src/sentry/snuba/metrics/extraction.py
  2. 13 0
      tests/sentry/snuba/test_extraction.py

+ 1 - 0
src/sentry/snuba/metrics/extraction.py

@@ -82,6 +82,7 @@ _SEARCH_TO_PROTOCOL_FIELDS = {
     "sdk.version": "sdk.version",
     # Subset of context fields
     "app.in_foreground": "contexts.app.in_foreground",
+    "device": "contexts.device.model",
     "device.arch": "contexts.device.arch",
     "device.battery_level": "contexts.device.battery_level",
     "device.brand": "contexts.device.brand",

+ 13 - 0
tests/sentry/snuba/test_extraction.py

@@ -180,6 +180,19 @@ def test_spec_simple_query_with_environment_only():
     assert spec.condition == {"name": "event.environment", "op": "eq", "value": "production"}
 
 
+def test_spec_context_mapping():
+    spec = OnDemandMetricSpec("count()", "device:SM-A226B")
+
+    assert spec._metric_type == "c"
+    assert spec.field_to_extract is None
+    assert spec.op == "sum"
+    assert spec.condition == {
+        "name": "event.contexts.device.model",
+        "op": "eq",
+        "value": "SM-A226B",
+    }
+
+
 def test_spec_query_with_parentheses_and_environment():
     spec = OnDemandMetricSpec(
         "count()", "(transaction.duration:>1s OR http.status_code:200)", "dev"