traceLink.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import styled from '@emotion/styled';
  2. import Link from 'sentry/components/links/link';
  3. import QuestionTooltip from 'sentry/components/questionTooltip';
  4. import {generateTraceTarget} from 'sentry/components/quickTrace/utils';
  5. import {IconChevron} from 'sentry/icons';
  6. import {t, tn} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import type {Event} from 'sentry/types';
  9. import {trackAnalytics} from 'sentry/utils/analytics';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import {useTraceTimelineEvents} from './useTraceTimelineEvents';
  12. interface TraceLinkProps {
  13. event: Event;
  14. }
  15. export function TraceLink({event}: TraceLinkProps) {
  16. const organization = useOrganization();
  17. const {data} = useTraceTimelineEvents({event});
  18. const traceTarget = generateTraceTarget(event, organization);
  19. if (!event.contexts?.trace?.trace_id) {
  20. return (
  21. <NoTraceAvailable>
  22. {t('No Trace Available')}
  23. <QuestionTooltip
  24. position="bottom"
  25. size="sm"
  26. title={t(
  27. 'Traces help you understand if there are any issues with other services connected to this event'
  28. )}
  29. />
  30. </NoTraceAvailable>
  31. );
  32. }
  33. return (
  34. <StyledLink
  35. to={traceTarget}
  36. onClick={() => {
  37. trackAnalytics('quick_trace.trace_id.clicked', {
  38. organization,
  39. source: 'issues',
  40. });
  41. }}
  42. >
  43. <span>
  44. {t('View Full Trace')}
  45. {data.length > 0 && tn(' (%s issue)', ' (%s issues)', data.length)}
  46. </span>
  47. <IconChevron direction="right" size="xs" />
  48. </StyledLink>
  49. );
  50. }
  51. const StyledLink = styled(Link)`
  52. display: flex;
  53. align-items: center;
  54. gap: ${space(0.25)};
  55. line-height: 1.2;
  56. font-size: ${p => p.theme.fontSizeMedium};
  57. svg {
  58. margin-top: 1px;
  59. }
  60. `;
  61. const NoTraceAvailable = styled('span')`
  62. display: flex;
  63. align-items: center;
  64. gap: ${space(0.25)};
  65. line-height: 1.2;
  66. color: ${p => p.theme.subText};
  67. font-size: ${p => p.theme.fontSizeMedium};
  68. svg {
  69. margin-top: 1px;
  70. }
  71. `;