breadcrumbs.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. NETWORK = 'network',
  29. DEVICE = 'device',
  30. }
  31. export enum BreadcrumbMessageFormat {
  32. SQL = 'sql',
  33. }
  34. interface BreadcrumbTypeBase {
  35. level: BreadcrumbLevelType;
  36. // it's recommended
  37. category?: string | null;
  38. event_id?: string | null;
  39. message?: string;
  40. messageFormat?: BreadcrumbMessageFormat.SQL;
  41. messageRaw?: string;
  42. timestamp?: string;
  43. }
  44. export interface BreadcrumbTypeSystem extends BreadcrumbTypeBase {
  45. action: string;
  46. extras: Record<string, any>;
  47. type: BreadcrumbType.SYSTEM;
  48. }
  49. export interface BreadcrumbTypeSession extends BreadcrumbTypeBase {
  50. action: string;
  51. extras: Record<string, any>;
  52. type: BreadcrumbType.SESSION;
  53. }
  54. export interface BreadcrumbTypeNavigation extends BreadcrumbTypeBase {
  55. type: BreadcrumbType.NAVIGATION;
  56. data?: null | {
  57. from?: string;
  58. to?: string;
  59. };
  60. }
  61. export interface BreadcrumbTypeInit extends BreadcrumbTypeBase {
  62. data: {
  63. action: 'replay-init';
  64. label: string;
  65. url: string;
  66. };
  67. type: BreadcrumbType.INIT;
  68. }
  69. export interface BreadcrumbTypeHTTP extends BreadcrumbTypeBase {
  70. type: BreadcrumbType.HTTP;
  71. data?: null | {
  72. method?:
  73. | 'POST'
  74. | 'PUT'
  75. | 'GET'
  76. | 'HEAD'
  77. | 'DELETE'
  78. | 'CONNECT'
  79. | 'OPTIONS'
  80. | 'TRACE'
  81. | 'PATCH';
  82. reason?: string;
  83. status_code?: number;
  84. url?: string;
  85. };
  86. }
  87. export interface BreadcrumbTypeDefault extends BreadcrumbTypeBase {
  88. type:
  89. | BreadcrumbType.INFO
  90. | BreadcrumbType.DEBUG
  91. | BreadcrumbType.QUERY
  92. | BreadcrumbType.UI
  93. | BreadcrumbType.USER
  94. | BreadcrumbType.EXCEPTION
  95. | BreadcrumbType.WARNING
  96. | BreadcrumbType.ERROR
  97. | BreadcrumbType.DEFAULT
  98. | BreadcrumbType.INIT
  99. | BreadcrumbType.SESSION
  100. | BreadcrumbType.SYSTEM
  101. | BreadcrumbType.TRANSACTION;
  102. data?: Record<string, any> | null;
  103. }
  104. export type RawCrumb =
  105. | BreadcrumbTypeNavigation
  106. | BreadcrumbTypeHTTP
  107. | BreadcrumbTypeDefault;
  108. interface BaseCrumb {
  109. color: Color;
  110. description: string;
  111. id: number;
  112. }
  113. interface NavigationCrumb extends BaseCrumb, BreadcrumbTypeNavigation {}
  114. interface HTTPCrumb extends BaseCrumb, BreadcrumbTypeHTTP {}
  115. interface DefaultCrumb extends BaseCrumb, BreadcrumbTypeDefault {}
  116. export type Crumb = NavigationCrumb | HTTPCrumb | DefaultCrumb;
  117. export function isBreadcrumbLogLevel(logLevel: string): logLevel is BreadcrumbLevelType {
  118. return Object.values(BreadcrumbLevelType).includes(logLevel as any);
  119. }
  120. export function isBreadcrumbTypeDefault(
  121. breadcrumb: Crumb
  122. ): breadcrumb is Extract<Crumb, BreadcrumbTypeDefault> {
  123. return ![BreadcrumbType.HTTP, BreadcrumbType.NAVIGATION].includes(breadcrumb.type);
  124. }