@libo11y/rum 0.6.0 → 0.7.0
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 +2 -2
- package/dist/contracts/runtime.d.ts +7 -2
- package/dist/contracts/session.d.ts +6 -0
- package/dist/contracts/summary.d.ts +13 -2
- package/dist/core-setup.js +14 -11
- package/dist/session/manager.d.ts +2 -2
- package/dist/session/manager.js +17 -1
- package/dist/summary/accumulator.d.ts +4 -3
- package/dist/summary/accumulator.js +23 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@ npm install @libo11y/rum
|
|
|
12
12
|
|
|
13
13
|
## Status
|
|
14
14
|
|
|
15
|
-
The package first ships in `ts/v0.3.0` and is published on npm at `0.
|
|
15
|
+
The package first ships in `ts/v0.3.0` and is published on npm at `0.7.0`
|
|
16
16
|
(also attached as a tarball to the
|
|
17
|
-
[`ts/v0.
|
|
17
|
+
[`ts/v0.7.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.7.0)).
|
|
18
18
|
|
|
19
19
|
The package has the core (sessions, consent, sampling, the retention
|
|
20
20
|
buffer and view summaries), the `views()`, `actions()`, `errors()`,
|
|
@@ -113,9 +113,14 @@ export interface RumRuntime {
|
|
|
113
113
|
/**
|
|
114
114
|
* Emits event name with session.id and o11y.rum.view.id of the current session and view added
|
|
115
115
|
* (attrs win). Dropped while the gate is closed. With body, the record carries it as its body
|
|
116
|
-
* for upstream events such as semconv's browser.web_vital that define one.
|
|
116
|
+
* for upstream events such as semconv's browser.web_vital that define one. time (epoch
|
|
117
|
+
* milliseconds) is when it happened, for an event of something earlier, such as a native crash a
|
|
118
|
+
* later launch delivers; default now. An event with a time gets nothing current added: no
|
|
119
|
+
* session, view or user, and no addEventAttributes attributes, so attrs carry its own. Returns
|
|
120
|
+
* whether the log export pipeline took the record: false while the gate is closed, or when it
|
|
121
|
+
* was dropped before export, as by a failing attrReplacer.
|
|
117
122
|
*/
|
|
118
|
-
emit(name: string, attrs?: LogAttributes, ctx?: Context, body?: EventBody):
|
|
123
|
+
emit(name: string, attrs?: LogAttributes, ctx?: Context, body?: EventBody, time?: number): boolean;
|
|
119
124
|
/** Adds a hook run on every fetch and XHR client span right after it starts. */
|
|
120
125
|
onRequestStart(hook: RequestStartHook): () => void;
|
|
121
126
|
/** The open action's span, while one is open. Requests started meanwhile become its children. */
|
|
@@ -61,6 +61,12 @@ export interface SessionManager {
|
|
|
61
61
|
retain(reason: "error" | "frustration"): boolean;
|
|
62
62
|
/** send for a kept session, buffer for the current unkept one, drop for an old unkept one. */
|
|
63
63
|
decide(sessionId: string | undefined): SessionDecision;
|
|
64
|
+
/**
|
|
65
|
+
* Tells decide whether an earlier process kept a session this context does not know, as a
|
|
66
|
+
* native report a later launch delivers says, so a record of that session keeps that decision.
|
|
67
|
+
* A session this context knows keeps its own.
|
|
68
|
+
*/
|
|
69
|
+
recall(sessionId: string, kept: boolean): void;
|
|
64
70
|
/** Forgets the session and removes it from the store (consent revoked). */
|
|
65
71
|
clear(): void;
|
|
66
72
|
subscribe(listener: (event: SessionEvent) => void): () => void;
|
|
@@ -21,8 +21,19 @@ export interface SummaryAccumulator {
|
|
|
21
21
|
visibility(visible: boolean): void;
|
|
22
22
|
/** Pins a view: while pinned, a closed view is not forgotten, so vitals held for it still reach it. */
|
|
23
23
|
pin(viewId: string, pinned: boolean): void;
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Sends a summary for every view with unsent data. Returns false when the pipeline did not take
|
|
26
|
+
* one of them.
|
|
27
|
+
*/
|
|
28
|
+
flush(): boolean;
|
|
26
29
|
/** Drops everything unsent (consent revoked). */
|
|
27
30
|
reset(): void;
|
|
31
|
+
/** The seq the next summary of a tracked view will carry, undefined for a view not tracked. */
|
|
32
|
+
nextSeq(viewId: string): number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Sends one summary of a view an earlier process showed, as a later launch does for a native
|
|
35
|
+
* crash or hang it delivers: seq, time on view 0 and key counted once. The view is not tracked.
|
|
36
|
+
* Returns whether the pipeline took it.
|
|
37
|
+
*/
|
|
38
|
+
late(view: SummaryView, seq: number, key: SummaryCountKey): boolean;
|
|
28
39
|
}
|
package/dist/core-setup.js
CHANGED
|
@@ -305,7 +305,7 @@ export async function setupRumCore(options, rumOptions, deps) {
|
|
|
305
305
|
const shown = lifecycle.visible;
|
|
306
306
|
const summary = createSummaryAccumulator({
|
|
307
307
|
platform,
|
|
308
|
-
emit: (attrs) => telemetry?.event(EVENT_RUM_VIEW_SUMMARY, attrs),
|
|
308
|
+
emit: (attrs) => telemetry?.event(EVENT_RUM_VIEW_SUMMARY, attrs) ?? false,
|
|
309
309
|
now: deps.perfNow,
|
|
310
310
|
visible: shown,
|
|
311
311
|
context: () => {
|
|
@@ -563,13 +563,16 @@ export async function setupRumCore(options, rumOptions, deps) {
|
|
|
563
563
|
settings: () => settings,
|
|
564
564
|
now: deps.perfNow,
|
|
565
565
|
timeOrigin: deps.timeOrigin ?? performance.timeOrigin,
|
|
566
|
-
emit(name, attrs = {}, ctx, body) {
|
|
566
|
+
emit(name, attrs = {}, ctx, body, time) {
|
|
567
567
|
if (sdkDisabled || !gate.recording())
|
|
568
|
-
return;
|
|
569
|
-
|
|
570
|
-
|
|
568
|
+
return false;
|
|
569
|
+
// An event of something earlier carries only what its caller knows of that time: the
|
|
570
|
+
// session, view, user and event attributes current now may not be its own.
|
|
571
|
+
const earlier = time !== undefined;
|
|
572
|
+
const s = earlier ? undefined : session.current();
|
|
573
|
+
const v = earlier ? undefined : views.current();
|
|
571
574
|
let decorated = {};
|
|
572
|
-
for (const d of decorators) {
|
|
575
|
+
for (const d of earlier ? [] : decorators) {
|
|
573
576
|
if (!d.names.has(name))
|
|
574
577
|
continue;
|
|
575
578
|
try {
|
|
@@ -582,15 +585,14 @@ export async function setupRumCore(options, rumOptions, deps) {
|
|
|
582
585
|
const merged = {
|
|
583
586
|
...(s === undefined ? {} : { [ATTR_SESSION_ID]: s.id }),
|
|
584
587
|
...(v === undefined ? {} : { [ATTR_RUM_VIEW_ID]: v.id }),
|
|
585
|
-
...(userId === undefined ? {} : { [ATTR_USER_ID]: userId }),
|
|
588
|
+
...(userId === undefined || earlier ? {} : { [ATTR_USER_ID]: userId }),
|
|
586
589
|
...decorated,
|
|
587
590
|
...attrs,
|
|
588
591
|
};
|
|
589
|
-
if (body === undefined)
|
|
590
|
-
t.event(name, merged, ctx);
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
592
|
+
if (body === undefined)
|
|
593
|
+
return t.event(name, merged, ctx, time === undefined ? undefined : new Date(time));
|
|
593
594
|
bodyLogger.emit({
|
|
595
|
+
...(time === undefined ? {} : { timestamp: time }),
|
|
594
596
|
eventName: name,
|
|
595
597
|
severityNumber: SeverityNumber.INFO,
|
|
596
598
|
severityText: "INFO",
|
|
@@ -599,6 +601,7 @@ export async function setupRumCore(options, rumOptions, deps) {
|
|
|
599
601
|
// Body events report page-level values at a hide, so the span active then is unrelated.
|
|
600
602
|
context: ctx ?? ROOT_CONTEXT,
|
|
601
603
|
});
|
|
604
|
+
return true;
|
|
602
605
|
},
|
|
603
606
|
onRequestStart(hook) {
|
|
604
607
|
hooks.add(hook);
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* removed session as its previous.
|
|
16
16
|
*
|
|
17
17
|
* decide(id): a missing ID means the current session. The current session sends when kept and
|
|
18
|
-
* buffers otherwise. Any of the last four sessions this context knew
|
|
19
|
-
* drops otherwise. An unknown ID drops.
|
|
18
|
+
* buffers otherwise. Any of the last four sessions this context knew, or recalled from an earlier
|
|
19
|
+
* process, sends when it was kept and drops otherwise. An unknown ID drops.
|
|
20
20
|
*/
|
|
21
21
|
import type { SessionManager, SessionStore } from "../contracts/session.ts";
|
|
22
22
|
export interface SessionManagerOptions {
|
package/dist/session/manager.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { randomUuid } from "../ids.js";
|
|
2
2
|
import { sessionSampled } from "./sampling.js";
|
|
3
3
|
const RECENT = 4;
|
|
4
|
+
/**
|
|
5
|
+
* The earlier processes' sessions recall keeps decisions for: as many as the native context
|
|
6
|
+
* history holds entries, so one poll's reports cannot push out each other's before export.
|
|
7
|
+
*/
|
|
8
|
+
const RECALLED = 64;
|
|
4
9
|
export function createSessionManager(opts) {
|
|
5
10
|
const now = opts.now ?? Date.now;
|
|
6
11
|
const randomId = opts.randomId ?? randomUuid;
|
|
@@ -8,6 +13,8 @@ export function createSessionManager(opts) {
|
|
|
8
13
|
const listeners = new Set();
|
|
9
14
|
/** Sessions this context knew, newest last, with whether each was kept. */
|
|
10
15
|
const recent = new Map();
|
|
16
|
+
/** Decisions recall gave for sessions an earlier process had, apart from recent. */
|
|
17
|
+
const recalled = new Map();
|
|
11
18
|
let state;
|
|
12
19
|
/** start() was called and not cleared since. */
|
|
13
20
|
let started = false;
|
|
@@ -143,13 +150,22 @@ export function createSessionManager(opts) {
|
|
|
143
150
|
return "drop";
|
|
144
151
|
if (s !== undefined && id === s.id)
|
|
145
152
|
return s.retained === undefined ? "buffer" : "send";
|
|
146
|
-
return recent.get(id) === true ? "send" : "drop";
|
|
153
|
+
return (recent.get(id) ?? recalled.get(id)) === true ? "send" : "drop";
|
|
154
|
+
},
|
|
155
|
+
recall(sessionId, kept) {
|
|
156
|
+
if (recent.has(sessionId) || live()?.id === sessionId)
|
|
157
|
+
return;
|
|
158
|
+
recalled.delete(sessionId);
|
|
159
|
+
recalled.set(sessionId, kept);
|
|
160
|
+
while (recalled.size > RECALLED)
|
|
161
|
+
recalled.delete(recalled.keys().next().value);
|
|
147
162
|
},
|
|
148
163
|
clear() {
|
|
149
164
|
generation++;
|
|
150
165
|
forgotten = undefined;
|
|
151
166
|
state = undefined;
|
|
152
167
|
recent.clear();
|
|
168
|
+
recalled.clear();
|
|
153
169
|
started = false;
|
|
154
170
|
ready = false;
|
|
155
171
|
unsubscribe?.();
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
* the view's previous summary; a zero count is omitted. A vital is accepted once per view and name
|
|
8
8
|
* and is sent in the next summary of that view. A closed view stays tracked, for late vitals, until
|
|
9
9
|
* ten newer views closed after it, and while it is pinned (vitals() pins the load view until it has
|
|
10
|
-
* committed its held vitals).
|
|
10
|
+
* committed its held vitals). late() sends a one-off summary of a view an earlier process showed,
|
|
11
|
+
* for a native crash or hang a later launch delivers (spec 1.4.0).
|
|
11
12
|
*/
|
|
12
13
|
import { type RUMPlatform } from "@libo11y/spec";
|
|
13
14
|
import type { SummaryAccumulator } from "../contracts/summary.ts";
|
|
14
15
|
export interface SummaryOptions {
|
|
15
16
|
readonly platform: RUMPlatform;
|
|
16
|
-
/** Emits one o11y.rum.view.summary record with these attributes. */
|
|
17
|
-
readonly emit: (attrs: Record<string, string | number>) =>
|
|
17
|
+
/** Emits one o11y.rum.view.summary record with these attributes; false when it was not taken. */
|
|
18
|
+
readonly emit: (attrs: Record<string, string | number>) => unknown;
|
|
18
19
|
/** performance.now(). */
|
|
19
20
|
readonly now: () => number;
|
|
20
21
|
/** Whether the page is visible now. */
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* the view's previous summary; a zero count is omitted. A vital is accepted once per view and name
|
|
8
8
|
* and is sent in the next summary of that view. A closed view stays tracked, for late vitals, until
|
|
9
9
|
* ten newer views closed after it, and while it is pinned (vitals() pins the load view until it has
|
|
10
|
-
* committed its held vitals).
|
|
10
|
+
* committed its held vitals). late() sends a one-off summary of a view an earlier process showed,
|
|
11
|
+
* for a native crash or hang a later launch delivers (spec 1.4.0).
|
|
11
12
|
*/
|
|
12
13
|
import { ATTR_RUM_PLATFORM, ATTR_RUM_SUMMARY_SEQ, ATTR_RUM_SUMMARY_TIME_ON_VIEW, ATTR_RUM_VIEW_ID, ATTR_RUM_VIEW_KIND, ATTR_RUM_VIEW_NAME, } from "@libo11y/spec";
|
|
13
14
|
import { ATTR_SESSION_ID, summaryCountKey, summaryVitalKey } from "../attrs.js";
|
|
@@ -23,10 +24,11 @@ export function createSummaryAccumulator(opts) {
|
|
|
23
24
|
t.resumedAt = n;
|
|
24
25
|
};
|
|
25
26
|
const pending = (t) => t.seq === 0 || t.counts.size > 0 || t.vitals.size > 0 || t.visibleMillis > 0;
|
|
27
|
+
/** Sends t's summary when it has unsent data; false when the pipeline did not take it. */
|
|
26
28
|
const send = (t) => {
|
|
27
29
|
accrue(t);
|
|
28
30
|
if (!pending(t))
|
|
29
|
-
return;
|
|
31
|
+
return true;
|
|
30
32
|
const attrs = {
|
|
31
33
|
...opts.context?.(),
|
|
32
34
|
...t.origin,
|
|
@@ -49,7 +51,7 @@ export function createSummaryAccumulator(opts) {
|
|
|
49
51
|
t.counts = new Map();
|
|
50
52
|
t.vitals = new Map();
|
|
51
53
|
t.visibleMillis = 0;
|
|
52
|
-
opts.emit(attrs);
|
|
54
|
+
return opts.emit(attrs) !== false;
|
|
53
55
|
};
|
|
54
56
|
const prune = () => {
|
|
55
57
|
const closed = [...tracked.values()].filter((t) => !t.open && !t.pinned);
|
|
@@ -116,13 +118,30 @@ export function createSummaryAccumulator(opts) {
|
|
|
116
118
|
}
|
|
117
119
|
},
|
|
118
120
|
flush() {
|
|
121
|
+
let taken = true;
|
|
119
122
|
for (const t of tracked.values())
|
|
120
|
-
send(t);
|
|
123
|
+
taken = send(t) && taken;
|
|
121
124
|
prune();
|
|
125
|
+
return taken;
|
|
122
126
|
},
|
|
123
127
|
reset() {
|
|
124
128
|
tracked.clear();
|
|
125
129
|
current = undefined;
|
|
126
130
|
},
|
|
131
|
+
nextSeq(viewId) {
|
|
132
|
+
return tracked.get(viewId)?.seq;
|
|
133
|
+
},
|
|
134
|
+
late(view, seq, key) {
|
|
135
|
+
return (opts.emit({
|
|
136
|
+
[ATTR_RUM_PLATFORM]: opts.platform,
|
|
137
|
+
[ATTR_RUM_VIEW_ID]: view.id,
|
|
138
|
+
[ATTR_RUM_VIEW_NAME]: view.name,
|
|
139
|
+
[ATTR_RUM_VIEW_KIND]: view.kind,
|
|
140
|
+
[ATTR_SESSION_ID]: view.sessionId,
|
|
141
|
+
[ATTR_RUM_SUMMARY_SEQ]: seq,
|
|
142
|
+
[ATTR_RUM_SUMMARY_TIME_ON_VIEW]: 0,
|
|
143
|
+
[summaryCountKey(key)]: 1,
|
|
144
|
+
}) !== false);
|
|
145
|
+
},
|
|
127
146
|
};
|
|
128
147
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The `@libo11y/rum` package version. scripts/release.ts keeps it equal to package.json. */
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.7.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The `@libo11y/rum` package version. scripts/release.ts keeps it equal to package.json. */
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.7.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libo11y/rum",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "libo11y RUM for browsers and MV3 extensions: sessions shared across tabs, consent, session sampling with a retention buffer, views, actions, frustration signals, errors with breadcrumbs, web vitals with attribution, resources and per-view summaries over @libo11y/web.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"directory": "ts/packages/rum"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@libo11y/core": "0.
|
|
37
|
-
"@libo11y/spec": "0.
|
|
38
|
-
"@libo11y/web": "0.
|
|
39
|
-
"@libo11y/webext": "0.
|
|
36
|
+
"@libo11y/core": "0.7.0",
|
|
37
|
+
"@libo11y/spec": "0.7.0",
|
|
38
|
+
"@libo11y/web": "0.7.0",
|
|
39
|
+
"@libo11y/webext": "0.7.0",
|
|
40
40
|
"@opentelemetry/core": "3.1.1",
|
|
41
41
|
"@opentelemetry/sdk-logs": "3.1.1",
|
|
42
42
|
"@opentelemetry/sdk-trace": "3.1.1",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@opentelemetry/api": ">=1.10.0 <1.11.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@libo11y/test": "0.
|
|
49
|
+
"@libo11y/test": "0.7.0",
|
|
50
50
|
"@opentelemetry/api": "1.10.0",
|
|
51
51
|
"fake-indexeddb": "6.2.7"
|
|
52
52
|
},
|