123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- import {Fragment} from 'react';
- import {RouteComponentProps} from 'react-router';
- import styled from '@emotion/styled';
- import {Alert} from 'sentry/components/alert';
- import GuideAnchor from 'sentry/components/assistant/guideAnchor';
- import ButtonBar from 'sentry/components/buttonBar';
- import DiscoverButton from 'sentry/components/discoverButton';
- import * as Layout from 'sentry/components/layouts/thirds';
- import ExternalLink from 'sentry/components/links/externalLink';
- import LoadingError from 'sentry/components/loadingError';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import TimeSince from 'sentry/components/timeSince';
- import {t, tct, tn} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import {Organization} from 'sentry/types';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import EventView from 'sentry/utils/discover/eventView';
- import {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
- import {getDuration} from 'sentry/utils/formatters';
- import getDynamicText from 'sentry/utils/getDynamicText';
- import {
- TraceError,
- TraceFullDetailed,
- TraceMeta,
- } from 'sentry/utils/performance/quickTrace/types';
- import {VisuallyCompleteWithData} from 'sentry/utils/performanceForSentry';
- import Breadcrumb from 'sentry/views/performance/breadcrumb';
- import {MetaData} from 'sentry/views/performance/transactionDetails/styles';
- import {TraceDetailHeader} from './styles';
- import TraceNotFound from './traceNotFound';
- import TraceView from './traceView';
- import {TraceInfo} from './types';
- import {getTraceInfo, hasTraceData, isRootTransaction} from './utils';
- type Props = Pick<RouteComponentProps<{traceSlug: string}, {}>, 'params' | 'location'> & {
- dateSelected: boolean;
- error: QueryError | null;
- isLoading: boolean;
- meta: TraceMeta | null;
- organization: Organization;
- traceEventView: EventView;
- traceSlug: string;
- traces: TraceFullDetailed[] | null;
- handleLimitChange?: (newLimit: number) => void;
- orphanErrors?: TraceError[];
- };
- function NewTraceDetailsContent(props: Props) {
- const renderTraceLoading = () => {
- return (
- <LoadingContainer>
- <StyledLoadingIndicator />
- {t('Hang in there, as we build your trace view!')}
- </LoadingContainer>
- );
- };
- const renderTraceRequiresDateRangeSelection = () => {
- return <LoadingError message={t('Trace view requires a date range selection.')} />;
- };
- const renderTraceHeader = (traceInfo: TraceInfo) => {
- const {meta} = props;
- const errors = meta?.errors ?? traceInfo.errors.size;
- const performanceIssues =
- meta?.performance_issues ?? traceInfo.performanceIssues.size;
- return (
- <TraceDetailHeader>
- <GuideAnchor target="trace_view_guide_breakdown">
- <MetaData
- headingText={t('Event Breakdown')}
- tooltipText={t(
- 'The number of transactions and issues there are in this trace.'
- )}
- bodyText={tct('[transactions] | [errors]', {
- transactions: tn(
- '%s Transaction',
- '%s Transactions',
- meta?.transactions ?? traceInfo.transactions.size
- ),
- errors: tn('%s Issue', '%s Issues', errors + performanceIssues),
- })}
- subtext={tn(
- 'Across %s project',
- 'Across %s projects',
- meta?.projects ?? traceInfo.projects.size
- )}
- />
- </GuideAnchor>
- <MetaData
- headingText={t('Total Duration')}
- tooltipText={t('The time elapsed between the start and end of this trace.')}
- bodyText={getDuration(
- traceInfo.endTimestamp - traceInfo.startTimestamp,
- 2,
- true
- )}
- subtext={getDynamicText({
- value: <TimeSince date={(traceInfo.endTimestamp || 0) * 1000} />,
- fixed: '5 days ago',
- })}
- />
- </TraceDetailHeader>
- );
- };
- const renderTraceWarnings = () => {
- const {traces, orphanErrors} = props;
- const {roots, orphans} = (traces ?? []).reduce(
- (counts, trace) => {
- if (isRootTransaction(trace)) {
- counts.roots++;
- } else {
- counts.orphans++;
- }
- return counts;
- },
- {roots: 0, orphans: 0}
- );
- let warning: React.ReactNode = null;
- if (roots === 0 && orphans > 0) {
- warning = (
- <Alert type="info" showIcon>
- <ExternalLink href="https://docs.sentry.io/product/performance/trace-view/#orphan-traces-and-broken-subtraces">
- {t(
- 'A root transaction is missing. Transactions linked by a dashed line have been orphaned and cannot be directly linked to the root.'
- )}
- </ExternalLink>
- </Alert>
- );
- } else if (roots === 1 && orphans > 0) {
- warning = (
- <Alert type="info" showIcon>
- <ExternalLink href="https://docs.sentry.io/product/performance/trace-view/#orphan-traces-and-broken-subtraces">
- {t(
- 'This trace has broken subtraces. Transactions linked by a dashed line have been orphaned and cannot be directly linked to the root.'
- )}
- </ExternalLink>
- </Alert>
- );
- } else if (roots > 1) {
- warning = (
- <Alert type="info" showIcon>
- <ExternalLink href="https://docs.sentry.io/product/sentry-basics/tracing/trace-view/#multiple-roots">
- {t('Multiple root transactions have been found with this trace ID.')}
- </ExternalLink>
- </Alert>
- );
- } else if (orphanErrors && orphanErrors.length > 1) {
- warning = (
- <Alert type="info" showIcon>
- {tct(
- "The good news is we know these errors are related to each other. The bad news is that we can't tell you more than that. If you haven't already, [tracingLink: configure performance monitoring for your SDKs] to learn more about service interactions.",
- {
- tracingLink: (
- <ExternalLink href="https://docs.sentry.io/product/performance/getting-started/" />
- ),
- }
- )}
- </Alert>
- );
- }
- return warning;
- };
- const renderContent = () => {
- const {
- dateSelected,
- isLoading,
- error,
- organization,
- location,
- traceEventView,
- traceSlug,
- traces,
- meta,
- orphanErrors,
- } = props;
- if (!dateSelected) {
- return renderTraceRequiresDateRangeSelection();
- }
- if (isLoading) {
- return renderTraceLoading();
- }
- const hasData = hasTraceData(traces, orphanErrors);
- if (error !== null || !hasData) {
- return (
- <TraceNotFound
- meta={meta}
- traceEventView={traceEventView}
- traceSlug={traceSlug}
- location={location}
- organization={organization}
- />
- );
- }
- const traceInfo = traces ? getTraceInfo(traces, orphanErrors) : undefined;
- return (
- <Fragment>
- {renderTraceWarnings()}
- {traceInfo && renderTraceHeader(traceInfo)}
- <Margin>
- <VisuallyCompleteWithData id="PerformanceDetails-TraceView" hasData={hasData}>
- <TraceView
- traceInfo={traceInfo}
- location={location}
- organization={organization}
- traceEventView={traceEventView}
- traceSlug={traceSlug}
- traces={traces || []}
- meta={meta}
- orphanErrors={orphanErrors || []}
- handleLimitChange={props.handleLimitChange}
- />
- </VisuallyCompleteWithData>
- </Margin>
- </Fragment>
- );
- };
- const {organization, location, traceEventView, traceSlug} = props;
- return (
- <Fragment>
- <Layout.Header>
- <Layout.HeaderContent>
- <Breadcrumb
- organization={organization}
- location={location}
- traceSlug={traceSlug}
- />
- <Layout.Title data-test-id="trace-header">
- {t('Trace ID: %s', traceSlug)}
- </Layout.Title>
- </Layout.HeaderContent>
- <Layout.HeaderActions>
- <ButtonBar gap={1}>
- <DiscoverButton
- size="sm"
- to={traceEventView.getResultsViewUrlTarget(organization.slug)}
- onClick={() => {
- trackAnalytics('performance_views.trace_view.open_in_discover', {
- organization,
- });
- }}
- >
- {t('Open in Discover')}
- </DiscoverButton>
- </ButtonBar>
- </Layout.HeaderActions>
- </Layout.Header>
- <Layout.Body>
- <Layout.Main fullWidth>{renderContent()}</Layout.Main>
- </Layout.Body>
- </Fragment>
- );
- }
- const StyledLoadingIndicator = styled(LoadingIndicator)`
- margin-bottom: 0;
- `;
- const LoadingContainer = styled('div')`
- font-size: ${p => p.theme.fontSizeLarge};
- color: ${p => p.theme.subText};
- text-align: center;
- `;
- const Margin = styled('div')`
- margin-top: ${space(2)};
- `;
- export default NewTraceDetailsContent;
|