breadcrumbs.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import type {Color} from 'sentry/utils/theme';
  2. export enum BreadcrumbLevelType {
  3. FATAL = 'fatal',
  4. ERROR = 'error',
  5. WARNING = 'warning',
  6. INFO = 'info',
  7. DEBUG = 'debug',
  8. UNDEFINED = 'undefined',
  9. LOG = 'log',
  10. }
  11. export enum BreadcrumbType {
  12. INFO = 'info',
  13. DEBUG = 'debug',
  14. MESSAGE = 'message',
  15. QUERY = 'query',
  16. UI = 'ui',
  17. USER = 'user',
  18. EXCEPTION = 'exception',
  19. WARNING = 'warning',
  20. ERROR = 'error',
  21. DEFAULT = 'default',
  22. HTTP = 'http',
  23. NAVIGATION = 'navigation',
  24. SYSTEM = 'system',
  25. SESSION = 'session',
  26. TRANSACTION = 'transaction',
  27. INIT = 'init',
  28. }
  29. type BreadcrumbTypeBase = {
  30. level: BreadcrumbLevelType;
  31. // it's recommended
  32. category?: string | null;
  33. event_id?: string | null;
  34. message?: string;
  35. timestamp?: string;
  36. };
  37. export type BreadcrumbTypeSystem = {
  38. action: string;
  39. extras: Record<string, any>;
  40. type: BreadcrumbType.SYSTEM;
  41. } & BreadcrumbTypeBase;
  42. export type BreadcrumbTypeSession = {
  43. action: string;
  44. extras: Record<string, any>;
  45. type: BreadcrumbType.SESSION;
  46. } & BreadcrumbTypeBase;
  47. export type BreadcrumbTypeNavigation = {
  48. type: BreadcrumbType.NAVIGATION;
  49. data?: null | {
  50. from?: string;
  51. to?: string;
  52. };
  53. } & BreadcrumbTypeBase;
  54. export type BreadcrumbTypeHTTP = {
  55. type: BreadcrumbType.HTTP;
  56. data?: null | {
  57. method?:
  58. | 'POST'
  59. | 'PUT'
  60. | 'GET'
  61. | 'HEAD'
  62. | 'DELETE'
  63. | 'CONNECT'
  64. | 'OPTIONS'
  65. | 'TRACE'
  66. | 'PATCH';
  67. reason?: string;
  68. status_code?: number;
  69. url?: string;
  70. };
  71. } & BreadcrumbTypeBase;
  72. export type BreadcrumbTypeDefault = {
  73. type:
  74. | BreadcrumbType.INFO
  75. | BreadcrumbType.DEBUG
  76. | BreadcrumbType.QUERY
  77. | BreadcrumbType.UI
  78. | BreadcrumbType.USER
  79. | BreadcrumbType.EXCEPTION
  80. | BreadcrumbType.WARNING
  81. | BreadcrumbType.ERROR
  82. | BreadcrumbType.DEFAULT
  83. | BreadcrumbType.INIT
  84. | BreadcrumbType.SESSION
  85. | BreadcrumbType.SYSTEM
  86. | BreadcrumbType.TRANSACTION;
  87. data?: Record<string, any> | null;
  88. } & BreadcrumbTypeBase;
  89. export type RawCrumb =
  90. | BreadcrumbTypeNavigation
  91. | BreadcrumbTypeHTTP
  92. | BreadcrumbTypeDefault;
  93. export type Crumb = RawCrumb & {
  94. color: Color;
  95. description: string;
  96. id: number;
  97. };
  98. export function isBreadcrumbTypeDefault(
  99. breadcrumb: RawCrumb
  100. ): breadcrumb is BreadcrumbTypeDefault {
  101. return ![BreadcrumbType.HTTP, BreadcrumbType.NAVIGATION].includes(breadcrumb.type);
  102. }