Skip to content

Commit 52949ce

Browse files
authored
Fix theFMP metric (#154)
1 parent 5455942 commit 52949ce

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

src/performance/fmp.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ class FMPTiming {
115115
return false;
116116
}
117117
const resultEls: ElementList = this.filterResult(tp.els);
118-
const fmpTiming: number = this.getFmpTime(resultEls);
119-
this.fmpTime = fmpTiming;
118+
this.fmpTime = this.getFmpTime(resultEls);
120119
} else {
121120
setTimeout(() => {
122121
this.calculateFinalScore();
@@ -288,4 +287,4 @@ class FMPTiming {
288287
}
289288
}
290289

291-
export default FMPTiming;
290+
export default new FMPTiming();

src/performance/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import {handleInteractionEntry, clearInteractions, getLongestInteraction, DEFAUL
3030

3131
const handler = {
3232
set(target: {[key: string]: unknown}, prop: string, value: unknown) {
33+
if (target[prop] !== undefined) {
34+
return true
35+
}
3336
target[prop] = value;
3437
const source: {[key: string]: unknown} = {
3538
...target,
@@ -110,17 +113,18 @@ class TracePerf {
110113
}
111114
new Report('RESOURCES', this.options.collector).sendByBeacon(list);
112115
}
113-
private async getCorePerf() {
114-
if (this.options.useWebVitals) {
115-
this.LCP();
116-
this.INP();
117-
this.CLS();
118-
const {fmpTime} = await new FMP();
119-
this.coreWebMetrics.fmpTime = Math.floor(fmpTime);
116+
private getCorePerf() {
117+
if (!this.options.useWebVitals) {
118+
return;
120119
}
120+
this.LCP();
121+
this.INP();
122+
this.CLS();
123+
setTimeout(() => {
124+
this.coreWebMetrics.fmpTime = Math.floor(FMP.fmpTime);
125+
}, 5000);
121126
}
122127
private CLS() {
123-
let clsTime = 0;
124128
let partValue = 0;
125129
let entryList: LayoutShift[] = [];
126130

@@ -142,7 +146,7 @@ class TracePerf {
142146
entryList.push(entry);
143147
}
144148
});
145-
if (partValue > clsTime) {
149+
if (partValue > 0) {
146150
this.coreWebMetrics.clsTime = Math.floor(partValue);
147151
}
148152
};

test/docker/index.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,33 @@
1515
* limitations under the License.
1616
*/
1717
import ClientMonitor from 'skywalking-client-js';
18-
import Vue from 'vue';
1918

2019
ClientMonitor.register({
2120
service: 'test-ui',
2221
pagePath: 'index.html',
2322
serviceVersion: 'v1.0.0',
24-
vue: Vue,
2523
traceTimeInterval: 2000,
2624
});
2725

28-
// vue error
29-
new Vue({
30-
methods: {
31-
test() {
32-
throw {
33-
msg: 'vue error',
34-
status: 3000
35-
}
36-
}
37-
},
38-
created() {
39-
this.test();
40-
}
41-
})
26+
// promise error
27+
function foo() {
28+
Promise.reject({
29+
message: 'promise test',
30+
stack: 'promise error'
31+
});
32+
}
33+
foo();
34+
function timeout() {
35+
return new Promise((resolve, reject) => {
36+
setTimeout(() => Math.random() > 0.5 ?
37+
resolve() :
38+
reject({
39+
message: 'timeout test',
40+
stack: 2000
41+
}), 500)
42+
})
43+
}
44+
timeout();
4245

4346
fetch('http://provider:9091/info', {
4447
method: 'POST',

test/expected/error-log.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ logs:
2323
message: {{ notEmpty .message }}
2424
line: 0
2525
col: 0
26-
stack: ""
27-
errorurl: http://testui/
26+
stack: {{ .stack }}
27+
errorurl: {{ notEmpty .errorurl }}
2828
firstreportederror: {{ .firstreportederror }}
2929
{{- end }}
3030
total: {{ gt .total 0 }}

0 commit comments

Comments
 (0)