breadcrumbs.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. interface 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 interface BreadcrumbTypeSystem extends BreadcrumbTypeBase {
  38. action: string;
  39. extras: Record<string, any>;
  40. type: BreadcrumbType.SYSTEM;
  41. }
  42. export interface BreadcrumbTypeSession extends BreadcrumbTypeBase {
  43. action: string;
  44. extras: Record<string, any>;
  45. type: BreadcrumbType.SESSION;
  46. }
  47. export interface BreadcrumbTypeNavigation extends BreadcrumbTypeBase {
  48. type: BreadcrumbType.NAVIGATION;
  49. data?: null | {
  50. from?: string;
  51. to?: string;
  52. };
  53. }
  54. export interface BreadcrumbTypeHTTP extends BreadcrumbTypeBase {
  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. }
  72. export interface BreadcrumbTypeDefault extends BreadcrumbTypeBase {
  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. }
  89. export type RawCrumb =
  90. | BreadcrumbTypeNavigation
  91. | BreadcrumbTypeHTTP
  92. | BreadcrumbTypeDefault;
  93. interface BaseCrumb {
  94. color: Color;
  95. description: string;
  96. id: number;
  97. }
  98. interface NavigationCrumb extends BaseCrumb, BreadcrumbTypeNavigation {}
  99. interface HTTPCrumb extends BaseCrumb, BreadcrumbTypeHTTP {}
  100. interface DefaultCrumb extends BaseCrumb, BreadcrumbTypeDefault {}
  101. export type Crumb = NavigationCrumb | HTTPCrumb | DefaultCrumb;
  102. export function isBreadcrumbLogLevel(logLevel: string): logLevel is BreadcrumbLevelType {
  103. return Object.values(BreadcrumbLevelType).includes(logLevel as any);
  104. }
  105. export function isBreadcrumbTypeDefault(
  106. breadcrumb: Crumb
  107. ): breadcrumb is Extract<Crumb, BreadcrumbTypeDefault> {
  108. return ![BreadcrumbType.HTTP, BreadcrumbType.NAVIGATION].includes(breadcrumb.type);
  109. }