replayFrameEvents.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import type {
  2. BreadcrumbFrameEvent as TBreadcrumbFrameEvent,
  3. OptionFrameEvent as TOptionFrameEvent,
  4. SpanFrameEvent as TSpanFrameEvent,
  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 TBreadcrumbFrameEvent | TSpanFrameEvent | TOptionFrameEvent
  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. * BreadcrumbFrameEvent({
  22. * timestamp,
  23. * data: {
  24. * payload: TestStubs.BreadcrumbFrameData.FOO({}),
  25. * },
  26. * });
  27. * ```
  28. */
  29. export function BreadcrumbFrameEvent(
  30. fields: TestableFrameEvent<TBreadcrumbFrameEvent>
  31. ): TBreadcrumbFrameEvent {
  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. * SpanFrameEvent({
  48. * timestamp,
  49. * data: {
  50. * payload: TestStubs.Replay.SpanFrame({
  51. * data: TestStubs.ReplaySpanFrameData.FOO({...})
  52. * }),
  53. * },
  54. * });
  55. * ```
  56. */
  57. export function SpanFrameEvent(
  58. fields: TestableFrameEvent<TSpanFrameEvent>
  59. ): TSpanFrameEvent {
  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 OptionFrameEvent(
  70. fields: TestableFrameEvent<TOptionFrameEvent>
  71. ): TOptionFrameEvent {
  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 OptionFrame(
  82. fields: Partial<TOptionFrameEvent['data']['payload']>
  83. ): TOptionFrameEvent['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. useCompression: false,
  95. useCompressionOption: false,
  96. ...fields,
  97. };
  98. }