content.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 =
  51. organization.features.includes('performance-spans-new-ui') &&
  52. organization.features.includes('insights-initial-modules');
  53. // TODO: When this feature is rolled out to GA, we will no longer need the entire `spanDetails` directory and can switch to `spanSummary`
  54. if (hasNewSpansUIFlag) {
  55. return <SpanSummary {...props} />;
  56. }
  57. return (
  58. <Fragment>
  59. <Layout.Header>
  60. <Layout.HeaderContent>
  61. <Breadcrumb
  62. organization={organization}
  63. location={location}
  64. transaction={{
  65. project: project?.id ?? '',
  66. name: transactionName,
  67. }}
  68. tab={Tab.SPANS}
  69. spanSlug={spanSlug}
  70. />
  71. <Layout.Title>
  72. {project && (
  73. <IdBadge
  74. project={project}
  75. avatarSize={28}
  76. hideName
  77. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  78. />
  79. )}
  80. {transactionName}
  81. </Layout.Title>
  82. </Layout.HeaderContent>
  83. </Layout.Header>
  84. <Layout.Body>
  85. <Layout.Main fullWidth>
  86. <DiscoverQuery
  87. eventView={getTotalsView(eventView)}
  88. orgSlug={organization.slug}
  89. location={location}
  90. referrer="api.performance.transaction-spans"
  91. cursor="0:0:1"
  92. noPagination
  93. >
  94. {({tableData}) => {
  95. const totalCount: number | null =
  96. (tableData?.data?.[0]?.['count()'] as number) ?? null;
  97. if (totalCount) {
  98. setGroupedEntityTag('spans.totalCount', 1000, totalCount);
  99. }
  100. return (
  101. <SuspectSpansQuery
  102. location={location}
  103. orgSlug={organization.slug}
  104. eventView={getSpansEventView(eventView)}
  105. perSuspect={0}
  106. spanOps={[spanSlug.op]}
  107. spanGroups={[spanSlug.group]}
  108. cursor="0:0:1"
  109. minExclusiveTime={minExclusiveTime}
  110. maxExclusiveTime={maxExclusiveTime}
  111. >
  112. {suspectSpansResults => (
  113. <SpanExamplesQuery
  114. location={location}
  115. orgSlug={organization.slug}
  116. eventView={eventView}
  117. spanOp={spanSlug.op}
  118. spanGroup={spanSlug.group}
  119. limit={10}
  120. minExclusiveTime={minExclusiveTime}
  121. maxExclusiveTime={maxExclusiveTime}
  122. >
  123. {spanExamplesResults => (
  124. <SpanDetailsContent
  125. location={location}
  126. organization={organization}
  127. project={project}
  128. eventView={eventView}
  129. spanSlug={spanSlug}
  130. transactionName={transactionName}
  131. totalCount={totalCount}
  132. suspectSpansResults={suspectSpansResults}
  133. spanExamplesResults={spanExamplesResults}
  134. />
  135. )}
  136. </SpanExamplesQuery>
  137. )}
  138. </SuspectSpansQuery>
  139. );
  140. }}
  141. </DiscoverQuery>
  142. </Layout.Main>
  143. </Layout.Body>
  144. </Fragment>
  145. );
  146. }
  147. type ContentProps = {
  148. eventView: EventView;
  149. location: Location;
  150. organization: Organization;
  151. project: Project | undefined;
  152. spanExamplesResults: SpanExamplesProps;
  153. spanSlug: SpanSlug;
  154. suspectSpansResults: SuspectSpansProps;
  155. totalCount: number;
  156. transactionName: string;
  157. };
  158. function SpanDetailsContent(props: ContentProps) {
  159. const {
  160. location,
  161. organization,
  162. project,
  163. eventView,
  164. spanSlug,
  165. transactionName,
  166. totalCount,
  167. suspectSpansResults,
  168. spanExamplesResults,
  169. } = props;
  170. // There should always be exactly 1 result
  171. const suspectSpan = suspectSpansResults.suspectSpans?.[0];
  172. const examples = spanExamplesResults.examples?.[0]?.examples;
  173. const transactionCountContainingSpan = suspectSpan?.frequency;
  174. return (
  175. <Fragment>
  176. <Feature features="performance-span-histogram-view">
  177. <SpanDetailsControls
  178. organization={organization}
  179. location={location}
  180. eventView={eventView}
  181. />
  182. </Feature>
  183. <SpanDetailsHeader
  184. spanSlug={spanSlug}
  185. totalCount={totalCount}
  186. suspectSpan={suspectSpan}
  187. />
  188. <SpanChart
  189. totalCount={transactionCountContainingSpan}
  190. organization={organization}
  191. eventView={eventView}
  192. spanSlug={spanSlug}
  193. />
  194. <SpanTable
  195. location={location}
  196. organization={organization}
  197. project={project}
  198. suspectSpan={suspectSpan}
  199. transactionName={transactionName}
  200. isLoading={spanExamplesResults.isLoading}
  201. examples={examples ?? []}
  202. pageLinks={spanExamplesResults.pageLinks}
  203. />
  204. </Fragment>
  205. );
  206. }
  207. function getSpansEventView(eventView: EventView): EventView {
  208. // TODO: There is a bug where if the sort is not avg occurrence,
  209. // then the avg occurrence will never be added to the fields
  210. eventView = eventView.withSorts([{field: SpanSortOthers.AVG_OCCURRENCE, kind: 'desc'}]);
  211. eventView.fields = [
  212. {field: 'count()'},
  213. {field: 'count_unique(id)'},
  214. {field: 'equation|count() / count_unique(id)'},
  215. {field: 'sumArray(spans_exclusive_time)'},
  216. {field: 'percentileArray(spans_exclusive_time, 0.50)'},
  217. {field: 'percentileArray(spans_exclusive_time, 0.75)'},
  218. {field: 'percentileArray(spans_exclusive_time, 0.95)'},
  219. {field: 'percentileArray(spans_exclusive_time, 0.99)'},
  220. ];
  221. return eventView;
  222. }