content.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import {Fragment} from 'react';
  2. import {setTag} from '@sentry/react';
  3. import {Location} from 'history';
  4. import Feature from 'sentry/components/acl/feature';
  5. import IdBadge from 'sentry/components/idBadge';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import {Organization, Project} from 'sentry/types';
  8. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  9. import EventView from 'sentry/utils/discover/eventView';
  10. import SpanExamplesQuery, {
  11. ChildrenProps as SpanExamplesProps,
  12. } from 'sentry/utils/performance/suspectSpans/spanExamplesQuery';
  13. import SuspectSpansQuery, {
  14. ChildrenProps as SuspectSpansProps,
  15. } from 'sentry/utils/performance/suspectSpans/suspectSpansQuery';
  16. import {SpanSlug} from 'sentry/utils/performance/suspectSpans/types';
  17. import {decodeScalar} from 'sentry/utils/queryString';
  18. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  19. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  20. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  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. return (
  51. <Fragment>
  52. <Layout.Header>
  53. <Layout.HeaderContent>
  54. <Breadcrumb
  55. organization={organization}
  56. location={location}
  57. transaction={{
  58. project: project?.id ?? '',
  59. name: transactionName,
  60. }}
  61. tab={Tab.Spans}
  62. spanSlug={spanSlug}
  63. />
  64. <Layout.Title>
  65. {project && (
  66. <IdBadge
  67. project={project}
  68. avatarSize={28}
  69. hideName
  70. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  71. />
  72. )}
  73. {transactionName}
  74. </Layout.Title>
  75. </Layout.HeaderContent>
  76. </Layout.Header>
  77. <Layout.Body>
  78. <Layout.Main fullWidth>
  79. <DiscoverQuery
  80. eventView={getTotalsView(eventView)}
  81. orgSlug={organization.slug}
  82. location={location}
  83. referrer="api.performance.transaction-spans"
  84. cursor="0:0:1"
  85. noPagination
  86. >
  87. {({tableData}) => {
  88. const totalCount: number | null =
  89. (tableData?.data?.[0]?.['count()'] as number) ?? null;
  90. if (totalCount) {
  91. setTag('spans.totalCount', totalCount);
  92. const countGroup = [
  93. 1, 5, 10, 20, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
  94. ].find(n => totalCount <= n);
  95. setTag('spans.totalCount.grouped', `<=${countGroup}`);
  96. }
  97. return (
  98. <SuspectSpansQuery
  99. location={location}
  100. orgSlug={organization.slug}
  101. eventView={getSpansEventView(eventView)}
  102. perSuspect={0}
  103. spanOps={[spanSlug.op]}
  104. spanGroups={[spanSlug.group]}
  105. cursor="0:0:1"
  106. minExclusiveTime={minExclusiveTime}
  107. maxExclusiveTime={maxExclusiveTime}
  108. >
  109. {suspectSpansResults => (
  110. <SpanExamplesQuery
  111. location={location}
  112. orgSlug={organization.slug}
  113. eventView={eventView}
  114. spanOp={spanSlug.op}
  115. spanGroup={spanSlug.group}
  116. limit={10}
  117. minExclusiveTime={minExclusiveTime}
  118. maxExclusiveTime={maxExclusiveTime}
  119. >
  120. {spanExamplesResults => (
  121. <SpanDetailsContent
  122. location={location}
  123. organization={organization}
  124. project={project}
  125. eventView={eventView}
  126. spanSlug={spanSlug}
  127. transactionName={transactionName}
  128. totalCount={totalCount}
  129. suspectSpansResults={suspectSpansResults}
  130. spanExamplesResults={spanExamplesResults}
  131. />
  132. )}
  133. </SpanExamplesQuery>
  134. )}
  135. </SuspectSpansQuery>
  136. );
  137. }}
  138. </DiscoverQuery>
  139. </Layout.Main>
  140. </Layout.Body>
  141. </Fragment>
  142. );
  143. }
  144. type ContentProps = {
  145. eventView: EventView;
  146. location: Location;
  147. organization: Organization;
  148. project: Project | undefined;
  149. spanExamplesResults: SpanExamplesProps;
  150. spanSlug: SpanSlug;
  151. suspectSpansResults: SuspectSpansProps;
  152. totalCount: number;
  153. transactionName: string;
  154. };
  155. function SpanDetailsContent(props: ContentProps) {
  156. const {
  157. location,
  158. organization,
  159. project,
  160. eventView,
  161. spanSlug,
  162. transactionName,
  163. totalCount,
  164. suspectSpansResults,
  165. spanExamplesResults,
  166. } = props;
  167. // There should always be exactly 1 result
  168. const suspectSpan = suspectSpansResults.suspectSpans?.[0];
  169. const examples = spanExamplesResults.examples?.[0]?.examples;
  170. const transactionCountContainingSpan = suspectSpan?.frequency;
  171. return (
  172. <Fragment>
  173. <Feature features={['performance-span-histogram-view']}>
  174. <SpanDetailsControls
  175. organization={organization}
  176. location={location}
  177. eventView={eventView}
  178. />
  179. </Feature>
  180. <SpanDetailsHeader
  181. spanSlug={spanSlug}
  182. totalCount={totalCount}
  183. suspectSpan={suspectSpan}
  184. />
  185. <SpanChart
  186. totalCount={transactionCountContainingSpan}
  187. organization={organization}
  188. eventView={eventView}
  189. spanSlug={spanSlug}
  190. />
  191. <SpanTable
  192. location={location}
  193. organization={organization}
  194. project={project}
  195. suspectSpan={suspectSpan}
  196. transactionName={transactionName}
  197. isLoading={spanExamplesResults.isLoading}
  198. examples={examples ?? []}
  199. pageLinks={spanExamplesResults.pageLinks}
  200. />
  201. </Fragment>
  202. );
  203. }
  204. function getSpansEventView(eventView: EventView): EventView {
  205. // TODO: There is a bug where if the sort is not avg occurrence,
  206. // then the avg occurrence will never be added to the fields
  207. eventView = eventView.withSorts([{field: SpanSortOthers.AVG_OCCURRENCE, kind: 'desc'}]);
  208. eventView.fields = [
  209. {field: 'count()'},
  210. {field: 'count_unique(id)'},
  211. {field: 'equation|count() / count_unique(id)'},
  212. {field: 'sumArray(spans_exclusive_time)'},
  213. {field: 'percentileArray(spans_exclusive_time, 0.50)'},
  214. {field: 'percentileArray(spans_exclusive_time, 0.75)'},
  215. {field: 'percentileArray(spans_exclusive_time, 0.95)'},
  216. {field: 'percentileArray(spans_exclusive_time, 0.99)'},
  217. ];
  218. return eventView;
  219. }