@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/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,288 @@
|
|
|
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
|
|
102
|
+
`performance.rnStartupTiming.startTime` (or, without it, when this
|
|
103
|
+
package was loaded) to the first screen's render, at most 60 seconds.
|
|
104
|
+
When consent is granted after the first screen rendered, even after
|
|
105
|
+
other screens, the span is still recorded, with the times remembered
|
|
106
|
+
from before the grant. An app that leaves its first screen before it
|
|
107
|
+
rendered records the 60-second cap.
|
|
108
|
+
- **Requests.** `@libo11y/react-native`'s fetch and XHR spans count
|
|
109
|
+
toward the screen's summary and leave breadcrumbs.
|
|
110
|
+
`rum.onRequestStart` hooks run on each of them, which is how
|
|
111
|
+
`connectRequestNaming` names Connect calls.
|
|
112
|
+
- **Errors**, with `errors()`. See [Errors](#errors).
|
|
113
|
+
- **Taps and frustration signals**, with `taps()` and `RumTouchBoundary`.
|
|
114
|
+
See [Taps](#taps).
|
|
115
|
+
|
|
116
|
+
Revoking consent removes the session, the retention buffer and the
|
|
117
|
+
remote configuration cache from the app's storage, also when only an
|
|
118
|
+
earlier launch had consent. An awaited `consent.revoke()` resolves once
|
|
119
|
+
storage holds none of them. A launch that starts with consent `denied`
|
|
120
|
+
removes them before setup resolves, so a later grant starts a new
|
|
121
|
+
session. A launch that starts `pending` leaves them in place.
|
|
122
|
+
|
|
123
|
+
The resource carries `o11y.rum.platform` `react_native`, and so do RUM's
|
|
124
|
+
own view spans, summaries and `o11y.rum.session.start`. App metrics export
|
|
125
|
+
with delta temporality, which the RUM gateway requires. Requests from an app carry no `Origin`, so the gateway's
|
|
126
|
+
entry for the app sets `allow_missing_origin` and a `client_token`.
|
|
127
|
+
|
|
128
|
+
Context does not carry across `await` on Hermes, which has no
|
|
129
|
+
`AsyncLocalStorage`. A request made after an `await` in a tap handler is
|
|
130
|
+
not that tap's child.
|
|
131
|
+
|
|
132
|
+
## Errors
|
|
133
|
+
|
|
134
|
+
`errors()` records each error as `o11y.rum.error` with its breadcrumbs
|
|
135
|
+
(screens, taps and requests). It counts in the screen's summary, and it
|
|
136
|
+
keeps a session that sampling left out, which then sends the detail its
|
|
137
|
+
retention buffer held. It records only while consent is granted.
|
|
138
|
+
|
|
139
|
+
- **Uncaught errors** reach React Native's global handler
|
|
140
|
+
(`ErrorUtils.setGlobalHandler`). RUM records each one as `uncaught`
|
|
141
|
+
and then hands it to the handler installed before it, so the red box,
|
|
142
|
+
LogBox and the crash still happen. In a release build a fatal error
|
|
143
|
+
ends the app, so RUM first emits the screen's summary and flushes,
|
|
144
|
+
which saves the batches to the app's storage, and hands the error on
|
|
145
|
+
when the flush is done or after 2 seconds. A batch the app could not
|
|
146
|
+
send goes out on the next launch. In development the error is handed
|
|
147
|
+
on at once.
|
|
148
|
+
- **Unhandled promise rejections** on Hermes are `unhandled_rejection`.
|
|
149
|
+
Hermes reports them only to the tracker
|
|
150
|
+
`HermesInternal.enablePromiseRejectionTracker` sets, React Native sets
|
|
151
|
+
one in development only, and a new one replaces it. RUM sets its own
|
|
152
|
+
and, in development, reports each rejection to the red box as React
|
|
153
|
+
Native's does. Another library that sets a tracker after RUM replaces
|
|
154
|
+
RUM's.
|
|
155
|
+
- **Failed requests**, ended without a response, are `network`, unless
|
|
156
|
+
the app aborted them.
|
|
157
|
+
- **Render errors** never reach the global handler: React hands them to
|
|
158
|
+
an error boundary. Wrap the app in `@libo11y/rum-react`'s
|
|
159
|
+
`RumErrorBoundary`, or report from the app's own boundary:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
componentDidCatch(error: unknown, info: React.ErrorInfo): void {
|
|
163
|
+
rum.addError(error, { source: "boundary", componentStack: info.componentStack ?? undefined });
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
A render error no boundary catches crashes the app without passing the
|
|
168
|
+
global handler, so RUM never sees it.
|
|
169
|
+
|
|
170
|
+
Release stacks reach the gateway readable. Hermes names the bundle by its
|
|
171
|
+
path on the device, so RUM rewrites each frame of the app's bundle to
|
|
172
|
+
`app:///main.jsbundle` on iOS and `app:///index.android.bundle` on
|
|
173
|
+
Android, and keeps engine frames (`native`, `InternalBytecode.js`). A
|
|
174
|
+
frame `address at` the bundle carries a bytecode offset, which Hermes
|
|
175
|
+
prints 0-based; RUM sends it as the 1-based column the gateway reads, so
|
|
176
|
+
offset 114 is sent as column 115. The gateway finds a stack's source map
|
|
177
|
+
by the resource's `service.version` and `o11y.rum.app.update_id` (which
|
|
178
|
+
`setupRumExpo` fills in) and that script path.
|
|
179
|
+
|
|
180
|
+
For an over-the-air update, `expo export --platform ios --source-maps`
|
|
181
|
+
writes the bytecode bundle `dist/_expo/static/js/ios/entry-<hash>.hbc`
|
|
182
|
+
and its map `dist/_expo/static/js/ios/entry-<hash>.hbc.map`, which Expo
|
|
183
|
+
has already composed from Metro's map and the Hermes compiler's, so it
|
|
184
|
+
maps bytecode offsets to your sources. Copy the map to
|
|
185
|
+
`main.jsbundle.map` and the bundle to `main.jsbundle` in a directory of
|
|
186
|
+
their own, and upload that directory under the iOS update's ID. Android
|
|
187
|
+
is the same with `android` in the path, `index.android.bundle` and the
|
|
188
|
+
Android update's ID:
|
|
189
|
+
|
|
190
|
+
```sh
|
|
191
|
+
mkdir -p maps/ios
|
|
192
|
+
cp dist/_expo/static/js/ios/entry-*.hbc maps/ios/main.jsbundle
|
|
193
|
+
cp dist/_expo/static/js/ios/entry-*.hbc.map maps/ios/main.jsbundle.map
|
|
194
|
+
libo11y-sourcemaps upload --endpoint https://app.example.com --service my-app \
|
|
195
|
+
--release 1.1.0 --update-id "$IOS_UPDATE_ID" --url-prefix ~/ maps/ios
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The lookup key is `service.version` and the update ID together. One
|
|
199
|
+
update served to two native app versions (two `--release` values) needs
|
|
200
|
+
its map uploaded once for each version. A store build's embedded bundle
|
|
201
|
+
has no update ID: upload its composed map with `--release` and no
|
|
202
|
+
`--update-id`.
|
|
203
|
+
|
|
204
|
+
Development stacks point at Metro and are sent as they are.
|
|
205
|
+
|
|
206
|
+
## Taps
|
|
207
|
+
|
|
208
|
+
`taps()` records the touches `RumTouchBoundary` passes it. A touch is a
|
|
209
|
+
tap when the finger moved at most 10 points and the touch was not
|
|
210
|
+
cancelled (a scroll view that takes it cancels it), and a long press when
|
|
211
|
+
it was held 500 ms or more. A gesture with a second finger is neither.
|
|
212
|
+
Each one is an action span, `action tap` or `action long_press`, with
|
|
213
|
+
`o11y.rum.element.selector` and, when there is a privacy-safe one, the
|
|
214
|
+
action name. The span ends when the work it caused settles, as a click's
|
|
215
|
+
does in the browser. A screen it opened links to it as its cause.
|
|
216
|
+
|
|
217
|
+
The name is the closest explicit name, from the touched element up:
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
<RumName name="save-project">
|
|
221
|
+
<Pressable onPress={save}>
|
|
222
|
+
<Text>Save</Text>
|
|
223
|
+
</Pressable>
|
|
224
|
+
</RumName>
|
|
225
|
+
<AppButton o11yName="open-project" onPress={open} /> {/* a component of the app that takes o11yName */}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Without one, it is the tapped element's `aria-label` or
|
|
229
|
+
`accessibilityLabel`. An app whose labels can carry a person's data (a
|
|
230
|
+
contact's name on a row, say) sets `taps({ accessibilityNames: false })`,
|
|
231
|
+
and then only `o11yName` and `RumName` name taps. RUM never records text
|
|
232
|
+
a person typed or the text of an element. The tapped element is the closest one, from the touched
|
|
233
|
+
element up, with an `onPress`, `onLongPress` or `onClick` handler, a
|
|
234
|
+
button-like role, or a responder that is accessible, which is what
|
|
235
|
+
`Pressable`, the Touchables and a pressable `Text` render. The selector
|
|
236
|
+
is the element's type after the names of up to four components above it,
|
|
237
|
+
such as `ProjectRow > Pressable > RCTView`, or `unknown`. A minified build
|
|
238
|
+
leaves one-letter names, which the selector skips. With
|
|
239
|
+
`taps({ testIds: true })`, a `testID` (or `nativeID`) on the element is the
|
|
240
|
+
selector `#<testID>` when it looks like a fixed name in code: lowercase
|
|
241
|
+
letters, `_` and `-`, starting with a letter, at most 64 characters. IDs
|
|
242
|
+
with digits, capitals, spaces or an at sign, such as `client-${email}` or
|
|
243
|
+
a record's ID, never are, because the selector reaches the gateway's
|
|
244
|
+
storage. It is off by default.
|
|
245
|
+
`o11yName` is not in React Native's prop types, so a component of the app
|
|
246
|
+
declares it, or `RumName` names what it wraps.
|
|
247
|
+
|
|
248
|
+
Frustration signals: three taps on one element within a second are a
|
|
249
|
+
`rage` signal, and an error within a second of a tap, or while its action
|
|
250
|
+
is open, an `error` signal. Dead taps are not detected, because React
|
|
251
|
+
Native has no signal that a tap changed nothing on screen.
|
|
252
|
+
`taps({ frustration: false })` turns both off, and `rageTaps` sets the
|
|
253
|
+
count.
|
|
254
|
+
|
|
255
|
+
### How taps are seen, and the trade-off
|
|
256
|
+
|
|
257
|
+
`RumTouchBoundary` is one plain `View` at the root with `onTouchStart`,
|
|
258
|
+
`onTouchEnd` and `onTouchCancel` handlers. Touch events bubble to it
|
|
259
|
+
whatever handles them, and it never asks to become the responder, so it
|
|
260
|
+
changes no press, gesture or scroll. It works with Fabric and React
|
|
261
|
+
Native 0.88's `EventTarget` event dispatch, and with the legacy dispatch.
|
|
262
|
+
|
|
263
|
+
- React Native runs the responder system, and so `onPress`, before the
|
|
264
|
+
touch events bubble. A tap is known only after its handler ran. The
|
|
265
|
+
tap's span starts then, the requests its handler started are not its
|
|
266
|
+
children (they started first), but the tap waits for them to finish
|
|
267
|
+
before it settles. A screen the handler navigated to starts after the
|
|
268
|
+
tap, so the link from the screen to the tap holds.
|
|
269
|
+
- React Native hands a touch handler only the touched host element. Its
|
|
270
|
+
props, and its parents', are reachable only through React's internal
|
|
271
|
+
instance handle (`__internalInstanceHandle` on Fabric, `_targetInst` on
|
|
272
|
+
the legacy dispatch). RUM reads them without changing anything, and a
|
|
273
|
+
React Native release that removes the handle leaves taps recorded
|
|
274
|
+
without a name.
|
|
275
|
+
|
|
276
|
+
The alternatives were wrapping every pressable, which needs code at each
|
|
277
|
+
element, and patching `React.createElement` or the JSX runtime to wrap
|
|
278
|
+
every `onPress`, which would put RUM inside every press of the app.
|
|
279
|
+
|
|
280
|
+
## Status
|
|
281
|
+
|
|
282
|
+
A preview. The package first ships in `ts/v0.6.0`, is published on npm at
|
|
283
|
+
`0.6.0` (and attached as a tarball to the
|
|
284
|
+
[`ts/v0.6.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.6.0)),
|
|
285
|
+
and its API can change in a minor release. Errors, taps and the Expo
|
|
286
|
+
Router adapter [`@libo11y/rum-expo-router`](../rum-expo-router) ship with
|
|
287
|
+
it. Native crashes, hangs and the native app start come with the native
|
|
288
|
+
module.
|
|
@@ -0,0 +1,36 @@
|
|
|
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 performance.rnStartupTiming.startTime when that is a finite
|
|
4
|
+
* time before setup (React Native's measure of the native process start), else when
|
|
5
|
+
* `@libo11y/rum-react-native` was first evaluated. The setup reports every rum.startView and
|
|
6
|
+
* rum.viewRendered here, consent or not, so the first screen's render is known even when consent
|
|
7
|
+
* comes later or after other screens. app_load is recorded when the first grant of the process
|
|
8
|
+
* begins the load view, with its session.id and view ID, and is the load view span's parent
|
|
9
|
+
* (appLoadStarted). It ends at the first screen's render, or capMillis after its start without one,
|
|
10
|
+
* as when the app moved to another screen before the first rendered.
|
|
11
|
+
*/
|
|
12
|
+
import { type RumRuntime } from "@libo11y/rum/core";
|
|
13
|
+
import type { RumReactNativeEnv } from "./contracts/env.ts";
|
|
14
|
+
/** app_load ends this long after it started at the latest. */
|
|
15
|
+
export declare const APP_LOAD_CAP_MILLIS = 60000;
|
|
16
|
+
/** The app start recorder of one process. */
|
|
17
|
+
export interface AppStart {
|
|
18
|
+
/** The app's start, in performance.now() time: where app_load and the first screen begin. */
|
|
19
|
+
readonly start: number;
|
|
20
|
+
/** Records app_load on runtime when its first grant begins the load view. */
|
|
21
|
+
attach(runtime: RumRuntime): void;
|
|
22
|
+
/** rum.startView was called: the first screen is gone. */
|
|
23
|
+
screenStarted(): void;
|
|
24
|
+
/** rum.viewRendered was called at, in performance.now() time. */
|
|
25
|
+
rendered(at: number): void;
|
|
26
|
+
/** Ends an open app_load now (shutdown) and stops listening. */
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
29
|
+
export interface AppStartOptions {
|
|
30
|
+
readonly env: RumReactNativeEnv;
|
|
31
|
+
/** performance.now(). */
|
|
32
|
+
readonly now: () => number;
|
|
33
|
+
/** Default APP_LOAD_CAP_MILLIS. */
|
|
34
|
+
readonly capMillis?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function createAppStart(o: AppStartOptions): AppStart;
|
|
@@ -0,0 +1,81 @@
|
|
|
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 performance.rnStartupTiming.startTime when that is a finite
|
|
4
|
+
* time before setup (React Native's measure of the native process start), else when
|
|
5
|
+
* `@libo11y/rum-react-native` was first evaluated. The setup reports every rum.startView and
|
|
6
|
+
* rum.viewRendered here, consent or not, so the first screen's render is known even when consent
|
|
7
|
+
* comes later or after other screens. app_load is recorded when the first grant of the process
|
|
8
|
+
* begins the load view, with its session.id and view ID, and is the load view span's parent
|
|
9
|
+
* (appLoadStarted). It ends at the first screen's render, or capMillis after its start without one,
|
|
10
|
+
* as when the app moved to another screen before the first rendered.
|
|
11
|
+
*/
|
|
12
|
+
import { APP_LOAD_SPAN, ATTR_SESSION_ID } from "@libo11y/rum/core";
|
|
13
|
+
import { ATTR_RUM_PLATFORM, ATTR_RUM_SPAN_SHAPE, ATTR_RUM_VIEW_ID, RUM_SPAN_SHAPE_VALUE_APP_LOAD, } from "@libo11y/spec";
|
|
14
|
+
import { ROOT_CONTEXT, SpanKind } from "@opentelemetry/api";
|
|
15
|
+
/** app_load ends this long after it started at the latest. */
|
|
16
|
+
export const APP_LOAD_CAP_MILLIS = 60_000;
|
|
17
|
+
/** The app start, in performance.now() time: React Native's process start when it is usable. */
|
|
18
|
+
function startOf(env, now) {
|
|
19
|
+
const s = env.startupTiming?.startTime;
|
|
20
|
+
return typeof s === "number" && Number.isFinite(s) && s >= 0 && s < now ? s : env.loadedAt;
|
|
21
|
+
}
|
|
22
|
+
export function createAppStart(o) {
|
|
23
|
+
const start = startOf(o.env, o.now());
|
|
24
|
+
const capAt = start + (o.capMillis ?? APP_LOAD_CAP_MILLIS);
|
|
25
|
+
let recorded = false;
|
|
26
|
+
/** The first screen was left before it rendered. */
|
|
27
|
+
let left = false;
|
|
28
|
+
let firstRender;
|
|
29
|
+
let timer;
|
|
30
|
+
let off;
|
|
31
|
+
/** Ends the open app_load at a performance.now() time, within its start and cap. */
|
|
32
|
+
let end;
|
|
33
|
+
const record = (rt, viewId, sessionId) => {
|
|
34
|
+
recorded = true;
|
|
35
|
+
const span = rt.tracer.startSpan(APP_LOAD_SPAN, {
|
|
36
|
+
kind: SpanKind.INTERNAL,
|
|
37
|
+
startTime: rt.timeOrigin + start,
|
|
38
|
+
attributes: {
|
|
39
|
+
[ATTR_RUM_SPAN_SHAPE]: RUM_SPAN_SHAPE_VALUE_APP_LOAD,
|
|
40
|
+
[ATTR_RUM_PLATFORM]: rt.platform,
|
|
41
|
+
[ATTR_RUM_VIEW_ID]: viewId,
|
|
42
|
+
[ATTR_SESSION_ID]: sessionId,
|
|
43
|
+
},
|
|
44
|
+
}, ROOT_CONTEXT);
|
|
45
|
+
rt.views.appLoadStarted(span.spanContext());
|
|
46
|
+
end = (at) => {
|
|
47
|
+
end = undefined;
|
|
48
|
+
o.env.clearTimeout(timer);
|
|
49
|
+
span.end(rt.timeOrigin + Math.max(start, Math.min(at, capAt)));
|
|
50
|
+
};
|
|
51
|
+
if (firstRender !== undefined)
|
|
52
|
+
end(firstRender);
|
|
53
|
+
else
|
|
54
|
+
timer = o.env.setTimeout(() => end?.(capAt), Math.max(0, capAt - o.now()));
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
start,
|
|
58
|
+
attach(rt) {
|
|
59
|
+
off?.();
|
|
60
|
+
off = rt.views.subscribe((e) => {
|
|
61
|
+
if (e.type !== "start" || recorded || e.view.id !== rt.views.loadView()?.id)
|
|
62
|
+
return;
|
|
63
|
+
record(rt, e.view.id, e.view.sessionId);
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
screenStarted() {
|
|
67
|
+
left = true;
|
|
68
|
+
},
|
|
69
|
+
rendered(at) {
|
|
70
|
+
if (left || firstRender !== undefined)
|
|
71
|
+
return;
|
|
72
|
+
firstRender = at;
|
|
73
|
+
end?.(at);
|
|
74
|
+
},
|
|
75
|
+
close() {
|
|
76
|
+
off?.();
|
|
77
|
+
off = undefined;
|
|
78
|
+
end?.(o.now());
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The React Native binding of the RUM core: setupRumCore hands it the setup options with
|
|
3
|
+
* RUM's span processor, context manager and forwarding span exporter in place, and the wrappers;
|
|
4
|
+
* it runs `@libo11y/react-native`'s setupReactNativeWith over deps with each wrapper applied. The
|
|
5
|
+
* lifecycle is the app's AppState: background, and inactive on iOS, hide the app; active shows it.
|
|
6
|
+
*/
|
|
7
|
+
import type { ReactNativeSetupOptions, ReactNativeTelemetry } from "@libo11y/react-native";
|
|
8
|
+
import { type AppLifecycle, type ReactNativeDeps } from "@libo11y/react-native/internal";
|
|
9
|
+
import type { RumBind, RumLifecycle } from "@libo11y/rum/core";
|
|
10
|
+
/** A binding of React Native: its setup options and telemetry. */
|
|
11
|
+
export type ReactNativeRumBind = RumBind<ReactNativeSetupOptions, ReactNativeTelemetry>;
|
|
12
|
+
/** How the binding runs the platform. */
|
|
13
|
+
export interface ReactNativeBindingOptions {
|
|
14
|
+
/** Install the telemetry globally, as setupReactNative does. */
|
|
15
|
+
readonly install: boolean;
|
|
16
|
+
/** The fetch the OTLP transport sends with instead of the pristine global fetch, as in tests. */
|
|
17
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
18
|
+
}
|
|
19
|
+
/** The React Native binding: setupReactNativeWith over deps with RUM's wrappers. */
|
|
20
|
+
export declare function reactNativeBinding(deps: ReactNativeDeps, o: ReactNativeBindingOptions): ReactNativeRumBind;
|
|
21
|
+
/**
|
|
22
|
+
* RUM's lifecycle over the app's: hide on going to the background, show on coming back. RUM
|
|
23
|
+
* subscribes before the binding runs the platform's setup, so on a hide the summaries are emitted
|
|
24
|
+
* before the platform's own listener flushes them. No restore: an app has no back/forward cache.
|
|
25
|
+
* The setup adds activity: a new screen, until the touch boundary records touches.
|
|
26
|
+
*/
|
|
27
|
+
export declare function rumLifecycle(app: AppLifecycle): RumLifecycle;
|
package/dist/binding.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { setupReactNativeWith, } from "@libo11y/react-native/internal";
|
|
2
|
+
/** The React Native binding: setupReactNativeWith over deps with RUM's wrappers. */
|
|
3
|
+
export function reactNativeBinding(deps, o) {
|
|
4
|
+
const fetch = o.fetch;
|
|
5
|
+
return (options, w) => setupReactNativeWith(options, {
|
|
6
|
+
...deps,
|
|
7
|
+
createConsentController: (co) => w.consentController(deps.createConsentController(co)),
|
|
8
|
+
createHttpTransport: (t) => deps.createHttpTransport(w.transportOptions(fetch === undefined ? t : { ...t, fetch })),
|
|
9
|
+
// Traces are injected, so the platform's span exporter goes unused; logs are routed by
|
|
10
|
+
// session. The gateway accepts only delta sums and histograms, so app metrics export with
|
|
11
|
+
// delta temporality.
|
|
12
|
+
createExporterSet: (req, d, endpoints, eo) => w.exporterSet(deps.createExporterSet(req, d, endpoints, { ...eo, metricTemporality: "delta" })),
|
|
13
|
+
installNetworkInstrumentation: (n) => deps.installNetworkInstrumentation({ ...n, onStart: w.onRequestStart }),
|
|
14
|
+
onPlatform: (platform, info) => {
|
|
15
|
+
w.platform({ delivery: info.delivery, endpoints: info.endpoints }, info.env);
|
|
16
|
+
deps.onPlatform?.(platform, info);
|
|
17
|
+
},
|
|
18
|
+
}, o.install);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* RUM's lifecycle over the app's: hide on going to the background, show on coming back. RUM
|
|
22
|
+
* subscribes before the binding runs the platform's setup, so on a hide the summaries are emitted
|
|
23
|
+
* before the platform's own listener flushes them. No restore: an app has no back/forward cache.
|
|
24
|
+
* The setup adds activity: a new screen, until the touch boundary records touches.
|
|
25
|
+
*/
|
|
26
|
+
export function rumLifecycle(app) {
|
|
27
|
+
return {
|
|
28
|
+
visible: () => app.visible(),
|
|
29
|
+
subscribe: (h) => app.subscribe((visible) => (visible ? h.show() : h.hide())),
|
|
30
|
+
};
|
|
31
|
+
}
|