content.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import {Fragment} from 'react';
  2. import type {Location} from 'history';
  3. import Feature from 'sentry/components/acl/feature';
  4. import IdBadge from 'sentry/components/idBadge';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import type {Organization} from 'sentry/types/organization';
  7. import type {Project} from 'sentry/types/project';
  8. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  9. import type EventView from 'sentry/utils/discover/eventView';
  10. import type {ChildrenProps as SpanExamplesProps} from 'sentry/utils/performance/suspectSpans/spanExamplesQuery';
  11. import SpanExamplesQuery from 'sentry/utils/performance/suspectSpans/spanExamplesQuery';
  12. import type {ChildrenProps as SuspectSpansProps} from 'sentry/utils/performance/suspectSpans/suspectSpansQuery';
  13. import SuspectSpansQuery from 'sentry/utils/performance/suspectSpans/suspectSpansQuery';
  14. import type {SpanSlug} from 'sentry/utils/performance/suspectSpans/types';
  15. import {setGroupedEntityTag} from 'sentry/utils/performanceForSentry';
  16. import {decodeScalar} from 'sentry/utils/queryString';
  17. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  18. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  19. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  20. import SpanSummary from 'sentry/views/performance/transactionSummary/transactionSpans/spanSummary/content';
  21. import {getSelectedProjectPlatforms} from 'sentry/views/performance/utils';
  22. import Tab from '../../tabs';
  23. import {SpanSortOthers} from '../types';
  24. import {getTotalsView} from '../utils';
  25. import SpanChart from './chart';
  26. import SpanDetailsControls from './spanDetailsControls';
  27. import SpanDetailsHeader from './spanDetailsHeader';
  28. import SpanTable from './spanDetailsTable';
  29. import {ZoomKeys} from './utils';
  30. type Props = {
  31. eventView: EventView;
  32. location: Location;
  33. organization: Organization;
  34. project: Project | undefined;
  35. spanSlug: SpanSlug;
  36. transactionName: string;
  37. };
  38. export default function SpanDetailsContentWrapper(props: Props) {
  39. const {location, organization, eventView, project, transactionName, spanSlug} = props;
  40. const minExclusiveTime = decodeScalar(location.query[ZoomKeys.MIN]);
  41. const maxExclusiveTime = decodeScalar(location.query[ZoomKeys.MAX]);
  42. // customize the route analytics event we send
  43. useRouteAnalyticsEventNames(
  44. 'performance_views.span_summary.view',
  45. 'Performance Views: Span Summary page viewed'
  46. );
  47. useRouteAnalyticsParams({
  48. project_platforms: project ? getSelectedProjectPlatforms(location, [project]) : '',
  49. });
  50. const hasNewSpansUIFlag = organization.features.includes('performance-spans-new-ui');
  51. // TODO: When this feature is rolled out to GA, we will no longer need the entire `spanDetails` directory and can switch to `spanSummary`
  52. if (hasNewSpansUIFlag) {
  53. return <SpanSummary {...props} />;
  54. }
  55. return (
  56. <Fragment>
  57. <Layout.Header>
  58. <Layout.HeaderContent>
  59. <Breadcrumb
  60. organization={organization}
  61. location={location}
  62. transaction={{
  63. project: project?.id ?? '',
  64. name: transactionName,
  65. }}
  66. tab={Tab.SPANS}
  67. spanSlug={spanSlug}
  68. />
  69. <Layout.Title>
  70. {project && (
  71. <IdBadge
  72. project={project}
  73. avatarSize={28}
  74. hideName
  75. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  76. />
  77. )}
  78. {transactionName}
  79. </Layout.Title>
  80. </Layout.HeaderContent>
  81. </Layout.Header>
  82. <Layout.Body>
  83. <Layout.Main fullWidth>
  84. <DiscoverQuery
  85. eventView={getTotalsView(eventView)}
  86. orgSlug={organization.slug}
  87. location={location}
  88. referrer="api.performance.transaction-spans"
  89. cursor="0:0:1"
  90. noPagination
  91. >
  92. {({tableData}) => {
  93. const totalCount: number | null =
  94. (tableData?.data?.[0]?.['count()'] as number) ?? null;
  95. if (totalCount) {
  96. setGroupedEntityTag('spans.totalCount', 1000, totalCount);
  97. }
  98. return (
  99. <SuspectSpansQuery
  100. location={location}
  101. orgSlug={organization.slug}
  102. eventView={getSpansEventView(eventView)}
  103. perSuspect={0}
  104. spanOps={[spanSlug.op]}
  105. spanGroups={[spanSlug.group]}
  106. cursor="0:0:1"
  107. minExclusiveTime={minExclusiveTime}
  108. maxExclusiveTime={maxExclusiveTime}
  109. >
  110. {suspectSpansResults => (
  111. <SpanExamplesQuery
  112. location={location}
  113. orgSlug={organization.slug}
  114. eventView={eventView}
  115. spanOp={spanSlug.op}
  116. spanGroup={spanSlug.group}
  117. limit={10}
  118. minExclusiveTime={minExclusiveTime}
  119. maxExclusiveTime={maxExclusiveTime}
  120. >
  121. {spanExamplesResults => (
  122. <SpanDetailsContent
  123. location={location}
  124. organization={organization}
  125. project={project}
  126. eventView={eventView}
  127. spanSlug={spanSlug}
  128. transactionName={transactionName}
  129. totalCount={totalCount}
  130. suspectSpansResults={suspectSpansResults}
  131. spanExamplesResults={spanExamplesResults}
  132. />
  133. )}
  134. </SpanExamplesQuery>
  135. )}
  136. </SuspectSpansQuery>
  137. );
  138. }}
  139. </DiscoverQuery>
  140. </Layout.Main>
  141. </Layout.Body>
  142. </Fragment>
  143. );
  144. }
  145. type ContentProps = {
  146. eventView: EventView;
  147. location: Location;
  148. organization: Organization;
  149. project: Project | undefined;
  150. spanExamplesResults: SpanExamplesProps;
  151. spanSlug: SpanSlug;
  152. suspectSpansResults: SuspectSpansProps;
  153. totalCount: number;
  154. transactionName: string;
  155. };
  156. function SpanDetailsContent(props: ContentProps) {
  157. const {
  158. location,
  159. organization,
  160. project,
  161. eventView,
  162. spanSlug,
  163. transactionName,
  164. totalCount,
  165. suspectSpansResults,
  166. spanExamplesResults,
  167. } = props;
  168. // There should always be exactly 1 result
  169. const suspectSpan = suspectSpansResults.suspectSpans?.[0];
  170. const examples = spanExamplesResults.examples?.[0]?.examples;
  171. const transactionCountContainingSpan = suspectSpan?.frequency;
  172. return (
  173. <Fragment>
  174. <Feature features="performance-span-histogram-view">
  175. <SpanDetailsControls
  176. organization={organization}
  177. location={location}
  178. eventView={eventView}
  179. />
  180. </Feature>
  181. <SpanDetailsHeader
  182. spanSlug={spanSlug}
  183. totalCount={totalCount}
  184. suspectSpan={suspectSpan}
  185. />
  186. <SpanChart
  187. totalCount={transactionCountContainingSpan}
  188. organization={organization}
  189. eventView={eventView}
  190. spanSlug={spanSlug}
  191. />
  192. <SpanTable
  193. location={location}
  194. organization={organization}
  195. project={project}
  196. suspectSpan={suspectSpan}
  197. transactionName={transactionName}
  198. isLoading={spanExamplesResults.isLoading}
  199. examples={examples ?? []}
  200. pageLinks={spanExamplesResults.pageLinks}
  201. />
  202. </Fragment>
  203. );
  204. }
  205. function getSpansEventView(eventView: EventView): EventView {
  206. // TODO: There is a bug where if the sort is not avg occurrence,
  207. // then the avg occurrence will never be added to the fields
  208. eventView = eventView.withSorts([{field: SpanSortOthers.AVG_OCCURRENCE, kind: 'desc'}]);
  209. eventView.fields = [
  210. {field: 'count()'},
  211. {field: 'count_unique(id)'},
  212. {field: 'equation|count() / count_unique(id)'},
  213. {field: 'sumArray(spans_exclusive_time)'},
  214. {field: 'percentileArray(spans_exclusive_time, 0.50)'},
  215. {field: 'percentileArray(spans_exclusive_time, 0.75)'},
  216. {field: 'percentileArray(spans_exclusive_time, 0.95)'},
  217. {field: 'percentileArray(spans_exclusive_time, 0.99)'},
  218. ];
  219. return eventView;
  220. }