@libo11y/rum-react-native 0.0.0-stage → 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/dist/errors.js ADDED
@@ -0,0 +1,247 @@
1
+ /**
2
+ * errors(): JavaScript errors on React Native.
3
+ *
4
+ * Sources. An error React Native's global handler receives (ErrorUtils.setGlobalHandler) is
5
+ * uncaught: the collector records it and hands it to the handler that was installed before it,
6
+ * always, so the red box, LogBox and the crash still happen. A fatal error in a release build is
7
+ * about to end the process, so the current screen's summary is emitted and the telemetry flushed
8
+ * (React Native telemetry saves every batch on device storage before it sends it) before the
9
+ * previous handler runs, for at most fatalFlushMillis. A fatal error while one is waiting is
10
+ * recorded and handed on after it, in order. When the previous handler throws there, the throw
11
+ * is raised again from a task, so it still ends the app; the crash path runs once, and fatal
12
+ * errors after it, the raised throw included (not recorded again), go straight to the previous
13
+ * handler. In development the previous handler runs at once.
14
+ *
15
+ * Hermes reports unhandled promise rejections only to the tracker HermesInternal's
16
+ * enablePromiseRejectionTracker sets, which React Native turns on in development alone, and a
17
+ * second call replaces the first. The collector sets one with allRejections: each unhandled
18
+ * rejection is unhandled_rejection, and in development the tracker also does what React Native's
19
+ * does, through the previous global handler (the red box path) and console.warn. Another engine
20
+ * reports no rejections.
21
+ *
22
+ * A request that ends without a status is network, type NetworkError, message "<METHOD> <host>
23
+ * failed", unless the app aborted it, as in the browser's errors().
24
+ *
25
+ * React renders errors through an error boundary, never this handler: `@libo11y/rum-react`'s
26
+ * RumErrorBoundary, or an app's own boundary calling rum.addError with source boundary.
27
+ *
28
+ * Stacks. In a release build Hermes names the bundle by its path on the device, sometimes after
29
+ * "address at ". Each frame of the app's bundle is rewritten to app:///main.jsbundle (iOS) or
30
+ * app:///index.android.bundle (Android), so the gateway finds the source map uploaded under that
31
+ * name for the app's service.version and o11y.rum.app.update_id, and no device path leaves the
32
+ * phone. Engine frames (native, InternalBytecode.js) are kept. Development stacks point at Metro
33
+ * and are kept as they are.
34
+ *
35
+ * Native crashes and hangs (iOS). With the libo11y native module (env.native), MetricKit's crash and
36
+ * hang reports become o11y.rum.error records with source crash or hang, attributed to the session
37
+ * and screen they happened in (native-reports.ts). Without the module, as on Android or on an app
38
+ * binary built before it, the collector records JavaScript errors only.
39
+ *
40
+ * Every error goes through recordError, so it counts in the screen's summary, retains an unsampled
41
+ * session, and carries the breadcrumbs. An error raised while one is being recorded is not recorded
42
+ * again. Stop restores the previous global handler while RUM's is still the installed one; a
43
+ * handler installed over RUM's keeps calling it, and it then only passes errors on.
44
+ */
45
+ import { normalizeError, recordError } from "@libo11y/rum/core";
46
+ import { diag } from "@opentelemetry/api";
47
+ import { hermesStack } from "./hermes-stack.js";
48
+ import { startNativeReports } from "./native-reports.js";
49
+ /** How long a fatal error in a release build waits for the flush before it reaches the previous handler. */
50
+ export const FATAL_FLUSH_MILLIS = 2000;
51
+ /** The error.type values of a request the app aborted, which is not a failure. */
52
+ const ABORTED = new Set(["AbortError", "abort"]);
53
+ /** An Error-like value recordError reads as is, so the type and message are exactly these. */
54
+ class Described extends Error {
55
+ constructor(name, message, stack) {
56
+ super(message);
57
+ this.name = name;
58
+ this.stack = stack ?? "";
59
+ }
60
+ }
61
+ function host(raw) {
62
+ try {
63
+ return new URL(raw).hostname;
64
+ }
65
+ catch {
66
+ return "";
67
+ }
68
+ }
69
+ /** React Native's development report of an unhandled rejection (promiseRejectionTrackingOptions). */
70
+ function devRejection(id, rejection) {
71
+ let message;
72
+ if (rejection === undefined)
73
+ message = "";
74
+ else if (Object.prototype.toString.call(rejection) === "[object Error]") {
75
+ message = Error.prototype.toString.call(rejection);
76
+ }
77
+ else if (typeof rejection === "string")
78
+ message = rejection;
79
+ else {
80
+ try {
81
+ message = JSON.stringify(rejection) ?? String(rejection);
82
+ }
83
+ catch {
84
+ message = String(rejection);
85
+ }
86
+ }
87
+ return new Error(`Uncaught (in promise, id: ${id})${message === "" ? "" : `: "${message}"`}`, {
88
+ cause: rejection,
89
+ });
90
+ }
91
+ /** The errors collector over env. */
92
+ export function errorsWith(env, o = {}) {
93
+ const flushMillis = o.fatalFlushMillis ?? FATAL_FLUSH_MILLIS;
94
+ return {
95
+ name: "errors",
96
+ // RUM erases its storage on a denied start and on every revoke, also when this collector is not
97
+ // running (remote configuration switched it off): the native module then stops keeping reports
98
+ // and deletes what it holds, and the erase waits until it has.
99
+ ...(env.native === undefined
100
+ ? {}
101
+ : {
102
+ clear: async () => {
103
+ try {
104
+ await env.native?.setRecording(false);
105
+ }
106
+ catch (err) {
107
+ // The module stops recording in this process anyway; the next denied start or
108
+ // revoke deletes again.
109
+ diag.warn("o11y: rum: the native module could not delete what it holds", err);
110
+ throw err;
111
+ }
112
+ },
113
+ }),
114
+ start(rt) {
115
+ let stopped = false;
116
+ let recording = false;
117
+ const describe = (error) => {
118
+ if (env.dev)
119
+ return error;
120
+ const n = normalizeError(error);
121
+ return n.stack === undefined ? error : new Described(n.type, n.message, hermesStack(n.stack, env.os));
122
+ };
123
+ const record = (source, error) => {
124
+ if (stopped || recording)
125
+ return;
126
+ recording = true;
127
+ try {
128
+ recordError(rt, source, describe(error));
129
+ }
130
+ catch (err) {
131
+ diag.warn("o11y: rum: recording an error failed", err);
132
+ }
133
+ finally {
134
+ recording = false;
135
+ }
136
+ };
137
+ const utils = env.errorUtils;
138
+ const found = utils?.getGlobalHandler();
139
+ const previous = typeof found === "function" ? found : undefined;
140
+ /** Fatal errors waiting for the flush, in order; undefined while none waits. */
141
+ let waiting;
142
+ /** The crash path ran: later fatal errors go straight to the previous handler. */
143
+ let crashed = false;
144
+ /** What the previous handler threw on the crash path, raised again from a task. */
145
+ const raised = new WeakSet();
146
+ const crash = () => {
147
+ const errors = waiting ?? [];
148
+ waiting = undefined;
149
+ crashed = true;
150
+ for (const e of errors) {
151
+ try {
152
+ previous?.(e, true);
153
+ }
154
+ catch (thrown) {
155
+ // A throw here would reject the flush's promise, which the rejection tracker records
156
+ // and the app survives. Raised from a task, it takes React Native's crash path.
157
+ if (typeof thrown === "object" && thrown !== null)
158
+ raised.add(thrown);
159
+ env.setTimeout(() => {
160
+ throw thrown;
161
+ }, 0);
162
+ }
163
+ }
164
+ };
165
+ const handler = (error, isFatal) => {
166
+ const again = typeof error === "object" && error !== null && raised.has(error);
167
+ if (!again)
168
+ record("uncaught", error);
169
+ if (isFatal !== true || env.dev || stopped || crashed) {
170
+ previous?.(error, isFatal);
171
+ return;
172
+ }
173
+ if (waiting !== undefined) {
174
+ waiting.push(error);
175
+ return;
176
+ }
177
+ waiting = [error];
178
+ let done = false;
179
+ let timer;
180
+ const go = () => {
181
+ if (done)
182
+ return;
183
+ done = true;
184
+ env.clearTimeout(timer);
185
+ crash();
186
+ };
187
+ timer = env.setTimeout(go, flushMillis);
188
+ try {
189
+ rt.summary.flush();
190
+ }
191
+ catch (err) {
192
+ diag.warn("o11y: rum: emitting the summary before a crash failed", err);
193
+ }
194
+ // The crash waits for the flush and for the fatal context, within the deadline.
195
+ Promise.all([nativeReports?.fatal(), rt.telemetry.forceFlush()]).then(go, go);
196
+ };
197
+ if (utils !== undefined && previous !== undefined)
198
+ utils.setGlobalHandler(handler);
199
+ const tracker = env.hermes?.enablePromiseRejectionTracker;
200
+ if (typeof tracker === "function") {
201
+ tracker.call(env.hermes, {
202
+ allRejections: true,
203
+ onUnhandled: (id, rejection) => {
204
+ record("unhandled_rejection", rejection);
205
+ if (env.dev)
206
+ previous?.(devRejection(id, rejection), false);
207
+ },
208
+ onHandled: (id) => {
209
+ if (!env.dev)
210
+ return;
211
+ env.warn(`Promise rejection handled (id: ${id})\nThis means you can ignore any previous messages of the form "Uncaught (in promise, id: ${id})"`);
212
+ },
213
+ });
214
+ }
215
+ // Requests in flight, so a failed one can be described by its method and host.
216
+ const requests = new Map();
217
+ const offBus = rt.bus.subscribe((s) => {
218
+ if (s.type === "request-start")
219
+ requests.set(s.spanId, { method: s.method, url: s.url });
220
+ else if (s.type === "request-end") {
221
+ const r = requests.get(s.spanId);
222
+ requests.delete(s.spanId);
223
+ if (r !== undefined && s.status === undefined && !ABORTED.has(s.errorType ?? "")) {
224
+ record("network", new Described("NetworkError", `${r.method} ${host(r.url)} failed`, undefined));
225
+ }
226
+ }
227
+ });
228
+ const nativeReports = env.native === undefined
229
+ ? undefined
230
+ : startNativeReports(rt, {
231
+ native: env.native,
232
+ setTimeout: env.setTimeout,
233
+ clearTimeout: env.clearTimeout,
234
+ ...(o.nativePollMillis === undefined ? {} : { pollMillis: o.nativePollMillis }),
235
+ });
236
+ return () => {
237
+ stopped = true;
238
+ nativeReports?.stop();
239
+ if (utils !== undefined && previous !== undefined && utils.getGlobalHandler() === handler) {
240
+ utils.setGlobalHandler(previous);
241
+ }
242
+ offBus();
243
+ requests.clear();
244
+ };
245
+ },
246
+ };
247
+ }
package/dist/expo.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { ReactNativeRumTelemetry, RumReactNativeSetupOptions } from "./options.ts";
2
+ export type { ReactNativeRumTelemetry, RumReactNativeOptions, RumReactNativeSetupOptions, } from "./options.ts";
3
+ /**
4
+ * setupRumReactNative with expoOptions() under the app's own options: an option the app sets
5
+ * wins, and resourceAttributes merge key by key with the app's winning, as setupExpo does.
6
+ */
7
+ export declare function setupRumExpo(options?: RumReactNativeSetupOptions): Promise<ReactNativeRumTelemetry>;
package/dist/expo.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * libo11y RUM for Expo apps: setupRumReactNative with the options `@libo11y/react-native/expo`
3
+ * fills in, the retry queue, the retention buffer, the session and the remote configuration
4
+ * cache in the app's documents (expo-file-system), the app version (expo-application), the ID of
5
+ * the over-the-air update the app runs (expo-updates) and the device class (expo-device).
6
+ */
7
+ import { expoOptions } from "@libo11y/react-native/expo";
8
+ import { withExpoOptions } from "@libo11y/react-native/internal";
9
+ import { setupRumReactNative } from "./index.js";
10
+ /**
11
+ * setupRumReactNative with expoOptions() under the app's own options: an option the app sets
12
+ * wins, and resourceAttributes merge key by key with the app's winning, as setupExpo does.
13
+ */
14
+ export function setupRumExpo(options = {}) {
15
+ return setupRumReactNative(withExpoOptions(expoOptions(), options));
16
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Hermes stacks in release builds name the app's bundle by its path on the device, sometimes after
3
+ * "address at ". hermesStack rewrites each frame of the app's bundle to app:///main.jsbundle (iOS)
4
+ * or app:///index.android.bundle (Android), the names its source map is uploaded under, and keeps
5
+ * engine frames. A frame "address at" a bundle carries a bytecode offset, which Hermes prints
6
+ * 0-based (React Native's parseHermesStack reads it as virtualOffset0Based); it becomes the
7
+ * 1-based column every other frame carries and the gateway reads. It imports nothing, so the
8
+ * gateway journey in `@libo11y/sourcemaps` can use it.
9
+ */
10
+ /** The name the app's bundle has in stack frames on platform os, and the name its source map is uploaded under. */
11
+ export declare function bundleName(os: string): string;
12
+ /** Rewrites each frame of the app's bundle in a Hermes stack to app:///bundleName(os), keeping engine frames. */
13
+ export declare function hermesStack(stack: string, os: string): string;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Hermes stacks in release builds name the app's bundle by its path on the device, sometimes after
3
+ * "address at ". hermesStack rewrites each frame of the app's bundle to app:///main.jsbundle (iOS)
4
+ * or app:///index.android.bundle (Android), the names its source map is uploaded under, and keeps
5
+ * engine frames. A frame "address at" a bundle carries a bytecode offset, which Hermes prints
6
+ * 0-based (React Native's parseHermesStack reads it as virtualOffset0Based); it becomes the
7
+ * 1-based column every other frame carries and the gateway reads. It imports nothing, so the
8
+ * gateway journey in `@libo11y/sourcemaps` can use it.
9
+ */
10
+ /** Frame locations that belong to the engine, not the app's bundle. */
11
+ const ENGINE = new Set(["native", "[native code]", "InternalBytecode.js"]);
12
+ const isDigits = (t) => t !== "" && [...t].every((c) => c >= "0" && c <= "9");
13
+ /**
14
+ * Splits "location:line:col" or "location:line" into the location and ":line:col", or undefined.
15
+ * It scans from the end without a regular expression, so a long line costs linear time.
16
+ */
17
+ function splitPosition(s) {
18
+ const last = s.lastIndexOf(":");
19
+ if (last <= 0 || !isDigits(s.slice(last + 1)))
20
+ return undefined;
21
+ const before = s.lastIndexOf(":", last - 1);
22
+ const cut = before > 0 && isDigits(s.slice(before + 1, last)) ? before : last;
23
+ return [s.slice(0, cut), s.slice(cut)];
24
+ }
25
+ /** ":line:offset" with the 0-based offset made a 1-based column. */
26
+ function oneBased(position) {
27
+ const last = position.lastIndexOf(":");
28
+ if (last <= 0)
29
+ return position;
30
+ return `${position.slice(0, last)}:${Number(position.slice(last + 1)) + 1}`;
31
+ }
32
+ /**
33
+ * The parts of a frame line: what comes before the location, the location, and what comes after
34
+ * it, with a bytecode offset made a 1-based column.
35
+ */
36
+ function frameParts(line) {
37
+ const body = line.trimStart();
38
+ if (!body.startsWith("at "))
39
+ return undefined;
40
+ const indent = line.slice(0, line.length - body.length);
41
+ let head;
42
+ let inner;
43
+ let tail;
44
+ if (body.endsWith(")")) {
45
+ const open = body.lastIndexOf("(");
46
+ if (open < 0)
47
+ return undefined;
48
+ head = body.slice(0, open + 1);
49
+ inner = body.slice(open + 1, -1);
50
+ tail = ")";
51
+ }
52
+ else {
53
+ head = "at ";
54
+ inner = body.slice(3);
55
+ tail = "";
56
+ if (inner.includes(" "))
57
+ return undefined;
58
+ }
59
+ const bytecode = inner.startsWith("address at ");
60
+ if (bytecode)
61
+ inner = inner.slice("address at ".length);
62
+ const split = splitPosition(inner);
63
+ if (split === undefined)
64
+ return undefined;
65
+ const position = bytecode ? oneBased(split[1]) : split[1];
66
+ return [`${indent}${head}`, split[0], `${position}${tail}`];
67
+ }
68
+ /** The name the app's bundle has in stack frames on platform os, and the name its source map is uploaded under. */
69
+ export function bundleName(os) {
70
+ return os === "android" ? "index.android.bundle" : "main.jsbundle";
71
+ }
72
+ /** Rewrites each frame of the app's bundle in a Hermes stack to app:///bundleName(os), keeping engine frames. */
73
+ export function hermesStack(stack, os) {
74
+ const app = `app:///${bundleName(os)}`;
75
+ return stack
76
+ .split("\n")
77
+ .map((line) => {
78
+ const parts = frameParts(line);
79
+ if (parts === undefined || ENGINE.has(parts[1]))
80
+ return line;
81
+ return `${parts[0]}${app}${parts[2]}`;
82
+ })
83
+ .join("\n");
84
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * libo11y RUM for React Native apps on Hermes: setupRumReactNative over `@libo11y/react-native`,
3
+ * the collectors it runs (screens, errors, taps), and RumTouchBoundary, which passes touches to
4
+ * taps(). telemetry.rum is the browser's Rum handle, so `@libo11y/rum-react` and
5
+ * `@libo11y/rum-connect` work with it as they are.
6
+ */
7
+ export type { KeyValueStorage, ReactNativeSetupOptions, ReactNativeTelemetry } from "@libo11y/react-native";
8
+ export type { AddErrorOptions, CollectorName, RemoteConfig, RemoteConfigOptions, RequestStartHook, Rum, RumCollector, RumOptions, RumRuntime, } from "@libo11y/rum";
9
+ import type { RemoteConfig, RemoteConfigOptions, RumCollector } from "@libo11y/rum";
10
+ import type { ReactNativeRumTelemetry, RumReactNativeSetupOptions } from "./options.ts";
11
+ import { type TapsOptions } from "./taps.ts";
12
+ export type { ReactNativeRumTelemetry, RumReactNativeOptions, RumReactNativeSetupOptions, } from "./options.ts";
13
+ export { RumName, type RumNameProps } from "./tap-target.ts";
14
+ export type { TapsOptions } from "./taps.ts";
15
+ export { RumTouchBoundary, type RumTouchBoundaryProps } from "./touch-boundary.ts";
16
+ export { VERSION } from "./version.ts";
17
+ /**
18
+ * Builds React Native telemetry with RUM and installs it globally, as setupReactNative does. Every
19
+ * view is a screen, and the first is named rum.initialViewName (default "app") until a router
20
+ * adapter or rum.setViewName names it. Nothing is recorded, stored or sent until consent is
21
+ * granted, unless consent.initial is "granted". options.storage holds the retry queue, the
22
+ * retention buffer, the session (a relaunch within the idle window continues it) and the remote
23
+ * configuration cache. The app_load span runs from the process start to the first screen's
24
+ * rum.viewRendered(), once per process, also when consent comes later. Calling it twice without a
25
+ * shutdown rejects with ALREADY_SETUP.
26
+ */
27
+ export declare function setupRumReactNative(options?: RumReactNativeSetupOptions): Promise<ReactNativeRumTelemetry>;
28
+ /**
29
+ * The screens collector: a view span per screen, ending at the first frame after
30
+ * rum.viewRendered() or 10 seconds after it started. The first screen's span is a child of
31
+ * app_load; a later screen's is a root linked to the action that caused it. Pass it in
32
+ * rum.collectors.
33
+ */
34
+ export declare function screens(): RumCollector;
35
+ /**
36
+ * Remote configuration from the RUM gateway, as `@libo11y/rum`'s remoteConfig, for rum.remoteConfig.
37
+ * It is fetched only once consent is granted, and cached in the app's storage.
38
+ */
39
+ export declare function remoteConfig(opts?: RemoteConfigOptions): RemoteConfig;
40
+ /**
41
+ * The errors collector: errors React Native's global handler receives (uncaught, handed on to the
42
+ * previous handler always; a fatal one in a release build after a flush of at most 2 seconds),
43
+ * unhandled promise rejections on Hermes, and requests that failed without a response. Release
44
+ * stacks name the app's bundle app:///main.jsbundle (iOS) or app:///index.android.bundle
45
+ * (Android), so the gateway finds the source maps uploaded under those names. Render errors reach
46
+ * RUM through an error boundary: `@libo11y/rum-react`'s RumErrorBoundary, or rum.addError with
47
+ * source boundary. On iOS, when the app binary has the libo11y native module of
48
+ * `@libo11y/react-native`, it also records the native crashes and hangs MetricKit reports on a later
49
+ * launch (sources crash and hang), attributed to the session and screen they happened in. Pass it in
50
+ * rum.collectors.
51
+ */
52
+ export declare function errors(): RumCollector;
53
+ /**
54
+ * The taps collector: taps and long presses as action spans, named from the closest o11yName prop
55
+ * or RumName, else the target's accessibilityLabel, never from text; and rage and error taps as
56
+ * frustration signals. It records the touches RumTouchBoundary passes it, so render the boundary
57
+ * around the app. Pass it in rum.collectors.
58
+ */
59
+ export declare function taps(opts?: TapsOptions): RumCollector;
package/dist/index.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * libo11y RUM for React Native apps on Hermes: setupRumReactNative over `@libo11y/react-native`,
3
+ * the collectors it runs (screens, errors, taps), and RumTouchBoundary, which passes touches to
4
+ * taps(). telemetry.rum is the browser's Rum handle, so `@libo11y/rum-react` and
5
+ * `@libo11y/rum-connect` work with it as they are.
6
+ */
7
+ import { remoteConfig as portableRemoteConfig } from "@libo11y/rum/core";
8
+ import { defaultErrorsEnv, defaultRumEnv, defaultRumReactNativeDeps, runtimeTimers } from "./env.js";
9
+ import { errorsWith } from "./errors.js";
10
+ import { screensWith } from "./screens.js";
11
+ import { setupRumReactNativeWith } from "./setup.js";
12
+ import { tapsWith } from "./taps.js";
13
+ export { RumName } from "./tap-target.js";
14
+ export { RumTouchBoundary } from "./touch-boundary.js";
15
+ export { VERSION } from "./version.js";
16
+ /**
17
+ * Builds React Native telemetry with RUM and installs it globally, as setupReactNative does. Every
18
+ * view is a screen, and the first is named rum.initialViewName (default "app") until a router
19
+ * adapter or rum.setViewName names it. Nothing is recorded, stored or sent until consent is
20
+ * granted, unless consent.initial is "granted". options.storage holds the retry queue, the
21
+ * retention buffer, the session (a relaunch within the idle window continues it) and the remote
22
+ * configuration cache. The app_load span runs from the process start to the first screen's
23
+ * rum.viewRendered(), once per process, also when consent comes later. Calling it twice without a
24
+ * shutdown rejects with ALREADY_SETUP.
25
+ */
26
+ export function setupRumReactNative(options = {}) {
27
+ return setupRumReactNativeWith(options, defaultRumReactNativeDeps(), true);
28
+ }
29
+ /**
30
+ * The screens collector: a view span per screen, ending at the first frame after
31
+ * rum.viewRendered() or 10 seconds after it started. The first screen's span is a child of
32
+ * app_load; a later screen's is a root linked to the action that caused it. Pass it in
33
+ * rum.collectors.
34
+ */
35
+ export function screens() {
36
+ return screensWith(defaultRumEnv());
37
+ }
38
+ /**
39
+ * Remote configuration from the RUM gateway, as `@libo11y/rum`'s remoteConfig, for rum.remoteConfig.
40
+ * It is fetched only once consent is granted, and cached in the app's storage.
41
+ */
42
+ export function remoteConfig(opts = {}) {
43
+ return portableRemoteConfig(opts);
44
+ }
45
+ /**
46
+ * The errors collector: errors React Native's global handler receives (uncaught, handed on to the
47
+ * previous handler always; a fatal one in a release build after a flush of at most 2 seconds),
48
+ * unhandled promise rejections on Hermes, and requests that failed without a response. Release
49
+ * stacks name the app's bundle app:///main.jsbundle (iOS) or app:///index.android.bundle
50
+ * (Android), so the gateway finds the source maps uploaded under those names. Render errors reach
51
+ * RUM through an error boundary: `@libo11y/rum-react`'s RumErrorBoundary, or rum.addError with
52
+ * source boundary. On iOS, when the app binary has the libo11y native module of
53
+ * `@libo11y/react-native`, it also records the native crashes and hangs MetricKit reports on a later
54
+ * launch (sources crash and hang), attributed to the session and screen they happened in. Pass it in
55
+ * rum.collectors.
56
+ */
57
+ export function errors() {
58
+ return errorsWith(defaultErrorsEnv());
59
+ }
60
+ /**
61
+ * The taps collector: taps and long presses as action spans, named from the closest o11yName prop
62
+ * or RumName, else the target's accessibilityLabel, never from text; and rage and error taps as
63
+ * frustration signals. It records the touches RumTouchBoundary passes it, so render the boundary
64
+ * around the app. Pass it in rum.collectors.
65
+ */
66
+ export function taps(opts = {}) {
67
+ return tapsWith(runtimeTimers, opts);
68
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @libo11y/rum-react-native/internal: the building blocks, for libo11y packages and fixtures. For
3
+ * libo11y packages only: it follows the package version and carries no compatibility promise.
4
+ * Nothing reachable from here imports react-native or Expo (boundary.test.ts enforces that), so
5
+ * node tests can load it.
6
+ */
7
+ export { runtimeOf } from "@libo11y/rum/core";
8
+ export { type AppStart, type AppStartOptions, createAppStart } from "./app-start.ts";
9
+ export { type ReactNativeBindingOptions, type ReactNativeRumBind, reactNativeBinding, rumLifecycle, } from "./binding.ts";
10
+ export { type PreloadedStorage, preloadedStorage } from "./config-cache.ts";
11
+ export type { ErrorsEnv, ErrorUtilsLike, GlobalErrorHandler, HermesInternalLike, RejectionTrackerOptions, RumReactNativeEnv, StartupTimingLike, } from "./contracts/env.ts";
12
+ export { type ErrorsWithOptions, errorsWith, FATAL_FLUSH_MILLIS } from "./errors.ts";
13
+ export { bundleName, hermesStack } from "./hermes-stack.ts";
14
+ export { attributeReport, type DescribedDiagnostic, describeDiagnostic, type NativeReports, type NativeReportsDeps, nativeStack, POLL_MILLIS, startNativeReports, } from "./native-reports.ts";
15
+ export type { ReactNativeRumTelemetry, RumReactNativeOptions, RumReactNativeSetupOptions, } from "./options.ts";
16
+ export { screensWith } from "./screens.ts";
17
+ export { type DeviceSessionStore, storageSessionStore } from "./session-store.ts";
18
+ export { APP_LOCATION, type RumReactNativeDeps, setupRumReactNativeWith } from "./setup.ts";
19
+ export { type FiberLike, fiberOfEvent, type TapTarget, type TapTargetOptions, tapTarget, } from "./tap-target.ts";
20
+ export { dispatchTouch, LONG_PRESS_MILLIS, TAP_SLOP, type TapsOptions, type TouchEventLike, type TouchPhase, tapsWith, } from "./taps.ts";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @libo11y/rum-react-native/internal: the building blocks, for libo11y packages and fixtures. For
3
+ * libo11y packages only: it follows the package version and carries no compatibility promise.
4
+ * Nothing reachable from here imports react-native or Expo (boundary.test.ts enforces that), so
5
+ * node tests can load it.
6
+ */
7
+ export { runtimeOf } from "@libo11y/rum/core";
8
+ export { createAppStart } from "./app-start.js";
9
+ export { reactNativeBinding, rumLifecycle, } from "./binding.js";
10
+ export { preloadedStorage } from "./config-cache.js";
11
+ export { errorsWith, FATAL_FLUSH_MILLIS } from "./errors.js";
12
+ export { bundleName, hermesStack } from "./hermes-stack.js";
13
+ export { attributeReport, describeDiagnostic, nativeStack, POLL_MILLIS, startNativeReports, } from "./native-reports.js";
14
+ export { screensWith } from "./screens.js";
15
+ export { storageSessionStore } from "./session-store.js";
16
+ export { APP_LOCATION, setupRumReactNativeWith } from "./setup.js";
17
+ export { fiberOfEvent, tapTarget, } from "./tap-target.js";
18
+ export { dispatchTouch, LONG_PRESS_MILLIS, TAP_SLOP, tapsWith, } from "./taps.js";
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Native crashes and hangs on iOS, through the libo11y native module (spec 1.4.0).
3
+ *
4
+ * MetricKit reports a crash, or a hang, to the app on a later launch, and a hang sometimes while
5
+ * its process still runs. The native module keeps a report on disk only while RUM records under
6
+ * consent (setRecording), and only when it names its process (iOS 17 and later) and that process
7
+ * wrote context under consent by the time the report's payload began. This file turns each report
8
+ * into one o11y.rum.error record and acknowledges it once the pipeline took the record and a flush
9
+ * exported it, or once it decided to drop it. A report tried again is counted once.
10
+ *
11
+ * Attribution. While RUM runs, every change of session, screen, screen name or whether the session
12
+ * is kept, and every hide (after its summaries went out), writes the current context through the
13
+ * module: session, view, the seq the view's next summary would have, whether the session is kept,
14
+ * service.version and the update ID, with the time. The module adds the process ID and start and
15
+ * keeps the last 64 entries. A report maps to the last entry its own process wrote (by process
16
+ * ID) at or before its payload ended. A report without a process ID, or whose process wrote no
17
+ * context by then, is dropped: nothing shows that process recorded under consent when it happened. A crash is never this process's; a hang may be. The
18
+ * native crash a fatal JavaScript error causes (RCTFatal) is dropped when that process marked its
19
+ * context fatal, because errors() recorded the JavaScript error already.
20
+ *
21
+ * The record carries the entry's session.id, o11y.rum.view.id, o11y.rum.app.update_id and
22
+ * service.version (else MetricKit's app version), so a crash an earlier version had is counted
23
+ * under that version, and the time the payload ended (not before the entry). It carries nothing
24
+ * current of this launch (no user.id). It retains the session when that is the current one, and
25
+ * an earlier session keeps the decision its entry recorded, so an earlier unkept session's record
26
+ * is dropped and a kept one's is sent. The error is always counted: in the view's own summary when
27
+ * it is this process's current view, else in one more summary of the entry's view (late),
28
+ * whatever the sampling. A late summary's seq follows the view's last one, and the module keeps
29
+ * the next (a late entry), so a later launch continues it.
30
+ *
31
+ * Reports arrive a moment after launch and sometimes later, so the module is read when the
32
+ * collector starts, at each of pollMillis, then every last of them until it stops. Stop on a
33
+ * revoke switches the module off, which deletes what it holds.
34
+ */
35
+ import type { Libo11yNative, NativeContextEntry, NativeDiagnostic } from "@libo11y/react-native/internal";
36
+ import type { RumRuntime } from "@libo11y/rum/core";
37
+ export { nativeStack } from "./native-stack.ts";
38
+ /**
39
+ * When the collector reads the module's reports after it starts, in milliseconds. It then reads
40
+ * them again every last of these.
41
+ */
42
+ export declare const POLL_MILLIS: readonly number[];
43
+ /** What one report becomes. */
44
+ export interface DescribedDiagnostic {
45
+ readonly source: "crash" | "hang";
46
+ readonly type: string;
47
+ readonly message: string;
48
+ readonly signal?: string;
49
+ readonly hangSeconds?: number;
50
+ readonly lines: readonly string[];
51
+ readonly images: readonly string[];
52
+ }
53
+ /**
54
+ * exception.type is the Objective-C or Swift exception name, else the Mach exception name, else the
55
+ * signal name, else NativeCrash; a hang is AppHang. The message is the exception's message, else the
56
+ * termination reason, else the exception and signal.
57
+ */
58
+ export declare function describeDiagnostic(d: NativeDiagnostic): DescribedDiagnostic;
59
+ /**
60
+ * The context a report happened in: the last entry its own process wrote at or before the
61
+ * report's payload ended, by process ID. A process ID is reused, so the process is the latest one
62
+ * with that ID that started before the end; only that choice allows for clock slack. The report
63
+ * may have happened anywhere from the payload's begin to its end, so the process must have written
64
+ * an entry at or before the begin, or stamped every entry with a first consent that early: consent
65
+ * covered the whole window. A report without a process
66
+ * ID, or whose window starts before its process's first entry, maps to nothing. A crash is never about the current
67
+ * process (currentStart); a hang may be. Late entries name no context.
68
+ */
69
+ export declare function attributeReport(d: NativeDiagnostic, history: readonly NativeContextEntry[], currentStart: number | undefined): NativeContextEntry | undefined;
70
+ /** What the reports collector needs besides the runtime. */
71
+ export interface NativeReportsDeps {
72
+ readonly native: Libo11yNative;
73
+ /**
74
+ * When to read the module's reports, in milliseconds after the start, then every last of these.
75
+ * Default POLL_MILLIS.
76
+ */
77
+ readonly pollMillis?: readonly number[];
78
+ setTimeout(cb: () => void, ms: number): unknown;
79
+ clearTimeout(handle: unknown): void;
80
+ }
81
+ /** What startNativeReports returns. */
82
+ export interface NativeReports {
83
+ /** Stops writing and reading; a revoke also switches the module off. */
84
+ stop(): void;
85
+ /**
86
+ * A fatal JavaScript error is ending the process: writes the context, after the summaries the
87
+ * crash path flushed, marked fatal, so the native crash it causes is not reported again.
88
+ * Resolves once the module has it.
89
+ */
90
+ fatal(): Promise<unknown>;
91
+ }
92
+ /** Starts writing the context and turning reports into records. */
93
+ export declare function startNativeReports(rt: RumRuntime, deps: NativeReportsDeps): NativeReports;