useSpanById.ts 750 B

1234567891011121314151617181920212223242526272829
  1. import {useQuery} from 'sentry/utils/queryClient';
  2. import type {Span} from 'sentry/views/starfish/queries/types';
  3. import {HOST} from 'sentry/views/starfish/utils/constants';
  4. export const useSpanById = (groupId: string, referrer: string) => {
  5. const query = `
  6. SELECT
  7. group_id,
  8. action,
  9. description,
  10. span_operation
  11. FROM spans_experimental_starfish
  12. WHERE group_id = '${groupId}'
  13. LIMIT 1
  14. `;
  15. const result = useQuery<Span[]>({
  16. queryKey: ['span-by-id', groupId],
  17. queryFn: () =>
  18. fetch(`${HOST}/?query=${query}&referrer=${referrer}&format=sql`).then(res =>
  19. res.json()
  20. ),
  21. retry: false,
  22. initialData: [],
  23. enabled: Boolean(groupId),
  24. });
  25. return {...result, data: result.data[0]};
  26. };