useErrorSamples.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {useDiscoverQuery} from 'sentry/utils/discover/discoverQuery';
  2. import type EventView from 'sentry/utils/discover/eventView';
  3. import type {QueryFieldValue} from 'sentry/utils/discover/fields';
  4. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. export default function useErrorSamples(eventView: EventView) {
  8. const location = useLocation();
  9. const organization = useOrganization();
  10. const columns: QueryFieldValue[] = [
  11. {
  12. field: 'timestamp',
  13. kind: 'field',
  14. },
  15. {
  16. field: 'http.status_code',
  17. kind: 'field',
  18. },
  19. {
  20. field: 'transaction.status',
  21. kind: 'field',
  22. },
  23. ];
  24. let errorSamplesEventView = eventView.clone();
  25. errorSamplesEventView.additionalConditions = new MutableSearch(
  26. 'http.status_code:[500,501,502,503,504,505,506,507,508,510,511]'
  27. );
  28. errorSamplesEventView = errorSamplesEventView.withColumns(columns).withSorts([
  29. {
  30. field: 'timestamp',
  31. kind: 'desc',
  32. },
  33. ]);
  34. const {isLoading, data} = useDiscoverQuery({
  35. eventView: errorSamplesEventView,
  36. referrer: 'starfish-transaction-summary-sample-events',
  37. location,
  38. orgSlug: organization.slug,
  39. limit: 6,
  40. });
  41. return {isLoading, data: data ? data.data : []};
  42. }