|
41 | 41 | from sentry.api.base import Endpoint, region_silo_endpoint
|
42 | 42 | from sentry.api.endpoints.organization_trace_item_attributes import as_attribute_key
|
43 | 43 | from sentry.constants import ENABLE_PR_REVIEW_TEST_GENERATION_DEFAULT
|
| 44 | +from sentry.exceptions import InvalidSearchQuery |
44 | 45 | from sentry.hybridcloud.rpc.service import RpcAuthenticationSetupException, RpcResolutionException
|
45 | 46 | from sentry.hybridcloud.rpc.sig import SerializableFunctionValueException
|
46 | 47 | from sentry.integrations.services.integration import integration_service
|
@@ -464,16 +465,36 @@ def get_attributes_and_values(
|
464 | 465 | )
|
465 | 466 | rpc_response = snuba_rpc.trace_item_stats_rpc(rpc_request)
|
466 | 467 |
|
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 | + ) |
477 | 498 |
|
478 | 499 | return {"attributes_and_values": attributes_and_values}
|
479 | 500 |
|
|
0 commit comments