index.tsx 5.4 KB

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