index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {Component} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import type {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 type {Organization} from 'sentry/types/organization';
  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 type {
  16. TraceMeta,
  17. TraceSplitResults,
  18. } from 'sentry/utils/performance/quickTrace/types';
  19. import {decodeScalar} from 'sentry/utils/queryString';
  20. import withApi from 'sentry/utils/withApi';
  21. import withOrganization from 'sentry/utils/withOrganization';
  22. import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  23. import {TraceView as TraceViewV1} from './../newTraceDetails';
  24. import TraceDetailsContent from './content';
  25. import {DEFAULT_TRACE_ROWS_LIMIT} from './limitExceededMessage';
  26. import NewTraceDetailsContent from './newTraceDetailsContent';
  27. import {getTraceSplitResults} from './utils';
  28. type Props = RouteComponentProps<{traceSlug: string}, {}> & {
  29. api: Client;
  30. organization: Organization;
  31. };
  32. type State = {
  33. limit: number;
  34. };
  35. class TraceSummary extends Component<Props> {
  36. state: State = {
  37. limit: DEFAULT_TRACE_ROWS_LIMIT,
  38. };
  39. componentDidMount(): void {
  40. const {query} = this.props.location;
  41. if (query.limit) {
  42. this.setState({limit: query.limit});
  43. }
  44. }
  45. handleLimitChange = (newLimit: number) => {
  46. this.setState({limit: newLimit});
  47. };
  48. getDocumentTitle(): string {
  49. return [t('Trace Details'), t('Performance')].join(' — ');
  50. }
  51. getTraceSlug(): string {
  52. const {traceSlug} = this.props.params;
  53. return typeof traceSlug === 'string' ? traceSlug.trim() : '';
  54. }
  55. getDateSelection() {
  56. const {location} = this.props;
  57. const queryParams = normalizeDateTimeParams(location.query, {
  58. allowAbsolutePageDatetime: true,
  59. });
  60. const start = decodeScalar(queryParams.start);
  61. const end = decodeScalar(queryParams.end);
  62. const statsPeriod = decodeScalar(queryParams.statsPeriod);
  63. return {start, end, statsPeriod};
  64. }
  65. getTraceEventView() {
  66. const traceSlug = this.getTraceSlug();
  67. const {start, end, statsPeriod} = this.getDateSelection();
  68. return EventView.fromSavedQuery({
  69. id: undefined,
  70. name: `Events with Trace ID ${traceSlug}`,
  71. fields: ['title', 'event.type', 'project', 'timestamp'],
  72. orderby: '-timestamp',
  73. query: `trace:${traceSlug}`,
  74. projects: [ALL_ACCESS_PROJECTS],
  75. version: 2,
  76. start,
  77. end,
  78. range: statsPeriod,
  79. });
  80. }
  81. renderContent() {
  82. const {location, organization, params} = this.props;
  83. const traceSlug = this.getTraceSlug();
  84. const {start, end, statsPeriod} = this.getDateSelection();
  85. const dateSelected = Boolean(statsPeriod || (start && end));
  86. const backend = decodeScalar(location.query.backend);
  87. const content = ({
  88. isLoading,
  89. error,
  90. traces,
  91. meta,
  92. }: {
  93. error: QueryError | null;
  94. isLoading: boolean;
  95. meta: TraceMeta | null;
  96. traces: (TraceTree.Transaction[] | TraceSplitResults<TraceTree.Transaction>) | null;
  97. }) => {
  98. const {transactions, orphanErrors} = getTraceSplitResults<TraceTree.Transaction>(
  99. traces ?? [],
  100. organization
  101. );
  102. const commonProps = {
  103. location,
  104. organization,
  105. params,
  106. traceSlug,
  107. traceEventView: this.getTraceEventView(),
  108. dateSelected,
  109. isLoading,
  110. error,
  111. orphanErrors,
  112. traces: transactions ?? (traces as TraceTree.Transaction[]),
  113. meta,
  114. handleLimitChange: this.handleLimitChange,
  115. };
  116. return organization.features.includes('performance-trace-details') ? (
  117. <NewTraceDetailsContent {...commonProps} />
  118. ) : (
  119. <TraceDetailsContent {...commonProps} />
  120. );
  121. };
  122. if (!dateSelected) {
  123. return content({
  124. isLoading: false,
  125. error: new QueryError('date selection not specified'),
  126. traces: null,
  127. meta: null,
  128. });
  129. }
  130. return (
  131. <TraceFullDetailedQuery
  132. type={backend === 'indexedSpans' ? 'spans' : 'detailed'}
  133. location={location}
  134. orgSlug={organization.slug}
  135. traceId={traceSlug}
  136. start={start}
  137. end={end}
  138. statsPeriod={statsPeriod}
  139. limit={this.state.limit}
  140. >
  141. {traceResults => (
  142. <TraceMetaQuery
  143. location={location}
  144. orgSlug={organization.slug}
  145. traceId={traceSlug}
  146. start={start}
  147. end={end}
  148. statsPeriod={statsPeriod}
  149. >
  150. {metaResults =>
  151. content({
  152. isLoading: traceResults.isLoading || metaResults.isLoading,
  153. error: traceResults.error || metaResults.error,
  154. traces: traceResults.traces as unknown as TraceTree.Transaction[],
  155. meta: metaResults.meta,
  156. })
  157. }
  158. </TraceMetaQuery>
  159. )}
  160. </TraceFullDetailedQuery>
  161. );
  162. }
  163. render() {
  164. const {organization} = this.props;
  165. if (organization.features.includes('trace-view-v1')) {
  166. return <TraceViewV1 />;
  167. }
  168. return (
  169. <SentryDocumentTitle title={this.getDocumentTitle()} orgSlug={organization.slug}>
  170. <Layout.Page>
  171. <NoProjectMessage organization={organization}>
  172. {this.renderContent()}
  173. </NoProjectMessage>
  174. </Layout.Page>
  175. </SentryDocumentTitle>
  176. );
  177. }
  178. }
  179. export default withOrganization(withApi(TraceSummary));