replayFrameEvents.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * `BreadcrumbFrameData` 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. * `SpanFrame()` is a factories to help consturt valid payloads given an operation name.
  44. * `ReplaySpanFrameData.*` contains more factories to build the required inner dataset.
  45. *
  46. * ```
  47. * SpanFrameEventFixture({
  48. * timestamp,
  49. * data: {
  50. * payload: ReplaySpanFrameEventFixture({
  51. * data: {...}
  52. * }),
  53. * },
  54. * });
  55. * ```
  56. */
  57. export function ReplaySpanFrameEventFixture(
  58. fields: TestableFrameEvent<SpanFrameEvent>
  59. ): SpanFrameEvent {
  60. return {
  61. type: EventType.Custom,
  62. timestamp: fields.timestamp.getTime(), // frame timestamps are in ms
  63. data: {
  64. tag: 'performanceSpan',
  65. payload: fields.data.payload,
  66. },
  67. };
  68. }
  69. export function ReplayOptionFrameEventFixture(
  70. fields: TestableFrameEvent<OptionFrameEvent>
  71. ): OptionFrameEvent {
  72. return {
  73. type: EventType.Custom,
  74. timestamp: fields.timestamp.getTime(), // frame timestamps are in ms
  75. data: {
  76. tag: 'options',
  77. payload: fields.data.payload,
  78. },
  79. };
  80. }
  81. export function ReplayOptionFrameFixture(
  82. fields: Partial<OptionFrameEvent['data']['payload']>
  83. ): OptionFrameEvent['data']['payload'] {
  84. return {
  85. blockAllMedia: false,
  86. errorSampleRate: 0,
  87. maskAllInputs: false,
  88. maskAllText: false,
  89. networkCaptureBodies: false,
  90. networkDetailHasUrls: false,
  91. networkRequestHasHeaders: false,
  92. networkResponseHasHeaders: false,
  93. sessionSampleRate: 0,
  94. shouldRecordCanvas: false,
  95. useCompression: false,
  96. useCompressionOption: false,
  97. ...fields,
  98. };
  99. }