@@ -275,70 +275,75 @@ def get(self, request: Request, organization: Organization) -> Response:
275275 include_internal = is_active_superuser (request ) or is_active_staff (request )
276276
277277 def data_fn (offset : int , limit : int ):
278- rpc_request = TraceItemAttributeNamesRequest (
279- meta = meta ,
280- limit = limit ,
281- page_token = PageToken (offset = offset ),
282- type = attr_type ,
283- value_substring_match = value_substring_match ,
284- intersecting_attributes_filter = query_filter ,
285- )
278+ with sentry_sdk .start_span (op = "query" , name = "attribute_names" ) as span :
279+ rpc_request = TraceItemAttributeNamesRequest (
280+ meta = meta ,
281+ limit = limit ,
282+ page_token = PageToken (offset = offset ),
283+ type = attr_type ,
284+ value_substring_match = value_substring_match ,
285+ intersecting_attributes_filter = query_filter ,
286+ )
286287
287- with handle_query_errors ():
288- rpc_response = snuba_rpc .attribute_names_rpc (rpc_request )
289-
290- if use_sentry_conventions :
291- attribute_keys = {}
292- for attribute in rpc_response .attributes :
293- if attribute .name and can_expose_attribute (
294- attribute .name ,
295- trace_item_type ,
296- include_internal = include_internal ,
297- ):
298- attr_key = as_attribute_key (
288+ with handle_query_errors ():
289+ rpc_response = snuba_rpc .attribute_names_rpc (rpc_request )
290+
291+ if use_sentry_conventions :
292+ attribute_keys = {}
293+ for attribute in rpc_response .attributes :
294+ if attribute .name and can_expose_attribute (
299295 attribute .name ,
300- serialized ["attribute_type" ],
301296 trace_item_type ,
302- )
303- public_alias = attr_key ["name" ]
304- replacement = translate_to_sentry_conventions (public_alias , trace_item_type )
305- if public_alias != replacement :
297+ include_internal = include_internal ,
298+ ):
306299 attr_key = as_attribute_key (
307- replacement ,
300+ attribute . name ,
308301 serialized ["attribute_type" ],
309302 trace_item_type ,
310303 )
311-
312- attribute_keys [attr_key ["name" ]] = attr_key
313-
314- attributes = list (attribute_keys .values ())
304+ public_alias = attr_key ["name" ]
305+ replacement = translate_to_sentry_conventions (
306+ public_alias , trace_item_type
307+ )
308+ if public_alias != replacement :
309+ attr_key = as_attribute_key (
310+ replacement ,
311+ serialized ["attribute_type" ],
312+ trace_item_type ,
313+ )
314+
315+ attribute_keys [attr_key ["name" ]] = attr_key
316+
317+ attributes = list (attribute_keys .values ())
318+ sentry_sdk .set_context ("api_response" , {"attributes" : attributes })
319+ return attributes
320+
321+ attributes = list (
322+ filter (
323+ lambda x : not is_sentry_convention_replacement_attribute (
324+ x ["name" ], trace_item_type
325+ ),
326+ [
327+ as_attribute_key (
328+ attribute .name ,
329+ serialized ["attribute_type" ],
330+ trace_item_type ,
331+ )
332+ for attribute in rpc_response .attributes
333+ if attribute .name
334+ and can_expose_attribute (
335+ attribute .name ,
336+ trace_item_type ,
337+ include_internal = include_internal ,
338+ )
339+ ],
340+ )
341+ )
315342 sentry_sdk .set_context ("api_response" , {"attributes" : attributes })
343+ span .set_data ("attribute_count" , len (attributes ))
344+ span .set_data ("attribute_type" , attribute_type )
316345 return attributes
317346
318- attributes = list (
319- filter (
320- lambda x : not is_sentry_convention_replacement_attribute (
321- x ["name" ], trace_item_type
322- ),
323- [
324- as_attribute_key (
325- attribute .name ,
326- serialized ["attribute_type" ],
327- trace_item_type ,
328- )
329- for attribute in rpc_response .attributes
330- if attribute .name
331- and can_expose_attribute (
332- attribute .name ,
333- trace_item_type ,
334- include_internal = include_internal ,
335- )
336- ],
337- )
338- )
339- sentry_sdk .set_context ("api_response" , {"attributes" : attributes })
340- return attributes
341-
342347 return self .paginate (
343348 request = request ,
344349 paginator = TraceItemAttributesNamesPaginator (data_fn = data_fn ),
0 commit comments