index.tsx 4.6 KB

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