breadcrumbs.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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?:
  72. | null
  73. | Record<string, any>
  74. // Though this is the expected type, more data can be attached to these crumbs
  75. | {
  76. method?:
  77. | 'POST'
  78. | 'PUT'
  79. | 'GET'
  80. | 'HEAD'
  81. | 'DELETE'
  82. | 'CONNECT'
  83. | 'OPTIONS'
  84. | 'TRACE'
  85. | 'PATCH';
  86. reason?: string;
  87. status_code?: number;
  88. url?: string;
  89. };
  90. }
  91. export interface BreadcrumbTypeDefault extends BreadcrumbTypeBase {
  92. type:
  93. | BreadcrumbType.INFO
  94. | BreadcrumbType.DEBUG
  95. | BreadcrumbType.QUERY
  96. | BreadcrumbType.UI
  97. | BreadcrumbType.USER
  98. | BreadcrumbType.EXCEPTION
  99. | BreadcrumbType.WARNING
  100. | BreadcrumbType.ERROR
  101. | BreadcrumbType.DEFAULT
  102. | BreadcrumbType.INIT
  103. | BreadcrumbType.SESSION
  104. | BreadcrumbType.SYSTEM
  105. | BreadcrumbType.TRANSACTION;
  106. data?: Record<string, any> | null;
  107. }
  108. export type RawCrumb =
  109. | BreadcrumbTypeNavigation
  110. | BreadcrumbTypeHTTP
  111. | BreadcrumbTypeDefault;
  112. interface BaseCrumb {
  113. color: Color;
  114. description: string;
  115. id: number;
  116. }
  117. interface NavigationCrumb extends BaseCrumb, BreadcrumbTypeNavigation {}
  118. interface HTTPCrumb extends BaseCrumb, BreadcrumbTypeHTTP {}
  119. interface DefaultCrumb extends BaseCrumb, BreadcrumbTypeDefault {}
  120. export type Crumb = NavigationCrumb | HTTPCrumb | DefaultCrumb;
  121. export function isBreadcrumbLogLevel(logLevel: string): logLevel is BreadcrumbLevelType {
  122. return Object.values(BreadcrumbLevelType).includes(logLevel as any);
  123. }
  124. export function isBreadcrumbTypeDefault(
  125. breadcrumb: Crumb
  126. ): breadcrumb is Extract<Crumb, BreadcrumbTypeDefault> {
  127. return ![BreadcrumbType.HTTP, BreadcrumbType.NAVIGATION].includes(breadcrumb.type);
  128. }