spanExamplesQuery.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 {SpanExample} from './types';
  9. type SpanExamplesProps = {
  10. spanGroup: string;
  11. spanOp: string;
  12. maxExclusiveTime?: string;
  13. minExclusiveTime?: string;
  14. };
  15. type RequestProps = DiscoverQueryProps & SpanExamplesProps;
  16. export type ChildrenProps = Omit<GenericChildrenProps<SpanExamplesProps>, 'tableData'> & {
  17. examples: SpanExample[] | null;
  18. };
  19. type Props = RequestProps & {
  20. children: (props: ChildrenProps) => React.ReactNode;
  21. };
  22. function getSuspectSpanPayload(props: RequestProps) {
  23. const {spanOp, spanGroup, minExclusiveTime, maxExclusiveTime} = props;
  24. const span =
  25. defined(spanOp) && defined(spanGroup) ? `${spanOp}:${spanGroup}` : undefined;
  26. const payload = defined(span)
  27. ? {span, min_exclusive_time: minExclusiveTime, max_exclusive_time: maxExclusiveTime}
  28. : {};
  29. const additionalPayload = omit(props.eventView.getEventsAPIPayload(props.location), [
  30. 'field',
  31. ]);
  32. return {...payload, ...additionalPayload};
  33. }
  34. function SuspectSpansQuery(props: Props) {
  35. return (
  36. <GenericDiscoverQuery<SpanExample[], SpanExamplesProps>
  37. route="events-spans"
  38. getRequestPayload={getSuspectSpanPayload}
  39. {...omit(props, 'children')}
  40. >
  41. {({tableData, ...rest}) => {
  42. return props.children({
  43. examples: tableData ?? null,
  44. ...rest,
  45. });
  46. }}
  47. </GenericDiscoverQuery>
  48. );
  49. }
  50. export default withApi(SuspectSpansQuery);