6
6
7
7
import sentry_sdk
8
8
from sentry_protos .snuba .v1 .endpoint_get_trace_pb2 import GetTraceRequest
9
- from sentry_protos .snuba .v1 .endpoint_time_series_pb2 import TimeSeries , TimeSeriesRequest
9
+ from sentry_protos .snuba .v1 .endpoint_time_series_pb2 import (
10
+ Expression ,
11
+ TimeSeries ,
12
+ TimeSeriesRequest ,
13
+ )
10
14
from sentry_protos .snuba .v1 .request_common_pb2 import TraceItemType
11
- from sentry_protos .snuba .v1 .trace_item_attribute_pb2 import AttributeAggregation , AttributeKey
15
+ from sentry_protos .snuba .v1 .trace_item_attribute_pb2 import AttributeKey
12
16
from sentry_protos .snuba .v1 .trace_item_filter_pb2 import AndFilter , OrFilter , TraceItemFilter
13
17
14
18
from sentry .api .event_search import SearchFilter , SearchKey , SearchValue
23
27
from sentry .search .eap .resolver import SearchResolver
24
28
from sentry .search .eap .spans .definitions import SPAN_DEFINITIONS
25
29
from sentry .search .eap .types import CONFIDENCES , EAPResponse , SearchResolverConfig
30
+ from sentry .search .eap .utils import transform_binary_formula_to_expression
26
31
from sentry .search .events .fields import is_function
27
32
from sentry .search .events .types import EventsMeta , SnubaData , SnubaParams
28
33
from sentry .snuba import rpc_dataset_common
33
38
logger = logging .getLogger ("sentry.snuba.spans_rpc" )
34
39
35
40
41
+ def categorize_aggregate (
42
+ column : ResolvedAggregate | ResolvedConditionalAggregate | ResolvedFormula ,
43
+ ) -> Expression :
44
+ if isinstance (column , ResolvedFormula ):
45
+ # TODO: Remove when https://github.com/getsentry/eap-planning/issues/206 is merged, since we can use formulas in both APIs at that point
46
+ return Expression (
47
+ formula = transform_binary_formula_to_expression (column .proto_definition ),
48
+ label = column .public_alias ,
49
+ )
50
+ if isinstance (column , ResolvedAggregate ):
51
+ return Expression (aggregation = column .proto_definition , label = column .public_alias )
52
+ if isinstance (column , ResolvedConditionalAggregate ):
53
+ return Expression (
54
+ conditional_aggregation = column .proto_definition , label = column .public_alias
55
+ )
56
+
57
+
36
58
@dataclass
37
59
class ProcessedTimeseries :
38
60
timeseries : SnubaData = field (default_factory = list )
@@ -89,7 +111,7 @@ def get_timeseries_query(
89
111
resolver = get_resolver (params = params , config = config )
90
112
meta = resolver .resolve_meta (referrer = referrer )
91
113
query , _ , query_contexts = resolver .resolve_query (query_string )
92
- (aggregations , _ ) = resolver .resolve_functions (y_axes )
114
+ (functions , _ ) = resolver .resolve_functions (y_axes )
93
115
(groupbys , _ ) = resolver .resolve_attributes (groupby )
94
116
if extra_conditions is not None :
95
117
if query is not None :
@@ -101,19 +123,15 @@ def get_timeseries_query(
101
123
TimeSeriesRequest (
102
124
meta = meta ,
103
125
filter = query ,
104
- aggregations = [
105
- agg .proto_definition
106
- for agg in aggregations
107
- if isinstance (agg .proto_definition , AttributeAggregation )
108
- ],
126
+ expressions = [categorize_aggregate (fn ) for fn in functions if fn .is_aggregate ],
109
127
group_by = [
110
128
groupby .proto_definition
111
129
for groupby in groupbys
112
130
if isinstance (groupby .proto_definition , AttributeKey )
113
131
],
114
132
granularity_secs = granularity_secs ,
115
133
),
116
- aggregations ,
134
+ functions ,
117
135
groupbys ,
118
136
)
119
137
@@ -178,7 +196,7 @@ def run_timeseries_query(
178
196
)
179
197
180
198
if comparison_delta is not None :
181
- if len (rpc_request .aggregations ) != 1 :
199
+ if len (rpc_request .expressions ) != 1 :
182
200
raise InvalidSearchQuery ("Only one column can be selected for comparison queries" )
183
201
184
202
comp_query_params = params .copy ()
@@ -305,7 +323,7 @@ def run_top_events_timeseries_query(
305
323
params ,
306
324
query_string ,
307
325
y_axes ,
308
- [], # in the other series, we want eveything in a single group, so remove the group by
326
+ [], # in the other series, we want eveything in a single group, so the group by
309
327
referrer ,
310
328
config ,
311
329
granularity_secs ,
0 commit comments