breadcrumbs.tsx 3.0 KB

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