useSpanSamples.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {useDiscoverQuery} from 'sentry/utils/discover/discoverQuery';
  2. import EventView from 'sentry/utils/discover/eventView';
  3. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import type {IndexedSpan} from 'sentry/views/starfish/queries/types';
  7. import {SpanIndexedFields} from 'sentry/views/starfish/types';
  8. const DEFAULT_LIMIT = 10;
  9. const DEFAULT_ORDER_BY = '-duration';
  10. export function useSpanSamples(
  11. groupId?: string,
  12. transaction?: string,
  13. limit?: number,
  14. orderBy?: string,
  15. referrer: string = 'use-span-samples'
  16. ) {
  17. const location = useLocation();
  18. const organization = useOrganization();
  19. const eventView = EventView.fromNewQueryWithLocation(
  20. {
  21. name: 'Span Samples',
  22. query: `${groupId ? ` group:${groupId}` : ''} ${
  23. transaction ? ` transaction:${transaction}` : ''
  24. }`,
  25. fields: [
  26. 'span_id',
  27. 'group',
  28. 'action',
  29. 'description',
  30. 'domain',
  31. 'module',
  32. SpanIndexedFields.SPAN_SELF_TIME,
  33. 'op',
  34. 'transaction_id',
  35. 'timestamp',
  36. ],
  37. dataset: DiscoverDatasets.SPANS_INDEXED,
  38. orderby: orderBy ?? DEFAULT_ORDER_BY,
  39. projects: [1],
  40. version: 2,
  41. },
  42. location
  43. );
  44. const response = useDiscoverQuery({
  45. eventView,
  46. orgSlug: organization.slug,
  47. location,
  48. referrer,
  49. limit: limit ?? DEFAULT_LIMIT,
  50. });
  51. const data = (response.data?.data ?? []) as unknown as IndexedSpan[];
  52. const pageLinks = response.pageLinks;
  53. return {...response, data, pageLinks};
  54. }