content.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import {Fragment} from 'react';
  2. import {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 {Organization, Project} from 'sentry/types';
  7. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  8. import EventView from 'sentry/utils/discover/eventView';
  9. import SpanExamplesQuery, {
  10. ChildrenProps as SpanExamplesProps,
  11. } from 'sentry/utils/performance/suspectSpans/spanExamplesQuery';
  12. import SuspectSpansQuery, {
  13. ChildrenProps as SuspectSpansProps,
  14. } from 'sentry/utils/performance/suspectSpans/suspectSpansQuery';
  15. import {SpanSlug} from 'sentry/utils/performance/suspectSpans/types';
  16. import {setGroupedEntityTag} from 'sentry/utils/performanceForSentry';
  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. setGroupedEntityTag('spans.totalCount', 1000, totalCount);
  92. }
  93. return (
  94. <SuspectSpansQuery
  95. location={location}
  96. orgSlug={organization.slug}
  97. eventView={getSpansEventView(eventView)}
  98. perSuspect={0}
  99. spanOps={[spanSlug.op]}
  100. spanGroups={[spanSlug.group]}
  101. cursor="0:0:1"
  102. minExclusiveTime={minExclusiveTime}
  103. maxExclusiveTime={maxExclusiveTime}
  104. >
  105. {suspectSpansResults => (
  106. <SpanExamplesQuery
  107. location={location}
  108. orgSlug={organization.slug}
  109. eventView={eventView}
  110. spanOp={spanSlug.op}
  111. spanGroup={spanSlug.group}
  112. limit={10}
  113. minExclusiveTime={minExclusiveTime}
  114. maxExclusiveTime={maxExclusiveTime}
  115. >
  116. {spanExamplesResults => (
  117. <SpanDetailsContent
  118. location={location}
  119. organization={organization}
  120. project={project}
  121. eventView={eventView}
  122. spanSlug={spanSlug}
  123. transactionName={transactionName}
  124. totalCount={totalCount}
  125. suspectSpansResults={suspectSpansResults}
  126. spanExamplesResults={spanExamplesResults}
  127. />
  128. )}
  129. </SpanExamplesQuery>
  130. )}
  131. </SuspectSpansQuery>
  132. );
  133. }}
  134. </DiscoverQuery>
  135. </Layout.Main>
  136. </Layout.Body>
  137. </Fragment>
  138. );
  139. }
  140. type ContentProps = {
  141. eventView: EventView;
  142. location: Location;
  143. organization: Organization;
  144. project: Project | undefined;
  145. spanExamplesResults: SpanExamplesProps;
  146. spanSlug: SpanSlug;
  147. suspectSpansResults: SuspectSpansProps;
  148. totalCount: number;
  149. transactionName: string;
  150. };
  151. function SpanDetailsContent(props: ContentProps) {
  152. const {
  153. location,
  154. organization,
  155. project,
  156. eventView,
  157. spanSlug,
  158. transactionName,
  159. totalCount,
  160. suspectSpansResults,
  161. spanExamplesResults,
  162. } = props;
  163. // There should always be exactly 1 result
  164. const suspectSpan = suspectSpansResults.suspectSpans?.[0];
  165. const examples = spanExamplesResults.examples?.[0]?.examples;
  166. const transactionCountContainingSpan = suspectSpan?.frequency;
  167. return (
  168. <Fragment>
  169. <Feature features={['performance-span-histogram-view']}>
  170. <SpanDetailsControls
  171. organization={organization}
  172. location={location}
  173. eventView={eventView}
  174. />
  175. </Feature>
  176. <SpanDetailsHeader
  177. spanSlug={spanSlug}
  178. totalCount={totalCount}
  179. suspectSpan={suspectSpan}
  180. />
  181. <SpanChart
  182. totalCount={transactionCountContainingSpan}
  183. organization={organization}
  184. eventView={eventView}
  185. spanSlug={spanSlug}
  186. />
  187. <SpanTable
  188. location={location}
  189. organization={organization}
  190. project={project}
  191. suspectSpan={suspectSpan}
  192. transactionName={transactionName}
  193. isLoading={spanExamplesResults.isLoading}
  194. examples={examples ?? []}
  195. pageLinks={spanExamplesResults.pageLinks}
  196. />
  197. </Fragment>
  198. );
  199. }
  200. function getSpansEventView(eventView: EventView): EventView {
  201. // TODO: There is a bug where if the sort is not avg occurrence,
  202. // then the avg occurrence will never be added to the fields
  203. eventView = eventView.withSorts([{field: SpanSortOthers.AVG_OCCURRENCE, kind: 'desc'}]);
  204. eventView.fields = [
  205. {field: 'count()'},
  206. {field: 'count_unique(id)'},
  207. {field: 'equation|count() / count_unique(id)'},
  208. {field: 'sumArray(spans_exclusive_time)'},
  209. {field: 'percentileArray(spans_exclusive_time, 0.50)'},
  210. {field: 'percentileArray(spans_exclusive_time, 0.75)'},
  211. {field: 'percentileArray(spans_exclusive_time, 0.95)'},
  212. {field: 'percentileArray(spans_exclusive_time, 0.99)'},
  213. ];
  214. return eventView;
  215. }