spanCountHistogramQuery.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import omit from 'lodash/omit';
  2. import GenericDiscoverQuery, {
  3. DiscoverQueryProps,
  4. GenericChildrenProps,
  5. } from 'sentry/utils/discover/genericDiscoverQuery';
  6. import {DataFilter, HistogramData} from 'sentry/utils/performance/histogram/types';
  7. type HistogramProps = {
  8. numBuckets: number;
  9. spanOp: string;
  10. dataFilter?: DataFilter;
  11. max?: string;
  12. min?: string;
  13. precision?: number;
  14. };
  15. type RequestProps = DiscoverQueryProps & HistogramProps;
  16. export type HistogramQueryChildrenProps = Omit<
  17. GenericChildrenProps<HistogramProps>,
  18. 'tableData'
  19. > & {
  20. histogram: HistogramData | null;
  21. };
  22. type Props = RequestProps & {
  23. children: (props: HistogramQueryChildrenProps) => React.ReactNode;
  24. };
  25. function getHistogramRequestPayload(props: RequestProps) {
  26. const {spanOp, numBuckets, min, max, precision, dataFilter, eventView, location} =
  27. props;
  28. const baseApiPayload = {
  29. spanOp,
  30. numBuckets,
  31. min,
  32. max,
  33. precision,
  34. dataFilter,
  35. };
  36. const additionalApiPayload = omit(eventView.getEventsAPIPayload(location), [
  37. 'sort',
  38. 'per_page',
  39. 'cursor',
  40. ]);
  41. const apiPayload = {...baseApiPayload, ...additionalApiPayload};
  42. return apiPayload;
  43. }
  44. function SpanCountHistogramQuery(props: Props) {
  45. return (
  46. <GenericDiscoverQuery<HistogramData, HistogramProps>
  47. route="events-spans-counts-histogram"
  48. getRequestPayload={getHistogramRequestPayload}
  49. {...omit(props, 'children')}
  50. >
  51. {({tableData, ...rest}) => {
  52. return props.children({histogram: tableData, ...rest});
  53. }}
  54. </GenericDiscoverQuery>
  55. );
  56. }
  57. export default SpanCountHistogramQuery;