useTraceAverageTransactionDuration.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import type {Location} from 'history';
  2. import type {Organization} from 'sentry/types/organization';
  3. import {useDiscoverQuery} from 'sentry/utils/discover/discoverQuery';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  6. import type {TraceTree, TraceTreeNode} from '../traceModels/traceTree';
  7. type Props = {
  8. location: Location;
  9. node: TraceTreeNode<TraceTree.Transaction>;
  10. organization: Organization;
  11. };
  12. export const useTraceAverageTransactionDuration = ({
  13. node,
  14. location,
  15. organization,
  16. }: Props) => {
  17. const conditions = new MutableSearch('');
  18. conditions.setFilterValues('event.type', ['transaction']);
  19. conditions.setFilterValues(' transaction', [node.value.transaction]);
  20. const eventView = EventView.fromSavedQuery({
  21. id: undefined,
  22. name: `Average durations of transactions in the trace`,
  23. fields: ['title', 'avg(transaction.duration)'],
  24. orderby: '-title',
  25. query: conditions.formatString(),
  26. projects: [node.value.project_id],
  27. version: 2,
  28. start: undefined,
  29. end: undefined,
  30. range: '24h',
  31. });
  32. return useDiscoverQuery({
  33. eventView,
  34. location,
  35. orgSlug: organization.slug,
  36. });
  37. };