useSpanMeta.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {Location} from 'history';
  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 {useSpansQuery} from 'sentry/views/starfish/utils/useSpansQuery';
  6. export type SpanMeta = {
  7. 'span.action': string;
  8. 'span.description': string;
  9. 'span.domain': string;
  10. 'span.op': string;
  11. };
  12. export const useSpanMeta = (
  13. group: string,
  14. queryFilters: {transactionName?: string} = {},
  15. referrer: string = 'span-metrics'
  16. ) => {
  17. const location = useLocation();
  18. return useSpansQuery<SpanMeta[]>({
  19. eventView: getEventView(group, location, queryFilters.transactionName),
  20. initialData: [],
  21. referrer,
  22. });
  23. };
  24. function getEventView(groupId, location: Location, transaction?: string) {
  25. return EventView.fromNewQueryWithLocation(
  26. {
  27. name: '',
  28. query: `span.group:${groupId}${transaction ? ` transaction:${transaction}` : ''}`,
  29. fields: ['span.op', 'span.description', 'span.action', 'span.domain', 'count()'], // TODO: Failing to pass a field like `count()` causes an error
  30. dataset: DiscoverDatasets.SPANS_METRICS,
  31. projects: [1],
  32. version: 2,
  33. },
  34. location
  35. );
  36. }