index.tsx 5.6 KB

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