@keyframerdev/vitals 0.1.5 → 0.1.6
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/README.md +1 -1
- package/dist/index.js +13 -8
- package/dist/types/controller.d.ts +5 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Before your store release, declare it in the stores' privacy forms (App Store: D
|
|
|
53
53
|
| `appVersion` | required | The version people see (`2.4.1`) |
|
|
54
54
|
| `build` | none | The build number (`812`) |
|
|
55
55
|
| `environment` | `'development'` when `__DEV__`, else `'production'` | Development reports are kept only when the project accepts development builds |
|
|
56
|
-
| `sampleRate` | `0.1` | The share of sessions that report
|
|
56
|
+
| `sampleRate` | `0.1` | The share of sessions that report. Release builds use it until the project's settings arrive, then the project's rate. Development builds always use it, and report every session when you leave it out (no daily cap either: someone is testing) |
|
|
57
57
|
| `navigationRef` | none | Screens are named from its routes |
|
|
58
58
|
| `screenName` | the route's name | `(route) => string`, to name routes yourself (still masked) |
|
|
59
59
|
| `storage` | none | Anything with `getItem`, `setItem` and `removeItem` (AsyncStorage, an MMKV wrapper) |
|
package/dist/index.js
CHANGED
|
@@ -624,7 +624,7 @@ var MAX_FRAME_MS = 10 * 60 * 1000;
|
|
|
624
624
|
|
|
625
625
|
// src/version.ts
|
|
626
626
|
var SDK_NAME = "@keyframerdev/vitals";
|
|
627
|
-
var SDK_VERSION = "0.1.
|
|
627
|
+
var SDK_VERSION = "0.1.6";
|
|
628
628
|
|
|
629
629
|
// src/controller.ts
|
|
630
630
|
var STORAGE_KEYS = {
|
|
@@ -794,9 +794,12 @@ class VitalsController {
|
|
|
794
794
|
this.seq = 0;
|
|
795
795
|
this.sampleRate = this.rate();
|
|
796
796
|
const env = this.opts.environment ?? "production";
|
|
797
|
-
const
|
|
798
|
-
|
|
799
|
-
|
|
797
|
+
const dev = env === "development";
|
|
798
|
+
const devOk = !dev || !this.config || this.config.collect.development;
|
|
799
|
+
const draw = this.env.random();
|
|
800
|
+
let sampled = devOk && this.sampleRate > 0 && draw < this.sampleRate;
|
|
801
|
+
let capped = false;
|
|
802
|
+
if (sampled && !dev) {
|
|
800
803
|
const day = (this.env.day ?? localDay)(this.env.wall());
|
|
801
804
|
if (!this.dayCount || this.dayCount.day !== day) {
|
|
802
805
|
const saved = await read(this.opts.storage, STORAGE_KEYS.day);
|
|
@@ -804,9 +807,10 @@ class VitalsController {
|
|
|
804
807
|
return;
|
|
805
808
|
this.dayCount = saved && saved.day === day ? saved : { day, n: 0 };
|
|
806
809
|
}
|
|
807
|
-
if (this.dayCount.n >= VITALS_MAX_SESSIONS_PER_DAY)
|
|
810
|
+
if (this.dayCount.n >= VITALS_MAX_SESSIONS_PER_DAY) {
|
|
808
811
|
sampled = false;
|
|
809
|
-
|
|
812
|
+
capped = true;
|
|
813
|
+
} else {
|
|
810
814
|
this.dayCount.n++;
|
|
811
815
|
await write(this.opts.storage, STORAGE_KEYS.day, this.dayCount);
|
|
812
816
|
if (run !== this.run)
|
|
@@ -814,7 +818,8 @@ class VitalsController {
|
|
|
814
818
|
}
|
|
815
819
|
}
|
|
816
820
|
this.sampled = sampled;
|
|
817
|
-
|
|
821
|
+
const why = sampled ? "" : !devOk ? ": the project does not keep development builds" : capped ? `: ${VITALS_MAX_SESSIONS_PER_DAY} sessions already reported today on this device (the daily cap)` : `: drew ${draw.toFixed(2)} against the rate`;
|
|
822
|
+
this.debug(`Motion Vitals ${SDK_VERSION}, session ${this.nonce.slice(0, 6)}: ${sampled ? "sampled" : "not sampled"} (rate ${this.sampleRate}, environment ${env})${why}`);
|
|
818
823
|
if (!sampled)
|
|
819
824
|
return;
|
|
820
825
|
this.collector.clear();
|
|
@@ -1284,7 +1289,7 @@ class VitalsController {
|
|
|
1284
1289
|
return true;
|
|
1285
1290
|
}
|
|
1286
1291
|
rate() {
|
|
1287
|
-
const r = this.config ? this.config.sampleRate : this.opts?.sampleRate ?? VITALS_DEFAULT_SAMPLE_RATE;
|
|
1292
|
+
const r = this.opts?.environment === "development" ? this.opts.sampleRate ?? 1 : this.config ? this.config.sampleRate : this.opts?.sampleRate ?? VITALS_DEFAULT_SAMPLE_RATE;
|
|
1288
1293
|
return Number.isFinite(r) ? Math.max(0, Math.min(1, r)) : VITALS_DEFAULT_SAMPLE_RATE;
|
|
1289
1294
|
}
|
|
1290
1295
|
clearTimers() {
|
|
@@ -236,6 +236,11 @@ export declare class VitalsController {
|
|
|
236
236
|
private developmentConfig;
|
|
237
237
|
private killSwitch;
|
|
238
238
|
private allowed;
|
|
239
|
+
/**
|
|
240
|
+
* Release builds: the project's rate once its config is known, the app's until then. Development builds:
|
|
241
|
+
* the app's own rate, else every session. Someone is testing, and the project's 10% left nine runs in
|
|
242
|
+
* ten silent after the first session.
|
|
243
|
+
*/
|
|
239
244
|
private rate;
|
|
240
245
|
private clearTimers;
|
|
241
246
|
private log;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** This package's version: sent in every report's `sdk`, and compared with the config's `minSdk`. Keep it in step with package.json. */
|
|
2
2
|
export declare const SDK_NAME = "@keyframerdev/vitals";
|
|
3
|
-
export declare const SDK_VERSION = "0.1.
|
|
3
|
+
export declare const SDK_VERSION = "0.1.6";
|
package/package.json
CHANGED