useTraceAverageTransactionDuration.tsx 1.2 KB

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