index.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import {Component} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import {Client} from 'sentry/api';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import NoProjectMessage from 'sentry/components/noProjectMessage';
  6. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  7. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  8. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  9. import {t} from 'sentry/locale';
  10. import {Organization} from 'sentry/types';
  11. import EventView from 'sentry/utils/discover/eventView';
  12. import {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
  13. import {TraceFullDetailedQuery} from 'sentry/utils/performance/quickTrace/traceFullQuery';
  14. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  15. import {
  16. TraceFullDetailed,
  17. TraceMeta,
  18. TraceSplitResults,
  19. } from 'sentry/utils/performance/quickTrace/types';
  20. import {decodeScalar} from 'sentry/utils/queryString';
  21. import withApi from 'sentry/utils/withApi';
  22. import withOrganization from 'sentry/utils/withOrganization';
  23. import TraceDetailsContent from './content';
  24. import {getTraceSplitResults} from './utils';
  25. type Props = RouteComponentProps<{traceSlug: string}, {}> & {
  26. api: Client;
  27. organization: Organization;
  28. };
  29. class TraceSummary extends Component<Props> {
  30. getDocumentTitle(): string {
  31. return [t('Trace Details'), t('Performance')].join(' — ');
  32. }
  33. getTraceSlug(): string {
  34. const {traceSlug} = this.props.params;
  35. return typeof traceSlug === 'string' ? traceSlug.trim() : '';
  36. }
  37. getDateSelection() {
  38. const {location} = this.props;
  39. const queryParams = normalizeDateTimeParams(location.query, {
  40. allowAbsolutePageDatetime: true,
  41. });
  42. const start = decodeScalar(queryParams.start);
  43. const end = decodeScalar(queryParams.end);
  44. const statsPeriod = decodeScalar(queryParams.statsPeriod);
  45. return {start, end, statsPeriod};
  46. }
  47. getTraceEventView() {
  48. const traceSlug = this.getTraceSlug();
  49. const {start, end, statsPeriod} = this.getDateSelection();
  50. return EventView.fromSavedQuery({
  51. id: undefined,
  52. name: `Events with Trace ID ${traceSlug}`,
  53. fields: ['title', 'event.type', 'project', 'timestamp'],
  54. orderby: '-timestamp',
  55. query: `trace:${traceSlug}`,
  56. projects: [ALL_ACCESS_PROJECTS],
  57. version: 2,
  58. start,
  59. end,
  60. range: statsPeriod,
  61. });
  62. }
  63. renderContent() {
  64. const {location, organization, params} = this.props;
  65. const traceSlug = this.getTraceSlug();
  66. const {start, end, statsPeriod} = this.getDateSelection();
  67. const dateSelected = Boolean(statsPeriod || (start && end));
  68. const content = ({
  69. isLoading,
  70. error,
  71. traces,
  72. meta,
  73. }: {
  74. error: QueryError | null;
  75. isLoading: boolean;
  76. meta: TraceMeta | null;
  77. traces: (TraceFullDetailed[] | TraceSplitResults<TraceFullDetailed>) | null;
  78. }) => {
  79. const {transactions, orphanErrors} = getTraceSplitResults<TraceFullDetailed>(
  80. traces ?? [],
  81. organization
  82. );
  83. return (
  84. <TraceDetailsContent
  85. location={location}
  86. organization={organization}
  87. params={params}
  88. traceSlug={traceSlug}
  89. traceEventView={this.getTraceEventView()}
  90. dateSelected={dateSelected}
  91. isLoading={isLoading}
  92. error={error}
  93. orphanErrors={orphanErrors}
  94. traces={transactions ?? (traces as TraceFullDetailed[])}
  95. meta={meta}
  96. />
  97. );
  98. };
  99. if (!dateSelected) {
  100. return content({
  101. isLoading: false,
  102. error: new QueryError('date selection not specified'),
  103. traces: null,
  104. meta: null,
  105. });
  106. }
  107. return (
  108. <TraceFullDetailedQuery
  109. location={location}
  110. orgSlug={organization.slug}
  111. traceId={traceSlug}
  112. start={start}
  113. end={end}
  114. statsPeriod={statsPeriod}
  115. >
  116. {traceResults => (
  117. <TraceMetaQuery
  118. location={location}
  119. orgSlug={organization.slug}
  120. traceId={traceSlug}
  121. start={start}
  122. end={end}
  123. statsPeriod={statsPeriod}
  124. >
  125. {metaResults =>
  126. content({
  127. isLoading: traceResults.isLoading || metaResults.isLoading,
  128. error: traceResults.error || metaResults.error,
  129. traces: traceResults.traces,
  130. meta: metaResults.meta,
  131. })
  132. }
  133. </TraceMetaQuery>
  134. )}
  135. </TraceFullDetailedQuery>
  136. );
  137. }
  138. render() {
  139. const {organization} = this.props;
  140. return (
  141. <SentryDocumentTitle title={this.getDocumentTitle()} orgSlug={organization.slug}>
  142. <Layout.Page>
  143. <NoProjectMessage organization={organization}>
  144. {this.renderContent()}
  145. </NoProjectMessage>
  146. </Layout.Page>
  147. </SentryDocumentTitle>
  148. );
  149. }
  150. }
  151. export default withOrganization(withApi(TraceSummary));