@libo11y/rum 0.4.0 → 0.6.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 +37 -20
- package/dist/actions/collector.js +2 -2
- package/dist/actions/naming.d.ts +1 -1
- package/dist/actions/naming.js +1 -1
- package/dist/actions/record.d.ts +1 -1
- package/dist/actions/record.js +1 -1
- package/dist/actions/settle.d.ts +1 -1
- package/dist/actions/settle.js +1 -1
- package/dist/bind.d.ts +1 -1
- package/dist/bootstrap/buffer.d.ts +1 -1
- package/dist/bootstrap/buffer.js +1 -1
- package/dist/bootstrap/replay.d.ts +1 -1
- package/dist/config/clamp.d.ts +2 -2
- package/dist/config/clamp.js +2 -2
- package/dist/config/remote.d.ts +30 -7
- package/dist/config/remote.js +78 -46
- package/dist/context-manager.d.ts +1 -1
- package/dist/context-manager.js +1 -1
- package/dist/contracts/binding.d.ts +4 -2
- package/dist/contracts/retention.d.ts +7 -3
- package/dist/contracts/runtime.d.ts +24 -14
- package/dist/contracts/session.d.ts +6 -1
- package/dist/contracts/summary.d.ts +2 -2
- package/dist/contracts/views.d.ts +3 -3
- package/dist/core-setup.d.ts +43 -8
- package/dist/core-setup.js +286 -71
- package/dist/core.d.ts +13 -9
- package/dist/core.js +6 -5
- package/dist/errors/breadcrumbs.d.ts +1 -1
- package/dist/errors/breadcrumbs.js +1 -1
- package/dist/errors/record.d.ts +1 -1
- package/dist/errors/record.js +1 -1
- package/dist/frustration/detect.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/internal.d.ts +15 -9
- package/dist/internal.js +4 -5
- package/dist/pending-spans.d.ts +1 -1
- package/dist/query.d.ts +1 -1
- package/dist/query.js +1 -1
- package/dist/retention/buffer.d.ts +9 -5
- package/dist/retention/buffer.js +41 -15
- package/dist/retention/exporters.d.ts +56 -2
- package/dist/retention/exporters.js +214 -0
- package/dist/session/manager.js +1 -1
- package/dist/session/sampling.js +1 -1
- package/dist/setup.d.ts +3 -1
- package/dist/setup.js +14 -6
- package/dist/span-processor.d.ts +3 -3
- package/dist/span-processor.js +2 -2
- package/dist/summary/accumulator.d.ts +7 -2
- package/dist/summary/accumulator.js +4 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/views/collector.js +8 -7
- package/dist/views/naming.d.ts +1 -1
- package/dist/views/naming.js +1 -1
- package/dist/views/tracker.d.ts +15 -6
- package/dist/views/tracker.js +10 -13
- package/dist/vitals/collector.js +2 -2
- package/dist/webext/config-storage.d.ts +15 -4
- package/dist/webext/config-storage.js +78 -27
- package/dist/webext/scope.d.ts +1 -1
- package/dist/webext/session-store.js +12 -2
- package/dist/webext/setup.d.ts +5 -2
- package/dist/webext/setup.js +29 -16
- package/dist/webext.d.ts +1 -1
- package/package.json +11 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EVENT_RUM_VIEW_SUMMARY } from "@libo11y/spec";
|
|
2
2
|
import { serializeLogs, serializeSpans } from "@libo11y/web/portable";
|
|
3
|
+
import { diag } from "@opentelemetry/api";
|
|
3
4
|
import { ExportResultCode } from "@opentelemetry/core";
|
|
4
5
|
import { ATTR_SESSION_ID } from "../attrs.js";
|
|
5
6
|
const SUCCESS = { code: ExportResultCode.SUCCESS };
|
|
@@ -37,6 +38,219 @@ export function retainingSpanExporter(inner, routing) {
|
|
|
37
38
|
: { forceFlush: () => inner.forceFlush?.() ?? Promise.resolve() }),
|
|
38
39
|
};
|
|
39
40
|
}
|
|
41
|
+
/** The most spans holdingSpanExporter holds. Past it the oldest are dropped first. */
|
|
42
|
+
export const HELD_SPANS_MAX = 1000;
|
|
43
|
+
/** The most log records holdingLogExporter holds. Past it the oldest are dropped first. */
|
|
44
|
+
export const HELD_LOGS_MAX = 1000;
|
|
45
|
+
/** How long one export the holding exporters start may take before it counts as failed, as upstream's batch processors wait. */
|
|
46
|
+
const HELD_EXPORT_TIMEOUT_MILLIS = 30_000;
|
|
47
|
+
function asError(err) {
|
|
48
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
49
|
+
}
|
|
50
|
+
function holding(inner, what, route, idOf, max, o) {
|
|
51
|
+
const allowed = o.allowed ?? (() => true);
|
|
52
|
+
const timeoutMillis = o.timeoutMillis ?? HELD_EXPORT_TIMEOUT_MILLIS;
|
|
53
|
+
let held = [];
|
|
54
|
+
let jobs = [];
|
|
55
|
+
/** An export whose caller is still waiting for it. */
|
|
56
|
+
let busy = false;
|
|
57
|
+
/** The inner exporter has not yet called back, even if the export timed out. */
|
|
58
|
+
let innerBusy = false;
|
|
59
|
+
let closed = false;
|
|
60
|
+
let epoch = 0;
|
|
61
|
+
/** The first release export that failed and was not yet reported by forceFlush or shutdown. */
|
|
62
|
+
let failure;
|
|
63
|
+
/** Waiting for every queued and in-flight export to finish. */
|
|
64
|
+
let idleWaiters = [];
|
|
65
|
+
let innerStopped;
|
|
66
|
+
/** Ends a shutdown that waits for a release, once close is called. */
|
|
67
|
+
let abort = () => { };
|
|
68
|
+
const aborted = new Promise((resolve) => {
|
|
69
|
+
abort = resolve;
|
|
70
|
+
});
|
|
71
|
+
const idle = () => !busy && jobs.length === 0 ? Promise.resolve() : new Promise((resolve) => idleWaiters.push(resolve));
|
|
72
|
+
const settleIdle = () => {
|
|
73
|
+
const waiters = idleWaiters;
|
|
74
|
+
idleWaiters = [];
|
|
75
|
+
for (const w of waiters)
|
|
76
|
+
w();
|
|
77
|
+
};
|
|
78
|
+
const stopInner = () => {
|
|
79
|
+
innerStopped ??= Promise.resolve().then(() => inner.shutdown());
|
|
80
|
+
return innerStopped;
|
|
81
|
+
};
|
|
82
|
+
const shutDown = () => ({
|
|
83
|
+
code: ExportResultCode.FAILED,
|
|
84
|
+
error: new Error(`o11y: rum: ${what} exporter is shut down`),
|
|
85
|
+
});
|
|
86
|
+
const timedOut = () => ({
|
|
87
|
+
code: ExportResultCode.FAILED,
|
|
88
|
+
error: new Error(`o11y: rum: exporting ${what} timed out`),
|
|
89
|
+
});
|
|
90
|
+
const pump = () => {
|
|
91
|
+
while (!busy) {
|
|
92
|
+
const job = jobs.shift();
|
|
93
|
+
if (job === undefined) {
|
|
94
|
+
settleIdle();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// What waits for its turn after a revoke, or past a grant revoked since, exports nothing.
|
|
98
|
+
if (closed || !allowed() || job.epoch !== epoch) {
|
|
99
|
+
job.done(closed && !job.release ? shutDown() : SUCCESS);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// The inner exporter has yet to answer an export that timed out, and never exports two
|
|
103
|
+
// batches at once: what is queued meanwhile fails.
|
|
104
|
+
if (innerBusy) {
|
|
105
|
+
job.done(timedOut());
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
busy = true;
|
|
109
|
+
innerBusy = true;
|
|
110
|
+
let answered = false;
|
|
111
|
+
let finished = false;
|
|
112
|
+
const finish = (r) => {
|
|
113
|
+
if (finished)
|
|
114
|
+
return;
|
|
115
|
+
finished = true;
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
busy = false;
|
|
118
|
+
job.done(r);
|
|
119
|
+
pump();
|
|
120
|
+
};
|
|
121
|
+
const timer = setTimeout(() => finish(timedOut()), timeoutMillis);
|
|
122
|
+
timer.unref?.();
|
|
123
|
+
const answer = (r) => {
|
|
124
|
+
if (answered)
|
|
125
|
+
return;
|
|
126
|
+
answered = true;
|
|
127
|
+
innerBusy = false;
|
|
128
|
+
finish(r);
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
inner.export(job.items, answer);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
answer({ code: ExportResultCode.FAILED, error: asError(err) });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const enqueue = (items, done, release) => {
|
|
139
|
+
jobs.push({ items, done, release, epoch });
|
|
140
|
+
pump();
|
|
141
|
+
};
|
|
142
|
+
/** Settles every queued export with r without exporting it; a release settles as a success. */
|
|
143
|
+
const drain = (r) => {
|
|
144
|
+
const queued = jobs;
|
|
145
|
+
jobs = [];
|
|
146
|
+
for (const job of queued)
|
|
147
|
+
job.done(job.release ? SUCCESS : r);
|
|
148
|
+
if (!busy)
|
|
149
|
+
settleIdle();
|
|
150
|
+
};
|
|
151
|
+
const report = () => {
|
|
152
|
+
const err = failure;
|
|
153
|
+
failure = undefined;
|
|
154
|
+
if (err !== undefined)
|
|
155
|
+
throw err;
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
export(items, done) {
|
|
159
|
+
if (closed) {
|
|
160
|
+
done({ code: ExportResultCode.FAILED, error: new Error(`o11y: rum: ${what} exporter is shut down`) });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const send = [];
|
|
164
|
+
for (const item of items) {
|
|
165
|
+
const r = route(item);
|
|
166
|
+
if (r === "send")
|
|
167
|
+
send.push(item);
|
|
168
|
+
else if (r === "buffer")
|
|
169
|
+
held.push({ id: idOf(item), item });
|
|
170
|
+
}
|
|
171
|
+
if (held.length > max)
|
|
172
|
+
held = held.slice(held.length - max);
|
|
173
|
+
if (send.length === 0)
|
|
174
|
+
done(SUCCESS);
|
|
175
|
+
else
|
|
176
|
+
enqueue(send, done, false);
|
|
177
|
+
},
|
|
178
|
+
release() {
|
|
179
|
+
if (closed)
|
|
180
|
+
return;
|
|
181
|
+
const send = [];
|
|
182
|
+
const keep = [];
|
|
183
|
+
for (const h of held) {
|
|
184
|
+
const r = h.id === undefined ? "drop" : route(h.item);
|
|
185
|
+
if (r === "send")
|
|
186
|
+
send.push(h.item);
|
|
187
|
+
else if (r === "buffer")
|
|
188
|
+
keep.push(h);
|
|
189
|
+
}
|
|
190
|
+
held = keep;
|
|
191
|
+
if (send.length === 0)
|
|
192
|
+
return;
|
|
193
|
+
enqueue(send, (r) => {
|
|
194
|
+
if (r.code === ExportResultCode.SUCCESS)
|
|
195
|
+
return;
|
|
196
|
+
const err = r.error ?? new Error(`o11y: rum: exporting held ${what} failed`);
|
|
197
|
+
diag.warn(`o11y: rum: exporting held ${what} failed`, err);
|
|
198
|
+
failure ??= err;
|
|
199
|
+
}, true);
|
|
200
|
+
},
|
|
201
|
+
discard(sessionId) {
|
|
202
|
+
if (sessionId !== undefined) {
|
|
203
|
+
held = held.filter((h) => h.id !== sessionId);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// A revoke: nothing held or queued under the grant it ends is exported, even after a new grant.
|
|
207
|
+
held = [];
|
|
208
|
+
epoch++;
|
|
209
|
+
drain(SUCCESS);
|
|
210
|
+
},
|
|
211
|
+
async forceFlush() {
|
|
212
|
+
await Promise.race([idle(), aborted]);
|
|
213
|
+
await inner.forceFlush?.();
|
|
214
|
+
report();
|
|
215
|
+
},
|
|
216
|
+
async shutdown() {
|
|
217
|
+
await Promise.race([idle(), aborted]);
|
|
218
|
+
await stopInner();
|
|
219
|
+
report();
|
|
220
|
+
},
|
|
221
|
+
async close() {
|
|
222
|
+
closed = true;
|
|
223
|
+
held = [];
|
|
224
|
+
abort();
|
|
225
|
+
// What still waits for its turn is not exported. A queued release is dropped as a revoke drops it.
|
|
226
|
+
drain(shutDown());
|
|
227
|
+
try {
|
|
228
|
+
await stopInner();
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
diag.debug(`o11y: rum: stopping the ${what} exporter failed`, err);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* A SpanExporter that routes each span by its session.id as retainingSpanExporter does, but holds
|
|
238
|
+
* the spans to be buffered in memory, at most max of them, instead of in the retention buffer. The
|
|
239
|
+
* retention buffer sends through the platform's delivery, so an exporter the app injected, or the
|
|
240
|
+
* console exporter, would never see a span that waited there. A held span without a session.id is
|
|
241
|
+
* never released.
|
|
242
|
+
*/
|
|
243
|
+
export function holdingSpanExporter(inner, decide, o = {}) {
|
|
244
|
+
return holding(inner, "spans", (s) => decide(sessionOf(s.attributes)), (s) => sessionOf(s.attributes), o.max ?? HELD_SPANS_MAX, o);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A LogRecordExporter that routes each record as holdingSpanExporter routes spans, sending every
|
|
248
|
+
* o11y.rum.view.summary record at once, as retainingLogExporter does.
|
|
249
|
+
*/
|
|
250
|
+
export function holdingLogExporter(inner, decide, o = {}) {
|
|
251
|
+
const h = holding(inner, "log records", (l) => (l.attributes["event.name"] === EVENT_RUM_VIEW_SUMMARY ? "send" : decide(sessionOf(l.attributes))), (l) => sessionOf(l.attributes), o.max ?? HELD_LOGS_MAX, o);
|
|
252
|
+
return { ...h, forceFlush: () => h.forceFlush?.() ?? Promise.resolve() };
|
|
253
|
+
}
|
|
40
254
|
/** A LogRecordExporter that routes each record by its session.id, sending every view summary. */
|
|
41
255
|
export function retainingLogExporter(inner, routing) {
|
|
42
256
|
return {
|
package/dist/session/manager.js
CHANGED
|
@@ -108,7 +108,7 @@ export function createSessionManager(opts) {
|
|
|
108
108
|
if (stored !== undefined && state === undefined) {
|
|
109
109
|
state = stored;
|
|
110
110
|
remember(stored);
|
|
111
|
-
// A live stored session was started elsewhere. An expired one is ended here
|
|
111
|
+
// A live stored session was started elsewhere. An expired one is ended here:
|
|
112
112
|
// live() below rotates it and emits its local end.
|
|
113
113
|
if (!expired(stored, now()))
|
|
114
114
|
emit({ type: "start", session: stored, local: false });
|
package/dist/session/sampling.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session sampling
|
|
2
|
+
* Session sampling. The decision is a hash of session.id, so every tab of a session,
|
|
3
3
|
* and every client language, agrees: kept when fnv1a32(utf8(id)) / 2^32 < rate.
|
|
4
4
|
*/
|
|
5
5
|
const encoder = new TextEncoder();
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* setupRum: @libo11y/web's setup with RUM wired in
|
|
2
|
+
* setupRum: @libo11y/web's setup with RUM wired in. setupRumWith binds the RUM core
|
|
3
3
|
* (core-setup.ts) to the web: web's setupWithDeps through webBinding, the page's lifecycle from
|
|
4
4
|
* visibilitychange, pagehide and pageshow, remote configuration cached in localStorage, and the
|
|
5
5
|
* bootstrap buffer replayed. The extension contexts pass their own binding and stores in deps.
|
|
@@ -32,6 +32,8 @@ export interface RumDeps extends Omit<RumCoreDeps<WebSetupOptions, WebTelemetry>
|
|
|
32
32
|
*/
|
|
33
33
|
readonly storage?: RumCoreDeps<WebSetupOptions, WebTelemetry>["storage"];
|
|
34
34
|
}
|
|
35
|
+
/** Browser dependencies shared by pages and extension contexts, without web setup or localStorage. */
|
|
36
|
+
export declare function defaultBrowserRumDeps(): Omit<RumDeps, "web" | "sessionStore">;
|
|
35
37
|
/** The real dependencies of a page. */
|
|
36
38
|
export declare function defaultRumDeps(): RumDeps;
|
|
37
39
|
/** Builds browser telemetry with RUM and installs it globally, as the setup of `@libo11y/web` does. */
|
package/dist/setup.js
CHANGED
|
@@ -5,14 +5,12 @@ import { replayBootstrap } from "./bootstrap/replay.js";
|
|
|
5
5
|
import { setupRumCore } from "./core-setup.js";
|
|
6
6
|
import { localStorageSessionStore } from "./session/local-store.js";
|
|
7
7
|
export { runtimeOf, SESSION_END_ELECTION_MILLIS } from "./core-setup.js";
|
|
8
|
-
/**
|
|
9
|
-
export function
|
|
8
|
+
/** Browser dependencies shared by pages and extension contexts, without web setup or localStorage. */
|
|
9
|
+
export function defaultBrowserRumDeps() {
|
|
10
10
|
const g = globalThis;
|
|
11
|
-
const
|
|
11
|
+
const doc = g.document;
|
|
12
12
|
return {
|
|
13
|
-
web,
|
|
14
13
|
openRetentionQueue: openQueue,
|
|
15
|
-
sessionStore: () => localStorageSessionStore(),
|
|
16
14
|
now: Date.now,
|
|
17
15
|
perfNow: () => performance.now(),
|
|
18
16
|
timeOrigin: performance.timeOrigin,
|
|
@@ -24,7 +22,17 @@ export function defaultRumDeps() {
|
|
|
24
22
|
return (nav?.activationStart ?? 0) > 0;
|
|
25
23
|
},
|
|
26
24
|
connection: () => g.navigator?.connection?.effectiveType,
|
|
27
|
-
document:
|
|
25
|
+
document: doc,
|
|
26
|
+
window: doc !== undefined && typeof g.addEventListener === "function" ? globalThis : undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** The real dependencies of a page. */
|
|
30
|
+
export function defaultRumDeps() {
|
|
31
|
+
const web = defaultSetupDeps();
|
|
32
|
+
return {
|
|
33
|
+
...defaultBrowserRumDeps(),
|
|
34
|
+
web,
|
|
35
|
+
sessionStore: () => localStorageSessionStore(),
|
|
28
36
|
window: web.window,
|
|
29
37
|
};
|
|
30
38
|
}
|
package/dist/span-processor.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* the attribute the gateway keys on. Its documentFetch child also belongs to the load view, and it
|
|
7
7
|
* is not a request of the view. It publishes client request starts and ends on the bus for
|
|
8
8
|
* actions, summaries and errors, and a breadcrumb for each finished request: "fetch <METHOD> <host>
|
|
9
|
-
* <status or failed>", or "rpc <method>" for a span with rpc.method, never a path
|
|
9
|
+
* <status or failed>", or "rpc <method>" for a span with rpc.method, never a path. It runs before the exporting processors, so they see the
|
|
10
10
|
* attributes. A span that starts while the session loads after a grant gets the same treatment,
|
|
11
|
-
* and waits in pending for its session.id and view
|
|
11
|
+
* and waits in pending for its session.id and view.
|
|
12
12
|
*/
|
|
13
13
|
import { type RUMPlatform } from "@libo11y/spec";
|
|
14
14
|
import type { SpanProcessor } from "@opentelemetry/sdk-trace";
|
|
@@ -31,7 +31,7 @@ export interface RumSpanProcessorOptions {
|
|
|
31
31
|
* performance.timeOrigin, to read a span's end time on the now() clock. Without it the bus
|
|
32
32
|
* reports now() alone.
|
|
33
33
|
*/
|
|
34
|
-
readonly timeOrigin?: number;
|
|
34
|
+
readonly timeOrigin?: number | undefined;
|
|
35
35
|
/** Where spans that start while the session loads wait for it. */
|
|
36
36
|
readonly pending?: Pick<PendingSpans, "isOpen" | "hold">;
|
|
37
37
|
}
|
package/dist/span-processor.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* the attribute the gateway keys on. Its documentFetch child also belongs to the load view, and it
|
|
7
7
|
* is not a request of the view. It publishes client request starts and ends on the bus for
|
|
8
8
|
* actions, summaries and errors, and a breadcrumb for each finished request: "fetch <METHOD> <host>
|
|
9
|
-
* <status or failed>", or "rpc <method>" for a span with rpc.method, never a path
|
|
9
|
+
* <status or failed>", or "rpc <method>" for a span with rpc.method, never a path. It runs before the exporting processors, so they see the
|
|
10
10
|
* attributes. A span that starts while the session loads after a grant gets the same treatment,
|
|
11
|
-
* and waits in pending for its session.id and view
|
|
11
|
+
* and waits in pending for its session.id and view.
|
|
12
12
|
*/
|
|
13
13
|
import { ATTR_RUM_PLATFORM, ATTR_RUM_SPAN_SHAPE, ATTR_RUM_VIEW_ID, RUM_SPAN_SHAPE_VALUE_APP_LOAD, } from "@libo11y/spec";
|
|
14
14
|
import { SpanKind } from "@opentelemetry/api";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The view summary accumulator (
|
|
2
|
+
* The view summary accumulator (spec 1.3.0 o11y.rum.view.summary). conformance/rum-summary
|
|
3
3
|
* holds the shared vectors.
|
|
4
4
|
*
|
|
5
5
|
* Rules. A tracked view emits on close, and on flush when it has never emitted (seq 0) or has a
|
|
@@ -19,7 +19,12 @@ export interface SummaryOptions {
|
|
|
19
19
|
readonly now: () => number;
|
|
20
20
|
/** Whether the page is visible now. */
|
|
21
21
|
readonly visible: () => boolean;
|
|
22
|
-
/** Optional attributes added to every summary: o11y.rum.connection.effective
|
|
22
|
+
/** Optional attributes added to every summary, read as it is emitted: o11y.rum.connection.effective. */
|
|
23
23
|
readonly context?: () => Readonly<Record<string, string | number>>;
|
|
24
|
+
/**
|
|
25
|
+
* Optional attributes read once, when a view opens, and added to every summary of that view, late
|
|
26
|
+
* vitals included: o11y.rum.config.version of the session the view opened in.
|
|
27
|
+
*/
|
|
28
|
+
readonly origin?: () => Readonly<Record<string, string | number>>;
|
|
24
29
|
}
|
|
25
30
|
export declare function createSummaryAccumulator(opts: SummaryOptions): SummaryAccumulator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The view summary accumulator (
|
|
2
|
+
* The view summary accumulator (spec 1.3.0 o11y.rum.view.summary). conformance/rum-summary
|
|
3
3
|
* holds the shared vectors.
|
|
4
4
|
*
|
|
5
5
|
* Rules. A tracked view emits on close, and on flush when it has never emitted (seq 0) or has a
|
|
@@ -28,7 +28,8 @@ export function createSummaryAccumulator(opts) {
|
|
|
28
28
|
if (!pending(t))
|
|
29
29
|
return;
|
|
30
30
|
const attrs = {
|
|
31
|
-
...
|
|
31
|
+
...opts.context?.(),
|
|
32
|
+
...t.origin,
|
|
32
33
|
[ATTR_RUM_PLATFORM]: opts.platform,
|
|
33
34
|
[ATTR_RUM_VIEW_ID]: t.view.id,
|
|
34
35
|
[ATTR_RUM_VIEW_NAME]: t.view.name,
|
|
@@ -67,6 +68,7 @@ export function createSummaryAccumulator(opts) {
|
|
|
67
68
|
resumedAt: opts.visible() ? opts.now() : undefined,
|
|
68
69
|
open: true,
|
|
69
70
|
pinned: false,
|
|
71
|
+
origin: opts.origin?.(),
|
|
70
72
|
};
|
|
71
73
|
tracked.set(view.id, t);
|
|
72
74
|
current = t;
|
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.6.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.6.0";
|
package/dist/views/collector.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Every view the tracker starts gets a view span named "view <o11y.rum.view.name>" with
|
|
5
5
|
* o11y.rum.span.shape view, the platform, the view's name, ID and kind, and its session.id. It
|
|
6
6
|
* starts at the view's startTime. A soft or bfcache_restore view span is a root, linked to the
|
|
7
|
-
* action that caused it when there is one.
|
|
8
|
-
* app_load (web's documentLoad span). Its creation waits for the span processor to report
|
|
7
|
+
* action that caused it when there is one. The load view's span (initial or prerender on the web,
|
|
8
|
+
* the first screen on React Native) is a child of app_load (web's documentLoad span). Its creation waits for the span processor to report
|
|
9
9
|
* app_load, and once the view span is due to end it waits at most APP_LOAD_WAIT_MILLIS more, then
|
|
10
10
|
* starts as a root. The tracker learns the span's context (attachSpan), so actions link to it.
|
|
11
11
|
*
|
|
@@ -40,7 +40,6 @@ export const MUTATIONS = {
|
|
|
40
40
|
attributes: true,
|
|
41
41
|
characterData: true,
|
|
42
42
|
};
|
|
43
|
-
const LOAD_SPAN_KINDS = new Set(["initial", "prerender"]);
|
|
44
43
|
export function viewsWith(opts, env) {
|
|
45
44
|
const followHistory = opts.history !== false;
|
|
46
45
|
return {
|
|
@@ -68,12 +67,12 @@ export function viewsWith(opts, env) {
|
|
|
68
67
|
o.offLoad = undefined;
|
|
69
68
|
};
|
|
70
69
|
// A fixed view (a content script) has no app_load: the host page's load is not its own.
|
|
71
|
-
const waitsForAppLoad = (o) =>
|
|
70
|
+
const waitsForAppLoad = (o) => o.load && rt.views.appLoad() === undefined && rt.scope?.fixedView !== true;
|
|
72
71
|
const create = (o) => {
|
|
73
72
|
if (o.span !== undefined)
|
|
74
73
|
return o.span;
|
|
75
74
|
const v = o.view;
|
|
76
|
-
const appLoad =
|
|
75
|
+
const appLoad = o.load ? rt.views.appLoad() : undefined;
|
|
77
76
|
const span = rt.tracer.startSpan(`view ${v.name}`, {
|
|
78
77
|
startTime: env.timeOrigin + v.startTime,
|
|
79
78
|
attributes: {
|
|
@@ -94,12 +93,13 @@ export function viewsWith(opts, env) {
|
|
|
94
93
|
const close = (o) => {
|
|
95
94
|
quiet(o);
|
|
96
95
|
open.delete(o.view.id);
|
|
97
|
-
|
|
96
|
+
const capAt = o.view.startTime + VIEW_SPAN_CAP_MILLIS;
|
|
97
|
+
create(o).end(env.timeOrigin + Math.min(o.endAt ?? rt.now(), capAt));
|
|
98
98
|
};
|
|
99
99
|
const finish = (o, at) => {
|
|
100
100
|
if (o.endAt !== undefined)
|
|
101
101
|
return;
|
|
102
|
-
o.endAt = at;
|
|
102
|
+
o.endAt = Math.min(at, o.view.startTime + VIEW_SPAN_CAP_MILLIS);
|
|
103
103
|
if (o.span !== undefined || !waitsForAppLoad(o)) {
|
|
104
104
|
close(o);
|
|
105
105
|
return;
|
|
@@ -151,6 +151,7 @@ export function viewsWith(opts, env) {
|
|
|
151
151
|
const start = (view, cause, atSetup, onScreen = false) => {
|
|
152
152
|
const o = {
|
|
153
153
|
view,
|
|
154
|
+
load: view.kind !== "bfcache_restore" && rt.views.loadView()?.id === view.id,
|
|
154
155
|
...(cause === undefined ? {} : { cause }),
|
|
155
156
|
rendered: false,
|
|
156
157
|
timers: new Set(),
|
package/dist/views/naming.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The view name when no router adapter names the view
|
|
2
|
+
* The view name when no router adapter names the view: the path, with every
|
|
3
3
|
* segment that holds a digit or is longer than 24 characters replaced by $id. Query and fragment
|
|
4
4
|
* are dropped, so a raw URL never becomes a view name.
|
|
5
5
|
*/
|
package/dist/views/naming.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The view name when no router adapter names the view
|
|
2
|
+
* The view name when no router adapter names the view: the path, with every
|
|
3
3
|
* segment that holds a digit or is longer than 24 characters replaced by $id. Query and fragment
|
|
4
4
|
* are dropped, so a raw URL never becomes a view name.
|
|
5
5
|
*/
|
package/dist/views/tracker.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The view tracker: the initial (or prerender) view at begin, a bfcache_restore view on a
|
|
3
|
-
* persisted pageshow, a soft view of the same name when the session changes
|
|
4
|
-
* the soft views views() and the router adapters start.
|
|
5
|
-
*
|
|
3
|
+
* persisted pageshow, a soft view of the same name when the session changes, and
|
|
4
|
+
* the soft views views() and the router adapters start. A platform whose views are all of one
|
|
5
|
+
* kind, as React Native's screens, passes viewKind: the first begin's view is then the load view and
|
|
6
|
+
* every view has that kind. Every view opens in the summary accumulator and closes when it ends.
|
|
7
|
+
* views() records the view spans and attaches their contexts.
|
|
6
8
|
*/
|
|
9
|
+
import type { RUMViewKind } from "@libo11y/spec";
|
|
7
10
|
import type { SessionManager } from "../contracts/session.ts";
|
|
8
11
|
import type { SummaryAccumulator } from "../contracts/summary.ts";
|
|
9
12
|
import type { ViewTracker } from "../contracts/views.ts";
|
|
@@ -15,12 +18,18 @@ export interface ViewTrackerOptions {
|
|
|
15
18
|
readonly location: () => string;
|
|
16
19
|
/** performance.now(). */
|
|
17
20
|
readonly now: () => number;
|
|
18
|
-
/** document.prerendering, or a navigation entry with activationStart > 0
|
|
21
|
+
/** document.prerendering, or a navigation entry with `activationStart > 0`. */
|
|
19
22
|
readonly prerendered: () => boolean;
|
|
20
23
|
/** Where pageshow fires, for back/forward-cache restores. */
|
|
21
|
-
readonly window?: EventTarget;
|
|
24
|
+
readonly window?: EventTarget | undefined;
|
|
22
25
|
/** When the initial view starts, performance.now(). Default 0, navigation start; a content script's view starts when RUM begins. */
|
|
23
|
-
readonly initialStart?: () => number;
|
|
26
|
+
readonly initialStart?: (() => number) | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The kind of every view the tracker starts itself (the load view, the view of a session change
|
|
29
|
+
* and of a later begin), for a platform with one kind of view, such as React Native's screen.
|
|
30
|
+
* Default the web's: initial or prerender, then soft.
|
|
31
|
+
*/
|
|
32
|
+
readonly viewKind?: RUMViewKind | undefined;
|
|
24
33
|
readonly randomId?: () => string;
|
|
25
34
|
}
|
|
26
35
|
export declare function createViewTracker(opts: ViewTrackerOptions): ViewTracker & {
|
package/dist/views/tracker.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The view tracker: the initial (or prerender) view at begin, a bfcache_restore view on a
|
|
3
|
-
* persisted pageshow, a soft view of the same name when the session changes (decision P14), and
|
|
4
|
-
* the soft views views() and the router adapters start. Every view opens in the summary
|
|
5
|
-
* accumulator and closes when it ends. views() records the view spans and attaches their contexts.
|
|
6
|
-
*/
|
|
7
1
|
import { randomUuid } from "../ids.js";
|
|
8
2
|
const LOAD_KINDS = new Set(["initial", "prerender", "bfcache_restore"]);
|
|
9
3
|
export function createViewTracker(opts) {
|
|
@@ -25,7 +19,9 @@ export function createViewTracker(opts) {
|
|
|
25
19
|
emit({ type: "end", view: ended });
|
|
26
20
|
return ended;
|
|
27
21
|
};
|
|
28
|
-
const
|
|
22
|
+
const later = opts.viewKind ?? "soft";
|
|
23
|
+
/** Starts a view; asLoad makes it the load view. */
|
|
24
|
+
const start = (o, asLoad = LOAD_KINDS.has(o.kind)) => {
|
|
29
25
|
const previous = endCurrent();
|
|
30
26
|
const session = opts.session.current();
|
|
31
27
|
const view = {
|
|
@@ -38,7 +34,7 @@ export function createViewTracker(opts) {
|
|
|
38
34
|
if (session === undefined)
|
|
39
35
|
return view; // no consent: nothing is tracked
|
|
40
36
|
current = view;
|
|
41
|
-
if (
|
|
37
|
+
if (asLoad)
|
|
42
38
|
load = view;
|
|
43
39
|
opts.summary.open(view);
|
|
44
40
|
emit({
|
|
@@ -60,12 +56,12 @@ export function createViewTracker(opts) {
|
|
|
60
56
|
if (e.type !== "start" || e.previous === undefined || current === undefined)
|
|
61
57
|
return;
|
|
62
58
|
if (current.sessionId !== e.session.id)
|
|
63
|
-
start({ kind:
|
|
59
|
+
start({ kind: later, name: current.name, rendered: true });
|
|
64
60
|
});
|
|
65
61
|
return {
|
|
66
62
|
current: () => current,
|
|
67
63
|
loadView: () => load,
|
|
68
|
-
start,
|
|
64
|
+
start: (o) => start(o),
|
|
69
65
|
rename(name) {
|
|
70
66
|
if (current === undefined)
|
|
71
67
|
return;
|
|
@@ -94,12 +90,13 @@ export function createViewTracker(opts) {
|
|
|
94
90
|
return;
|
|
95
91
|
// The initial view starts at time origin: a view covers getting into it from navigation start.
|
|
96
92
|
// A later begin (consent granted again) is a new session on a page already loaded, so its
|
|
97
|
-
// view is soft and starts now
|
|
93
|
+
// view is soft and starts now.
|
|
98
94
|
if (load === undefined) {
|
|
99
|
-
|
|
95
|
+
const kind = opts.viewKind ?? (opts.prerendered() ? "prerender" : "initial");
|
|
96
|
+
start({ kind, startTime: opts.initialStart?.() ?? 0 }, true);
|
|
100
97
|
}
|
|
101
98
|
else
|
|
102
|
-
start({ kind:
|
|
99
|
+
start({ kind: later, name: load.name });
|
|
103
100
|
},
|
|
104
101
|
end() {
|
|
105
102
|
endCurrent();
|
package/dist/vitals/collector.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The vitals() collector: LCP, INP, CLS, FCP and TTFB from the web-vitals attribution build
|
|
3
|
-
*
|
|
2
|
+
* The vitals() collector: LCP, INP, CLS, FCP and TTFB from the web-vitals attribution build,
|
|
3
|
+
* attributed to the view that loaded the page.
|
|
4
4
|
*
|
|
5
5
|
* Rules. The web-vitals callbacks are registered once per page, on the first start, with
|
|
6
6
|
* reportAllChanges true, and forward to the running collector: a revoked and granted page does not
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { type RemoteConfigStorage } from "../config/remote.ts";
|
|
1
2
|
import type { RumChromeLike } from "./chrome.ts";
|
|
2
|
-
/** The synchronous storage remote configuration caches in. */
|
|
3
|
-
export type ConfigStorage =
|
|
4
|
-
/**
|
|
5
|
-
|
|
3
|
+
/** The synchronous storage remote configuration caches in, with flush for its writes to chrome.storage.local. */
|
|
4
|
+
export type ConfigStorage = RemoteConfigStorage & {
|
|
5
|
+
/** Resolves once every earlier write reached storage. Never rejects. */
|
|
6
|
+
flush(): Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
/** The slice of navigator.locks an update runs under. */
|
|
9
|
+
export interface ConfigLocks {
|
|
10
|
+
request(name: string, cb: () => Promise<void>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A cache over chrome.storage.local once the stored values are read, or undefined without the area.
|
|
14
|
+
* locks null updates without a lock. Never rejects.
|
|
15
|
+
*/
|
|
16
|
+
export declare function chromeConfigStorage(chrome: RumChromeLike, locks?: ConfigLocks | null | undefined): Promise<(ConfigStorage & {
|
|
6
17
|
close(): void;
|
|
7
18
|
}) | undefined>;
|