123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import {useDiscoverQuery} from 'sentry/utils/discover/discoverQuery';
- import EventView from 'sentry/utils/discover/eventView';
- import {DiscoverDatasets} from 'sentry/utils/discover/types';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- import type {IndexedSpan} from 'sentry/views/starfish/queries/types';
- import {SpanIndexedFields} from 'sentry/views/starfish/types';
- const DEFAULT_LIMIT = 10;
- const DEFAULT_ORDER_BY = '-duration';
- export function useSpanSamples(
- groupId?: string,
- transaction?: string,
- limit?: number,
- orderBy?: string,
- referrer: string = 'use-span-samples'
- ) {
- const location = useLocation();
- const organization = useOrganization();
- const eventView = EventView.fromNewQueryWithLocation(
- {
- name: 'Span Samples',
- query: `${groupId ? ` group:${groupId}` : ''} ${
- transaction ? ` transaction:${transaction}` : ''
- }`,
- fields: [
- 'span_id',
- 'group',
- 'action',
- 'description',
- 'domain',
- 'module',
- SpanIndexedFields.SPAN_SELF_TIME,
- 'op',
- 'transaction_id',
- 'timestamp',
- ],
- dataset: DiscoverDatasets.SPANS_INDEXED,
- orderby: orderBy ?? DEFAULT_ORDER_BY,
- projects: [1],
- version: 2,
- },
- location
- );
- const response = useDiscoverQuery({
- eventView,
- orgSlug: organization.slug,
- location,
- referrer,
- limit: limit ?? DEFAULT_LIMIT,
- });
- const data = (response.data?.data ?? []) as unknown as IndexedSpan[];
- const pageLinks = response.pageLinks;
- return {...response, data, pageLinks};
- }
|