Skip to content

Commit f06fa45

Browse files
authored
chore(seer rpc): Use public alias (#95559)
- Use public alias - Change return type to dict
1 parent cb40807 commit f06fa45

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

src/sentry/api/endpoints/seer_rpc.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from sentry.api.base import Endpoint, region_silo_endpoint
4242
from sentry.api.endpoints.organization_trace_item_attributes import as_attribute_key
4343
from sentry.constants import ENABLE_PR_REVIEW_TEST_GENERATION_DEFAULT
44+
from sentry.exceptions import InvalidSearchQuery
4445
from sentry.hybridcloud.rpc.service import RpcAuthenticationSetupException, RpcResolutionException
4546
from sentry.hybridcloud.rpc.sig import SerializableFunctionValueException
4647
from sentry.integrations.services.integration import integration_service
@@ -464,16 +465,36 @@ def get_attributes_and_values(
464465
)
465466
rpc_response = snuba_rpc.trace_item_stats_rpc(rpc_request)
466467

467-
attributes_and_values = [
468-
{
469-
attribute.attribute_name: [
470-
{"value": value.label, "count": value.value} for value in attribute.buckets
471-
]
472-
}
473-
for result in rpc_response.results
474-
for attribute in result.attribute_distributions.attributes
475-
if attribute.buckets
476-
]
468+
resolver = SearchResolver(
469+
params=SnubaParams(
470+
start=start,
471+
end=end,
472+
),
473+
config=SearchResolverConfig(),
474+
definitions=SPAN_DEFINITIONS,
475+
)
476+
477+
attributes_and_values: dict[str, list[dict[str, Any]]] = {}
478+
for result in rpc_response.results:
479+
for attribute in result.attribute_distributions.attributes:
480+
try:
481+
resolved_attribute, _ = resolver.resolve_attribute(attribute.attribute_name)
482+
attribute_name = resolved_attribute.public_alias
483+
except InvalidSearchQuery:
484+
attribute_name = attribute.attribute_name
485+
486+
if attribute.buckets:
487+
if attribute_name not in attributes_and_values:
488+
attributes_and_values[attribute_name] = []
489+
attributes_and_values[attribute_name].extend(
490+
[
491+
{
492+
"value": value.label,
493+
"count": value.value,
494+
}
495+
for value in attribute.buckets
496+
]
497+
)
477498

478499
return {"attributes_and_values": attributes_and_values}
479500

tests/snuba/api/endpoints/test_seer_attributes.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,16 @@ def test_get_attributes_and_values(self):
125125
)
126126

127127
assert result == {
128-
"attributes_and_values": [
129-
{
130-
"test_tag": [
131-
{"value": "foo", "count": 1.0},
132-
{"value": "baz", "count": 1.0},
133-
{"value": "bar", "count": 1.0},
134-
],
135-
},
136-
{
137-
"another_tag": [
138-
{"value": "another_value", "count": 1.0},
139-
],
140-
},
141-
]
128+
"attributes_and_values": {
129+
"test_tag": [
130+
{"value": "foo", "count": 1.0},
131+
{"value": "baz", "count": 1.0},
132+
{"value": "bar", "count": 1.0},
133+
],
134+
"another_tag": [
135+
{"value": "another_value", "count": 1.0},
136+
],
137+
},
142138
}
143139

144140
def test_get_attribute_values_with_substring_empty_field_list(self):

0 commit comments

Comments
 (0)