@@ -2,40 +2,12 @@ import { browserPerformanceTimeOrigin } from '@sentry/utils';
22import { record } from 'rrweb' ;
33
44import { WINDOW } from './constants' ;
5- import type { AllPerformanceEntry , PerformanceNavigationTiming , PerformancePaintTiming } from './types' ;
6-
7- export interface ReplayPerformanceEntry {
8- /**
9- * One of these types https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType
10- */
11- type : string ;
12-
13- /**
14- * A more specific description of the performance entry
15- */
16- name : string ;
17-
18- /**
19- * The start timestamp in seconds
20- */
21- start : number ;
22-
23- /**
24- * The end timestamp in seconds
25- */
26- end : number ;
27-
28- /**
29- * Additional unstructured data to be included
30- */
31- data ?: Record < string , unknown > ;
32- }
33-
34- interface MemoryInfo {
35- jsHeapSizeLimit : number ;
36- totalJSHeapSize : number ;
37- usedJSHeapSize : number ;
38- }
5+ import type {
6+ AllPerformanceEntry ,
7+ PerformanceNavigationTiming ,
8+ PerformancePaintTiming ,
9+ ReplayPerformanceEntry ,
10+ } from './types' ;
3911
4012// Map entryType -> function to normalize data for event
4113// @ts -ignore TODO: entry type does not fit the create* functions entry type
@@ -46,9 +18,12 @@ const ENTRY_TYPES: Record<string, (entry: AllPerformanceEntry) => null | ReplayP
4618 // @ts -ignore TODO: entry type does not fit the create* functions entry type
4719 navigation : createNavigationEntry ,
4820 // @ts -ignore TODO: entry type does not fit the create* functions entry type
49- [ 'largest-contentful-paint' ] : createLargestContentfulPaint ,
21+ 'largest-contentful-paint' : createLargestContentfulPaint ,
5022} ;
5123
24+ /**
25+ * Create replay performance entries from the browser performance entries.
26+ */
5227export function createPerformanceEntries ( entries : AllPerformanceEntry [ ] ) : ReplayPerformanceEntry [ ] {
5328 return entries . map ( createPerformanceEntry ) . filter ( Boolean ) as ReplayPerformanceEntry [ ] ;
5429}
@@ -67,9 +42,7 @@ function getAbsoluteTime(time: number): number {
6742 return ( ( browserPerformanceTimeOrigin || WINDOW . performance . timeOrigin ) + time ) / 1000 ;
6843}
6944
70- // TODO: type definition!
71- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
72- function createPaintEntry ( entry : PerformancePaintTiming ) {
45+ function createPaintEntry ( entry : PerformancePaintTiming ) : ReplayPerformanceEntry {
7346 const { duration, entryType, name, startTime } = entry ;
7447
7548 const start = getAbsoluteTime ( startTime ) ;
@@ -81,9 +54,7 @@ function createPaintEntry(entry: PerformancePaintTiming) {
8154 } ;
8255}
8356
84- // TODO: type definition!
85- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
86- function createNavigationEntry ( entry : PerformanceNavigationTiming ) {
57+ function createNavigationEntry ( entry : PerformanceNavigationTiming ) : ReplayPerformanceEntry | null {
8758 // TODO: There looks to be some more interesting bits in here (domComplete, domContentLoaded)
8859 const { entryType, name, duration, domComplete, startTime, transferSize, type } = entry ;
8960
@@ -104,9 +75,7 @@ function createNavigationEntry(entry: PerformanceNavigationTiming) {
10475 } ;
10576}
10677
107- // TODO: type definition!
108- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
109- function createResourceEntry ( entry : PerformanceResourceTiming ) {
78+ function createResourceEntry ( entry : PerformanceResourceTiming ) : ReplayPerformanceEntry | null {
11079 const { entryType, initiatorType, name, responseEnd, startTime, encodedBodySize, transferSize } = entry ;
11180
11281 // Core SDK handles these
@@ -126,9 +95,9 @@ function createResourceEntry(entry: PerformanceResourceTiming) {
12695 } ;
12796}
12897
129- // TODO: type definition!
130- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
131- function createLargestContentfulPaint ( entry : PerformanceEntry & { size : number ; element : Node } ) {
98+ function createLargestContentfulPaint (
99+ entry : PerformanceEntry & { size : number ; element : Node } ,
100+ ) : ReplayPerformanceEntry {
132101 const { duration, entryType, startTime, size } = entry ;
133102
134103 const start = getAbsoluteTime ( startTime ) ;
@@ -147,25 +116,3 @@ function createLargestContentfulPaint(entry: PerformanceEntry & { size: number;
147116 } ,
148117 } ;
149118}
150-
151- type ReplayMemoryEntry = ReplayPerformanceEntry & { data : { memory : MemoryInfo } } ;
152-
153- export function createMemoryEntry ( memoryEntry : MemoryInfo ) : ReplayMemoryEntry {
154- const { jsHeapSizeLimit, totalJSHeapSize, usedJSHeapSize } = memoryEntry ;
155- // we don't want to use `getAbsoluteTime` because it adds the event time to the
156- // time origin, so we get the current timestamp instead
157- const time = new Date ( ) . getTime ( ) / 1000 ;
158- return {
159- type : 'memory' ,
160- name : 'memory' ,
161- start : time ,
162- end : time ,
163- data : {
164- memory : {
165- jsHeapSizeLimit,
166- totalJSHeapSize,
167- usedJSHeapSize,
168- } ,
169- } ,
170- } ;
171- }
0 commit comments