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