From b642b90b158894b7ee3d411711130b96a5dfa6a4 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Tue, 25 Nov 2025 13:06:22 -0500 Subject: [PATCH] chore(trace-items): Add debug data to attribute items endpoint --- .../organization_trace_item_attributes.py | 113 +++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/src/sentry/api/endpoints/organization_trace_item_attributes.py b/src/sentry/api/endpoints/organization_trace_item_attributes.py index 8566abdbdf1d58..318edcf710a0cc 100644 --- a/src/sentry/api/endpoints/organization_trace_item_attributes.py +++ b/src/sentry/api/endpoints/organization_trace_item_attributes.py @@ -275,70 +275,75 @@ def get(self, request: Request, organization: Organization) -> Response: include_internal = is_active_superuser(request) or is_active_staff(request) def data_fn(offset: int, limit: int): - rpc_request = TraceItemAttributeNamesRequest( - meta=meta, - limit=limit, - page_token=PageToken(offset=offset), - type=attr_type, - value_substring_match=value_substring_match, - intersecting_attributes_filter=query_filter, - ) + with sentry_sdk.start_span(op="query", name="attribute_names") as span: + rpc_request = TraceItemAttributeNamesRequest( + meta=meta, + limit=limit, + page_token=PageToken(offset=offset), + type=attr_type, + value_substring_match=value_substring_match, + intersecting_attributes_filter=query_filter, + ) - with handle_query_errors(): - rpc_response = snuba_rpc.attribute_names_rpc(rpc_request) - - if use_sentry_conventions: - attribute_keys = {} - for attribute in rpc_response.attributes: - if attribute.name and can_expose_attribute( - attribute.name, - trace_item_type, - include_internal=include_internal, - ): - attr_key = as_attribute_key( + with handle_query_errors(): + rpc_response = snuba_rpc.attribute_names_rpc(rpc_request) + + if use_sentry_conventions: + attribute_keys = {} + for attribute in rpc_response.attributes: + if attribute.name and can_expose_attribute( attribute.name, - serialized["attribute_type"], trace_item_type, - ) - public_alias = attr_key["name"] - replacement = translate_to_sentry_conventions(public_alias, trace_item_type) - if public_alias != replacement: + include_internal=include_internal, + ): attr_key = as_attribute_key( - replacement, + attribute.name, serialized["attribute_type"], trace_item_type, ) - - attribute_keys[attr_key["name"]] = attr_key - - attributes = list(attribute_keys.values()) + public_alias = attr_key["name"] + replacement = translate_to_sentry_conventions( + public_alias, trace_item_type + ) + if public_alias != replacement: + attr_key = as_attribute_key( + replacement, + serialized["attribute_type"], + trace_item_type, + ) + + attribute_keys[attr_key["name"]] = attr_key + + attributes = list(attribute_keys.values()) + sentry_sdk.set_context("api_response", {"attributes": attributes}) + return attributes + + attributes = list( + filter( + lambda x: not is_sentry_convention_replacement_attribute( + x["name"], trace_item_type + ), + [ + as_attribute_key( + attribute.name, + serialized["attribute_type"], + trace_item_type, + ) + for attribute in rpc_response.attributes + if attribute.name + and can_expose_attribute( + attribute.name, + trace_item_type, + include_internal=include_internal, + ) + ], + ) + ) sentry_sdk.set_context("api_response", {"attributes": attributes}) + span.set_data("attribute_count", len(attributes)) + span.set_data("attribute_type", attribute_type) return attributes - attributes = list( - filter( - lambda x: not is_sentry_convention_replacement_attribute( - x["name"], trace_item_type - ), - [ - as_attribute_key( - attribute.name, - serialized["attribute_type"], - trace_item_type, - ) - for attribute in rpc_response.attributes - if attribute.name - and can_expose_attribute( - attribute.name, - trace_item_type, - include_internal=include_internal, - ) - ], - ) - ) - sentry_sdk.set_context("api_response", {"attributes": attributes}) - return attributes - return self.paginate( request=request, paginator=TraceItemAttributesNamesPaginator(data_fn=data_fn),