1
- import { Fragment , memo , useCallback } from 'react' ;
1
+ import { Fragment , memo , useCallback , useMemo } from 'react' ;
2
2
import styled from '@emotion/styled' ;
3
3
4
4
import GridEditable , {
5
5
COL_WIDTH_UNDEFINED ,
6
6
type GridColumnHeader ,
7
7
type GridColumnOrder ,
8
8
} from 'sentry/components/gridEditable' ;
9
+ import ProjectBadge from 'sentry/components/idBadge/projectBadge' ;
10
+ import Link from 'sentry/components/links/link' ;
9
11
import Pagination from 'sentry/components/pagination' ;
12
+ import TimeSince from 'sentry/components/timeSince' ;
10
13
import { t } from 'sentry/locale' ;
11
14
import { space } from 'sentry/styles/space' ;
12
- import { useNavigate } from 'sentry/utils/useNavigate' ;
15
+ import { DiscoverDatasets } from 'sentry/utils/discover/types' ;
16
+ import getDuration from 'sentry/utils/duration/getDuration' ;
17
+ import { useLocation } from 'sentry/utils/useLocation' ;
18
+ import useOrganization from 'sentry/utils/useOrganization' ;
19
+ import usePageFilters from 'sentry/utils/usePageFilters' ;
20
+ import useProjects from 'sentry/utils/useProjects' ;
21
+ import { useTraces } from 'sentry/views/explore/hooks/useTraces' ;
13
22
import { HeadSortCell } from 'sentry/views/insights/agentMonitoring/components/headSortCell' ;
14
23
import { useColumnOrder } from 'sentry/views/insights/agentMonitoring/hooks/useColumnOrder' ;
24
+ import { getAITracesFilter } from 'sentry/views/insights/agentMonitoring/utils/query' ;
25
+ import { TraceViewSources } from 'sentry/views/performance/newTraceDetails/traceHeader/breadcrumbs' ;
26
+ import { getTraceDetailsUrl } from 'sentry/views/performance/traceDetails/utils' ;
15
27
16
28
interface TableData {
17
29
agentFlow : string ;
18
30
duration : number ;
19
31
errors : number ;
20
- timestamp : string ;
21
- tokens : string ;
22
- tools : number ;
32
+ project : string ;
33
+ timestamp : number ;
23
34
traceId : string ;
24
- user : string ;
25
35
}
26
36
27
37
const EMPTY_ARRAY : never [ ] = [ ] ;
28
38
29
39
const defaultColumnOrder : Array < GridColumnOrder < string > > = [
30
40
{ key : 'traceId' , name : t ( 'Trace ID' ) , width : 120 } ,
41
+ { key : 'project' , name : t ( 'Project' ) , width : 180 } ,
31
42
{ key : 'agentFlow' , name : t ( 'Agent Flow' ) , width : COL_WIDTH_UNDEFINED } ,
32
43
{ key : 'duration' , name : t ( 'Duration' ) , width : 100 } ,
33
44
{ key : 'errors' , name : t ( 'Errors' ) , width : 100 } ,
34
- { key : 'tokens' , name : t ( 'Tokens used' ) , width : 140 } ,
35
- { key : 'tools' , name : t ( 'Tool calls' ) , width : 120 } ,
36
- { key : 'user' , name : t ( 'User' ) , width : 120 } ,
37
45
{ key : 'timestamp' , name : t ( 'Timestamp' ) , width : 120 } ,
38
46
] ;
39
47
40
48
export function TracesTable ( ) {
41
- const navigate = useNavigate ( ) ;
42
49
const { columnOrder, onResizeColumn} = useColumnOrder ( defaultColumnOrder ) ;
43
50
44
- // TODO: Replace with actual request
45
- const tracesRequest = {
46
- data : [ ] ,
47
- isPending : false ,
48
- error : false ,
49
- pageLinks : null ,
50
- isPlaceholderData : false ,
51
- } ;
51
+ const tracesRequest = useTraces ( {
52
+ dataset : DiscoverDatasets . SPANS_EAP ,
53
+ query : `${ getAITracesFilter ( ) } ` ,
54
+ sort : '-timestamp' ,
55
+ limit : 10 ,
56
+ } ) ;
52
57
53
- const tableData = tracesRequest . data ;
58
+ const tableData = useMemo ( ( ) => {
59
+ if ( ! tracesRequest . data ) {
60
+ return [ ] ;
61
+ }
62
+
63
+ return tracesRequest . data . data . map ( span => ( {
64
+ traceId : span . trace ,
65
+ project : span . project ?? '' ,
66
+ agentFlow : span . name ?? '' ,
67
+ duration : span . duration ,
68
+ errors : span . numErrors ,
69
+ timestamp : span . start ,
70
+ } ) ) ;
71
+ } , [ tracesRequest . data ] ) ;
54
72
55
73
const renderHeadCell = useCallback ( ( column : GridColumnHeader < string > ) => {
56
74
return (
@@ -86,18 +104,7 @@ export function TracesTable() {
86
104
/>
87
105
{ tracesRequest . isPlaceholderData && < LoadingOverlay /> }
88
106
</ GridEditableContainer >
89
- < Pagination
90
- pageLinks = { tracesRequest . pageLinks }
91
- onCursor = { ( cursor , path , currentQuery ) => {
92
- navigate (
93
- {
94
- pathname : path ,
95
- query : { ...currentQuery , pathsCursor : cursor } ,
96
- } ,
97
- { replace : true , preventScrollReset : true }
98
- ) ;
99
- } }
100
- />
107
+ < Pagination pageLinks = { '#' } />
101
108
</ Fragment >
102
109
) ;
103
110
}
@@ -109,21 +116,48 @@ const BodyCell = memo(function BodyCell({
109
116
column : GridColumnHeader < string > ;
110
117
dataRow : TableData ;
111
118
} ) {
119
+ const location = useLocation ( ) ;
120
+ const organization = useOrganization ( ) ;
121
+ const { selection} = usePageFilters ( ) ;
122
+ const { projects} = useProjects ( ) ;
123
+
124
+ const project = useMemo (
125
+ ( ) => projects . find ( p => p . slug === dataRow . project ) ,
126
+ [ projects , dataRow . project ]
127
+ ) ;
128
+
129
+ const traceViewTarget = getTraceDetailsUrl ( {
130
+ eventId : dataRow . traceId ,
131
+ timestamp : dataRow . timestamp ,
132
+ source : TraceViewSources . SCREEN_LOADS_MODULE ,
133
+ organization,
134
+ location,
135
+ traceSlug : dataRow . traceId ,
136
+ dateSelection : {
137
+ start : selection . datetime . start ,
138
+ end : selection . datetime . end ,
139
+ statsPeriod : selection . datetime . period ,
140
+ } ,
141
+ } ) ;
142
+
112
143
switch ( column . key ) {
113
144
case 'traceId' :
114
- return dataRow . traceId ;
145
+ return < Link to = { traceViewTarget } > { dataRow . traceId . slice ( 0 , 8 ) } </ Link > ;
146
+ case 'project' :
147
+ return project ? (
148
+ < ProjectBadge project = { project } avatarSize = { 16 } />
149
+ ) : (
150
+ < ProjectBadge project = { { slug : dataRow . project } } avatarSize = { 16 } />
151
+ ) ;
152
+
115
153
case 'agentFlow' :
116
154
return dataRow . agentFlow ;
117
155
case 'duration' :
118
- return dataRow . duration ;
156
+ return getDuration ( dataRow . duration / 1000 , 2 , true ) ;
119
157
case 'errors' :
120
158
return dataRow . errors ;
121
- case 'tokens' :
122
- return dataRow . tokens ;
123
- case 'tools' :
124
- return dataRow . tools ;
125
- case 'user' :
126
- return dataRow . user ;
159
+ case 'timestamp' :
160
+ return < TimeSince unitStyle = "extraShort" date = { new Date ( dataRow . timestamp ) } /> ;
127
161
default :
128
162
return null ;
129
163
}
0 commit comments