helpers.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import * as BreadcrumbFrameData from 'sentry-fixture/replay/replayBreadcrumbFrameData';
  2. import * as ReplayFrameEvents from 'sentry-fixture/replay/replayFrameEvents';
  3. import * as ReplaySpanFrameData from 'sentry-fixture/replay/replaySpanFrameData';
  4. import {SlowClickFrame} from 'sentry/utils/replays/types';
  5. export function ConsoleEvent({timestamp, message}: {timestamp: Date; message?: string}) {
  6. return ReplayFrameEvents.BreadcrumbFrameEvent({
  7. timestamp,
  8. data: {
  9. payload: BreadcrumbFrameData.ConsoleFrame({
  10. timestamp,
  11. message: message ?? 'Hello World',
  12. }),
  13. },
  14. });
  15. }
  16. export function ClickEvent({timestamp}: {timestamp: Date}) {
  17. return ReplayFrameEvents.BreadcrumbFrameEvent({
  18. timestamp,
  19. data: {
  20. payload: BreadcrumbFrameData.ClickFrame({
  21. timestamp,
  22. message: 'nav[aria-label="Primary Navigation"] > div > a#sidebar-item-projects',
  23. data: {
  24. nodeId: 42,
  25. },
  26. }),
  27. },
  28. });
  29. }
  30. export function DeadClickEvent({timestamp}: {timestamp: Date}) {
  31. return ReplayFrameEvents.BreadcrumbFrameEvent({
  32. timestamp,
  33. data: {
  34. payload: BreadcrumbFrameData.SlowClickFrame({
  35. timestamp,
  36. message: 'nav[aria-label="Primary Navigation"] > div > a#sidebar-item-projects',
  37. data: {
  38. node: {
  39. tagName: 'a',
  40. },
  41. nodeId: 42,
  42. url: '',
  43. timeAfterClickMs: 7000,
  44. endReason: 'timeout',
  45. },
  46. } as SlowClickFrame),
  47. },
  48. });
  49. }
  50. export function NavigateEvent({
  51. startTimestamp,
  52. endTimestamp,
  53. }: {
  54. endTimestamp: Date;
  55. startTimestamp: Date;
  56. }) {
  57. const duration = endTimestamp.getTime() - startTimestamp.getTime(); // in MS
  58. return ReplayFrameEvents.SpanFrameEvent({
  59. timestamp: startTimestamp,
  60. data: {
  61. payload: ReplaySpanFrameData.NavigationFrame({
  62. op: 'navigation.navigate',
  63. startTimestamp,
  64. endTimestamp,
  65. description: '',
  66. data: {
  67. size: 1149,
  68. decodedBodySize: 1712,
  69. encodedBodySize: 849,
  70. duration,
  71. domInteractive: duration - 200,
  72. domContentLoadedEventStart: duration - 50,
  73. domContentLoadedEventEnd: duration - 48,
  74. loadEventStart: duration, // real value would be approx the same
  75. loadEventEnd: duration, // real value would be approx the same
  76. domComplete: duration, // real value would be approx the same
  77. redirectCount: 0,
  78. },
  79. }),
  80. },
  81. });
  82. }
  83. export function MemoryEvent({
  84. startTimestamp,
  85. endTimestamp,
  86. }: {
  87. endTimestamp: Date;
  88. startTimestamp: Date;
  89. }) {
  90. return ReplayFrameEvents.SpanFrameEvent({
  91. timestamp: startTimestamp,
  92. data: {
  93. payload: ReplaySpanFrameData.MemoryFrame({
  94. op: 'memory',
  95. startTimestamp,
  96. endTimestamp,
  97. description: '',
  98. }),
  99. },
  100. });
  101. }