1
+ import * as Sentry from '@sentry/react' ;
1
2
import trimStart from 'lodash/trimStart' ;
2
3
3
4
import type { PageFilters } from 'sentry/types/core' ;
@@ -14,7 +15,7 @@ import {decodeBoolean, decodeScalar, decodeSorts} from 'sentry/utils/queryString
14
15
import { MutableSearch } from 'sentry/utils/tokenizeSearch' ;
15
16
import normalizeUrl from 'sentry/utils/url/normalizeUrl' ;
16
17
import type { DashboardFilters , Widget } from 'sentry/views/dashboards/types' ;
17
- import { DisplayType } from 'sentry/views/dashboards/types' ;
18
+ import { DisplayType , WidgetType } from 'sentry/views/dashboards/types' ;
18
19
import {
19
20
applyDashboardFilters ,
20
21
eventViewFromWidget ,
@@ -29,9 +30,58 @@ import {
29
30
LOGS_QUERY_KEY ,
30
31
} from 'sentry/views/explore/contexts/logs/logsPageParams' ;
31
32
import { Mode } from 'sentry/views/explore/contexts/pageParamsContext/mode' ;
33
+ import { getLogsUrl } from 'sentry/views/explore/logs/utils' ;
34
+ import { TraceItemDataset } from 'sentry/views/explore/types' ;
32
35
import { getExploreMultiQueryUrl , getExploreUrl } from 'sentry/views/explore/utils' ;
33
36
import { ChartType } from 'sentry/views/insights/common/components/chart' ;
34
37
38
+ function getTraceItemDatasetFromWidgetType ( widgetType ?: WidgetType ) : TraceItemDataset {
39
+ switch ( widgetType ) {
40
+ case WidgetType . LOGS :
41
+ return TraceItemDataset . LOGS ;
42
+ case WidgetType . SPANS :
43
+ return TraceItemDataset . SPANS ;
44
+ default :
45
+ return TraceItemDataset . SPANS ; // Default to spans for backwards compatibility
46
+ }
47
+ }
48
+
49
+ function getWidgetExploreUrlWithDataset ( traceItemDataset : TraceItemDataset ) {
50
+ return (
51
+ widget : Widget ,
52
+ dashboardFilters : DashboardFilters | undefined ,
53
+ selection : PageFilters ,
54
+ organization : Organization ,
55
+ preferMode ?: Mode
56
+ ) => {
57
+ return _getWidgetExploreUrl (
58
+ widget ,
59
+ dashboardFilters ,
60
+ selection ,
61
+ organization ,
62
+ preferMode ,
63
+ undefined ,
64
+ traceItemDataset
65
+ ) ;
66
+ } ;
67
+ }
68
+
69
+ const WIDGET_TRACE_ITEM_TO_URL_FUNCTION : Record <
70
+ TraceItemDataset ,
71
+ | ( (
72
+ widget : Widget ,
73
+ dashboardFilters : DashboardFilters | undefined ,
74
+ selection : PageFilters ,
75
+ organization : Organization ,
76
+ preferMode ?: Mode
77
+ ) => string )
78
+ | undefined
79
+ > = {
80
+ [ TraceItemDataset . LOGS ] : getWidgetExploreUrlWithDataset ( TraceItemDataset . LOGS ) ,
81
+ [ TraceItemDataset . SPANS ] : getWidgetExploreUrlWithDataset ( TraceItemDataset . SPANS ) ,
82
+ [ TraceItemDataset . UPTIME_RESULTS ] : undefined ,
83
+ } ;
84
+
35
85
export function getWidgetLogURL (
36
86
widget : Widget ,
37
87
dashboardFilters : DashboardFilters | undefined ,
@@ -105,21 +155,39 @@ export function getWidgetExploreUrl(
105
155
organization : Organization ,
106
156
preferMode ?: Mode
107
157
) {
158
+ const traceItemDataset = getTraceItemDatasetFromWidgetType ( widget . widgetType ) ;
159
+
108
160
if ( widget . queries . length > 1 ) {
161
+ if ( traceItemDataset === TraceItemDataset . LOGS ) {
162
+ Sentry . captureException (
163
+ new Error (
164
+ `getWidgetExploreUrl: multiple queries for logs is unsupported, widget_id: ${ widget . id } , organization_id: ${ organization . id } , dashboard_id: ${ widget . dashboardId } `
165
+ )
166
+ ) ;
167
+ }
109
168
return _getWidgetExploreUrlForMultipleQueries (
110
169
widget ,
111
170
dashboardFilters ,
112
171
selection ,
113
- organization
172
+ organization ,
173
+ traceItemDataset
114
174
) ;
115
175
}
116
176
177
+ const urlFunction = WIDGET_TRACE_ITEM_TO_URL_FUNCTION [ traceItemDataset ] ;
178
+
179
+ if ( urlFunction ) {
180
+ return urlFunction ( widget , dashboardFilters , selection , organization , preferMode ) ;
181
+ }
182
+
117
183
return _getWidgetExploreUrl (
118
184
widget ,
119
185
dashboardFilters ,
120
186
selection ,
121
187
organization ,
122
- preferMode
188
+ preferMode ,
189
+ undefined ,
190
+ traceItemDataset
123
191
) ;
124
192
}
125
193
@@ -165,7 +233,8 @@ function _getWidgetExploreUrl(
165
233
selection : PageFilters ,
166
234
organization : Organization ,
167
235
preferMode ?: Mode ,
168
- overrideQuery ?: MutableSearch
236
+ overrideQuery ?: MutableSearch ,
237
+ traceItemDataset ?: TraceItemDataset
169
238
) {
170
239
const eventView = eventViewFromWidget ( widget . title , widget . queries [ 0 ] ! , selection ) ;
171
240
const locationQueryParams = eventView . generateQueryStringObject ( ) ;
@@ -287,6 +356,19 @@ function _getWidgetExploreUrl(
287
356
getWidgetInterval ( widget , selection . datetime ) ,
288
357
} ;
289
358
359
+ if ( traceItemDataset === TraceItemDataset . LOGS ) {
360
+ return getLogsUrl ( {
361
+ organization : queryParams . organization ,
362
+ selection : queryParams . selection ,
363
+ query : queryParams . query ,
364
+ field : queryParams . field ,
365
+ groupBy : queryParams . groupBy ,
366
+ aggregateFields : queryParams . visualize ,
367
+ interval : queryParams . interval ,
368
+ mode : queryParams . mode ,
369
+ } ) ;
370
+ }
371
+
290
372
return getExploreUrl ( queryParams ) ;
291
373
}
292
374
@@ -299,7 +381,8 @@ function _getWidgetExploreUrlForMultipleQueries(
299
381
widget : Widget ,
300
382
dashboardFilters : DashboardFilters | undefined ,
301
383
selection : PageFilters ,
302
- organization : Organization
384
+ organization : Organization ,
385
+ _traceItemDataset : TraceItemDataset
303
386
) : string {
304
387
const eventView = eventViewFromWidget ( widget . title , widget . queries [ 0 ] ! , selection ) ;
305
388
const locationQueryParams = eventView . generateQueryStringObject ( ) ;
0 commit comments