@libo11y/rum-react-native 0.0.0-stage → 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/LICENSE +202 -0
- package/README.md +287 -2
- package/dist/app-start.d.ts +36 -0
- package/dist/app-start.js +81 -0
- package/dist/binding.d.ts +27 -0
- package/dist/binding.js +31 -0
- package/dist/config-cache.d.ts +19 -0
- package/dist/config-cache.js +38 -0
- package/dist/contracts/env.d.ts +62 -0
- package/dist/contracts/env.js +5 -0
- package/dist/env.d.ts +12 -0
- package/dist/env.js +54 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.js +213 -0
- package/dist/expo.d.ts +7 -0
- package/dist/expo.js +16 -0
- package/dist/hermes-stack.d.ts +13 -0
- package/dist/hermes-stack.js +84 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +65 -0
- package/dist/internal.d.ts +19 -0
- package/dist/internal.js +17 -0
- package/dist/options.d.ts +27 -0
- package/dist/options.js +1 -0
- package/dist/screens.d.ts +12 -0
- package/dist/screens.js +32 -0
- package/dist/session-store.d.ts +20 -0
- package/dist/session-store.js +28 -0
- package/dist/setup.d.ts +38 -0
- package/dist/setup.js +81 -0
- package/dist/tap-target.d.ts +74 -0
- package/dist/tap-target.js +147 -0
- package/dist/taps.d.ts +80 -0
- package/dist/taps.js +206 -0
- package/dist/touch-boundary.d.ts +22 -0
- package/dist/touch-boundary.js +28 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +56 -4
package/dist/taps.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* taps(): taps and long presses as actions, and frustration signals, from the touches
|
|
3
|
+
* RumTouchBoundary (touch-boundary.ts) passes to dispatchTouch.
|
|
4
|
+
*
|
|
5
|
+
* A gesture is one finger down and up. It is a tap when the finger moved at most TAP_SLOP points
|
|
6
|
+
* and was not cancelled (a scroll view taking the touch cancels it), and a long press when it was
|
|
7
|
+
* down LONG_PRESS_MILLIS or more. A gesture that ever had a second finger is neither. A touch
|
|
8
|
+
* start with one finger on the screen always begins a new gesture.
|
|
9
|
+
*
|
|
10
|
+
* React Native runs the responder system, and so onPress and onLongPress, before the touch events
|
|
11
|
+
* bubble to the boundary, so a tap is known only after its handler ran. The action span "action
|
|
12
|
+
* tap" (or "action long_press") starts then, at the touch's end (a long press at the moment React
|
|
13
|
+
* Native's Pressability fires onLongPress, LONG_PRESS_MILLIS after the touch began), as a root
|
|
14
|
+
* with o11y.rum.span.shape action, the type, the name, o11y.rum.element.selector and the view ID,
|
|
15
|
+
* linked to the view span (tap-target.ts names the target). It is the open action until it
|
|
16
|
+
* settles, by the browser's rule: the RUM context manager makes it the parent of requests started
|
|
17
|
+
* meanwhile, and those requests, the requests started since the touch began (the ones its handler
|
|
18
|
+
* started) and view starts are its activity. A view the handler navigated to starts after the
|
|
19
|
+
* tap opened (router adapters start it when the new navigation state is committed), so the tap is
|
|
20
|
+
* its cause. Each tap touches the session, and its breadcrumb (type and name, else the target's
|
|
21
|
+
* type) is published when it starts.
|
|
22
|
+
*
|
|
23
|
+
* Frustration (when frustration is not false): rageTaps taps on one element within a second are a
|
|
24
|
+
* rage signal, and an error within a second of a tap, or while its action is open, an error
|
|
25
|
+
* signal, as the browser's actions() detects them for clicks. Dead taps are not detected: React
|
|
26
|
+
* Native has no mutation signal to tell that a tap changed nothing. Each signal counts in the
|
|
27
|
+
* summary, is published, retains the session and is emitted as o11y.rum.frustration in the open
|
|
28
|
+
* action's context. Stop removes the collector from the boundary, ends the open action and
|
|
29
|
+
* cancels every timer.
|
|
30
|
+
*/
|
|
31
|
+
import { actionSpanName, actionSpanStart, createFrustrationDetector, createSettleTracker, } from "@libo11y/rum/core";
|
|
32
|
+
import { ATTR_RUM_ELEMENT_SELECTOR, ATTR_RUM_FRUSTRATION_TYPE, EVENT_RUM_FRUSTRATION, } from "@libo11y/spec";
|
|
33
|
+
import { context, diag, ROOT_CONTEXT, trace } from "@opentelemetry/api";
|
|
34
|
+
import { fiberOfEvent, tapTarget } from "./tap-target.js";
|
|
35
|
+
/** How far, in points, a finger may move and still tap. */
|
|
36
|
+
export const TAP_SLOP = 10;
|
|
37
|
+
/** A touch held this long is a long press, as React Native's Pressability defaults its delayLongPress. */
|
|
38
|
+
export const LONG_PRESS_MILLIS = 500;
|
|
39
|
+
/** Requests remembered while in flight, so a tap can adopt the ones its handler started. */
|
|
40
|
+
const MAX_IN_FLIGHT = 256;
|
|
41
|
+
/** The running collectors' sinks. RumTouchBoundary dispatches every touch to them. */
|
|
42
|
+
const sinks = new Set();
|
|
43
|
+
/**
|
|
44
|
+
* Passes one phase of a touch to every running taps() collector. RumTouchBoundary calls it from
|
|
45
|
+
* its touch handlers; it never throws.
|
|
46
|
+
*/
|
|
47
|
+
export function dispatchTouch(phase, event) {
|
|
48
|
+
for (const sink of [...sinks]) {
|
|
49
|
+
try {
|
|
50
|
+
sink(phase, event);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
diag.warn("o11y: rum: a touch could not be recorded", err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function num(v) {
|
|
58
|
+
return typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
59
|
+
}
|
|
60
|
+
/** How many fingers the event says are on the screen. */
|
|
61
|
+
function fingers(e) {
|
|
62
|
+
const t = e.nativeEvent?.touches;
|
|
63
|
+
return Array.isArray(t) ? t.length : 0;
|
|
64
|
+
}
|
|
65
|
+
/** The taps collector over timers. */
|
|
66
|
+
export function tapsWith(timers, opts = {}) {
|
|
67
|
+
const idleMillis = opts.idleMillis ?? 100;
|
|
68
|
+
const capMillis = opts.capMillis ?? 10_000;
|
|
69
|
+
const targetOptions = {
|
|
70
|
+
...(opts.accessibilityNames === undefined ? {} : { accessibilityNames: opts.accessibilityNames }),
|
|
71
|
+
...(opts.testIds === undefined ? {} : { testIds: opts.testIds }),
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
name: "actions",
|
|
75
|
+
start(rt) {
|
|
76
|
+
let current;
|
|
77
|
+
/** The span of the last tap, so an error counts against it only while its own action is open. */
|
|
78
|
+
let lastTapSpan;
|
|
79
|
+
let gesture;
|
|
80
|
+
/** Requests in flight: span ID to start time. */
|
|
81
|
+
const inFlight = new Map();
|
|
82
|
+
const signal = (type, key, at) => {
|
|
83
|
+
const selector = key.split("\u0000")[0] ?? key;
|
|
84
|
+
rt.summary.count(`frustrations.${type}`);
|
|
85
|
+
rt.bus.publish({ type: "frustration", frustration: type, selector, at });
|
|
86
|
+
rt.session.retain("frustration");
|
|
87
|
+
const action = current?.span;
|
|
88
|
+
rt.emit(EVENT_RUM_FRUSTRATION, { [ATTR_RUM_FRUSTRATION_TYPE]: type, [ATTR_RUM_ELEMENT_SELECTOR]: selector }, action === undefined ? undefined : trace.setSpan(context.active(), action));
|
|
89
|
+
};
|
|
90
|
+
const detector = opts.frustration === false
|
|
91
|
+
? undefined
|
|
92
|
+
: createFrustrationDetector({
|
|
93
|
+
timers,
|
|
94
|
+
onSignal: signal,
|
|
95
|
+
...(opts.rageTaps === undefined ? {} : { rageClicks: opts.rageTaps }),
|
|
96
|
+
});
|
|
97
|
+
const begin = (type, g) => {
|
|
98
|
+
current?.settle.end();
|
|
99
|
+
const now = rt.now();
|
|
100
|
+
const start = type === "long_press" ? Math.min(now, g.at + LONG_PRESS_MILLIS) : now;
|
|
101
|
+
const target = tapTarget(g.fiber, targetOptions);
|
|
102
|
+
const span = rt.tracer.startSpan(actionSpanName(type), {
|
|
103
|
+
startTime: rt.timeOrigin + start,
|
|
104
|
+
...actionSpanStart(rt, type, target.name, { [ATTR_RUM_ELEMENT_SELECTOR]: target.selector }),
|
|
105
|
+
}, ROOT_CONTEXT);
|
|
106
|
+
const settle = createSettleTracker({
|
|
107
|
+
start,
|
|
108
|
+
idleMillis,
|
|
109
|
+
capMillis,
|
|
110
|
+
now: rt.now,
|
|
111
|
+
timers,
|
|
112
|
+
onSettle: (end) => {
|
|
113
|
+
span.end(rt.timeOrigin + end);
|
|
114
|
+
if (current?.span === span)
|
|
115
|
+
current = undefined;
|
|
116
|
+
if (rt.activeAction() === span)
|
|
117
|
+
rt.setActiveAction(undefined);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
// The requests the tap's handler started ran before the tap was known.
|
|
121
|
+
for (const [id, at] of inFlight)
|
|
122
|
+
if (at >= g.at)
|
|
123
|
+
settle.requestStarted(id, at);
|
|
124
|
+
current = { span, settle };
|
|
125
|
+
rt.setActiveAction(span);
|
|
126
|
+
rt.session.touch();
|
|
127
|
+
rt.bus.publish({ type: "breadcrumb", kind: type, label: target.label, at: start });
|
|
128
|
+
lastTapSpan = span;
|
|
129
|
+
detector?.click(target.key, start, false);
|
|
130
|
+
};
|
|
131
|
+
const onTouch = (phase, e) => {
|
|
132
|
+
if (phase === "cancel") {
|
|
133
|
+
gesture = undefined;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const x = num(e.nativeEvent?.pageX);
|
|
137
|
+
const y = num(e.nativeEvent?.pageY);
|
|
138
|
+
if (phase === "start") {
|
|
139
|
+
const n = fingers(e);
|
|
140
|
+
// One finger on the screen starts a gesture, whatever an earlier one left (an end that
|
|
141
|
+
// never bubbled to the boundary). A second finger, or a start whose count is unknown
|
|
142
|
+
// while a gesture is open, makes it a multi-touch gesture.
|
|
143
|
+
if (n > 1 || (n === 0 && gesture !== undefined)) {
|
|
144
|
+
if (gesture !== undefined)
|
|
145
|
+
gesture.multi = true;
|
|
146
|
+
else
|
|
147
|
+
gesture = { at: rt.now(), x, y, fiber: undefined, multi: true };
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
gesture = { at: rt.now(), x, y, fiber: fiberOfEvent(e), multi: false };
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const g = gesture;
|
|
154
|
+
if (g === undefined)
|
|
155
|
+
return;
|
|
156
|
+
if (fingers(e) > 0) {
|
|
157
|
+
g.multi = true;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
gesture = undefined;
|
|
161
|
+
if (g.multi)
|
|
162
|
+
return;
|
|
163
|
+
if (x !== undefined && y !== undefined && g.x !== undefined && g.y !== undefined) {
|
|
164
|
+
if (Math.hypot(x - g.x, y - g.y) > TAP_SLOP)
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
begin(rt.now() - g.at >= LONG_PRESS_MILLIS ? "long_press" : "tap", g);
|
|
168
|
+
};
|
|
169
|
+
sinks.add(onTouch);
|
|
170
|
+
const offBus = rt.bus.subscribe((s) => {
|
|
171
|
+
const a = current;
|
|
172
|
+
if (s.type === "request-start") {
|
|
173
|
+
inFlight.set(s.spanId, s.at);
|
|
174
|
+
if (inFlight.size > MAX_IN_FLIGHT) {
|
|
175
|
+
const oldest = inFlight.keys().next().value;
|
|
176
|
+
if (oldest !== undefined)
|
|
177
|
+
inFlight.delete(oldest);
|
|
178
|
+
}
|
|
179
|
+
if (a !== undefined && s.parentSpanId === a.span.spanContext().spanId) {
|
|
180
|
+
a.settle.requestStarted(s.spanId, s.at);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if (s.type === "request-end") {
|
|
184
|
+
inFlight.delete(s.spanId);
|
|
185
|
+
a?.settle.requestEnded(s.spanId, s.at);
|
|
186
|
+
}
|
|
187
|
+
else if (s.type === "error")
|
|
188
|
+
detector?.error(s.at, a !== undefined && a.span === lastTapSpan);
|
|
189
|
+
});
|
|
190
|
+
const offViews = rt.views.subscribe((e) => {
|
|
191
|
+
if (e.type === "start")
|
|
192
|
+
current?.settle.activity(rt.now());
|
|
193
|
+
});
|
|
194
|
+
return () => {
|
|
195
|
+
sinks.delete(onTouch);
|
|
196
|
+
offBus();
|
|
197
|
+
offViews();
|
|
198
|
+
current?.settle.end();
|
|
199
|
+
current = undefined;
|
|
200
|
+
gesture = undefined;
|
|
201
|
+
inFlight.clear();
|
|
202
|
+
detector?.stop();
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RumTouchBoundary: the one view at the root of an app whose touch events taps() records. It is a
|
|
3
|
+
* plain View that fills its parent and listens to touchstart, touchend and touchcancel as they
|
|
4
|
+
* bubble. It never asks to become the responder, so it changes no gesture, press or scroll. The
|
|
5
|
+
* only module that renders React Native components, so node tests never load it (boundary.test.ts
|
|
6
|
+
* enforces that).
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
9
|
+
import { type StyleProp, type ViewStyle } from "react-native";
|
|
10
|
+
/** Props of RumTouchBoundary. */
|
|
11
|
+
export interface RumTouchBoundaryProps {
|
|
12
|
+
/** The app. */
|
|
13
|
+
readonly children?: ReactNode;
|
|
14
|
+
/** Style after the boundary's own flex: 1. */
|
|
15
|
+
readonly style?: StyleProp<ViewStyle>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wraps the app so taps() sees its touches: render it once, around everything the user can touch,
|
|
19
|
+
* inside any provider that must stay outermost. Without it taps() records nothing. Touches reach
|
|
20
|
+
* it only while taps() runs, that is while consent is granted.
|
|
21
|
+
*/
|
|
22
|
+
export declare function RumTouchBoundary(props: RumTouchBoundaryProps): ReactElement;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RumTouchBoundary: the one view at the root of an app whose touch events taps() records. It is a
|
|
3
|
+
* plain View that fills its parent and listens to touchstart, touchend and touchcancel as they
|
|
4
|
+
* bubble. It never asks to become the responder, so it changes no gesture, press or scroll. The
|
|
5
|
+
* only module that renders React Native components, so node tests never load it (boundary.test.ts
|
|
6
|
+
* enforces that).
|
|
7
|
+
*/
|
|
8
|
+
import { createElement } from "react";
|
|
9
|
+
import { View } from "react-native";
|
|
10
|
+
import { dispatchTouch } from "./taps.js";
|
|
11
|
+
const FILL = { flex: 1 };
|
|
12
|
+
const onTouchStart = (e) => dispatchTouch("start", e);
|
|
13
|
+
const onTouchEnd = (e) => dispatchTouch("end", e);
|
|
14
|
+
const onTouchCancel = (e) => dispatchTouch("cancel", e);
|
|
15
|
+
/**
|
|
16
|
+
* Wraps the app so taps() sees its touches: render it once, around everything the user can touch,
|
|
17
|
+
* inside any provider that must stay outermost. Without it taps() records nothing. Touches reach
|
|
18
|
+
* it only while taps() runs, that is while consent is granted.
|
|
19
|
+
*/
|
|
20
|
+
export function RumTouchBoundary(props) {
|
|
21
|
+
return createElement(View, {
|
|
22
|
+
style: props.style === undefined ? FILL : [FILL, props.style],
|
|
23
|
+
collapsable: false,
|
|
24
|
+
onTouchStart,
|
|
25
|
+
onTouchEnd,
|
|
26
|
+
onTouchCancel,
|
|
27
|
+
}, props.children);
|
|
28
|
+
}
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libo11y/rum-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "libo11y RUM for React Native apps on Hermes: sessions that survive a relaunch, consent, session sampling with a retention buffer on device storage, screens, the app_load span and per-screen summaries over @libo11y/react-native. The handle works with @libo11y/rum-react and @libo11y/rum-connect.",
|
|
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
|
+
"./expo": {
|
|
14
|
+
"types": "./dist/expo.d.ts",
|
|
15
|
+
"default": "./dist/expo.js"
|
|
16
|
+
},
|
|
17
|
+
"./internal": {
|
|
18
|
+
"types": "./dist/internal.d.ts",
|
|
19
|
+
"default": "./dist/internal.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/libo11y/libo11y.git",
|
|
25
|
+
"directory": "ts/packages/rum-react-native"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@libo11y/core": "0.6.0",
|
|
29
|
+
"@libo11y/react-native": "0.6.0",
|
|
30
|
+
"@libo11y/rum": "0.6.0",
|
|
31
|
+
"@libo11y/spec": "0.6.0",
|
|
32
|
+
"@libo11y/web": "0.6.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@opentelemetry/api": ">=1.10.0 <1.11.0",
|
|
36
|
+
"react": "^19.0.0",
|
|
37
|
+
"react-native": ">=0.88.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@libo11y/rum-connect": "0.6.0",
|
|
41
|
+
"@libo11y/rum-react": "0.6.0",
|
|
42
|
+
"@libo11y/test": "0.6.0",
|
|
43
|
+
"@opentelemetry/api": "1.10.0",
|
|
44
|
+
"@opentelemetry/sdk-trace": "3.1.1",
|
|
45
|
+
"@types/react": "19.3.0",
|
|
46
|
+
"react": "19.3.1",
|
|
47
|
+
"react-native": "0.88.1"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"README.md",
|
|
52
|
+
"LICENSE"
|
|
53
|
+
],
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"provenance": true
|
|
57
|
+
}
|
|
58
|
+
}
|