@lwrjs/o11y 0.6.0 → 0.6.4
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 +1 @@
|
|
|
1
|
-
import{getInstrumentation as t}from"o11y/client";import{registerDecorators as
|
|
1
|
+
import{getInstrumentation as t}from"o11y/client";import{registerDecorators as e}from"lwc";import{MODULE_FETCH as r,MAPPINGS_FETCH as s,MODULE_DEFINE as n,MODULE_DEFINE_COUNT as i,BOOTSTRAP_END as a,MODULE_FETCH_DURATION as o,MAPPINGS_FETCH_DURATION as c,BOOTSTRAP_DURATION as m,BOOTSTRAP_AVAILABILITY as h,MODULE_FETCH_COUNT as u,MODULE_AVAILABILITY as l,MAPPINGS_FETCH_COUNT as k,MAPPINGS_AVAILABILITY as f,BOOTSTRAP_ERROR as p,MODULE_ERROR as g,MAPPINGS_ERROR as b}from"lwr/metrics";class d{constructor(t,e){this.marks={},this.config=e||{},this.instrumentation=t}track(){this.trackExistingMarks(),this.setupObserver()}isClearable(t){return!t.startsWith(r)&&!t.startsWith(s)}trackExistingMarks(){const t=performance.getEntriesByType("mark").filter((t=>t.name.startsWith(n)));t.length>0&&this.instrumentation.incrementCounter(i,t.length)}setupObserver(){let t=0,e=0,d=0;new PerformanceObserver((W=>{const T=[];W.getEntries().forEach((r=>{const{name:s,entryType:n,duration:i}=r;"mark"===n&&s.startsWith("lwr.")&&T.push(r),s===a&&(this.marks[s]=r),s===p&&(t+=1),s===g&&(e+=1),s===b&&(d+=1),this.config.enableModuleFetchTracking&&s.startsWith(o)&&this.instrumentation.trackValue(s,i),this.config.enableMappingFetchTracking&&s.startsWith(c)&&this.instrumentation.trackValue(s,i)})),void 0!==this.marks[a]&&(this.instrumentation.trackValue(m,this.marks[a].startTime),this.instrumentation.trackValue(h,1/(1+t)*100),delete this.marks[a]);const y=T.reduce(((t,e)=>e.name.startsWith(n)?t+1:t),0);y>0&&this.instrumentation.incrementCounter(i,y);const C=T.reduce(((t,e)=>e.name.startsWith(r)?t+1:t),0);C>0&&(this.instrumentation.incrementCounter(u,C),this.instrumentation.trackValue(l,C/(C+e)*100));const v=T.reduce(((t,e)=>e.name.startsWith(s)?t+1:t),0);v>0&&(this.instrumentation.incrementCounter(k,v),this.instrumentation.trackValue(f,v/(v+d)*100)),T.forEach((t=>this.isClearable(t.name)&&performance.clearMarks(t.name)))})).observe({entryTypes:["mark","measure"]})}}e(d,{fields:["marks"]});const W=void 0!==globalThis.performance&&"function"==typeof globalThis.performance.mark,T=globalThis.LWR,y={track:()=>{}};function C(e){const r=t("lwrjs"),s=T.metricsConfig||{};(W?new d(r,s):y).track()}export default C;
|
|
@@ -3,6 +3,7 @@ import { PerformanceApiSink } from './performanceApiSink'; // Check if the Perfo
|
|
|
3
3
|
// e.g. JSDom (used in Jest) doesn't implement these
|
|
4
4
|
|
|
5
5
|
const isPerfSupported = typeof globalThis.performance !== 'undefined' && typeof globalThis.performance.mark === 'function';
|
|
6
|
+
const clientBootstrapConfig = globalThis.LWR;
|
|
6
7
|
|
|
7
8
|
const noop = () => {// noop
|
|
8
9
|
};
|
|
@@ -17,6 +18,7 @@ const NAMESPACE = 'lwrjs';
|
|
|
17
18
|
|
|
18
19
|
export default function hookO11yClient(serviceApi) {
|
|
19
20
|
const instrumentation = getInstrumentation(NAMESPACE);
|
|
20
|
-
const
|
|
21
|
+
const metricsConfig = clientBootstrapConfig.metricsConfig || {};
|
|
22
|
+
const sink = isPerfSupported ? new PerformanceApiSink(instrumentation, metricsConfig) : noopSink;
|
|
21
23
|
sink.track();
|
|
22
24
|
}
|
|
@@ -2,7 +2,8 @@ import { BOOTSTRAP_AVAILABILITY, BOOTSTRAP_DURATION, BOOTSTRAP_END, BOOTSTRAP_ER
|
|
|
2
2
|
export class PerformanceApiSink {
|
|
3
3
|
marks = {};
|
|
4
4
|
|
|
5
|
-
constructor(instrumentation) {
|
|
5
|
+
constructor(instrumentation, config) {
|
|
6
|
+
this.config = config || {};
|
|
6
7
|
this.instrumentation = instrumentation;
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -75,7 +76,11 @@ export class PerformanceApiSink {
|
|
|
75
76
|
loaderMappingsErrorcount += 1;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
if (
|
|
79
|
+
if (this.config.enableModuleFetchTracking && name.startsWith(MODULE_FETCH_DURATION)) {
|
|
80
|
+
this.instrumentation.trackValue(name, duration);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.config.enableMappingFetchTracking && name.startsWith(MAPPINGS_FETCH_DURATION)) {
|
|
79
84
|
this.instrumentation.trackValue(name, duration);
|
|
80
85
|
}
|
|
81
86
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.
|
|
7
|
+
"version": "0.6.4",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build:bundle": "rollup --config scripts/rollup.moduleBundle.config.cjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lwrjs/shared-utils": "0.6.
|
|
27
|
+
"@lwrjs/shared-utils": "0.6.4",
|
|
28
28
|
"o11y": "238.1.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=14.15.4 <17"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "80b73fe4558dc3db0afcdbe80eb17f5a1464e34e"
|
|
50
50
|
}
|