import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse'; import type {PageFilters} from 'sentry/types/core'; import type {DiscoverDatasets} from 'sentry/utils/discover/types'; import {useApiQuery} from 'sentry/utils/queryClient'; import useOrganization from 'sentry/utils/useOrganization'; import usePageFilters from 'sentry/utils/usePageFilters'; import type {TraceResult} from './useTraces'; export type SpanResult = Record; export interface SpanResults { data: SpanResult[]; meta: any; } interface UseTraceSpansOptions { fields: F[]; trace: TraceResult; dataset?: DiscoverDatasets; datetime?: PageFilters['datetime']; enabled?: boolean; limit?: number; query?: string | string[]; sort?: string[]; } export function useTraceSpans({ fields, trace, dataset, datetime, enabled, limit, query, sort, }: UseTraceSpansOptions) { const organization = useOrganization(); const {selection} = usePageFilters(); const path = `/organizations/${organization.slug}/trace/${trace.trace}/spans/`; const endpointOptions = { query: { project: selection.projects, environment: selection.environments, ...normalizeDateTimeParams(datetime ?? selection.datetime), dataset, field: fields, query, sort, per_page: limit, maxSpansPerTrace: 10, }, }; const result = useApiQuery>([path, endpointOptions], { staleTime: 0, refetchOnWindowFocus: false, retry: false, enabled, }); return result; }