useFullSpanDescription.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import {useEventJSON} from 'sentry/views/starfish/queries/useEventJSON';
  2. import {useIndexedSpans} from 'sentry/views/starfish/queries/useIndexedSpans';
  3. import {SpanIndexedFields} from 'sentry/views/starfish/types';
  4. // NOTE: Fetching the top one is a bit naive, but works for now. A better
  5. // approach might be to fetch several at a time, and let the hook consumer
  6. // decide how to display them
  7. export function useFullSpanDescription(group: string) {
  8. const {data: indexedSpans} = useIndexedSpans(
  9. {
  10. [SpanIndexedFields.SPAN_GROUP]: group,
  11. },
  12. 1
  13. );
  14. const firstIndexedSpan = indexedSpans?.[0];
  15. const response = useEventJSON(
  16. firstIndexedSpan ? firstIndexedSpan[SpanIndexedFields.TRANSACTION_ID] : undefined,
  17. firstIndexedSpan ? firstIndexedSpan[SpanIndexedFields.PROJECT] : undefined
  18. );
  19. const fullSpanDescription = response?.data?.spans?.find(
  20. span => span.span_id === firstIndexedSpan?.[SpanIndexedFields.ID]
  21. )?.description;
  22. return {
  23. ...response,
  24. data: fullSpanDescription,
  25. };
  26. }