suspectSpansQuery.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import omit from 'lodash/omit';
  2. import {defined} from 'sentry/utils';
  3. import GenericDiscoverQuery, {
  4. DiscoverQueryProps,
  5. GenericChildrenProps,
  6. } from 'sentry/utils/discover/genericDiscoverQuery';
  7. import withApi from 'sentry/utils/withApi';
  8. import {SuspectSpans} from './types';
  9. type SuspectSpansProps = {
  10. perSuspect?: number;
  11. spanGroups?: string[];
  12. spanOps?: string[];
  13. };
  14. type RequestProps = DiscoverQueryProps & SuspectSpansProps;
  15. export type ChildrenProps = Omit<GenericChildrenProps<SuspectSpansProps>, 'tableData'> & {
  16. suspectSpans: SuspectSpans | null;
  17. };
  18. type Props = RequestProps & {
  19. children: (props: ChildrenProps) => React.ReactNode;
  20. };
  21. function getSuspectSpanPayload(props: RequestProps) {
  22. const {perSuspect, spanOps, spanGroups} = props;
  23. const payload = {perSuspect, spanOp: spanOps, spanGroup: spanGroups};
  24. if (!defined(payload.perSuspect)) {
  25. delete payload.perSuspect;
  26. }
  27. if (!defined(payload.spanOp)) {
  28. delete payload.spanOp;
  29. }
  30. if (!defined(payload.spanGroup)) {
  31. delete payload.spanGroup;
  32. }
  33. const additionalPayload = props.eventView.getEventsAPIPayload(props.location);
  34. return Object.assign(payload, additionalPayload);
  35. }
  36. function SuspectSpansQuery(props: Props) {
  37. return (
  38. <GenericDiscoverQuery<SuspectSpans, SuspectSpansProps>
  39. route="events-spans-performance"
  40. getRequestPayload={getSuspectSpanPayload}
  41. {...omit(props, 'children')}
  42. >
  43. {({tableData, ...rest}) => {
  44. return props.children({suspectSpans: tableData, ...rest});
  45. }}
  46. </GenericDiscoverQuery>
  47. );
  48. }
  49. export default withApi(SuspectSpansQuery);