@@ -2,40 +2,12 @@ import { browserPerformanceTimeOrigin } from '@sentry/utils';
2
2
import { record } from 'rrweb' ;
3
3
4
4
import { 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' ;
39
11
40
12
// Map entryType -> function to normalize data for event
41
13
// @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
46
18
// @ts -ignore TODO: entry type does not fit the create* functions entry type
47
19
navigation : createNavigationEntry ,
48
20
// @ts -ignore TODO: entry type does not fit the create* functions entry type
49
- [ 'largest-contentful-paint' ] : createLargestContentfulPaint ,
21
+ 'largest-contentful-paint' : createLargestContentfulPaint ,
50
22
} ;
51
23
24
+ /**
25
+ * Create replay performance entries from the browser performance entries.
26
+ */
52
27
export function createPerformanceEntries ( entries : AllPerformanceEntry [ ] ) : ReplayPerformanceEntry [ ] {
53
28
return entries . map ( createPerformanceEntry ) . filter ( Boolean ) as ReplayPerformanceEntry [ ] ;
54
29
}
@@ -67,9 +42,7 @@ function getAbsoluteTime(time: number): number {
67
42
return ( ( browserPerformanceTimeOrigin || WINDOW . performance . timeOrigin ) + time ) / 1000 ;
68
43
}
69
44
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 {
73
46
const { duration, entryType, name, startTime } = entry ;
74
47
75
48
const start = getAbsoluteTime ( startTime ) ;
@@ -81,9 +54,7 @@ function createPaintEntry(entry: PerformancePaintTiming) {
81
54
} ;
82
55
}
83
56
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 {
87
58
// TODO: There looks to be some more interesting bits in here (domComplete, domContentLoaded)
88
59
const { entryType, name, duration, domComplete, startTime, transferSize, type } = entry ;
89
60
@@ -104,9 +75,7 @@ function createNavigationEntry(entry: PerformanceNavigationTiming) {
104
75
} ;
105
76
}
106
77
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 {
110
79
const { entryType, initiatorType, name, responseEnd, startTime, encodedBodySize, transferSize } = entry ;
111
80
112
81
// Core SDK handles these
@@ -126,9 +95,9 @@ function createResourceEntry(entry: PerformanceResourceTiming) {
126
95
} ;
127
96
}
128
97
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 {
132
101
const { duration, entryType, startTime, size } = entry ;
133
102
134
103
const start = getAbsoluteTime ( startTime ) ;
@@ -147,25 +116,3 @@ function createLargestContentfulPaint(entry: PerformanceEntry & { size: number;
147
116
} ,
148
117
} ;
149
118
}
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