quickTraceMeta.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {Location} from 'history';
  2. import Feature from 'sentry/components/acl/feature';
  3. import FeatureDisabled from 'sentry/components/acl/featureDisabled';
  4. import ErrorBoundary from 'sentry/components/errorBoundary';
  5. import {Hovercard} from 'sentry/components/hovercard';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Link from 'sentry/components/links/link';
  8. import Placeholder from 'sentry/components/placeholder';
  9. import QuickTrace from 'sentry/components/quickTrace';
  10. import {generateTraceTarget} from 'sentry/components/quickTrace/utils';
  11. import {t, tct, tn} from 'sentry/locale';
  12. import {AvatarProject, OrganizationSummary} from 'sentry/types';
  13. import {Event} from 'sentry/types/event';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import {getConfigureTracingDocsLink} from 'sentry/utils/docs';
  16. import {getShortEventId} from 'sentry/utils/events';
  17. import {
  18. QuickTraceQueryChildrenProps,
  19. TraceMeta,
  20. } from 'sentry/utils/performance/quickTrace/types';
  21. import useOrganization from 'sentry/utils/useOrganization';
  22. import {MetaData} from './styles';
  23. type Props = Pick<
  24. React.ComponentProps<typeof QuickTrace>,
  25. 'errorDest' | 'transactionDest'
  26. > & {
  27. anchor: 'left' | 'right';
  28. event: Event;
  29. location: Location;
  30. quickTrace: QuickTraceQueryChildrenProps | null;
  31. traceMeta: TraceMeta | null;
  32. project?: AvatarProject;
  33. };
  34. function handleTraceLink(organization: OrganizationSummary) {
  35. trackAnalytics('quick_trace.trace_id.clicked', {
  36. organization: organization.id,
  37. source: 'events',
  38. });
  39. }
  40. export default function QuickTraceMeta({
  41. event,
  42. location,
  43. quickTrace,
  44. traceMeta,
  45. anchor,
  46. errorDest,
  47. transactionDest,
  48. project,
  49. }: Props) {
  50. const organization = useOrganization();
  51. const features = ['performance-view'];
  52. const noFeatureMessage = t('Requires performance monitoring.');
  53. const docsLink = getConfigureTracingDocsLink(project);
  54. const traceId = event.contexts?.trace?.trace_id ?? null;
  55. const traceTarget = generateTraceTarget(event, organization);
  56. let body: React.ReactNode;
  57. let footer: React.ReactNode;
  58. if (!traceId || !quickTrace || quickTrace.trace === null) {
  59. // this platform doesn't support performance don't show anything here
  60. if (docsLink === null) {
  61. return null;
  62. }
  63. body = t('Missing Trace');
  64. // need to configure tracing
  65. footer = <ExternalLink href={docsLink}>{t('Read the docs')}</ExternalLink>;
  66. } else {
  67. if (quickTrace.isLoading) {
  68. body = <Placeholder height="20px" />;
  69. } else if (quickTrace.error) {
  70. body = '\u2014';
  71. } else {
  72. body = (
  73. <ErrorBoundary mini>
  74. <QuickTrace
  75. event={event}
  76. quickTrace={{
  77. type: quickTrace.type,
  78. trace: quickTrace.trace,
  79. }}
  80. location={location}
  81. organization={organization}
  82. anchor={anchor}
  83. errorDest={errorDest}
  84. transactionDest={transactionDest}
  85. />
  86. </ErrorBoundary>
  87. );
  88. }
  89. footer = (
  90. <Link to={traceTarget} onClick={() => handleTraceLink(organization)}>
  91. {tct('View Full Trace: [id][events]', {
  92. id: getShortEventId(traceId ?? ''),
  93. events: traceMeta
  94. ? tn(' (%s event)', ' (%s events)', traceMeta.transactions + traceMeta.errors)
  95. : '',
  96. })}
  97. </Link>
  98. );
  99. }
  100. return (
  101. <Feature hookName="feature-disabled:performance-quick-trace" features={features}>
  102. {({hasFeature}) => {
  103. // also need to enable the performance feature
  104. if (!hasFeature) {
  105. footer = (
  106. <Hovercard
  107. body={
  108. <FeatureDisabled
  109. features={features}
  110. hideHelpToggle
  111. message={noFeatureMessage}
  112. featureName={noFeatureMessage}
  113. />
  114. }
  115. >
  116. {footer}
  117. </Hovercard>
  118. );
  119. }
  120. return <QuickTraceMetaBase body={body} footer={footer} />;
  121. }}
  122. </Feature>
  123. );
  124. }
  125. export function QuickTraceMetaBase({
  126. body,
  127. footer,
  128. }: {
  129. body: React.ReactNode;
  130. footer: React.ReactNode;
  131. }) {
  132. return (
  133. <MetaData
  134. headingText={t('Trace Navigator')}
  135. tooltipText={t(
  136. 'An abbreviated version of the full trace. Related frontend and backend services can be added to provide further visibility.'
  137. )}
  138. bodyText={<div data-test-id="quick-trace-body">{body}</div>}
  139. subtext={<div data-test-id="quick-trace-footer">{footer}</div>}
  140. />
  141. );
  142. }