@@ -4,14 +4,12 @@ import styled from '@emotion/styled';
4
4
import { Select } from 'sentry/components/core/select' ;
5
5
import { t } from 'sentry/locale' ;
6
6
import { space } from 'sentry/styles/space' ;
7
- import type { TagCollection } from 'sentry/types/group' ;
8
7
import { defined } from 'sentry/utils' ;
9
8
import { parseFunction } from 'sentry/utils/discover/fields' ;
10
9
import {
11
10
AggregationKey ,
12
11
ALLOWED_EXPLORE_VISUALIZE_AGGREGATES ,
13
12
NO_ARGUMENT_SPAN_AGGREGATES ,
14
- prettifyTagKey ,
15
13
} from 'sentry/utils/fields' ;
16
14
import { Dataset , type EventTypes } from 'sentry/views/alerts/rules/metric/types' ;
17
15
import { getTraceItemTypeForDatasetAndEventType } from 'sentry/views/alerts/wizard/utils' ;
@@ -20,7 +18,10 @@ import {
20
18
updateVisualizeAggregate ,
21
19
} from 'sentry/views/explore/contexts/pageParamsContext/visualizes' ;
22
20
import { useTraceItemAttributes } from 'sentry/views/explore/contexts/traceItemAttributeContext' ;
23
- import type { OurLogsAggregate } from 'sentry/views/explore/logs/types' ;
21
+ import {
22
+ OurLogKnownFieldKey ,
23
+ type OurLogsAggregate ,
24
+ } from 'sentry/views/explore/logs/types' ;
24
25
import { TraceItemDataset } from 'sentry/views/explore/types' ;
25
26
26
27
const DEFAULT_EAP_AGGREGATION = 'count' ;
@@ -42,11 +43,21 @@ const SPAN_OPERATIONS = [
42
43
] ;
43
44
44
45
const LOG_OPERATIONS = [
45
- {
46
- label : AggregationKey . COUNT ,
47
- value : AggregationKey . COUNT ,
48
- } ,
49
- ] satisfies Array < { label : string ; value : OurLogsAggregate } > ;
46
+ AggregationKey . COUNT ,
47
+ AggregationKey . COUNT_UNIQUE ,
48
+ AggregationKey . SUM ,
49
+ AggregationKey . AVG ,
50
+ AggregationKey . P50 ,
51
+ AggregationKey . P75 ,
52
+ AggregationKey . P90 ,
53
+ AggregationKey . P95 ,
54
+ AggregationKey . P99 ,
55
+ AggregationKey . MIN ,
56
+ AggregationKey . MAX ,
57
+ ] . map ( aggregate => ( {
58
+ label : aggregate ,
59
+ value : aggregate as OurLogsAggregate ,
60
+ } ) ) satisfies Array < { label : string ; value : OurLogsAggregate } > ;
50
61
51
62
function EAPFieldWrapper ( { aggregate, onChange, eventTypes} : Props ) {
52
63
return < EAPField aggregate = { aggregate } onChange = { onChange } eventTypes = { eventTypes } /> ;
@@ -69,15 +80,8 @@ function EAPField({aggregate, onChange, eventTypes}: Props) {
69
80
70
81
const storedTags =
71
82
aggregation === AggregationKey . COUNT_UNIQUE ? storedStringTags : storedNumberTags ;
72
- const numberTags : TagCollection = useMemo ( ( ) => {
73
- const availableTags : TagCollection = storedTags ;
74
- if ( field && ! defined ( storedTags [ field ] ) ) {
75
- availableTags [ field ] = { key : field , name : prettifyTagKey ( field ) } ;
76
- }
77
- return availableTags ;
78
- } , [ field , storedTags ] ) ;
79
83
80
- const fieldsArray = Object . values ( numberTags ) ;
84
+ const fieldsArray = Object . values ( storedTags ) ;
81
85
82
86
// When using the async variant of SelectControl, we need to pass in an option object instead of just the value
83
87
const [ lockOptions , selectedOption ] = useMemo ( ( ) => {
@@ -105,7 +109,7 @@ function EAPField({aggregate, onChange, eventTypes}: Props) {
105
109
return ;
106
110
}
107
111
108
- const selectedMeta = field ? numberTags [ field ] : undefined ;
112
+ const selectedMeta = field ? storedTags [ field ] : undefined ;
109
113
if ( ! field || ! selectedMeta ) {
110
114
const newSelection = fieldsArray [ 0 ] ;
111
115
if ( newSelection ) {
@@ -114,29 +118,44 @@ function EAPField({aggregate, onChange, eventTypes}: Props) {
114
118
onChange ( DEFAULT_EAP_METRICS_ALERT_FIELD , { } ) ;
115
119
}
116
120
}
117
- } , [ lockOptions , onChange , aggregate , aggregation , field , numberTags , fieldsArray ] ) ;
121
+ } , [ lockOptions , onChange , aggregate , aggregation , field , storedTags , fieldsArray ] ) ;
118
122
119
123
const handleFieldChange = useCallback (
120
124
( option : any ) => {
121
- const selectedMeta = numberTags [ option . value ] ;
125
+ const selectedMeta = storedTags [ option . value ] ;
122
126
if ( ! selectedMeta ) {
123
127
return ;
124
128
}
125
129
onChange ( `${ aggregation } (${ selectedMeta . key } )` , { } ) ;
126
130
} ,
127
- [ numberTags , onChange , aggregation ]
131
+ [ storedTags , onChange , aggregation ]
128
132
) ;
129
133
130
134
const handleOperationChange = useCallback (
131
135
( option : any ) => {
132
- const newAggregate = updateVisualizeAggregate ( {
133
- newAggregate : option . value ,
134
- oldAggregate : aggregation || DEFAULT_EAP_AGGREGATION ,
135
- oldArgument : field || DEFAULT_EAP_FIELD ,
136
- } ) ;
136
+ let newAggregate : string ;
137
+ if ( traceItemType === TraceItemDataset . LOGS ) {
138
+ if ( [ AggregationKey . COUNT , AggregationKey . COUNT_UNIQUE ] . includes ( option . value ) ) {
139
+ newAggregate = `${ option . value } (${ OurLogKnownFieldKey . MESSAGE } )` ;
140
+ } else if ( NO_ARGUMENT_SPAN_AGGREGATES . includes ( option . value as AggregationKey ) ) {
141
+ newAggregate = `${ option . value } ()` ;
142
+ } else {
143
+ const argument =
144
+ field && defined ( storedNumberTags [ field ] )
145
+ ? field
146
+ : ( Object . values ( storedNumberTags ) ?. [ 0 ] ?. key ?? '' ) ;
147
+ newAggregate = `${ option . value } (${ argument } )` ;
148
+ }
149
+ } else {
150
+ newAggregate = updateVisualizeAggregate ( {
151
+ newAggregate : option . value ,
152
+ oldAggregate : aggregation || DEFAULT_EAP_AGGREGATION ,
153
+ oldArgument : field || DEFAULT_EAP_FIELD ,
154
+ } ) ;
155
+ }
137
156
onChange ( newAggregate , { } ) ;
138
157
} ,
139
- [ aggregation , field , onChange ]
158
+ [ aggregation , field , onChange , storedNumberTags , traceItemType ]
140
159
) ;
141
160
142
161
// As SelectControl does not support an options size limit out of the box
0 commit comments