@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/LICENSE +202 -0
- package/README.md +400 -2
- package/dist/app-start.d.ts +39 -0
- package/dist/app-start.js +93 -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 +73 -0
- package/dist/contracts/env.js +1 -0
- package/dist/env.d.ts +15 -0
- package/dist/env.js +63 -0
- package/dist/errors.d.ts +57 -0
- package/dist/errors.js +247 -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 +59 -0
- package/dist/index.js +68 -0
- package/dist/internal.d.ts +20 -0
- package/dist/internal.js +18 -0
- package/dist/native-reports.d.ts +93 -0
- package/dist/native-reports.js +368 -0
- package/dist/native-stack.d.ts +14 -0
- package/dist/native-stack.js +81 -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/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,401 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @libo11y/rum-react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Real user monitoring for React Native apps on Hermes, over
|
|
4
|
+
[`@libo11y/react-native`](../react-native). It records sessions, screens,
|
|
5
|
+
per-screen summaries, the app's start, JavaScript errors, taps and
|
|
6
|
+
frustration signals, gated on consent, and joins them to the backend
|
|
7
|
+
traces of the requests the app makes. The handle it returns is the same
|
|
8
|
+
`Rum` the browser's `@libo11y/rum` returns, so
|
|
9
|
+
[`@libo11y/rum-react`](../rum-react) and
|
|
10
|
+
[`@libo11y/rum-connect`](../rum-connect) work with it as they are.
|
|
11
|
+
[`@libo11y/rum-expo-router`](../rum-expo-router) names screens by Expo
|
|
12
|
+
Router route template.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @libo11y/react-native @libo11y/rum-react-native
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
It needs React Native 0.88 or later and React 19 as peer dependencies. It
|
|
19
|
+
contains no native code, so adding it changes no native build.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
An Expo app imports `setupRumExpo` from `@libo11y/rum-react-native/expo`,
|
|
24
|
+
which keeps everything RUM stores in the app's documents and fills in the
|
|
25
|
+
app version and the over-the-air update ID, as `setupExpo` does:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { errors, remoteConfig, screens, taps } from "@libo11y/rum-react-native";
|
|
29
|
+
import { setupRumExpo } from "@libo11y/rum-react-native/expo";
|
|
30
|
+
|
|
31
|
+
export const telemetryReady = setupRumExpo({
|
|
32
|
+
serviceName: "my-app",
|
|
33
|
+
environment: "production",
|
|
34
|
+
endpoint: "https://app.example.com/_o11y",
|
|
35
|
+
consent: { initial: "pending" },
|
|
36
|
+
instrumentations: { propagateTo: ["https://api.example.com"] },
|
|
37
|
+
rum: {
|
|
38
|
+
clientToken: "pub-my-app",
|
|
39
|
+
collectors: [screens(), errors(), taps()],
|
|
40
|
+
remoteConfig: remoteConfig(),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A bare React Native app calls `setupRumReactNative` with the same options
|
|
46
|
+
and a `storage` of its own, such as AsyncStorage. Without one, RUM keeps
|
|
47
|
+
its state in memory and loses it when the app stops.
|
|
48
|
+
|
|
49
|
+
`telemetryReady` is a promise, because Metro bundles do not support
|
|
50
|
+
top-level `await`. The root component renders `RumTouchBoundary` around
|
|
51
|
+
the app, so `taps()` sees its touches, and an error boundary that reports
|
|
52
|
+
to RUM:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { RumErrorBoundary, RumProvider } from "@libo11y/rum-react";
|
|
56
|
+
import { RumTouchBoundary } from "@libo11y/rum-react-native";
|
|
57
|
+
|
|
58
|
+
<RumTouchBoundary>
|
|
59
|
+
<RumProvider rum={telemetry.rum}>
|
|
60
|
+
<RumErrorBoundary fallback={<Oops />}>
|
|
61
|
+
<App />
|
|
62
|
+
</RumErrorBoundary>
|
|
63
|
+
</RumProvider>
|
|
64
|
+
</RumTouchBoundary>;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
An Expo Router app calls `useExpoRouterRum(telemetry?.rum)` from
|
|
68
|
+
[`@libo11y/rum-expo-router`](../rum-expo-router) in its root layout. Other
|
|
69
|
+
apps report screens themselves on the telemetry `telemetryReady` resolves
|
|
70
|
+
with:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
telemetry.rum.startView({ name: "/settings" }); // a new screen
|
|
74
|
+
telemetry.rum.setViewName("/"); // names the current screen
|
|
75
|
+
telemetry.rum.viewRendered(); // the screen's content is on screen
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Call `rum.viewRendered()` once the first screen is up, for example in an
|
|
79
|
+
effect of the root component. It ends the first screen's span and the
|
|
80
|
+
`app_load` span.
|
|
81
|
+
|
|
82
|
+
## What it records
|
|
83
|
+
|
|
84
|
+
- **Sessions.** A session ends after 15 minutes without activity or 4
|
|
85
|
+
hours after it started. It is stored in the app's storage once consent
|
|
86
|
+
is granted, so a relaunch within the idle window continues it, and a
|
|
87
|
+
crash and relaunch stay in one session. A new screen (`rum.startView`),
|
|
88
|
+
a tap (with `taps()`) and coming back to the foreground count as
|
|
89
|
+
activity. Sampling, the retention buffer of sessions not yet kept and
|
|
90
|
+
the session events work as in `@libo11y/rum`; the buffer lives in the
|
|
91
|
+
app's storage.
|
|
92
|
+
- **Screens.** Every view has `o11y.rum.view.kind` `screen`. The first is
|
|
93
|
+
named `rum.initialViewName` (default `"app"`) until something names it.
|
|
94
|
+
It starts when the app started, as `app_load` does.
|
|
95
|
+
With `screens()` in `rum.collectors`, each screen gets a view span that
|
|
96
|
+
ends at the first frame after `rum.viewRendered()`, or 10 seconds after
|
|
97
|
+
it started. The first screen's span is a child of `app_load`; a later
|
|
98
|
+
screen's is a root linked to the action that caused it. Going to the
|
|
99
|
+
background (AppState `background`, or `inactive` on iOS) emits the
|
|
100
|
+
screen's `o11y.rum.view.summary` and flushes.
|
|
101
|
+
- **App start.** One `app_load` span per process, from the process start
|
|
102
|
+
to the first screen's render, at most 60 seconds. With the libo11y
|
|
103
|
+
native module (see [Native crashes and hangs](#native-crashes-and-hangs))
|
|
104
|
+
the start is the kernel's process start time, unless iOS prewarmed the
|
|
105
|
+
process before the person opened the app. Without it, the start is
|
|
106
|
+
`performance.rnStartupTiming.startTime`, or when this package was
|
|
107
|
+
loaded.
|
|
108
|
+
When consent is granted after the first screen rendered, even after
|
|
109
|
+
other screens, the span is still recorded, with the times remembered
|
|
110
|
+
from before the grant. An app that leaves its first screen before it
|
|
111
|
+
rendered records the 60-second cap.
|
|
112
|
+
- **Requests.** `@libo11y/react-native`'s fetch and XHR spans count
|
|
113
|
+
toward the screen's summary and leave breadcrumbs.
|
|
114
|
+
`rum.onRequestStart` hooks run on each of them, which is how
|
|
115
|
+
`connectRequestNaming` names Connect calls.
|
|
116
|
+
- **Errors**, with `errors()`. See [Errors](#errors). On iOS with the
|
|
117
|
+
native module, also native crashes and hangs. See
|
|
118
|
+
[Native crashes and hangs](#native-crashes-and-hangs).
|
|
119
|
+
- **Taps and frustration signals**, with `taps()` and `RumTouchBoundary`.
|
|
120
|
+
See [Taps](#taps).
|
|
121
|
+
|
|
122
|
+
Revoking consent removes the session, the retention buffer and the
|
|
123
|
+
remote configuration cache from the app's storage, also when only an
|
|
124
|
+
earlier launch had consent. An awaited `consent.revoke()` resolves once
|
|
125
|
+
storage holds none of them. A launch that starts with consent `denied`
|
|
126
|
+
removes them before setup resolves, so a later grant starts a new
|
|
127
|
+
session. A launch that starts `pending` leaves them in place.
|
|
128
|
+
|
|
129
|
+
The resource carries `o11y.rum.platform` `react_native`, and so do RUM's
|
|
130
|
+
own view spans, summaries and `o11y.rum.session.start`. App metrics export
|
|
131
|
+
with delta temporality, which the RUM gateway requires. Requests from an app carry no `Origin`, so the gateway's
|
|
132
|
+
entry for the app sets `allow_missing_origin` and a `client_token`.
|
|
133
|
+
|
|
134
|
+
Context does not carry across `await` on Hermes, which has no
|
|
135
|
+
`AsyncLocalStorage`. A request made after an `await` in a tap handler is
|
|
136
|
+
not that tap's child.
|
|
137
|
+
|
|
138
|
+
## Errors
|
|
139
|
+
|
|
140
|
+
`errors()` records each error as `o11y.rum.error` with its breadcrumbs
|
|
141
|
+
(screens, taps and requests). It counts in the screen's summary, and it
|
|
142
|
+
keeps a session that sampling left out, which then sends the detail its
|
|
143
|
+
retention buffer held. It records only while consent is granted.
|
|
144
|
+
|
|
145
|
+
- **Uncaught errors** reach React Native's global handler
|
|
146
|
+
(`ErrorUtils.setGlobalHandler`). RUM records each one as `uncaught`
|
|
147
|
+
and then hands it to the handler installed before it, so the red box,
|
|
148
|
+
LogBox and the crash still happen. In a release build a fatal error
|
|
149
|
+
ends the app, so RUM first emits the screen's summary and flushes,
|
|
150
|
+
which saves the batches to the app's storage, and hands the error on
|
|
151
|
+
when the flush is done or after 2 seconds. A batch the app could not
|
|
152
|
+
send goes out on the next launch. In development the error is handed
|
|
153
|
+
on at once.
|
|
154
|
+
- **Unhandled promise rejections** on Hermes are `unhandled_rejection`.
|
|
155
|
+
Hermes reports them only to the tracker
|
|
156
|
+
`HermesInternal.enablePromiseRejectionTracker` sets, React Native sets
|
|
157
|
+
one in development only, and a new one replaces it. RUM sets its own
|
|
158
|
+
and, in development, reports each rejection to the red box as React
|
|
159
|
+
Native's does. Another library that sets a tracker after RUM replaces
|
|
160
|
+
RUM's.
|
|
161
|
+
- **Failed requests**, ended without a response, are `network`, unless
|
|
162
|
+
the app aborted them.
|
|
163
|
+
- **Render errors** never reach the global handler: React hands them to
|
|
164
|
+
an error boundary. Wrap the app in `@libo11y/rum-react`'s
|
|
165
|
+
`RumErrorBoundary`, or report from the app's own boundary:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
componentDidCatch(error: unknown, info: React.ErrorInfo): void {
|
|
169
|
+
rum.addError(error, { source: "boundary", componentStack: info.componentStack ?? undefined });
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
A render error no boundary catches crashes the app without passing the
|
|
174
|
+
global handler, so RUM never sees it.
|
|
175
|
+
|
|
176
|
+
Release stacks reach the gateway readable. Hermes names the bundle by its
|
|
177
|
+
path on the device, so RUM rewrites each frame of the app's bundle to
|
|
178
|
+
`app:///main.jsbundle` on iOS and `app:///index.android.bundle` on
|
|
179
|
+
Android, and keeps engine frames (`native`, `InternalBytecode.js`). A
|
|
180
|
+
frame `address at` the bundle carries a bytecode offset, which Hermes
|
|
181
|
+
prints 0-based; RUM sends it as the 1-based column the gateway reads, so
|
|
182
|
+
offset 114 is sent as column 115. The gateway finds a stack's source map
|
|
183
|
+
by the resource's `service.version` and `o11y.rum.app.update_id` (which
|
|
184
|
+
`setupRumExpo` fills in) and that script path.
|
|
185
|
+
|
|
186
|
+
For an over-the-air update, `expo export --platform ios --source-maps`
|
|
187
|
+
writes the bytecode bundle `dist/_expo/static/js/ios/entry-<hash>.hbc`
|
|
188
|
+
and its map `dist/_expo/static/js/ios/entry-<hash>.hbc.map`, which Expo
|
|
189
|
+
has already composed from Metro's map and the Hermes compiler's, so it
|
|
190
|
+
maps bytecode offsets to your sources. Copy the map to
|
|
191
|
+
`main.jsbundle.map` and the bundle to `main.jsbundle` in a directory of
|
|
192
|
+
their own, and upload that directory under the iOS update's ID. Android
|
|
193
|
+
is the same with `android` in the path, `index.android.bundle` and the
|
|
194
|
+
Android update's ID:
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
mkdir -p maps/ios
|
|
198
|
+
cp dist/_expo/static/js/ios/entry-*.hbc maps/ios/main.jsbundle
|
|
199
|
+
cp dist/_expo/static/js/ios/entry-*.hbc.map maps/ios/main.jsbundle.map
|
|
200
|
+
libo11y-sourcemaps upload --endpoint https://app.example.com --service my-app \
|
|
201
|
+
--release 1.1.0 --update-id "$IOS_UPDATE_ID" --url-prefix ~/ maps/ios
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The lookup key is `service.version` and the update ID together. One
|
|
205
|
+
update served to two native app versions (two `--release` values) needs
|
|
206
|
+
its map uploaded once for each version. A store build's embedded bundle
|
|
207
|
+
has no update ID: upload its composed map with `--release` and no
|
|
208
|
+
`--update-id`.
|
|
209
|
+
|
|
210
|
+
Development stacks point at Metro and are sent as they are.
|
|
211
|
+
|
|
212
|
+
## Native crashes and hangs
|
|
213
|
+
|
|
214
|
+
On iOS, `@libo11y/react-native` ships an Expo module, `Libo11yNative`.
|
|
215
|
+
With it in the app binary, `errors()` also records the crashes and hangs
|
|
216
|
+
that MetricKit reports. MetricKit reports a crash on the app's next
|
|
217
|
+
launch, not when it happens, and a hang on the next launch or while the
|
|
218
|
+
app still runs. It runs outside the app, so it cannot crash the app or
|
|
219
|
+
slow it down. MetricKit names the process a report is about from iOS 17,
|
|
220
|
+
and only such reports are recorded.
|
|
221
|
+
|
|
222
|
+
- A **crash** is `o11y.rum.error` with source `crash`. `exception.type` is
|
|
223
|
+
the Objective-C or Swift exception name when iOS reports one (iOS 17
|
|
224
|
+
and later), else the Mach exception (`EXC_BAD_ACCESS`), else the
|
|
225
|
+
signal. `o11y.rum.error.signal` is the signal, such as `SIGSEGV`.
|
|
226
|
+
- A **hang** is source `hang`, type `AppHang`, with
|
|
227
|
+
`o11y.rum.error.hang_duration` in seconds.
|
|
228
|
+
- `exception.stacktrace` holds the crashed thread's stack, or for a hang
|
|
229
|
+
the main thread's most sampled stack, innermost frame first, one frame
|
|
230
|
+
per line as
|
|
231
|
+
`<index> <binary> 0x<address> 0x<load address> + <offset>`.
|
|
232
|
+
`o11y.rum.error.binary_images` lists the UUID, load address and name of
|
|
233
|
+
each binary in it. The gateway resolves the frames of every binary
|
|
234
|
+
whose dSYM was uploaded with `libo11y-sourcemaps dsyms`, and leaves
|
|
235
|
+
system frameworks as they are.
|
|
236
|
+
|
|
237
|
+
Each record keeps the session, screen, update ID and time of the moment
|
|
238
|
+
it happened, and nothing of the launch that delivers it, such as the
|
|
239
|
+
current user ID. While RUM runs, every change of session, screen, screen
|
|
240
|
+
name or whether the session is kept, and every move to the background,
|
|
241
|
+
writes them to a small history file through the module, which adds the
|
|
242
|
+
process ID and start time. MetricKit gives a report only the time range
|
|
243
|
+
of the payload it came in, so the report may have happened anywhere in
|
|
244
|
+
it. A report maps to the last entry its own process wrote at or before
|
|
245
|
+
the range's end, and is kept only when that process wrote an entry at or
|
|
246
|
+
before the range's start, so consent covered the whole range. Any other
|
|
247
|
+
report, and one without a process ID, is dropped, because nothing shows
|
|
248
|
+
its process recorded under consent when it happened. The cost: reports
|
|
249
|
+
from the launch that first granted consent, and any whose range starts
|
|
250
|
+
before its launch wrote its first entry, are dropped. A fatal JavaScript error marks its entry, so the native crash
|
|
251
|
+
React Native raises for it (`RCTFatal`) is not reported a second time.
|
|
252
|
+
The error also counts in a view summary of that screen, so the gateway's
|
|
253
|
+
error metrics include it for every consented session: in the screen's
|
|
254
|
+
own summary for a hang of the running app on its current screen, else in
|
|
255
|
+
one more summary of that screen, whose index the history keeps so a
|
|
256
|
+
later launch continues it. The record carries the `service.version` of
|
|
257
|
+
the launch that crashed, from its context entry or else from MetricKit,
|
|
258
|
+
so a crash of an earlier app version reported after an update is counted
|
|
259
|
+
under that version.
|
|
260
|
+
|
|
261
|
+
Consent applies as for JavaScript errors. The module keeps reports only
|
|
262
|
+
while RUM records under consent, and drops a report whose time is before
|
|
263
|
+
recording was switched on, so a report is about a process that could
|
|
264
|
+
have had consent. Revoking consent, or a launch that starts denied,
|
|
265
|
+
deletes the reports and the history it holds. Reports already handled are
|
|
266
|
+
remembered for 8 days, so MetricKit delivering one again does not send it
|
|
267
|
+
twice.
|
|
268
|
+
A report of an earlier session keeps the decision that session had: it
|
|
269
|
+
is sent when the session was kept, and when sampling left it out it is
|
|
270
|
+
not sent but still counted in the summary. A report is acknowledged, and
|
|
271
|
+
deleted from the module, once the pipeline took its record and its
|
|
272
|
+
summary, a flush exported them to delivery or its retry queue, and the
|
|
273
|
+
module wrote the mark that it was counted, so a crash before then does
|
|
274
|
+
not lose it. A report whose record or summary the pipeline dropped, as a
|
|
275
|
+
failing `attrReplacer` does, or whose mark could not be written, stays
|
|
276
|
+
for the next read. One read again after a failed flush sends
|
|
277
|
+
its record and its summary again; one read again after it was marked
|
|
278
|
+
counted sends its record but no summary.
|
|
279
|
+
|
|
280
|
+
Delivery is known per batch, not per record. A flush that fails for any
|
|
281
|
+
batch of logs leaves every report of that read for the next one, so a
|
|
282
|
+
report whose own batch did get through is sent, and counted, twice, and
|
|
283
|
+
a record the batch processor drops when its queue is full is not seen.
|
|
284
|
+
|
|
285
|
+
Revoking consent, or a launch that starts denied, returns once the
|
|
286
|
+
module has deleted what it holds. When it cannot delete a file, the
|
|
287
|
+
failure is logged, and nothing is recorded or read until a later
|
|
288
|
+
cleanup succeeds: the next revoke or denied start, or the next grant,
|
|
289
|
+
which retries it first. A fatal JavaScript error waits, within its
|
|
290
|
+
deadline, for the flush and for its context to be marked fatal. The module reads
|
|
291
|
+
its reports when `errors()` starts, 15 and 60 seconds later, then every
|
|
292
|
+
minute while RUM records, because MetricKit delivers a moment after
|
|
293
|
+
launch and sometimes later.
|
|
294
|
+
|
|
295
|
+
### Adopting the module in an Expo app
|
|
296
|
+
|
|
297
|
+
The module needs a new native build. Over-the-air updates keep working
|
|
298
|
+
on a binary built without it: the JavaScript finds no module and runs as
|
|
299
|
+
before.
|
|
300
|
+
|
|
301
|
+
1. Add `@libo11y/react-native` to the app's own `dependencies`, at the
|
|
302
|
+
same version as `@libo11y/rum-react-native`, so Expo's autolinking
|
|
303
|
+
finds it. No config plugin and no `app.json` change is needed, because
|
|
304
|
+
MetricKit needs no entitlement and no `Info.plist` key.
|
|
305
|
+
2. Build as usual. `npx expo prebuild` (or EAS Build) and `pod install`
|
|
306
|
+
add the `Libo11yNative` pod. It needs iOS 16.4 or later, the minimum
|
|
307
|
+
of Expo SDK 58's modules. Android builds include nothing from it.
|
|
308
|
+
3. Keep `errors()` in `rum.collectors`.
|
|
309
|
+
4. Upload each build's dSYMs, so native frames resolve. See
|
|
310
|
+
[`@libo11y/sourcemaps`](../sourcemaps#dsyms). Hermes is a prebuilt
|
|
311
|
+
framework without a dSYM in the archive. Download its dSYM from the
|
|
312
|
+
React Native release and upload it too.
|
|
313
|
+
|
|
314
|
+
The iOS simulator delivers no MetricKit reports. Check native crashes on
|
|
315
|
+
a device: crash the app, open it again, and the crash arrives with the
|
|
316
|
+
first batch.
|
|
317
|
+
|
|
318
|
+
## Taps
|
|
319
|
+
|
|
320
|
+
`taps()` records the touches `RumTouchBoundary` passes it. A touch is a
|
|
321
|
+
tap when the finger moved at most 10 points and the touch was not
|
|
322
|
+
cancelled (a scroll view that takes it cancels it), and a long press when
|
|
323
|
+
it was held 500 ms or more. A gesture with a second finger is neither.
|
|
324
|
+
Each one is an action span, `action tap` or `action long_press`, with
|
|
325
|
+
`o11y.rum.element.selector` and, when there is a privacy-safe one, the
|
|
326
|
+
action name. The span ends when the work it caused settles, as a click's
|
|
327
|
+
does in the browser. A screen it opened links to it as its cause.
|
|
328
|
+
|
|
329
|
+
The name is the closest explicit name, from the touched element up:
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
<RumName name="save-project">
|
|
333
|
+
<Pressable onPress={save}>
|
|
334
|
+
<Text>Save</Text>
|
|
335
|
+
</Pressable>
|
|
336
|
+
</RumName>
|
|
337
|
+
<AppButton o11yName="open-project" onPress={open} /> {/* a component of the app that takes o11yName */}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Without one, it is the tapped element's `aria-label` or
|
|
341
|
+
`accessibilityLabel`. An app whose labels can carry a person's data (a
|
|
342
|
+
contact's name on a row, say) sets `taps({ accessibilityNames: false })`,
|
|
343
|
+
and then only `o11yName` and `RumName` name taps. RUM never records text
|
|
344
|
+
a person typed or the text of an element. The tapped element is the closest one, from the touched
|
|
345
|
+
element up, with an `onPress`, `onLongPress` or `onClick` handler, a
|
|
346
|
+
button-like role, or a responder that is accessible, which is what
|
|
347
|
+
`Pressable`, the Touchables and a pressable `Text` render. The selector
|
|
348
|
+
is the element's type after the names of up to four components above it,
|
|
349
|
+
such as `ProjectRow > Pressable > RCTView`, or `unknown`. A minified build
|
|
350
|
+
leaves one-letter names, which the selector skips. With
|
|
351
|
+
`taps({ testIds: true })`, a `testID` (or `nativeID`) on the element is the
|
|
352
|
+
selector `#<testID>` when it looks like a fixed name in code: lowercase
|
|
353
|
+
letters, `_` and `-`, starting with a letter, at most 64 characters. IDs
|
|
354
|
+
with digits, capitals, spaces or an at sign, such as `client-${email}` or
|
|
355
|
+
a record's ID, never are, because the selector reaches the gateway's
|
|
356
|
+
storage. It is off by default.
|
|
357
|
+
`o11yName` is not in React Native's prop types, so a component of the app
|
|
358
|
+
declares it, or `RumName` names what it wraps.
|
|
359
|
+
|
|
360
|
+
Frustration signals: three taps on one element within a second are a
|
|
361
|
+
`rage` signal, and an error within a second of a tap, or while its action
|
|
362
|
+
is open, an `error` signal. Dead taps are not detected, because React
|
|
363
|
+
Native has no signal that a tap changed nothing on screen.
|
|
364
|
+
`taps({ frustration: false })` turns both off, and `rageTaps` sets the
|
|
365
|
+
count.
|
|
366
|
+
|
|
367
|
+
### How taps are seen, and the trade-off
|
|
368
|
+
|
|
369
|
+
`RumTouchBoundary` is one plain `View` at the root with `onTouchStart`,
|
|
370
|
+
`onTouchEnd` and `onTouchCancel` handlers. Touch events bubble to it
|
|
371
|
+
whatever handles them, and it never asks to become the responder, so it
|
|
372
|
+
changes no press, gesture or scroll. It works with Fabric and React
|
|
373
|
+
Native 0.88's `EventTarget` event dispatch, and with the legacy dispatch.
|
|
374
|
+
|
|
375
|
+
- React Native runs the responder system, and so `onPress`, before the
|
|
376
|
+
touch events bubble. A tap is known only after its handler ran. The
|
|
377
|
+
tap's span starts then, the requests its handler started are not its
|
|
378
|
+
children (they started first), but the tap waits for them to finish
|
|
379
|
+
before it settles. A screen the handler navigated to starts after the
|
|
380
|
+
tap, so the link from the screen to the tap holds.
|
|
381
|
+
- React Native hands a touch handler only the touched host element. Its
|
|
382
|
+
props, and its parents', are reachable only through React's internal
|
|
383
|
+
instance handle (`__internalInstanceHandle` on Fabric, `_targetInst` on
|
|
384
|
+
the legacy dispatch). RUM reads them without changing anything, and a
|
|
385
|
+
React Native release that removes the handle leaves taps recorded
|
|
386
|
+
without a name.
|
|
387
|
+
|
|
388
|
+
The alternatives were wrapping every pressable, which needs code at each
|
|
389
|
+
element, and patching `React.createElement` or the JSX runtime to wrap
|
|
390
|
+
every `onPress`, which would put RUM inside every press of the app.
|
|
391
|
+
|
|
392
|
+
## Status
|
|
393
|
+
|
|
394
|
+
A preview. The package first ships in `ts/v0.6.0`, is published on npm at
|
|
395
|
+
`0.7.0` (and attached as a tarball to the
|
|
396
|
+
[`ts/v0.7.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.7.0)),
|
|
397
|
+
and its API can change in a minor release. Errors, taps and the Expo
|
|
398
|
+
Router adapter [`@libo11y/rum-expo-router`](../rum-expo-router) ship with
|
|
399
|
+
it. Native crashes and hangs on iOS and the native app start come with
|
|
400
|
+
the native module in `@libo11y/react-native`, from `ts/v0.7.0`. Android
|
|
401
|
+
native crashes are not recorded yet.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app_load span on React Native: once per process, the app's start until its
|
|
3
|
+
* first screen rendered. It starts at the process start the libo11y native module reads from the
|
|
4
|
+
* kernel (sysctl kinfo_proc) when the app binary has the module, else at
|
|
5
|
+
* performance.rnStartupTiming.startTime when that is a finite time before setup (React Native's
|
|
6
|
+
* measure of the native process start), else when `@libo11y/rum-react-native` was first evaluated. The setup reports every rum.startView and
|
|
7
|
+
* rum.viewRendered here, consent or not, so the first screen's render is known even when consent
|
|
8
|
+
* comes later or after other screens. app_load is recorded when the first grant of the process
|
|
9
|
+
* begins the load view, with its session.id and view ID, and is the load view span's parent
|
|
10
|
+
* (appLoadStarted). It ends at the first screen's render, or capMillis after its start without one,
|
|
11
|
+
* as when the app moved to another screen before the first rendered.
|
|
12
|
+
*/
|
|
13
|
+
import { type RumRuntime } from "@libo11y/rum/core";
|
|
14
|
+
import type { RumReactNativeEnv } from "./contracts/env.ts";
|
|
15
|
+
/** app_load ends this long after it started at the latest. */
|
|
16
|
+
export declare const APP_LOAD_CAP_MILLIS = 60000;
|
|
17
|
+
/** The app start recorder of one process. */
|
|
18
|
+
export interface AppStart {
|
|
19
|
+
/** The app's start, in performance.now() time: where app_load and the first screen begin. */
|
|
20
|
+
readonly start: number;
|
|
21
|
+
/** Records app_load on runtime when its first grant begins the load view. */
|
|
22
|
+
attach(runtime: RumRuntime): void;
|
|
23
|
+
/** rum.startView was called: the first screen is gone. */
|
|
24
|
+
screenStarted(): void;
|
|
25
|
+
/** rum.viewRendered was called at, in performance.now() time. */
|
|
26
|
+
rendered(at: number): void;
|
|
27
|
+
/** Ends an open app_load now (shutdown) and stops listening. */
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
30
|
+
export interface AppStartOptions {
|
|
31
|
+
readonly env: RumReactNativeEnv;
|
|
32
|
+
/** performance.now(). */
|
|
33
|
+
readonly now: () => number;
|
|
34
|
+
/** The epoch milliseconds performance.now() counts from, to place env.processStart. Default 0. */
|
|
35
|
+
readonly timeOrigin?: number;
|
|
36
|
+
/** Default APP_LOAD_CAP_MILLIS. */
|
|
37
|
+
readonly capMillis?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function createAppStart(o: AppStartOptions): AppStart;
|