header.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import {useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import Feature from 'sentry/components/acl/feature';
  5. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import {CreateAlertFromViewButton} from 'sentry/components/createAlertButton';
  8. import FeatureBadge from 'sentry/components/featureBadge';
  9. import IdBadge from 'sentry/components/idBadge';
  10. import * as Layout from 'sentry/components/layouts/thirds';
  11. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  12. import {TabList} from 'sentry/components/tabs';
  13. import {Tooltip} from 'sentry/components/tooltip';
  14. import {t} from 'sentry/locale';
  15. import type {Organization, Project} from 'sentry/types';
  16. import {trackAnalytics} from 'sentry/utils/analytics';
  17. import type EventView from 'sentry/utils/discover/eventView';
  18. import type {MetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  19. import HasMeasurementsQuery from 'sentry/utils/performance/vitals/hasMeasurementsQuery';
  20. import {isProfilingSupportedOrProjectHasProfiles} from 'sentry/utils/profiling/platforms';
  21. import useReplayCountForTransactions from 'sentry/utils/replayCount/useReplayCountForTransactions';
  22. import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  23. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  24. import {getCurrentLandingDisplay, LandingDisplayField} from '../landing/utils';
  25. import Tab from './tabs';
  26. import TeamKeyTransactionButton from './teamKeyTransactionButton';
  27. import TransactionThresholdButton from './transactionThresholdButton';
  28. import type {TransactionThresholdMetric} from './transactionThresholdModal';
  29. type Props = {
  30. currentTab: Tab;
  31. eventView: EventView;
  32. hasWebVitals: 'maybe' | 'yes' | 'no';
  33. location: Location;
  34. organization: Organization;
  35. projectId: string;
  36. projects: Project[];
  37. transactionName: string;
  38. metricsCardinality?: MetricsCardinalityContext;
  39. onChangeThreshold?: (threshold: number, metric: TransactionThresholdMetric) => void;
  40. };
  41. function TransactionHeader({
  42. eventView,
  43. organization,
  44. projects,
  45. projectId,
  46. metricsCardinality,
  47. location,
  48. transactionName,
  49. onChangeThreshold,
  50. currentTab,
  51. hasWebVitals,
  52. }: Props) {
  53. function handleCreateAlertSuccess() {
  54. trackAnalytics('performance_views.summary.create_alert_clicked', {
  55. organization,
  56. });
  57. }
  58. const project = projects.find(p => p.id === projectId);
  59. const hasAnomalyDetection = organization.features?.includes(
  60. 'performance-anomaly-detection-ui'
  61. );
  62. const hasSessionReplay =
  63. organization.features.includes('session-replay') &&
  64. project &&
  65. projectSupportsReplay(project);
  66. const hasProfiling =
  67. project &&
  68. organization.features.includes('profiling') &&
  69. isProfilingSupportedOrProjectHasProfiles(project);
  70. const hasAggregateWaterfall = organization.features.includes(
  71. 'starfish-aggregate-span-waterfall'
  72. );
  73. const getWebVitals = useCallback(
  74. (hasMeasurements: boolean) => {
  75. switch (hasWebVitals) {
  76. case 'maybe':
  77. // need to check if the web vitals tab should be shown
  78. // frontend projects should always show the web vitals tab
  79. if (
  80. getCurrentLandingDisplay(location, projects, eventView).field ===
  81. LandingDisplayField.FRONTEND_OTHER
  82. ) {
  83. return true;
  84. }
  85. // if it is not a frontend project, then we check to see if there
  86. // are any web vitals associated with the transaction recently
  87. return hasMeasurements;
  88. case 'yes':
  89. // always show the web vitals tab
  90. return true;
  91. case 'no':
  92. default:
  93. // never show the web vitals tab
  94. return false;
  95. }
  96. },
  97. [hasWebVitals, location, projects, eventView]
  98. );
  99. const {getReplayCountForTransaction} = useReplayCountForTransactions({
  100. statsPeriod: '90d',
  101. });
  102. const replaysCount = getReplayCountForTransaction(transactionName);
  103. const hasTransactionSummaryCleanupFlag = organization.features.includes(
  104. 'performance-transaction-summary-cleanup'
  105. );
  106. return (
  107. <Layout.Header>
  108. <Layout.HeaderContent>
  109. <Breadcrumb
  110. organization={organization}
  111. location={location}
  112. transaction={{
  113. project: projectId,
  114. name: transactionName,
  115. }}
  116. tab={currentTab}
  117. />
  118. <Layout.Title>
  119. {project && (
  120. <IdBadge
  121. project={project}
  122. avatarSize={28}
  123. hideName
  124. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  125. />
  126. )}
  127. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  128. <TransactionName>{transactionName}</TransactionName>
  129. </Tooltip>
  130. </Layout.Title>
  131. </Layout.HeaderContent>
  132. <Layout.HeaderActions>
  133. <ButtonBar gap={1}>
  134. <Feature organization={organization} features="incidents">
  135. {({hasFeature}) =>
  136. hasFeature && !metricsCardinality?.isLoading ? (
  137. <CreateAlertFromViewButton
  138. size="sm"
  139. eventView={eventView}
  140. organization={organization}
  141. projects={projects}
  142. onClick={handleCreateAlertSuccess}
  143. referrer="performance"
  144. alertType="trans_duration"
  145. aria-label={t('Create Alert')}
  146. disableMetricDataset={
  147. metricsCardinality?.outcome?.forceTransactionsOnly
  148. }
  149. />
  150. ) : null
  151. }
  152. </Feature>
  153. <TeamKeyTransactionButton
  154. transactionName={transactionName}
  155. eventView={eventView}
  156. organization={organization}
  157. />
  158. <GuideAnchor target="project_transaction_threshold_override" position="bottom">
  159. <TransactionThresholdButton
  160. organization={organization}
  161. transactionName={transactionName}
  162. eventView={eventView}
  163. onChangeThreshold={onChangeThreshold}
  164. />
  165. </GuideAnchor>
  166. </ButtonBar>
  167. </Layout.HeaderActions>
  168. <HasMeasurementsQuery
  169. location={location}
  170. orgSlug={organization.slug}
  171. eventView={eventView}
  172. transaction={transactionName}
  173. type="web"
  174. >
  175. {({hasMeasurements}) => {
  176. const renderWebVitals = getWebVitals(!!hasMeasurements);
  177. return (
  178. <TabList
  179. hideBorder
  180. outerWrapStyles={{
  181. gridColumn: '1 / -1',
  182. }}
  183. >
  184. <TabList.Item key={Tab.TRANSACTION_SUMMARY}>{t('Overview')}</TabList.Item>
  185. <TabList.Item key={Tab.EVENTS}>{t('Sampled Events')}</TabList.Item>
  186. <TabList.Item key={Tab.TAGS}>{t('Tags')}</TabList.Item>
  187. <TabList.Item key={Tab.SPANS} hidden={hasTransactionSummaryCleanupFlag}>
  188. {t('Spans')}
  189. </TabList.Item>
  190. <TabList.Item
  191. key={Tab.ANOMALIES}
  192. textValue={t('Anomalies')}
  193. hidden={!hasAnomalyDetection}
  194. >
  195. {t('Anomalies')}
  196. <FeatureBadge type="alpha" tooltipProps={{disabled: true}} />
  197. </TabList.Item>
  198. <TabList.Item
  199. key={Tab.WEB_VITALS}
  200. textValue={t('Web Vitals')}
  201. hidden={!renderWebVitals}
  202. >
  203. {t('Web Vitals')}
  204. </TabList.Item>
  205. <TabList.Item
  206. key={Tab.REPLAYS}
  207. textValue={t('Replays')}
  208. hidden={!hasSessionReplay}
  209. >
  210. {t('Replays')}
  211. <ReplayCountBadge count={replaysCount} />
  212. </TabList.Item>
  213. <TabList.Item
  214. key={Tab.PROFILING}
  215. textValue={t('Profiling')}
  216. hidden={!hasProfiling}
  217. >
  218. {t('Profiles')}
  219. </TabList.Item>
  220. <TabList.Item
  221. key={Tab.AGGREGATE_WATERFALL}
  222. textValue={t('Aggregate Spans')}
  223. hidden={!hasAggregateWaterfall}
  224. >
  225. {t('Aggregate Spans')}
  226. </TabList.Item>
  227. </TabList>
  228. );
  229. }}
  230. </HasMeasurementsQuery>
  231. </Layout.Header>
  232. );
  233. }
  234. const TransactionName = styled('div')`
  235. ${p => p.theme.overflowEllipsis}
  236. `;
  237. export default TransactionHeader;