traceLink.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import Link from 'sentry/components/links/link';
  4. import {generateTraceTarget} from 'sentry/components/quickTrace/utils';
  5. import {tct, tn} from 'sentry/locale';
  6. import type {Event} from 'sentry/types/event';
  7. import {trackAnalytics} from 'sentry/utils/analytics';
  8. import {getShortEventId} from 'sentry/utils/events';
  9. import type {QuickTraceContextChildrenProps} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  10. import type {TraceMeta} from 'sentry/utils/performance/quickTrace/types';
  11. import {useLocation} from 'sentry/utils/useLocation';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. type TraceLinkProps = {
  14. event: Event;
  15. quickTrace: QuickTraceContextChildrenProps;
  16. source: 'events' | 'issues';
  17. traceMeta: TraceMeta | null;
  18. };
  19. export function TraceLink({event, traceMeta, source, quickTrace}: TraceLinkProps) {
  20. const organization = useOrganization();
  21. const location = useLocation();
  22. const traceTarget = generateTraceTarget(event, organization, location);
  23. const traceId = event.contexts?.trace?.trace_id ?? '';
  24. const handleTraceLink = useCallback(() => {
  25. trackAnalytics('quick_trace.trace_id.clicked', {
  26. organization,
  27. source,
  28. });
  29. }, [organization, source]);
  30. if (
  31. !quickTrace ||
  32. quickTrace.isLoading ||
  33. quickTrace.error ||
  34. quickTrace.type === 'empty'
  35. ) {
  36. return null;
  37. }
  38. return (
  39. <StyledLink to={traceTarget} onClick={handleTraceLink}>
  40. {tct('View Full Trace: [id][events]', {
  41. id: getShortEventId(traceId ?? ''),
  42. events: traceMeta
  43. ? tn(' (%s event)', ' (%s events)', traceMeta.transactions + traceMeta.errors)
  44. : '',
  45. })}
  46. </StyledLink>
  47. );
  48. }
  49. const StyledLink = styled(Link)<{}>`
  50. font-size: ${p => p.theme.fontSizeSmall};
  51. `;