utils.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {BreadcrumbType, Crumb} from 'sentry/types/breadcrumbs';
  2. /**
  3. * Generate breadcrumb descriptions based on type
  4. */
  5. export function getDescription(crumb: Crumb, startTimestampMs?: number) {
  6. if (crumb.data && 'action' in crumb.data) {
  7. switch (crumb.data.action) {
  8. case 'largest-contentful-paint':
  9. if (crumb.timestamp && startTimestampMs) {
  10. return `${new Date(crumb.timestamp).getTime() - startTimestampMs}ms`;
  11. }
  12. break;
  13. default:
  14. break;
  15. }
  16. }
  17. switch (crumb.type) {
  18. case BreadcrumbType.NAVIGATION:
  19. return `${crumb.data?.to ?? ''}`;
  20. case BreadcrumbType.DEFAULT:
  21. return JSON.stringify(crumb.data);
  22. default:
  23. return crumb.message || '';
  24. }
  25. }
  26. /**
  27. * Get title of breadcrumb
  28. */
  29. export function getTitle(crumb: Crumb) {
  30. // Supports replay specific breadcrumbs
  31. if (crumb.data && 'label' in crumb.data && crumb.data.label) {
  32. return crumb.data.label;
  33. }
  34. const [type, action] = crumb.category?.split('.') || [];
  35. if (type === 'ui') {
  36. return `User ${action || ''}`;
  37. }
  38. return `${type} ${action || ''}`;
  39. }
  40. /**
  41. * Generate breadcrumb title + descriptions
  42. */
  43. export function getDetails(crumb: Crumb, startTimestampMs?: number) {
  44. return {title: getTitle(crumb), description: getDescription(crumb, startTimestampMs)};
  45. }