@libo11y/rum 0.0.0-stage → 0.4.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/LICENSE +202 -0
- package/README.md +461 -2
- package/dist/actions/collector.d.ts +29 -0
- package/dist/actions/collector.js +260 -0
- package/dist/actions/naming.d.ts +15 -0
- package/dist/actions/naming.js +65 -0
- package/dist/actions/record.d.ts +13 -0
- package/dist/actions/record.js +28 -0
- package/dist/actions/settle.d.ts +28 -0
- package/dist/actions/settle.js +53 -0
- package/dist/attrs.d.ts +10 -0
- package/dist/attrs.js +12 -0
- package/dist/bind.d.ts +23 -0
- package/dist/bind.js +55 -0
- package/dist/bootstrap/buffer.d.ts +72 -0
- package/dist/bootstrap/buffer.js +95 -0
- package/dist/bootstrap/replay.d.ts +10 -0
- package/dist/bootstrap/replay.js +11 -0
- package/dist/bootstrap.d.ts +17 -0
- package/dist/bootstrap.js +33 -0
- package/dist/bus.d.ts +3 -0
- package/dist/bus.js +21 -0
- package/dist/config/clamp.d.ts +34 -0
- package/dist/config/clamp.js +79 -0
- package/dist/config/remote.d.ts +80 -0
- package/dist/config/remote.js +209 -0
- package/dist/context-manager.d.ts +8 -0
- package/dist/context-manager.js +29 -0
- package/dist/contracts/binding.d.ts +80 -0
- package/dist/contracts/binding.js +1 -0
- package/dist/contracts/retention.d.ts +28 -0
- package/dist/contracts/retention.js +1 -0
- package/dist/contracts/runtime.d.ts +154 -0
- package/dist/contracts/runtime.js +1 -0
- package/dist/contracts/session.d.ts +63 -0
- package/dist/contracts/session.js +1 -0
- package/dist/contracts/summary.d.ts +28 -0
- package/dist/contracts/summary.js +1 -0
- package/dist/contracts/views.d.ts +71 -0
- package/dist/contracts/views.js +1 -0
- package/dist/core-setup.d.ts +86 -0
- package/dist/core-setup.js +902 -0
- package/dist/core.d.ts +42 -0
- package/dist/core.js +35 -0
- package/dist/errors/breadcrumbs.d.ts +16 -0
- package/dist/errors/breadcrumbs.js +27 -0
- package/dist/errors/collector.d.ts +17 -0
- package/dist/errors/collector.js +186 -0
- package/dist/errors/normalize.d.ts +7 -0
- package/dist/errors/normalize.js +31 -0
- package/dist/errors/record.d.ts +20 -0
- package/dist/errors/record.js +46 -0
- package/dist/frustration/detect.d.ts +38 -0
- package/dist/frustration/detect.js +62 -0
- package/dist/ids.d.ts +2 -0
- package/dist/ids.js +2 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +12 -0
- package/dist/internal.d.ts +28 -0
- package/dist/internal.js +26 -0
- package/dist/loaf.d.ts +15 -0
- package/dist/loaf.js +27 -0
- package/dist/options.d.ts +84 -0
- package/dist/options.js +1 -0
- package/dist/pending-spans.d.ts +29 -0
- package/dist/pending-spans.js +92 -0
- package/dist/query.d.ts +2 -0
- package/dist/query.js +19 -0
- package/dist/resources/collector.d.ts +76 -0
- package/dist/resources/collector.js +270 -0
- package/dist/resources/server-timing.d.ts +18 -0
- package/dist/resources/server-timing.js +21 -0
- package/dist/retention/buffer.d.ts +25 -0
- package/dist/retention/buffer.js +104 -0
- package/dist/retention/exporters.d.ts +17 -0
- package/dist/retention/exporters.js +67 -0
- package/dist/retention/sessions.d.ts +4 -0
- package/dist/retention/sessions.js +30 -0
- package/dist/session/local-store.d.ts +25 -0
- package/dist/session/local-store.js +91 -0
- package/dist/session/manager.d.ts +36 -0
- package/dist/session/manager.js +169 -0
- package/dist/session/sampling.d.ts +4 -0
- package/dist/session/sampling.js +20 -0
- package/dist/session/state.d.ts +4 -0
- package/dist/session/state.js +28 -0
- package/dist/settings.d.ts +8 -0
- package/dist/settings.js +36 -0
- package/dist/setup.d.ts +40 -0
- package/dist/setup.js +49 -0
- package/dist/span-processor.d.ts +38 -0
- package/dist/span-processor.js +125 -0
- package/dist/summary/accumulator.d.ts +25 -0
- package/dist/summary/accumulator.js +126 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/dist/views/collector.d.ts +40 -0
- package/dist/views/collector.js +285 -0
- package/dist/views/history.d.ts +18 -0
- package/dist/views/history.js +42 -0
- package/dist/views/naming.d.ts +6 -0
- package/dist/views/naming.js +12 -0
- package/dist/views/paint.d.ts +12 -0
- package/dist/views/paint.js +15 -0
- package/dist/views/tracker.d.ts +28 -0
- package/dist/views/tracker.js +117 -0
- package/dist/vitals/attribution.d.ts +14 -0
- package/dist/vitals/attribution.js +60 -0
- package/dist/vitals/collector.d.ts +24 -0
- package/dist/vitals/collector.js +232 -0
- package/dist/vitals/lcp.d.ts +32 -0
- package/dist/vitals/lcp.js +49 -0
- package/dist/webext/chrome.d.ts +45 -0
- package/dist/webext/chrome.js +13 -0
- package/dist/webext/config-storage.d.ts +7 -0
- package/dist/webext/config-storage.js +47 -0
- package/dist/webext/scope.d.ts +22 -0
- package/dist/webext/scope.js +50 -0
- package/dist/webext/session-access.d.ts +13 -0
- package/dist/webext/session-access.js +9 -0
- package/dist/webext/session-store.d.ts +5 -0
- package/dist/webext/session-store.js +94 -0
- package/dist/webext/setup.d.ts +71 -0
- package/dist/webext/setup.js +193 -0
- package/dist/webext.d.ts +10 -0
- package/dist/webext.js +8 -0
- package/dist/wire.d.ts +13 -0
- package/dist/wire.js +30 -0
- package/package.json +57 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ContentScriptSetupOptions, ContentScriptTelemetry, WorkerSetupOptions, WorkerTelemetry } from "@libo11y/webext";
|
|
2
|
+
import { type ContentDeps, type WorkerDeps } from "@libo11y/webext/internal";
|
|
3
|
+
import type { WebRumBind } from "../bind.ts";
|
|
4
|
+
import type { Rum, RumOptions } from "../options.ts";
|
|
5
|
+
import { type RumDeps } from "../setup.ts";
|
|
6
|
+
import { type RumChromeLike } from "./chrome.ts";
|
|
7
|
+
/** The name of a content script's view when content.viewName does not give one. */
|
|
8
|
+
export declare const CONTENT_VIEW_NAME = "content-script";
|
|
9
|
+
/** Options for setupRumExtension: the content script setup options of `@libo11y/webext` and RUM's own. */
|
|
10
|
+
export interface RumExtensionOptions extends ContentScriptSetupOptions {
|
|
11
|
+
/** "page" for popups, options pages and side panels; "content" for content scripts. */
|
|
12
|
+
readonly context: "page" | "content";
|
|
13
|
+
/**
|
|
14
|
+
* RUM's options. Remote configuration needs an absolute URL here. In a content script viewName is
|
|
15
|
+
* replaced by the fixed view name, and vitals(), resources() and long animation frames are refused.
|
|
16
|
+
*/
|
|
17
|
+
readonly rum?: RumOptions;
|
|
18
|
+
/** Content scripts only. */
|
|
19
|
+
readonly content?: {
|
|
20
|
+
/** The extension's own UI in the page, such as its shadow host. Actions are recorded only inside it; without it, none. */
|
|
21
|
+
readonly uiRoot?: Node;
|
|
22
|
+
/** The name of the content script's one view. Default "content-script". */
|
|
23
|
+
readonly viewName?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** An extension page's or content script's telemetry with RUM. Its records go to the worker. */
|
|
27
|
+
export interface RumExtensionTelemetry extends ContentScriptTelemetry {
|
|
28
|
+
readonly rum: Rum;
|
|
29
|
+
}
|
|
30
|
+
/** What setupRumExtensionWith builds on. Internal: tests replace any of it. */
|
|
31
|
+
export interface RumExtensionDeps {
|
|
32
|
+
readonly chrome: RumChromeLike | undefined;
|
|
33
|
+
readonly content: ContentDeps;
|
|
34
|
+
/** RUM's dependencies. The platform, binding, session store and cache storage are replaced, and in a content script the retention queue. */
|
|
35
|
+
readonly rum: RumDeps;
|
|
36
|
+
/** Install the telemetry globally. Default true. */
|
|
37
|
+
readonly install?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** The real dependencies of this context. */
|
|
40
|
+
export declare function defaultRumExtensionDeps(): RumExtensionDeps;
|
|
41
|
+
/** The binding of extension contexts: @libo11y/webext's setupContentScriptWith with RUM's wrappers. */
|
|
42
|
+
export declare function contentBinding(content: ContentDeps, install: boolean): WebRumBind;
|
|
43
|
+
/** Builds telemetry with RUM for an extension page or content script and installs it globally. */
|
|
44
|
+
export declare function setupRumExtension(options: RumExtensionOptions): Promise<RumExtensionTelemetry>;
|
|
45
|
+
/** setupRumExtension over deps. Internal: the seam the unit tests use. */
|
|
46
|
+
export declare function setupRumExtensionWith(options: RumExtensionOptions, deps: RumExtensionDeps): Promise<RumExtensionTelemetry>;
|
|
47
|
+
/** Options for setupRumWorker: the worker setup options of `@libo11y/webext` and the gateway's client token. */
|
|
48
|
+
export interface RumWorkerSetupOptions extends WorkerSetupOptions {
|
|
49
|
+
readonly rum?: {
|
|
50
|
+
/** The app's public client token for the RUM gateway, sent with sent_at on every request. */
|
|
51
|
+
readonly clientToken?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** What setupRumWorkerWith builds on. Internal: tests replace any of it. */
|
|
55
|
+
export interface RumWorkerDeps {
|
|
56
|
+
readonly worker: WorkerDeps;
|
|
57
|
+
/** The fetch the transport posts with. Default the transport's own. */
|
|
58
|
+
readonly fetch?: typeof fetch;
|
|
59
|
+
/** Epoch milliseconds, for sent_at. Default Date.now. */
|
|
60
|
+
readonly now?: () => number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Builds the service worker's telemetry for an extension that runs RUM: setupWorker from
|
|
64
|
+
* `@libo11y/webext`, posting to the RUM gateway with the wire parameters sent_at and client_token
|
|
65
|
+
* and app metrics in delta temporality, and allowRumSessionInContentScripts, so content scripts
|
|
66
|
+
* share the extension's session. Call it at the top level of the worker on every wake, as
|
|
67
|
+
* setupWorker.
|
|
68
|
+
*/
|
|
69
|
+
export declare function setupRumWorker(options?: RumWorkerSetupOptions): Promise<WorkerTelemetry>;
|
|
70
|
+
/** setupRumWorker over deps. Internal: the seam the unit tests use. */
|
|
71
|
+
export declare function setupRumWorkerWith(options: RumWorkerSetupOptions, deps: RumWorkerDeps): Promise<WorkerTelemetry>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RUM in Manifest V3 extensions (decision P20). setupRumExtension runs in extension pages (popups,
|
|
3
|
+
* options pages, side panels) and content scripts; setupRumWorker runs in the service worker.
|
|
4
|
+
*
|
|
5
|
+
* Both contexts of setupRumExtension bind through @libo11y/webext's content script setup, so their
|
|
6
|
+
* records go to the worker by runtime messaging and the worker sends them. Their platform is
|
|
7
|
+
* webext, and they share one session through chrome.storage.session (chromeSessionStore), which a
|
|
8
|
+
* content script reaches once the worker called allowRumSessionInContentScripts (setupRumWorker
|
|
9
|
+
* does). Remote configuration is cached in chrome.storage.local, never in a page's localStorage,
|
|
10
|
+
* and needs an absolute URL, because an extension context has no gateway origin of its own.
|
|
11
|
+
*
|
|
12
|
+
* An extension page behaves as setupRum does, with its retention buffer in IndexedDB at the
|
|
13
|
+
* extension's origin. A content script shares the host page's document, so it records only what is
|
|
14
|
+
* the extension's own:
|
|
15
|
+
* - one view, named content.viewName or "content-script", never named from the URL, starting when
|
|
16
|
+
* RUM starts and on screen at once. Its span carries the host page's url.domain and no other URL;
|
|
17
|
+
* - actions only on events whose composed path holds content.uiRoot, and none without it;
|
|
18
|
+
* - errors only from the extension's own scripts (errorSourceUrl starts with getURL(""));
|
|
19
|
+
* - no vitals(), resources() or long animation frames, which would measure the host page, and no
|
|
20
|
+
* documentLoad span: each is refused with O11yError INVALID_OPTION;
|
|
21
|
+
* - a retention buffer in memory, because its IndexedDB is the host page's.
|
|
22
|
+
*/
|
|
23
|
+
import { O11yError } from "@libo11y/core";
|
|
24
|
+
import { browserEnv, createExporterSet, createMemoryQueue } from "@libo11y/web/internal";
|
|
25
|
+
import { defaultContentDeps, defaultWorkerDeps, setupContentScriptWith, setupWorkerWith, } from "@libo11y/webext/internal";
|
|
26
|
+
import { diag } from "@opentelemetry/api";
|
|
27
|
+
import { defaultRumDeps, setupRumWith } from "../setup.js";
|
|
28
|
+
import { gatewayTransportOptions } from "../wire.js";
|
|
29
|
+
import { getRumChrome } from "./chrome.js";
|
|
30
|
+
import { chromeConfigStorage } from "./config-storage.js";
|
|
31
|
+
import { contentScope } from "./scope.js";
|
|
32
|
+
import { allowRumSessionInContentScripts, chromeSessionStore } from "./session-store.js";
|
|
33
|
+
/** The name of a content script's view when content.viewName does not give one. */
|
|
34
|
+
export const CONTENT_VIEW_NAME = "content-script";
|
|
35
|
+
/** Collectors that would measure the host page, refused in a content script. */
|
|
36
|
+
const HOST_PAGE_COLLECTORS = new Set([
|
|
37
|
+
"vitals",
|
|
38
|
+
"resources",
|
|
39
|
+
"long_animation_frames",
|
|
40
|
+
]);
|
|
41
|
+
/** The real dependencies of this context. */
|
|
42
|
+
export function defaultRumExtensionDeps() {
|
|
43
|
+
return { chrome: getRumChrome(), content: defaultContentDeps(), rum: defaultRumDeps() };
|
|
44
|
+
}
|
|
45
|
+
/** The binding of extension contexts: @libo11y/webext's setupContentScriptWith with RUM's wrappers. */
|
|
46
|
+
export function contentBinding(content, install) {
|
|
47
|
+
return (options, w) => setupContentScriptWith(options, {
|
|
48
|
+
...content,
|
|
49
|
+
createConsentController: (o) => w.consentController(content.createConsentController(o)),
|
|
50
|
+
webPlatform: (po) => {
|
|
51
|
+
w.platform(po, browserEnv(options, po.endpoints));
|
|
52
|
+
const platform = content.webPlatform(po);
|
|
53
|
+
return {
|
|
54
|
+
...platform,
|
|
55
|
+
// Logs are routed by session; app metrics export with delta temporality for the gateway.
|
|
56
|
+
buildExporters: (req) => w.exporterSet(createExporterSet(req, po.delivery, po.endpoints, {
|
|
57
|
+
...(po.mode === undefined ? {} : { mode: po.mode }),
|
|
58
|
+
metricTemporality: "delta",
|
|
59
|
+
})),
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
installFetchInstrumentation: (o) => content.installFetchInstrumentation({ ...o, onStart: w.onRequestStart }),
|
|
63
|
+
installXhrInstrumentation: (o) => content.installXhrInstrumentation({ ...o, onStart: w.onRequestStart }),
|
|
64
|
+
}, install);
|
|
65
|
+
}
|
|
66
|
+
function hostOf(url) {
|
|
67
|
+
try {
|
|
68
|
+
return new URL(url).hostname;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function absolute(url) {
|
|
75
|
+
try {
|
|
76
|
+
return /^https?:$/.test(new URL(url).protocol);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Builds telemetry with RUM for an extension page or content script and installs it globally. */
|
|
83
|
+
export function setupRumExtension(options) {
|
|
84
|
+
return setupRumExtensionWith(options, defaultRumExtensionDeps());
|
|
85
|
+
}
|
|
86
|
+
/** setupRumExtension over deps. Internal: the seam the unit tests use. */
|
|
87
|
+
export async function setupRumExtensionWith(options, deps) {
|
|
88
|
+
const { context, rum, content, ...base } = options;
|
|
89
|
+
const chrome = deps.chrome;
|
|
90
|
+
if (chrome === undefined) {
|
|
91
|
+
throw new Error("o11y: setupRumExtension needs the extension API (chrome.runtime)");
|
|
92
|
+
}
|
|
93
|
+
const inContent = context === "content";
|
|
94
|
+
if (inContent) {
|
|
95
|
+
for (const c of rum?.collectors ?? []) {
|
|
96
|
+
if (HOST_PAGE_COLLECTORS.has(c.name)) {
|
|
97
|
+
throw new O11yError("INVALID_OPTION", `rum: a content script cannot run ${c.name}, which would measure the host page`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (base.instrumentations?.documentLoad === true) {
|
|
101
|
+
throw new O11yError("INVALID_OPTION", "rum: a content script records no documentLoad, the host page's load");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const configAt = rum?.remoteConfig?.url;
|
|
105
|
+
if (rum?.remoteConfig !== undefined && (configAt === undefined || !absolute(configAt))) {
|
|
106
|
+
throw new O11yError("INVALID_OPTION", "rum.remoteConfig needs an absolute http(s) url in an extension");
|
|
107
|
+
}
|
|
108
|
+
let cache;
|
|
109
|
+
let shutDown = false;
|
|
110
|
+
const extensionBase = chrome.runtime.getURL?.("") ?? `chrome-extension://${chrome.runtime.id}/`;
|
|
111
|
+
const rumDeps = {
|
|
112
|
+
...deps.rum,
|
|
113
|
+
platform: "webext",
|
|
114
|
+
bind: contentBinding(deps.content, deps.install !== false),
|
|
115
|
+
sessionStore: () => chromeSessionStore(chrome),
|
|
116
|
+
storage: async () => {
|
|
117
|
+
const opened = cache ?? (await chromeConfigStorage(chrome));
|
|
118
|
+
// A cache that finished loading after shutdown stops listening at once.
|
|
119
|
+
if (shutDown)
|
|
120
|
+
opened?.close();
|
|
121
|
+
else
|
|
122
|
+
cache = opened;
|
|
123
|
+
return opened;
|
|
124
|
+
},
|
|
125
|
+
...(inContent
|
|
126
|
+
? {
|
|
127
|
+
openRetentionQueue: async (o) => createMemoryQueue(o),
|
|
128
|
+
prerendered: () => false,
|
|
129
|
+
scope: contentScope({
|
|
130
|
+
base: extensionBase,
|
|
131
|
+
host: hostOf(deps.rum.location()),
|
|
132
|
+
...(content?.uiRoot === undefined ? {} : { uiRoot: content.uiRoot }),
|
|
133
|
+
}),
|
|
134
|
+
}
|
|
135
|
+
: {}),
|
|
136
|
+
};
|
|
137
|
+
const viewName = content?.viewName ?? CONTENT_VIEW_NAME;
|
|
138
|
+
const rumOptions = inContent ? { ...rum, viewName: () => viewName } : rum;
|
|
139
|
+
const t = await setupRumWith({
|
|
140
|
+
...base,
|
|
141
|
+
...(inContent ? { instrumentations: { ...base.instrumentations, documentLoad: false } } : {}),
|
|
142
|
+
...(rumOptions === undefined ? {} : { rum: rumOptions }),
|
|
143
|
+
}, rumDeps);
|
|
144
|
+
const handle = t;
|
|
145
|
+
const rumShutdown = handle.shutdown.bind(handle);
|
|
146
|
+
handle.shutdown = async (opts) => {
|
|
147
|
+
shutDown = true;
|
|
148
|
+
const report = await rumShutdown(opts);
|
|
149
|
+
cache?.close();
|
|
150
|
+
return report;
|
|
151
|
+
};
|
|
152
|
+
return handle;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Builds the service worker's telemetry for an extension that runs RUM: setupWorker from
|
|
156
|
+
* `@libo11y/webext`, posting to the RUM gateway with the wire parameters sent_at and client_token
|
|
157
|
+
* and app metrics in delta temporality, and allowRumSessionInContentScripts, so content scripts
|
|
158
|
+
* share the extension's session. Call it at the top level of the worker on every wake, as
|
|
159
|
+
* setupWorker.
|
|
160
|
+
*/
|
|
161
|
+
export function setupRumWorker(options = {}) {
|
|
162
|
+
return setupRumWorkerWith(options, { worker: defaultWorkerDeps() });
|
|
163
|
+
}
|
|
164
|
+
/** setupRumWorker over deps. Internal: the seam the unit tests use. */
|
|
165
|
+
export async function setupRumWorkerWith(options, deps) {
|
|
166
|
+
const { rum, ...workerOptions } = options;
|
|
167
|
+
const token = rum?.clientToken;
|
|
168
|
+
if (token !== undefined && (typeof token !== "string" || token === "")) {
|
|
169
|
+
throw new O11yError("INVALID_OPTION", "rum.clientToken must be a non-empty string");
|
|
170
|
+
}
|
|
171
|
+
const w = deps.worker;
|
|
172
|
+
// Started before setupWorker awaits anything, so a content script that wakes the worker finds
|
|
173
|
+
// the session open as soon as it can.
|
|
174
|
+
const access = w.chrome === undefined
|
|
175
|
+
? Promise.resolve()
|
|
176
|
+
: allowRumSessionInContentScripts(w.chrome).catch((err) => diag.warn("o11y: rum: could not open chrome.storage.session to content scripts", err));
|
|
177
|
+
const t = await setupWorkerWith(workerOptions, {
|
|
178
|
+
...w,
|
|
179
|
+
createHttpTransport: (o) => w.createHttpTransport(gatewayTransportOptions(deps.fetch === undefined ? o : { ...o, fetch: deps.fetch }, token, deps.now ?? Date.now)),
|
|
180
|
+
webPlatform: (po) => {
|
|
181
|
+
const platform = w.webPlatform(po);
|
|
182
|
+
return {
|
|
183
|
+
...platform,
|
|
184
|
+
buildExporters: (req) => createExporterSet(req, po.delivery, po.endpoints, {
|
|
185
|
+
...(po.mode === undefined ? {} : { mode: po.mode }),
|
|
186
|
+
metricTemporality: "delta",
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
await access;
|
|
192
|
+
return t;
|
|
193
|
+
}
|
package/dist/webext.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @libo11y/rum/webext: RUM in Manifest V3 extensions. setupRumExtension for extension pages and
|
|
3
|
+
* content scripts, setupRumWorker for the service worker that sends their records, and
|
|
4
|
+
* allowRumSessionInContentScripts for a worker set up with @libo11y/webext's setupWorker directly.
|
|
5
|
+
* The collectors come from @libo11y/rum; the types its options and handle name are re-exported here.
|
|
6
|
+
*/
|
|
7
|
+
export type { AddErrorOptions, BootstrapEntry, CollectorName, EventBody, RemoteConfig, RemoteConfigClient, RemoteConfigConnection, RemoteConfigDocument, RemoteConfigOpenOptions, RemoteConfigTimers, RequestStartHook, Rum, RumBus, RumCollector, RumOptions, RumRuntime, RumScope, RumSettings, RumSignal, SessionDecision, SessionEvent, SessionManager, SessionState, SummaryAccumulator, SummaryCountKey, SummaryView, ViewEvent, ViewStartOptions, ViewState, ViewTracker, VitalName, } from "./index.ts";
|
|
8
|
+
export type { ChromeSessionStorageLike, RumChromeLike, StorageAreaLike, StorageChangeListener, StorageChanges, } from "./webext/chrome.ts";
|
|
9
|
+
export { allowRumSessionInContentScripts } from "./webext/session-access.ts";
|
|
10
|
+
export { CONTENT_VIEW_NAME, type RumExtensionOptions, type RumExtensionTelemetry, type RumWorkerSetupOptions, setupRumExtension, setupRumWorker, } from "./webext/setup.ts";
|
package/dist/webext.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @libo11y/rum/webext: RUM in Manifest V3 extensions. setupRumExtension for extension pages and
|
|
3
|
+
* content scripts, setupRumWorker for the service worker that sends their records, and
|
|
4
|
+
* allowRumSessionInContentScripts for a worker set up with @libo11y/webext's setupWorker directly.
|
|
5
|
+
* The collectors come from @libo11y/rum; the types its options and handle name are re-exported here.
|
|
6
|
+
*/
|
|
7
|
+
export { allowRumSessionInContentScripts } from "./webext/session-access.js";
|
|
8
|
+
export { CONTENT_VIEW_NAME, setupRumExtension, setupRumWorker, } from "./webext/setup.js";
|
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract with the RUM gateway: every OTLP request carries the query parameters sent_at
|
|
3
|
+
* (the client's Unix time in milliseconds at send time) and client_token (the app's public token),
|
|
4
|
+
* because sendBeacon cannot set headers. The gateway uses sent_at to correct client clock skew.
|
|
5
|
+
*/
|
|
6
|
+
import { type HttpTransportOptions } from "@libo11y/web/portable";
|
|
7
|
+
/** url with sent_at, and client_token when there is one, appended to its query. */
|
|
8
|
+
export declare function withWireParams(url: string, clientToken: string | undefined, sentAt: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* The transport options with fetch and sendBeacon wrapped, so each attempt, retries included, posts
|
|
11
|
+
* to the signal URL with the wire parameters of the moment it is sent.
|
|
12
|
+
*/
|
|
13
|
+
export declare function gatewayTransportOptions(opts: HttpTransportOptions, clientToken: string | undefined, now: () => number): HttpTransportOptions;
|
package/dist/wire.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract with the RUM gateway: every OTLP request carries the query parameters sent_at
|
|
3
|
+
* (the client's Unix time in milliseconds at send time) and client_token (the app's public token),
|
|
4
|
+
* because sendBeacon cannot set headers. The gateway uses sent_at to correct client clock skew.
|
|
5
|
+
*/
|
|
6
|
+
import { pristineFetch, pristineSendBeacon } from "@libo11y/web/portable";
|
|
7
|
+
/** url with sent_at, and client_token when there is one, appended to its query. */
|
|
8
|
+
export function withWireParams(url, clientToken, sentAt) {
|
|
9
|
+
const params = new URLSearchParams({ sent_at: String(sentAt) });
|
|
10
|
+
if (clientToken !== undefined)
|
|
11
|
+
params.set("client_token", clientToken);
|
|
12
|
+
return `${url}${url.includes("?") ? "&" : "?"}${params.toString()}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The transport options with fetch and sendBeacon wrapped, so each attempt, retries included, posts
|
|
16
|
+
* to the signal URL with the wire parameters of the moment it is sent.
|
|
17
|
+
*/
|
|
18
|
+
export function gatewayTransportOptions(opts, clientToken, now) {
|
|
19
|
+
const baseFetch = opts.fetch ?? pristineFetch;
|
|
20
|
+
const baseBeacon = "sendBeacon" in opts ? opts.sendBeacon : pristineSendBeacon;
|
|
21
|
+
const wrap = (url) => withWireParams(url, clientToken, now());
|
|
22
|
+
const fetchWithParams = baseFetch === undefined
|
|
23
|
+
? undefined
|
|
24
|
+
: ((input, init) => baseFetch(input instanceof Request ? input : wrap(String(input)), init));
|
|
25
|
+
return {
|
|
26
|
+
...opts,
|
|
27
|
+
...(fetchWithParams === undefined ? {} : { fetch: fetchWithParams }),
|
|
28
|
+
sendBeacon: baseBeacon === undefined ? undefined : (url, data) => baseBeacon(wrap(url), data),
|
|
29
|
+
};
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libo11y/rum",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
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
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./bootstrap": {
|
|
14
|
+
"types": "./dist/bootstrap.d.ts",
|
|
15
|
+
"default": "./dist/bootstrap.js"
|
|
16
|
+
},
|
|
17
|
+
"./core": {
|
|
18
|
+
"types": "./dist/core.d.ts",
|
|
19
|
+
"default": "./dist/core.js"
|
|
20
|
+
},
|
|
21
|
+
"./webext": {
|
|
22
|
+
"types": "./dist/webext.d.ts",
|
|
23
|
+
"default": "./dist/webext.js"
|
|
24
|
+
},
|
|
25
|
+
"./internal": {
|
|
26
|
+
"types": "./dist/internal.d.ts",
|
|
27
|
+
"default": "./dist/internal.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/jamesainslie/libo11y.git",
|
|
33
|
+
"directory": "ts/packages/rum"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@libo11y/core": "0.4.0",
|
|
37
|
+
"@libo11y/spec": "0.4.0",
|
|
38
|
+
"@libo11y/web": "0.4.0",
|
|
39
|
+
"@libo11y/webext": "0.4.0",
|
|
40
|
+
"@opentelemetry/api": "1.10.0",
|
|
41
|
+
"@opentelemetry/core": "3.1.1",
|
|
42
|
+
"@opentelemetry/sdk-logs": "3.1.1",
|
|
43
|
+
"@opentelemetry/sdk-trace": "3.1.1",
|
|
44
|
+
"web-vitals": "5.3.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@libo11y/test": "0.4.0",
|
|
48
|
+
"fake-indexeddb": "6.2.7"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"README.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
],
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
58
|
+
}
|
|
59
|
+
}
|