useQueuesMetricsQuery.tsx 1.3 KB

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