2020 TraceItemType as ProtoTraceItemType ,
2121)
2222from sentry_protos .snuba .v1 .trace_item_attribute_pb2 import AttributeKey
23- from sentry_protos .snuba .v1 .trace_item_filter_pb2 import ExistsFilter , OrFilter , TraceItemFilter
23+ from sentry_protos .snuba .v1 .trace_item_filter_pb2 import (
24+ ExistsFilter ,
25+ OrFilter ,
26+ TraceItemFilter ,
27+ )
2428
2529from sentry import features , options
2630from sentry .api .api_owners import ApiOwner
5458from sentry .search .eap .resolver import SearchResolver
5559from sentry .search .eap .spans .definitions import SPAN_DEFINITIONS
5660from sentry .search .eap .trace_metrics .definitions import TRACE_METRICS_DEFINITIONS
57- from sentry .search .eap .types import SearchResolverConfig , SupportedTraceItemType
61+ from sentry .search .eap .types import (
62+ AttributeSourceType ,
63+ SearchResolverConfig ,
64+ SupportedTraceItemType ,
65+ )
5866from sentry .search .eap .utils import (
5967 can_expose_attribute ,
6068 get_secondary_aliases ,
7987POSSIBLE_ATTRIBUTE_TYPES = ["string" , "number" , "boolean" ]
8088
8189
90+ class ProxyResolvedAttribute (ResolvedAttribute ):
91+ pass
92+
93+
8294class TraceItemAttributeKey (TypedDict ):
8395 key : str
8496 name : str
@@ -218,6 +230,7 @@ def as_attribute_key(
218230 name : str ,
219231 attr_type : Literal ["string" , "number" , "boolean" ],
220232 item_type : SupportedTraceItemType ,
233+ is_proxy : bool = False ,
221234) -> TraceItemAttributeKey :
222235 public_key , public_name , attribute_source = translate_internal_to_public_alias (
223236 name , attr_type , item_type
@@ -237,7 +250,11 @@ def as_attribute_key(
237250 public_name = name
238251
239252 serialized_source : dict [str , str | bool ] = {
240- "source_type" : attribute_source ["source_type" ].value
253+ "source_type" : (
254+ attribute_source ["source_type" ].value
255+ if not is_proxy
256+ else AttributeSourceType .SENTRY .value
257+ )
241258 }
242259 if attribute_source .get ("is_transformed_alias" ):
243260 serialized_source ["is_transformed_alias" ] = True
@@ -378,15 +395,33 @@ def query_trace_attributes(
378395 all_aliased_attributes = []
379396 # our aliases don't exist in the db, so filter over our aliases
380397 # virtually page through defined aliases before we hit the db
381- if substring_match and offset <= len (column_definitions .columns ):
382- for index , column in enumerate (column_definitions .columns .values ()):
398+ if substring_match and offset <= len (column_definitions .columns ) + len (
399+ column_definitions .contexts
400+ ):
401+ for column in column_definitions .columns .values ():
383402 if (
384403 column .proto_type == attr_type
385404 and substring_match in column .public_alias
386405 and not column .secondary_alias
387406 and not column .private
388407 ):
389408 all_aliased_attributes .append (column )
409+ for (
410+ public_label ,
411+ virtual_context ,
412+ ) in column_definitions .contexts .items ():
413+ if (
414+ substring_match in public_label
415+ and virtual_context .search_type is not None
416+ and constants .TYPE_MAP [virtual_context .search_type ] == attr_type
417+ ):
418+ all_aliased_attributes .append (
419+ ProxyResolvedAttribute (
420+ public_alias = public_label ,
421+ internal_name = public_label ,
422+ search_type = virtual_context .search_type ,
423+ )
424+ )
390425 aliased_attributes = all_aliased_attributes [offset : offset + limit ]
391426 with sentry_sdk .start_span (op = "query" , name = "attribute_names" ) as span :
392427 if len (aliased_attributes ) < limit - 1 :
@@ -433,7 +468,7 @@ def serialize_trace_attributes_using_sentry_conventions(
433468 trace_item_type : SupportedTraceItemType ,
434469 include_internal : bool ,
435470 substring_match : str ,
436- aliased_attributes : list [ResolvedAttribute ],
471+ aliased_attributes : list [ResolvedAttribute | ProxyResolvedAttribute ],
437472 ) -> list [TraceItemAttributeKey ]:
438473 attribute_keys = {}
439474 for attribute in rpc_response .attributes :
@@ -462,6 +497,7 @@ def serialize_trace_attributes_using_sentry_conventions(
462497 aliased_attr .internal_name ,
463498 attribute_type ,
464499 trace_item_type ,
500+ is_proxy = isinstance (aliased_attr , ProxyResolvedAttribute ),
465501 )
466502 attribute_keys [attr_key ["name" ]] = attr_key
467503
@@ -476,7 +512,7 @@ def serialize_trace_attributes(
476512 trace_item_type : SupportedTraceItemType ,
477513 include_internal : bool ,
478514 substring_match : str ,
479- aliased_attributes : list [ResolvedAttribute ],
515+ aliased_attributes : list [ResolvedAttribute | ProxyResolvedAttribute ],
480516 ) -> list [TraceItemAttributeKey ]:
481517 attributes = list (
482518 filter (
@@ -513,6 +549,7 @@ def serialize_trace_attributes(
513549 aliased_attr .internal_name ,
514550 attribute_type ,
515551 trace_item_type ,
552+ is_proxy = isinstance (aliased_attr , ProxyResolvedAttribute ),
516553 )
517554 attributes .append (attr_key )
518555 return attributes
0 commit comments