suspectSpansQuery.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. maxExclusiveTime?: string;
  11. minExclusiveTime?: string;
  12. perSuspect?: number;
  13. spanGroups?: string[];
  14. spanOps?: string[];
  15. };
  16. type RequestProps = DiscoverQueryProps & SuspectSpansProps;
  17. export type ChildrenProps = Omit<GenericChildrenProps<SuspectSpansProps>, 'tableData'> & {
  18. suspectSpans: SuspectSpans | null;
  19. };
  20. type Props = RequestProps & {
  21. children: (props: ChildrenProps) => React.ReactNode;
  22. };
  23. function getSuspectSpanPayload(props: RequestProps) {
  24. const {perSuspect, spanOps, spanGroups, minExclusiveTime, maxExclusiveTime} = props;
  25. const payload = {
  26. perSuspect,
  27. spanOp: spanOps,
  28. spanGroup: spanGroups,
  29. min_exclusive_time: minExclusiveTime,
  30. max_exclusive_time: maxExclusiveTime,
  31. };
  32. if (!defined(payload.perSuspect)) {
  33. delete payload.perSuspect;
  34. }
  35. if (!defined(payload.spanOp)) {
  36. delete payload.spanOp;
  37. }
  38. if (!defined(payload.spanGroup)) {
  39. delete payload.spanGroup;
  40. }
  41. const additionalPayload = props.eventView.getEventsAPIPayload(props.location);
  42. return {
  43. ...payload,
  44. ...additionalPayload,
  45. };
  46. }
  47. function SuspectSpansQuery(props: Props) {
  48. return (
  49. <GenericDiscoverQuery<SuspectSpans, SuspectSpansProps>
  50. route="events-spans-performance"
  51. getRequestPayload={getSuspectSpanPayload}
  52. {...omit(props, 'children')}
  53. >
  54. {({tableData, ...rest}) => {
  55. return props.children({suspectSpans: tableData, ...rest});
  56. }}
  57. </GenericDiscoverQuery>
  58. );
  59. }
  60. export default withApi(SuspectSpansQuery);