replayFrameEvents.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import type {
  2. BreadcrumbFrameEvent,
  3. OptionFrameEvent,
  4. SpanFrameEvent,
  5. } from 'sentry/utils/replays/types';
  6. import {EventType} from 'sentry/utils/replays/types';
  7. type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
  8. type TestableFrameEvent<
  9. FrameEvent extends BreadcrumbFrameEvent | SpanFrameEvent | OptionFrameEvent,
  10. > = Overwrite<
  11. Omit<FrameEvent, 'type'>,
  12. {
  13. data: Omit<FrameEvent['data'], 'tag'>;
  14. timestamp: Date;
  15. }
  16. >;
  17. /**
  18. * `replayBreadcrumbFrameData.tsx` has factories to help construct the correct payloads.
  19. *
  20. * ```
  21. * ReplayBreadcrumbFrameEventFixture({
  22. * timestamp,
  23. * data: {
  24. * payload: {...},
  25. * },
  26. * });
  27. * ```
  28. */
  29. export function ReplayBreadcrumbFrameEventFixture(
  30. fields: TestableFrameEvent<BreadcrumbFrameEvent>
  31. ): BreadcrumbFrameEvent {
  32. return {
  33. type: EventType.Custom,
  34. timestamp: fields.timestamp.getTime(), // frame timestamps are in ms
  35. data: {
  36. tag: 'breadcrumb',
  37. payload: fields.data.payload,
  38. metric: fields.data.metric,
  39. },
  40. };
  41. }
  42. /**
  43. * `replaySpanFrameData.tsx` has factories to help consturt valid payloads given an operation name.
  44. *
  45. * ```
  46. * ReplaySpanFrameEventFixture({
  47. * timestamp,
  48. * data: {
  49. * payload: ReplayNavigationFrameFixture({
  50. * data: {...}
  51. * }),
  52. * },
  53. * });
  54. * ```
  55. */
  56. export function ReplaySpanFrameEventFixture(
  57. fields: TestableFrameEvent<SpanFrameEvent>
  58. ): SpanFrameEvent {
  59. return {
  60. type: EventType.Custom,
  61. timestamp: fields.timestamp.getTime(), // frame timestamps are in ms
  62. data: {
  63. tag: 'performanceSpan',
  64. payload: fields.data.payload,
  65. },
  66. };
  67. }
  68. export function ReplayOptionFrameEventFixture(
  69. fields: TestableFrameEvent<OptionFrameEvent>
  70. ): OptionFrameEvent {
  71. return {
  72. type: EventType.Custom,
  73. timestamp: fields.timestamp.getTime(), // frame timestamps are in ms
  74. data: {
  75. tag: 'options',
  76. payload: fields.data.payload,
  77. },
  78. };
  79. }
  80. export function ReplayOptionFrameFixture(
  81. fields: Partial<OptionFrameEvent['data']['payload']> = {}
  82. ): OptionFrameEvent['data']['payload'] {
  83. return {
  84. blockAllMedia: false,
  85. errorSampleRate: 0,
  86. maskAllInputs: false,
  87. maskAllText: false,
  88. networkCaptureBodies: false,
  89. networkDetailHasUrls: false,
  90. networkRequestHasHeaders: false,
  91. networkResponseHasHeaders: false,
  92. sessionSampleRate: 0,
  93. shouldRecordCanvas: false,
  94. useCompression: false,
  95. useCompressionOption: false,
  96. ...fields,
  97. };
  98. }