index.tsx 4.7 KB

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