Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iambriccardo committed Nov 11, 2024
1 parent 1ff55bf commit 486bebc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sentry/snuba/metrics/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ def _map_field_name(search_key: str) -> str:
if resolved == "transaction_name":
transaction_field = _SEARCH_TO_PROTOCOL_FIELDS.get("transaction")
return f"event.{transaction_field}"

if resolved.startswith("tags["):
stripped_search_key = resolved[5:-1]
# In case a field is identified as a tag but the stripped search key is matching
Expand Down
20 changes: 20 additions & 0 deletions tests/sentry/snuba/metrics/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ def test_spec_context_mapping() -> None:
}


def test_spec_tags_mapping() -> None:
spec = OnDemandMetricSpec(
"count()",
"tags[os]:Mac OR os:Windows OR tags[device.family]:Computer OR device.family:Laptop",
)

assert spec._metric_type == "c"
assert spec.field_to_extract is None
assert spec.op == "sum"
assert spec.condition == {
"inner": [
{"name": "event.contexts.os", "op": "eq", "value": "Mac"},
{"name": "event.contexts.os", "op": "eq", "value": "Windows"},
{"name": "event.contexts.device.family", "op": "eq", "value": "Computer"},
{"name": "event.contexts.device.family", "op": "eq", "value": "Laptop"},
],
"op": "or",
}


def test_spec_query_or_precedence_with_environment() -> None:
spec_1 = OnDemandMetricSpec(
"count()",
Expand Down

0 comments on commit 486bebc

Please sign in to comment.