replayBreadcrumbFrameData.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import {BreadcrumbType} from 'sentry/types/breadcrumbs';
  2. import {RawBreadcrumbFrame, RawHydrationErrorFrame} from 'sentry/utils/replays/types';
  3. type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
  4. type TestableFrame<Cat extends RawBreadcrumbFrame['category']> = Overwrite<
  5. Partial<Extract<RawBreadcrumbFrame, {category: Cat}>>,
  6. {timestamp: Date}
  7. >;
  8. type MockFrame<Cat extends RawBreadcrumbFrame['category']> = Extract<
  9. RawBreadcrumbFrame,
  10. {category: Cat}
  11. >;
  12. export function ReplayConsoleFrameFixture(
  13. fields: TestableFrame<'console'>
  14. ): MockFrame<'console'> {
  15. return {
  16. category: 'console',
  17. data: fields.data ?? {
  18. logger: 'unknown',
  19. },
  20. level: fields.level ?? 'fatal',
  21. message: fields.message ?? '',
  22. timestamp: fields.timestamp.getTime() / 1000,
  23. type: BreadcrumbType.DEBUG,
  24. };
  25. }
  26. export function ReplayClickFrameFixture(
  27. fields: TestableFrame<'ui.click'>
  28. ): MockFrame<'ui.click'> {
  29. return {
  30. category: 'ui.click',
  31. data: fields.data ?? {},
  32. message: fields.message ?? '',
  33. timestamp: fields.timestamp.getTime() / 1000,
  34. type: BreadcrumbType.UI,
  35. };
  36. }
  37. export function ReplayInputFrameFixture(
  38. fields: TestableFrame<'ui.input'>
  39. ): MockFrame<'ui.input'> {
  40. return {
  41. category: 'ui.input',
  42. message: fields.message ?? '',
  43. timestamp: fields.timestamp.getTime() / 1000,
  44. type: BreadcrumbType.DEFAULT,
  45. };
  46. }
  47. export function ReplayKeyboardEventFrameFixture(
  48. fields: TestableFrame<'ui.keyDown'>
  49. ): MockFrame<'ui.keyDown'> {
  50. return {
  51. category: 'ui.keyDown',
  52. data: fields.data ?? {
  53. altKey: false,
  54. ctrlKey: false,
  55. key: 'A',
  56. metaKey: false,
  57. shiftKey: false,
  58. },
  59. message: fields.message,
  60. timestamp: fields.timestamp.getTime() / 1000,
  61. type: BreadcrumbType.DEFAULT,
  62. };
  63. }
  64. export function ReplayBlurFrameFixture(
  65. fields: TestableFrame<'ui.blur'>
  66. ): MockFrame<'ui.blur'> {
  67. return {
  68. category: 'ui.blur',
  69. message: fields.message,
  70. timestamp: fields.timestamp.getTime() / 1000,
  71. type: BreadcrumbType.DEFAULT,
  72. };
  73. }
  74. export function ReplayFocusFrameFixture(
  75. fields: TestableFrame<'ui.focus'>
  76. ): MockFrame<'ui.focus'> {
  77. return {
  78. category: 'ui.focus',
  79. message: fields.message,
  80. timestamp: fields.timestamp.getTime() / 1000,
  81. type: BreadcrumbType.DEFAULT,
  82. };
  83. }
  84. export function ReplaySlowClickFrameFixture(
  85. fields: TestableFrame<'ui.slowClickDetected'>
  86. ): MockFrame<'ui.slowClickDetected'> {
  87. return {
  88. category: 'ui.slowClickDetected',
  89. data: fields.data ?? {
  90. clickCount: undefined,
  91. endReason: '',
  92. timeAfterClickMs: 5,
  93. url: '/',
  94. },
  95. message: fields.message,
  96. timestamp: fields.timestamp.getTime() / 1000,
  97. type: BreadcrumbType.DEFAULT,
  98. };
  99. }
  100. export function ReplayHydrationErrorFrameFixture(
  101. fields: TestableFrame<'replay.hydrate-error'>
  102. ): RawHydrationErrorFrame {
  103. return {
  104. category: 'replay.hydrate-error',
  105. message: '',
  106. timestamp: fields.timestamp.getTime() / 1000,
  107. data: fields.data ?? undefined,
  108. type: BreadcrumbType.DEFAULT,
  109. };
  110. }
  111. export function ReplayMutationFrameFixture(
  112. fields: TestableFrame<'replay.mutations'>
  113. ): MockFrame<'replay.mutations'> {
  114. return {
  115. category: 'replay.mutations',
  116. data: fields.data ?? {
  117. count: 1100,
  118. limit: true,
  119. },
  120. message: fields.message,
  121. timestamp: fields.timestamp.getTime() / 1000,
  122. type: '',
  123. };
  124. }
  125. export function ReplayNavFrameFixture(
  126. fields: TestableFrame<'navigation'>
  127. ): MockFrame<'navigation'> {
  128. return {
  129. category: 'navigation',
  130. data: fields.data ?? {
  131. from: '',
  132. to: '',
  133. },
  134. message: fields.message ?? '',
  135. timestamp: fields.timestamp.getTime() / 1000,
  136. type: '',
  137. };
  138. }