@lwrjs/o11y 0.6.5 → 0.7.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020, Salesforce.com, Inc.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getInstrumentation as t}from"o11y/client";import{
|
|
1
|
+
import{getInstrumentation as t}from"o11y/client";import{MODULE_DEFINE as e,MODULE_DEFINE_COUNT as r,BOOTSTRAP_END as n,BOOTSTRAP_DURATION as s,MODULE_FETCH_DURATION as i,MAPPINGS_FETCH_DURATION as a,MODULE_FETCH as o,MAPPINGS_FETCH as c,ROUTER_NAV as m,ROUTER_VIEW as h,ROUTER_NAV_DURATION as l,ROUTER_VIEW_DURATION as u,BOOTSTRAP_ERROR as f,BOOTSTRAP_ERROR_COUNT as k,MODULE_FETCH_COUNT as g,MODULE_ERROR as p,MODULE_ERROR_COUNT as b,MAPPINGS_FETCH_COUNT as T,MAPPINGS_ERROR as y,MAPPINGS_ERROR_COUNT as W,ROUTER_NAV_COUNT as d,ROUTER_ERROR as v,ROUTER_ERROR_COUNT as E}from"lwr/metrics";const M=[o,c,m,h],w=[l,u],O={[f]:k,[e]:r,[o]:g,[p]:b,[c]:T,[y]:W,[m]:d,[v]:E},V=Object.keys(O);class x{constructor(t,e){this.config=e||{},this.instrumentation=t}track(){this.trackExistingMarks(),this.setupObserver()}trackExistingMarks(){const t=performance.getEntriesByType("mark").filter((t=>t.name.startsWith(e)));t.length>0&&this.instrumentation.incrementCounter(r,t.length)}setupObserver(){new PerformanceObserver((t=>{t.getEntries().forEach((t=>{const{name:e,duration:r,startTime:o}=t;e===n&&this.instrumentation.trackValue(s,o);const c=V.find((t=>e.startsWith(t)));c&&this.instrumentation.incrementCounter(O[c],1),this.config.enableModuleFetchTracking&&e.startsWith(i)&&this.instrumentation.trackValue(e,r),this.config.enableMappingFetchTracking&&e.startsWith(a)&&this.instrumentation.trackValue(e,r),w.some((t=>e.startsWith(t)))&&this.instrumentation.trackValue(e,r),M.some((t=>e.startsWith(t)))||performance.clearMarks(e)}))})).observe({entryTypes:["mark","measure"]})}}const C=void 0!==globalThis.performance&&"function"==typeof globalThis.performance.mark,j=globalThis.LWR,F={track:()=>{}};function B(e){const r=t("lwrjs"),n=j.metricsConfig||{};(C?new x(r,n):F).track()}export default B;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BOOTSTRAP_DURATION, BOOTSTRAP_END, BOOTSTRAP_ERROR, BOOTSTRAP_ERROR_COUNT, MAPPINGS_ERROR, MAPPINGS_ERROR_COUNT, MAPPINGS_FETCH, MAPPINGS_FETCH_COUNT, MAPPINGS_FETCH_DURATION, MODULE_DEFINE, MODULE_DEFINE_COUNT, MODULE_ERROR, MODULE_ERROR_COUNT, MODULE_FETCH, MODULE_FETCH_COUNT, MODULE_FETCH_DURATION, ROUTER_ERROR, ROUTER_ERROR_COUNT, ROUTER_NAV, ROUTER_NAV_COUNT, ROUTER_NAV_DURATION, ROUTER_VIEW, ROUTER_VIEW_DURATION } from 'lwr/metrics';
|
|
2
|
+
const doNotClear = [MODULE_FETCH, MAPPINGS_FETCH, ROUTER_NAV, ROUTER_VIEW];
|
|
3
|
+
const durationMetrics = [ROUTER_NAV_DURATION, ROUTER_VIEW_DURATION];
|
|
4
|
+
const countMap = {
|
|
5
|
+
[BOOTSTRAP_ERROR]: BOOTSTRAP_ERROR_COUNT,
|
|
6
|
+
[MODULE_DEFINE]: MODULE_DEFINE_COUNT,
|
|
7
|
+
[MODULE_FETCH]: MODULE_FETCH_COUNT,
|
|
8
|
+
[MODULE_ERROR]: MODULE_ERROR_COUNT,
|
|
9
|
+
[MAPPINGS_FETCH]: MAPPINGS_FETCH_COUNT,
|
|
10
|
+
[MAPPINGS_ERROR]: MAPPINGS_ERROR_COUNT,
|
|
11
|
+
[ROUTER_NAV]: ROUTER_NAV_COUNT,
|
|
12
|
+
[ROUTER_ERROR]: ROUTER_ERROR_COUNT
|
|
13
|
+
};
|
|
14
|
+
const metricsToCount = Object.keys(countMap);
|
|
2
15
|
export class PerformanceApiSink {
|
|
3
|
-
marks = {};
|
|
4
|
-
|
|
5
16
|
constructor(instrumentation, config) {
|
|
6
17
|
this.config = config || {};
|
|
7
18
|
this.instrumentation = instrumentation;
|
|
@@ -10,71 +21,43 @@ export class PerformanceApiSink {
|
|
|
10
21
|
track() {
|
|
11
22
|
this.trackExistingMarks();
|
|
12
23
|
this.setupObserver();
|
|
13
|
-
} //
|
|
14
|
-
// logOperationEnd clears the marks and measures passed to it, so these are NOT clearable
|
|
15
|
-
// As of now, only "lwr.loader.*.fetch" metrics have durations (i.e. are not clearable)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
isClearable(name) {
|
|
19
|
-
return !name.startsWith(MODULE_FETCH) && !name.startsWith(MAPPINGS_FETCH);
|
|
20
|
-
} // Retrieve existing metrics to this point
|
|
24
|
+
} // Retrieve existing loader define metrics to this point
|
|
21
25
|
|
|
22
26
|
|
|
23
27
|
trackExistingMarks() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
const marks = performance.getEntriesByType('mark').filter(e => e.name.startsWith(MODULE_DEFINE)); // initialize the module define count
|
|
28
|
-
// at this point in time, the count will include modules NOT fetched by the loader:
|
|
28
|
+
const defineMarks = performance.getEntriesByType('mark').filter(e => e.name.startsWith(MODULE_DEFINE)); // Initialize the module define count
|
|
29
|
+
// At this point in time, the count will include modules NOT fetched by the loader:
|
|
29
30
|
// - required modules
|
|
30
31
|
// - preload modules
|
|
31
32
|
// - the application bootstrap module
|
|
32
33
|
// - the loader module itself
|
|
33
34
|
|
|
34
|
-
if (
|
|
35
|
-
this.instrumentation.incrementCounter(MODULE_DEFINE_COUNT,
|
|
35
|
+
if (defineMarks.length > 0) {
|
|
36
|
+
this.instrumentation.incrementCounter(MODULE_DEFINE_COUNT, defineMarks.length);
|
|
36
37
|
}
|
|
37
38
|
} // Add observer to log future metrics
|
|
38
|
-
// observe lwr client runtime performance metrics
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
setupObserver() {
|
|
42
|
-
let bootstrapErrorCount = 0;
|
|
43
|
-
let loaderModuleErrorCount = 0;
|
|
44
|
-
let loaderMappingsErrorcount = 0;
|
|
45
42
|
const observer = new PerformanceObserver(list => {
|
|
46
|
-
// grab the lwr performance marks
|
|
47
|
-
const marks = [];
|
|
48
|
-
/**
|
|
49
|
-
* Bootstrap and Loader marks
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
43
|
list.getEntries().forEach(entry => {
|
|
53
44
|
const {
|
|
54
45
|
name,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} = entry;
|
|
58
|
-
|
|
59
|
-
if (entryType === 'mark' && name.startsWith('lwr.')) {
|
|
60
|
-
marks.push(entry);
|
|
61
|
-
}
|
|
46
|
+
duration,
|
|
47
|
+
startTime
|
|
48
|
+
} = entry; // Track the bootstrap duration from navigation.start to lwr.bootstrap.end
|
|
62
49
|
|
|
63
50
|
if (name === BOOTSTRAP_END) {
|
|
64
|
-
this.
|
|
65
|
-
}
|
|
51
|
+
this.instrumentation.trackValue(BOOTSTRAP_DURATION, startTime);
|
|
52
|
+
} // Increment count metrics
|
|
66
53
|
|
|
67
|
-
if (name === BOOTSTRAP_ERROR) {
|
|
68
|
-
bootstrapErrorCount += 1;
|
|
69
|
-
}
|
|
70
54
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
55
|
+
const metricToCount = metricsToCount.find(c => name.startsWith(c));
|
|
56
|
+
|
|
57
|
+
if (metricToCount) {
|
|
58
|
+
this.instrumentation.incrementCounter(countMap[metricToCount], 1);
|
|
59
|
+
} // Record duration metrics
|
|
74
60
|
|
|
75
|
-
if (name === MAPPINGS_ERROR) {
|
|
76
|
-
loaderMappingsErrorcount += 1;
|
|
77
|
-
}
|
|
78
61
|
|
|
79
62
|
if (this.config.enableModuleFetchTracking && name.startsWith(MODULE_FETCH_DURATION)) {
|
|
80
63
|
this.instrumentation.trackValue(name, duration);
|
|
@@ -83,46 +66,17 @@ export class PerformanceApiSink {
|
|
|
83
66
|
if (this.config.enableMappingFetchTracking && name.startsWith(MAPPINGS_FETCH_DURATION)) {
|
|
84
67
|
this.instrumentation.trackValue(name, duration);
|
|
85
68
|
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (this.marks[BOOTSTRAP_END] !== undefined) {
|
|
89
|
-
this.instrumentation.trackValue(BOOTSTRAP_DURATION, this.marks[BOOTSTRAP_END].startTime);
|
|
90
|
-
this.instrumentation.trackValue(BOOTSTRAP_AVAILABILITY, 1 / (1 + bootstrapErrorCount) * 100); // reset to prevent multiple reports
|
|
91
69
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const moduleDefineCount = marks.reduce((count, mark) => {
|
|
97
|
-
return mark.name.startsWith(MODULE_DEFINE) ? count + 1 : count;
|
|
98
|
-
}, 0);
|
|
99
|
-
|
|
100
|
-
if (moduleDefineCount > 0) {
|
|
101
|
-
this.instrumentation.incrementCounter(MODULE_DEFINE_COUNT, moduleDefineCount);
|
|
102
|
-
} // count how many modules were loaded and report the count
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const moduleLoadCount = marks.reduce((count, mark) => {
|
|
106
|
-
return mark.name.startsWith(MODULE_FETCH) ? count + 1 : count;
|
|
107
|
-
}, 0);
|
|
108
|
-
|
|
109
|
-
if (moduleLoadCount > 0) {
|
|
110
|
-
this.instrumentation.incrementCounter(MODULE_FETCH_COUNT, moduleLoadCount);
|
|
111
|
-
this.instrumentation.trackValue(MODULE_AVAILABILITY, moduleLoadCount / (moduleLoadCount + loaderModuleErrorCount) * 100);
|
|
112
|
-
} // count how many mapping resources were loaded and report the count
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const mappingLoadCount = marks.reduce((count, mark) => {
|
|
116
|
-
return mark.name.startsWith(MAPPINGS_FETCH) ? count + 1 : count;
|
|
117
|
-
}, 0);
|
|
118
|
-
|
|
119
|
-
if (mappingLoadCount > 0) {
|
|
120
|
-
this.instrumentation.incrementCounter(MAPPINGS_FETCH_COUNT, mappingLoadCount);
|
|
121
|
-
this.instrumentation.trackValue(MAPPINGS_AVAILABILITY, mappingLoadCount / (mappingLoadCount + loaderMappingsErrorcount) * 100);
|
|
122
|
-
} // remove clearable marks
|
|
70
|
+
if (durationMetrics.some(d => name.startsWith(d))) {
|
|
71
|
+
this.instrumentation.trackValue(name, duration);
|
|
72
|
+
} // Remove clearable marks
|
|
73
|
+
// A mark is clearable if it does not have a corresponding logOperationEnd / measure
|
|
123
74
|
|
|
124
75
|
|
|
125
|
-
|
|
76
|
+
if (!doNotClear.some(m => name.startsWith(m))) {
|
|
77
|
+
performance.clearMarks(name);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
126
80
|
});
|
|
127
81
|
observer.observe({
|
|
128
82
|
entryTypes: ['mark', 'measure']
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.7.0-alpha.10",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"build:bundle": "rollup --config scripts/rollup.moduleBundle.config.cjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lwrjs/shared-utils": "0.
|
|
28
|
-
"o11y": "238.
|
|
27
|
+
"@lwrjs/shared-utils": "0.7.0-alpha.10",
|
|
28
|
+
"o11y": "238.9.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"rollup-plugin-terser": "^7.0.2"
|
|
@@ -45,5 +45,6 @@
|
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=14.15.4 <17"
|
|
48
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "83c1e65e2169094cb55ac2c37e5aef16d3a9aa4a"
|
|
49
50
|
}
|