import {Fragment, useMemo, useState} from 'react'; import type {Location} from 'history'; import ButtonBar from 'sentry/components/buttonBar'; import DiscoverButton from 'sentry/components/discoverButton'; import * as Layout from 'sentry/components/layouts/thirds'; import NoProjectMessage from 'sentry/components/noProjectMessage'; import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse'; import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle'; import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters'; import {t} from 'sentry/locale'; import type {EventTransaction, Organization} from 'sentry/types'; import {trackAnalytics} from 'sentry/utils/analytics'; import EventView from 'sentry/utils/discover/eventView'; import {TraceFullDetailedQuery} from 'sentry/utils/performance/quickTrace/traceFullQuery'; import TraceMetaQuery, { type TraceMetaQueryChildrenProps, } from 'sentry/utils/performance/quickTrace/traceMetaQuery'; import type { TraceFullDetailed, TraceSplitResults, } from 'sentry/utils/performance/quickTrace/types'; import {useApiQuery} from 'sentry/utils/queryClient'; import {decodeScalar} from 'sentry/utils/queryString'; import {useLocation} from 'sentry/utils/useLocation'; import useOrganization from 'sentry/utils/useOrganization'; import {useParams} from 'sentry/utils/useParams'; import useProjects from 'sentry/utils/useProjects'; import Breadcrumb from '../breadcrumb'; import Trace from './trace'; import TraceHeader from './traceHeader'; import {TraceTree} from './traceTree'; import TraceWarnings from './traceWarnings'; const DOCUMENT_TITLE = [t('Trace Details'), t('Performance')].join(' — '); export function TraceView() { const location = useLocation(); const organization = useOrganization(); const params = useParams<{traceSlug?: string}>(); const traceSlug = params.traceSlug?.trim() ?? ''; const dateSelection = useMemo(() => { const queryParams = normalizeDateTimeParams(location.query, { allowAbsolutePageDatetime: true, }); const start = decodeScalar(queryParams.start); const end = decodeScalar(queryParams.end); const statsPeriod = decodeScalar(queryParams.statsPeriod); return {start, end, statsPeriod}; }, [location.query]); const _traceEventView = useMemo(() => { const {start, end, statsPeriod} = dateSelection; return EventView.fromSavedQuery({ id: undefined, name: `Events with Trace ID ${traceSlug}`, fields: ['title', 'event.type', 'project', 'timestamp'], orderby: '-timestamp', query: `trace:${traceSlug}`, projects: [ALL_ACCESS_PROJECTS], version: 2, start, end, range: statsPeriod, }); }, [dateSelection, traceSlug]); const [_limit, _setLimit] = useState(); // const _handleLimithange = useCallback((newLimit: number) => { // setLimit(newLimit); // }, []); return ( {trace => ( {metaResults => ( )} )} ); } type TraceViewContentProps = { location: Location; metaResults: TraceMetaQueryChildrenProps; organization: Organization; traceEventView: EventView; traceSlug: string; traceSplitResult: TraceSplitResults | null; }; function TraceViewContent(props: TraceViewContentProps) { const rootEvent = props.traceSplitResult?.transactions?.[0]; const {projects} = useProjects(); const tree = useMemo(() => { if (!props.traceSplitResult) { return TraceTree.Loading({ project_slug: projects?.[0]?.slug ?? '', event_id: props.traceSlug, }); } return TraceTree.FromTrace(props.traceSplitResult); }, [props.traceSlug, props.traceSplitResult, projects]); const traceType = useMemo(() => { return TraceTree.GetTraceType(tree.root); }, [tree]); const rootEventResults = useApiQuery( [ `/organizations/${props.organization.slug}/events/${rootEvent?.project_slug}:${rootEvent?.event_id}/`, { query: { referrer: 'trace-details-summary', }, }, ], { staleTime: 0, enabled: !!( props.traceSplitResult?.transactions && props.traceSplitResult.transactions.length > 0 ), } ); return ( {t('Trace ID: %s', props.traceSlug)} { trackAnalytics('performance_views.trace_view.open_in_discover', { organization: props.organization, }); }} > {t('Open in Discover')} {traceType ? : null} ); }