breadcrumbs.tsx 3.1 KB

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