import {Fragment} from 'react'; import GenericDiscoverQuery, { DiscoverQueryProps, } from 'sentry/utils/discover/genericDiscoverQuery'; import { BaseTraceChildrenProps, FullQuickTrace, TraceFull, TraceFullDetailed, TraceRequestProps, } from 'sentry/utils/performance/quickTrace/types'; import { getTraceRequestPayload, makeEventView, } from 'sentry/utils/performance/quickTrace/utils'; import withApi from 'sentry/utils/withApi'; type AdditionalQueryProps = { detailed?: boolean; eventId?: string; }; type TraceFullQueryChildrenProps = BaseTraceChildrenProps & Omit & { /** * The `event-trace` endpoint returns a full trace with the parent-child * relationships. It can be flattened into a `QuickTraceEvent` if necessary. */ traces: T | null; }; type QueryProps = Omit & AdditionalQueryProps & { children: (props: TraceFullQueryChildrenProps) => React.ReactNode; }; function getTraceFullRequestPayload({ detailed, eventId, ...props }: DiscoverQueryProps & AdditionalQueryProps) { const additionalApiPayload: any = getTraceRequestPayload(props); additionalApiPayload.detailed = detailed ? '1' : '0'; if (eventId) { additionalApiPayload.event_id = eventId; } return additionalApiPayload; } function EmptyTrace({children}: Pick, 'children'>) { return ( {children({ isLoading: false, error: null, traces: null, type: 'full', })} ); } function GenericTraceFullQuery({ traceId, start, end, statsPeriod, children, ...props }: QueryProps) { if (!traceId) { return >{children}; } const eventView = makeEventView({start, end, statsPeriod}); return ( route={`events-trace/${traceId}`} getRequestPayload={getTraceFullRequestPayload} eventView={eventView} {...props} > {({tableData, ...rest}) => children({ // This is using '||` instead of '??` here because // the client returns a empty string when the response // is 204. And we want the empty string, undefined and // null to be converted to null. traces: tableData || null, type: 'full', ...rest, }) } ); } export const TraceFullQuery = withApi( (props: Omit, 'detailed'>) => ( {...props} detailed={false} /> ) ); export const TraceFullDetailedQuery = withApi( (props: Omit, 'detailed'>) => ( {...props} detailed /> ) );