useQueuesByTransactionQuery.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import type {Sort} from 'sentry/utils/discover/fields';
  2. import {decodeScalar} from 'sentry/utils/queryString';
  3. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import type {Referrer} from 'sentry/views/performance/queues/referrers';
  6. import {DEFAULT_QUERY_FILTER} from 'sentry/views/performance/queues/settings';
  7. import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  8. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  9. type Props = {
  10. referrer: Referrer;
  11. destination?: string;
  12. enabled?: boolean;
  13. sort?: Sort;
  14. };
  15. export function useQueuesByTransactionQuery({
  16. destination,
  17. enabled,
  18. sort,
  19. referrer,
  20. }: Props) {
  21. const location = useLocation();
  22. const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);
  23. const mutableSearch = new MutableSearch(DEFAULT_QUERY_FILTER);
  24. if (destination) {
  25. mutableSearch.addFilterValue('messaging.destination.name', destination);
  26. }
  27. const response = useSpanMetrics(
  28. {
  29. search: mutableSearch,
  30. fields: [
  31. 'transaction',
  32. 'span.op',
  33. 'count()',
  34. 'count_op(queue.publish)',
  35. 'count_op(queue.process)',
  36. 'sum(span.duration)',
  37. 'avg(span.duration)',
  38. 'avg_if(span.duration,span.op,queue.publish)',
  39. 'avg_if(span.duration,span.op,queue.process)',
  40. 'avg(messaging.message.receive.latency)',
  41. 'trace_status_rate(ok)',
  42. 'time_spent_percentage(app,span.duration)',
  43. ],
  44. enabled,
  45. sorts: sort ? [sort] : [],
  46. limit: 10,
  47. cursor,
  48. },
  49. referrer
  50. );
  51. return response;
  52. }