index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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';
  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. 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 {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 content = ({
  87. isLoading,
  88. error,
  89. traces,
  90. meta,
  91. }: {
  92. error: QueryError | null;
  93. isLoading: boolean;
  94. meta: TraceMeta | null;
  95. traces: (TraceFullDetailed[] | TraceSplitResults<TraceFullDetailed>) | null;
  96. }) => {
  97. const {transactions, orphanErrors} = getTraceSplitResults<TraceFullDetailed>(
  98. traces ?? [],
  99. organization
  100. );
  101. const commonProps = {
  102. location,
  103. organization,
  104. params,
  105. traceSlug,
  106. traceEventView: this.getTraceEventView(),
  107. dateSelected,
  108. isLoading,
  109. error,
  110. orphanErrors,
  111. traces: transactions ?? (traces as TraceFullDetailed[]),
  112. meta,
  113. handleLimitChange: this.handleLimitChange,
  114. };
  115. return organization.features.includes('performance-trace-details') ? (
  116. <NewTraceDetailsContent {...commonProps} />
  117. ) : (
  118. <TraceDetailsContent {...commonProps} />
  119. );
  120. };
  121. if (!dateSelected) {
  122. return content({
  123. isLoading: false,
  124. error: new QueryError('date selection not specified'),
  125. traces: null,
  126. meta: null,
  127. });
  128. }
  129. return (
  130. <TraceFullDetailedQuery
  131. type="detailed"
  132. location={location}
  133. orgSlug={organization.slug}
  134. traceId={traceSlug}
  135. start={start}
  136. end={end}
  137. statsPeriod={statsPeriod}
  138. limit={this.state.limit}
  139. >
  140. {traceResults => (
  141. <TraceMetaQuery
  142. location={location}
  143. orgSlug={organization.slug}
  144. traceId={traceSlug}
  145. start={start}
  146. end={end}
  147. statsPeriod={statsPeriod}
  148. >
  149. {metaResults =>
  150. content({
  151. isLoading: traceResults.isLoading || metaResults.isLoading,
  152. error: traceResults.error || metaResults.error,
  153. traces: traceResults.traces,
  154. meta: metaResults.meta,
  155. })
  156. }
  157. </TraceMetaQuery>
  158. )}
  159. </TraceFullDetailedQuery>
  160. );
  161. }
  162. render() {
  163. const {organization} = this.props;
  164. if (organization.features.includes('trace-view-v1')) {
  165. return <TraceViewV1 />;
  166. }
  167. return (
  168. <SentryDocumentTitle title={this.getDocumentTitle()} orgSlug={organization.slug}>
  169. <Layout.Page>
  170. <NoProjectMessage organization={organization}>
  171. {this.renderContent()}
  172. </NoProjectMessage>
  173. </Layout.Page>
  174. </SentryDocumentTitle>
  175. );
  176. }
  177. }
  178. export default withOrganization(withApi(TraceSummary));