@lwrjs/o11y 0.9.0-alpha.3 → 0.9.0-alpha.30
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.
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { getInstrumentation } from 'o11y/client';
|
|
2
|
-
import { PerformanceApiSink } from './performanceApiSink';
|
|
3
|
-
// e.g. JSDom (used in Jest) doesn't implement these
|
|
2
|
+
import { PerformanceApiSink } from './performanceApiSink';
|
|
4
3
|
|
|
4
|
+
// Check if the Performance API is available
|
|
5
|
+
// e.g. JSDom (used in Jest) doesn't implement these
|
|
5
6
|
const isPerfSupported = typeof globalThis.performance !== 'undefined' && typeof globalThis.performance.mark === 'function';
|
|
6
7
|
const clientBootstrapConfig = globalThis.LWR;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const noop = () => {
|
|
9
|
+
// noop
|
|
9
10
|
};
|
|
10
|
-
|
|
11
11
|
const noopSink = {
|
|
12
12
|
track: noop
|
|
13
13
|
};
|
|
14
14
|
const NAMESPACE = 'lwrjs';
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Sets up o11y instrumentation instance.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
19
|
export default function hookO11yClient(serviceApi) {
|
|
20
20
|
const instrumentation = getInstrumentation(NAMESPACE);
|
|
21
21
|
const metricsConfig = clientBootstrapConfig.metricsConfig || {};
|
|
@@ -17,27 +17,27 @@ export class PerformanceApiSink {
|
|
|
17
17
|
this.config = config || {};
|
|
18
18
|
this.instrumentation = instrumentation;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
track() {
|
|
22
21
|
this.trackExistingMarks();
|
|
23
22
|
this.setupObserver();
|
|
24
|
-
}
|
|
25
|
-
|
|
23
|
+
}
|
|
26
24
|
|
|
25
|
+
// Retrieve existing loader define metrics to this point
|
|
27
26
|
trackExistingMarks() {
|
|
28
|
-
const defineMarks = performance.getEntriesByType('mark').filter(e => e.name.startsWith(MODULE_DEFINE));
|
|
27
|
+
const defineMarks = performance.getEntriesByType('mark').filter(e => e.name.startsWith(MODULE_DEFINE));
|
|
28
|
+
|
|
29
|
+
// Initialize the module define count
|
|
29
30
|
// At this point in time, the count will include modules NOT fetched by the loader:
|
|
30
31
|
// - required modules
|
|
31
32
|
// - preload modules
|
|
32
33
|
// - the application bootstrap module
|
|
33
34
|
// - the loader module itself
|
|
34
|
-
|
|
35
35
|
if (defineMarks.length > 0) {
|
|
36
36
|
this.instrumentation.incrementCounter(MODULE_DEFINE_COUNT, defineMarks.length);
|
|
37
37
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
38
|
+
}
|
|
40
39
|
|
|
40
|
+
// Add observer to log future metrics
|
|
41
41
|
setupObserver() {
|
|
42
42
|
const observer = new PerformanceObserver(list => {
|
|
43
43
|
list.getEntries().forEach(entry => {
|
|
@@ -45,34 +45,32 @@ export class PerformanceApiSink {
|
|
|
45
45
|
name,
|
|
46
46
|
duration,
|
|
47
47
|
startTime
|
|
48
|
-
} = entry;
|
|
48
|
+
} = entry;
|
|
49
49
|
|
|
50
|
+
// Track the bootstrap duration from navigation.start to lwr.bootstrap.end
|
|
50
51
|
if (name === BOOTSTRAP_END) {
|
|
51
52
|
this.instrumentation.trackValue(BOOTSTRAP_DURATION, startTime);
|
|
52
|
-
}
|
|
53
|
-
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
+
// Increment count metrics
|
|
55
56
|
const metricToCount = metricsToCount.find(c => name.startsWith(c));
|
|
56
|
-
|
|
57
57
|
if (metricToCount) {
|
|
58
58
|
this.instrumentation.incrementCounter(countMap[metricToCount], 1);
|
|
59
|
-
}
|
|
60
|
-
|
|
59
|
+
}
|
|
61
60
|
|
|
61
|
+
// Record duration metrics
|
|
62
62
|
if (this.config.enableModuleFetchTracking && name.startsWith(MODULE_FETCH_DURATION)) {
|
|
63
63
|
this.instrumentation.trackValue(name, duration);
|
|
64
64
|
}
|
|
65
|
-
|
|
66
65
|
if (this.config.enableMappingFetchTracking && name.startsWith(MAPPINGS_FETCH_DURATION)) {
|
|
67
66
|
this.instrumentation.trackValue(name, duration);
|
|
68
67
|
}
|
|
69
|
-
|
|
70
68
|
if (durationMetrics.some(d => name.startsWith(d))) {
|
|
71
69
|
this.instrumentation.trackValue(name, duration);
|
|
72
|
-
}
|
|
73
|
-
// A mark is clearable if it does not have a corresponding logOperationEnd / measure
|
|
74
|
-
|
|
70
|
+
}
|
|
75
71
|
|
|
72
|
+
// Remove clearable marks
|
|
73
|
+
// A mark is clearable if it does not have a corresponding logOperationEnd / measure
|
|
76
74
|
if (!doNotClear.some(m => name.startsWith(m))) {
|
|
77
75
|
performance.clearMarks(name);
|
|
78
76
|
}
|
|
@@ -82,5 +80,4 @@ export class PerformanceApiSink {
|
|
|
82
80
|
entryTypes: ['mark', 'measure']
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
|
-
|
|
86
83
|
}
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.30",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/salesforce/lwr.git",
|
|
11
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
|
|
12
12
|
"directory": "packages/@lwrjs/o11y"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/salesforce/lwr/issues"
|
|
15
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"files": [
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
"build:bundle": "rollup --config scripts/rollup.moduleBundle.config.cjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lwrjs/shared-utils": "0.9.0-alpha.
|
|
28
|
-
"o11y": "242.3.3"
|
|
27
|
+
"@lwrjs/shared-utils": "0.9.0-alpha.30"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"rollup-plugin-terser": "^7.0.2"
|
|
32
31
|
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"o11y": "244.x"
|
|
34
|
+
},
|
|
33
35
|
"lwc": {
|
|
34
36
|
"modules": [
|
|
35
37
|
{
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
]
|
|
45
47
|
},
|
|
46
48
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
49
|
+
"node": ">=16.0.0 <20"
|
|
48
50
|
},
|
|
49
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6e18768b8e47066c41ae0b792bf4aa766b0b784b"
|
|
50
52
|
}
|