@libo11y/rum 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +461 -2
  3. package/dist/actions/collector.d.ts +29 -0
  4. package/dist/actions/collector.js +260 -0
  5. package/dist/actions/naming.d.ts +15 -0
  6. package/dist/actions/naming.js +65 -0
  7. package/dist/actions/record.d.ts +13 -0
  8. package/dist/actions/record.js +28 -0
  9. package/dist/actions/settle.d.ts +28 -0
  10. package/dist/actions/settle.js +53 -0
  11. package/dist/attrs.d.ts +10 -0
  12. package/dist/attrs.js +12 -0
  13. package/dist/bind.d.ts +23 -0
  14. package/dist/bind.js +55 -0
  15. package/dist/bootstrap/buffer.d.ts +72 -0
  16. package/dist/bootstrap/buffer.js +95 -0
  17. package/dist/bootstrap/replay.d.ts +10 -0
  18. package/dist/bootstrap/replay.js +11 -0
  19. package/dist/bootstrap.d.ts +17 -0
  20. package/dist/bootstrap.js +33 -0
  21. package/dist/bus.d.ts +3 -0
  22. package/dist/bus.js +21 -0
  23. package/dist/config/clamp.d.ts +34 -0
  24. package/dist/config/clamp.js +79 -0
  25. package/dist/config/remote.d.ts +80 -0
  26. package/dist/config/remote.js +209 -0
  27. package/dist/context-manager.d.ts +8 -0
  28. package/dist/context-manager.js +29 -0
  29. package/dist/contracts/binding.d.ts +80 -0
  30. package/dist/contracts/binding.js +1 -0
  31. package/dist/contracts/retention.d.ts +28 -0
  32. package/dist/contracts/retention.js +1 -0
  33. package/dist/contracts/runtime.d.ts +154 -0
  34. package/dist/contracts/runtime.js +1 -0
  35. package/dist/contracts/session.d.ts +63 -0
  36. package/dist/contracts/session.js +1 -0
  37. package/dist/contracts/summary.d.ts +28 -0
  38. package/dist/contracts/summary.js +1 -0
  39. package/dist/contracts/views.d.ts +71 -0
  40. package/dist/contracts/views.js +1 -0
  41. package/dist/core-setup.d.ts +86 -0
  42. package/dist/core-setup.js +902 -0
  43. package/dist/core.d.ts +42 -0
  44. package/dist/core.js +35 -0
  45. package/dist/errors/breadcrumbs.d.ts +16 -0
  46. package/dist/errors/breadcrumbs.js +27 -0
  47. package/dist/errors/collector.d.ts +17 -0
  48. package/dist/errors/collector.js +186 -0
  49. package/dist/errors/normalize.d.ts +7 -0
  50. package/dist/errors/normalize.js +31 -0
  51. package/dist/errors/record.d.ts +20 -0
  52. package/dist/errors/record.js +46 -0
  53. package/dist/frustration/detect.d.ts +38 -0
  54. package/dist/frustration/detect.js +62 -0
  55. package/dist/ids.d.ts +2 -0
  56. package/dist/ids.js +2 -0
  57. package/dist/index.d.ts +19 -0
  58. package/dist/index.js +12 -0
  59. package/dist/internal.d.ts +28 -0
  60. package/dist/internal.js +26 -0
  61. package/dist/loaf.d.ts +15 -0
  62. package/dist/loaf.js +27 -0
  63. package/dist/options.d.ts +84 -0
  64. package/dist/options.js +1 -0
  65. package/dist/pending-spans.d.ts +29 -0
  66. package/dist/pending-spans.js +92 -0
  67. package/dist/query.d.ts +2 -0
  68. package/dist/query.js +19 -0
  69. package/dist/resources/collector.d.ts +76 -0
  70. package/dist/resources/collector.js +270 -0
  71. package/dist/resources/server-timing.d.ts +18 -0
  72. package/dist/resources/server-timing.js +21 -0
  73. package/dist/retention/buffer.d.ts +25 -0
  74. package/dist/retention/buffer.js +104 -0
  75. package/dist/retention/exporters.d.ts +17 -0
  76. package/dist/retention/exporters.js +67 -0
  77. package/dist/retention/sessions.d.ts +4 -0
  78. package/dist/retention/sessions.js +30 -0
  79. package/dist/session/local-store.d.ts +25 -0
  80. package/dist/session/local-store.js +91 -0
  81. package/dist/session/manager.d.ts +36 -0
  82. package/dist/session/manager.js +169 -0
  83. package/dist/session/sampling.d.ts +4 -0
  84. package/dist/session/sampling.js +20 -0
  85. package/dist/session/state.d.ts +4 -0
  86. package/dist/session/state.js +28 -0
  87. package/dist/settings.d.ts +8 -0
  88. package/dist/settings.js +36 -0
  89. package/dist/setup.d.ts +40 -0
  90. package/dist/setup.js +49 -0
  91. package/dist/span-processor.d.ts +38 -0
  92. package/dist/span-processor.js +125 -0
  93. package/dist/summary/accumulator.d.ts +25 -0
  94. package/dist/summary/accumulator.js +126 -0
  95. package/dist/version.d.ts +2 -0
  96. package/dist/version.js +2 -0
  97. package/dist/views/collector.d.ts +40 -0
  98. package/dist/views/collector.js +285 -0
  99. package/dist/views/history.d.ts +18 -0
  100. package/dist/views/history.js +42 -0
  101. package/dist/views/naming.d.ts +6 -0
  102. package/dist/views/naming.js +12 -0
  103. package/dist/views/paint.d.ts +12 -0
  104. package/dist/views/paint.js +15 -0
  105. package/dist/views/tracker.d.ts +28 -0
  106. package/dist/views/tracker.js +117 -0
  107. package/dist/vitals/attribution.d.ts +14 -0
  108. package/dist/vitals/attribution.js +60 -0
  109. package/dist/vitals/collector.d.ts +24 -0
  110. package/dist/vitals/collector.js +232 -0
  111. package/dist/vitals/lcp.d.ts +32 -0
  112. package/dist/vitals/lcp.js +49 -0
  113. package/dist/webext/chrome.d.ts +45 -0
  114. package/dist/webext/chrome.js +13 -0
  115. package/dist/webext/config-storage.d.ts +7 -0
  116. package/dist/webext/config-storage.js +47 -0
  117. package/dist/webext/scope.d.ts +22 -0
  118. package/dist/webext/scope.js +50 -0
  119. package/dist/webext/session-access.d.ts +13 -0
  120. package/dist/webext/session-access.js +9 -0
  121. package/dist/webext/session-store.d.ts +5 -0
  122. package/dist/webext/session-store.js +94 -0
  123. package/dist/webext/setup.d.ts +71 -0
  124. package/dist/webext/setup.js +193 -0
  125. package/dist/webext.d.ts +10 -0
  126. package/dist/webext.js +8 -0
  127. package/dist/wire.d.ts +13 -0
  128. package/dist/wire.js +30 -0
  129. package/package.json +57 -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,462 @@
1
- # Temporary Holding Version
1
+ # @libo11y/rum
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Real user monitoring (RUM) for browsers, built on
4
+ [`@libo11y/web`](https://github.com/jamesainslie/libo11y/tree/main/ts/packages/web).
5
+ `setupRum()` runs the web platform with RUM wired in. It keeps one session
6
+ across the tabs of an origin, samples sessions, and sends a summary of
7
+ every view to the RUM gateway.
8
+
9
+ ```sh
10
+ npm install @libo11y/rum
11
+ ```
12
+
13
+ ## Status
14
+
15
+ The package first ships in `ts/v0.3.0`. It is not on npm yet. Until its
16
+ first npm publish, install it from the tarball attached to the
17
+ [`ts/v0.4.0` GitHub Release](https://github.com/jamesainslie/libo11y/releases/tag/ts/v0.4.0),
18
+ whose notes list the exact URL:
19
+
20
+ ```sh
21
+ npm install \
22
+ https://github.com/jamesainslie/libo11y/releases/download/ts/v0.4.0/libo11y-rum-0.4.0.tgz
23
+ ```
24
+
25
+ The package has the core (sessions, consent, sampling, the retention
26
+ buffer and view summaries), the `views()`, `actions()`, `errors()`,
27
+ `vitals()`, `resources()` and `longAnimationFrames()` collectors, remote
28
+ configuration, the two-part loader and `@libo11y/rum/webext` for
29
+ extensions.
30
+
31
+ ## Quick start
32
+
33
+ ```ts
34
+ import { actions, errors, resources, setupRum, views, vitals } from "@libo11y/rum";
35
+
36
+ const telemetry = await setupRum({
37
+ serviceName: "storefront",
38
+ environment: "production",
39
+ serviceVersion: "1.4.0",
40
+ endpoint: "/_o11y",
41
+ rum: {
42
+ sessionSampleRate: 0.1,
43
+ clientToken: "pub-storefront",
44
+ collectors: [views(), actions(), errors(), vitals(), resources()],
45
+ },
46
+ });
47
+
48
+ // Later, once the user agrees:
49
+ telemetry.consent.grant();
50
+ ```
51
+
52
+ `setupRum` takes every option of the web `setup`. RUM's own options go
53
+ under `rum`. `clientToken` is the app's public token for the gateway. It
54
+ is not a secret. Collectors run only while consent is granted.
55
+
56
+ App metrics from the Meter API export with delta temporality, because the
57
+ RUM gateway accepts only delta sums and histograms.
58
+
59
+ ## Consent
60
+
61
+ Nothing is recorded, stored or sent before `telemetry.consent.grant()`.
62
+ No session exists until then, and RUM writes nothing to `localStorage` or
63
+ IndexedDB. `telemetry.consent.revoke()` stops RUM, removes the session
64
+ from storage and empties the retention buffer. To start with consent
65
+ already given, pass `consent: { initial: "granted" }`.
66
+
67
+ ## Sessions
68
+
69
+ A session belongs to the origin, so every tab shares it. It ends after 15
70
+ minutes without activity (`rum.sessionIdleMillis`) or 4 hours after it
71
+ started (`rum.sessionMaxMillis`). The next record after that starts a new
72
+ session. `telemetry.rum.sessionId()` returns the current session's ID.
73
+
74
+ `telemetry.rum.identify(userId)` sets `user.id` on later spans and on the
75
+ events collectors emit. View summaries and session events do not carry it.
76
+ Pass a pseudonymous ID, never an email address: `identify` refuses a value
77
+ with an at sign.
78
+
79
+ ## Sampling and retention
80
+
81
+ `rum.sessionSampleRate` is the share of sessions whose detail is sent from
82
+ the start. The decision is a hash of the session ID, so every tab agrees.
83
+ `docs/RUM.md` in the repository gives the formula.
84
+
85
+ Every consented session sends `o11y.rum.view.summary` records for every
86
+ view, each with the counts and time since the view's previous summary, so
87
+ counts and rates stay exact at any sample rate. A session that was not
88
+ sampled keeps its other records in a retention buffer in IndexedDB, at
89
+ most 2 MiB and 15 minutes old by default (`rum.retention`). When an error
90
+ or a frustration signal keeps the session, the buffer is sent. A session
91
+ that ends without being kept drops its buffer.
92
+
93
+ ## Privacy
94
+
95
+ Recorded URLs keep only the query parameters in `rum.queryAllowList`.
96
+ View names come from the path, with every segment that holds a digit or is
97
+ longer than 24 characters replaced by `$id`, so a raw URL never becomes a
98
+ view name. Pass `rum.viewName` to name views yourself.
99
+
100
+ ## Collectors
101
+
102
+ Each collector is a factory you list in `rum.collectors`. A collector you
103
+ do not list is not in your bundle.
104
+
105
+ ### `views()`
106
+
107
+ Every view gets a span named `view <view name>`. The initial view's span is
108
+ a child of `app_load`. A soft navigation's span is a root span, linked to
109
+ the action that caused it. A view span ends at the first paint after the
110
+ view rendered, and 10 seconds after it started at the latest. The view
111
+ summary, not the span, carries the time spent on the view.
112
+
113
+ By default (`views({ history: true })`) a change of the URL path through
114
+ `pushState`, `replaceState` or `popstate` starts a soft view. A change of
115
+ only the query or the fragment does not. A soft view counts as rendered
116
+ once the DOM has been quiet for 100 ms. With a router adapter, pass
117
+ `views({ history: false })`, and the adapter calls `rum.startView()` and
118
+ `rum.viewRendered()` instead.
119
+
120
+ A view name is the URL path with every segment that holds a digit, or is
121
+ longer than 24 characters, replaced by `$id`. The query and fragment are
122
+ dropped, so a raw URL never becomes a view name. Pass `rum.viewName` to
123
+ name views yourself, or call `rum.setViewName()` with a route template.
124
+
125
+ ### `actions()`
126
+
127
+ A click, Enter or Space on a control, or a form submit is an action. The
128
+ span is named `action <type>`, such as `action click`. Its name comes only
129
+ from a `data-o11y` attribute on the element or an ancestor, or from the
130
+ `aria-label` of an interactive element. Visible text never becomes a name.
131
+ Nothing inside an element with `data-o11y-mask` gets a name. The span also
132
+ carries a CSS selector of the element, built from a stable ID, a
133
+ `data-o11y` label, or a short path of tags and classes. IDs and classes
134
+ that look generated are left out. The key a user pressed is never
135
+ recorded.
136
+
137
+ Requests started while an action is open are its children. An action ends
138
+ once none of its requests are pending and the page has been idle for
139
+ 100 ms. Its end time is its last activity, a request end or a DOM change,
140
+ so the 100 ms wait is not part of its duration. An action ends 10 seconds
141
+ after it started at the latest, and at once when the next action starts.
142
+ Change the timing with `actions({ idleMillis, capMillis })`.
143
+
144
+ `actions()` also reports frustration signals. Turn them off with
145
+ `actions({ frustration: false })`.
146
+
147
+ - A rage click is three or more clicks on the same element within one
148
+ second. It is reported once per burst.
149
+ - A dead click is a click that starts no request, changes no DOM and starts
150
+ no view within one second. Clicks on form fields, labels, editable
151
+ content and links, and clicks inside a text selection, are never dead.
152
+ - An error click is an error within one second of a click, or while its
153
+ action is open.
154
+
155
+ Every frustration signal counts in the view summary, is sent as an
156
+ `o11y.rum.frustration` event, and keeps the session.
157
+
158
+ ### `errors()`
159
+
160
+ `errors()` records uncaught errors, unhandled promise rejections,
161
+ resources that fail to load, Content Security Policy violations and
162
+ requests that fail without a response. `errors({ console: true })` also
163
+ records `console.error` calls, and still calls the original. Resource
164
+ error messages carry the URL without its query or fragment.
165
+
166
+ An error object is recorded once. React 19 logs an error that an error
167
+ boundary caught through `console.error` before the boundary's
168
+ `componentDidCatch` runs, so a `console.error` that logs an error object
169
+ waits one task. When `rum.addError` records the same object first, with
170
+ its component stack, the console call records nothing.
171
+
172
+ Every error counts in the view summary, keeps the session, and is sent as
173
+ an `o11y.rum.error` event, at most 100 events per view. Each event carries
174
+ `o11y.rum.error.breadcrumbs`: the last 20 actions, view starts and
175
+ requests before it, oldest first, one per line, such as `click Sign
176
+ -1530ms`. A request breadcrumb is its method, host and status, such as
177
+ `fetch POST api.example.com 500`, never its path.
178
+
179
+ ### `vitals()`
180
+
181
+ `vitals()` records Largest Contentful Paint (LCP), Interaction to Next
182
+ Paint (INP), Cumulative Layout Shift (CLS), First Contentful Paint (FCP)
183
+ and Time to First Byte (TTFB). It uses the attribution build of the
184
+ Chrome team's [`web-vitals`](https://github.com/GoogleChrome/web-vitals)
185
+ package, pinned to one version. CrUX and the web.dev thresholds are defined
186
+ against that package. It already handles back/forward cache restores,
187
+ prerendering, page visibility and how INP groups the events of one
188
+ interaction. The package adds about 5 KiB gzipped, and only apps that list
189
+ `vitals()` pay for it.
190
+
191
+ Vitals belong to the view that loaded the page: the initial or prerender
192
+ view, or the `bfcache_restore` view after a page comes back from the
193
+ back/forward cache. Soft views carry no vitals. INP and CLS therefore
194
+ cover the page until it is first hidden, as the page-level values of CrUX
195
+ do.
196
+
197
+ Each vital goes into the view summary once, as
198
+ `o11y.rum.summary.<vital>.value`, in the first summary sent after it is
199
+ known. FCP and TTFB are known when the browser reports them. LCP, CLS and
200
+ INP keep changing while the page is visible, so RUM takes their latest
201
+ values when the page is first hidden, just before that hide sends the
202
+ summary. A CLS or INP value after the page returns from hidden stays out
203
+ of the summary, even when it is the first INP of the page. A kept session
204
+ still records it as detail. CrUX reports
205
+ the final value at page unload, so on long-lived pages the p75 of CLS and
206
+ INP can differ from CrUX. LCP, INP, FCP and TTFB are in seconds. CLS has no
207
+ unit.
208
+
209
+ Kept sessions also send each value as the semconv `browser.web_vital`
210
+ event. Its body holds the vital's `name` (`lcp`, `inp`, `cls`, `fcp` or
211
+ `ttfb`), `value`, `delta` since the last event for it, and `id`, in the
212
+ same units. Its attributes are the view, the session and the attribution:
213
+ the `o11y.rum.vital.attribution.*` phases of INP and LCP, the largest shift
214
+ of CLS, and the element as `o11y.rum.element.selector`. The selector is
215
+ built as for actions, never from text. When one frame paints several LCP
216
+ candidates, the LCP element is the largest of them. Firefox reports each of
217
+ them with the same time, and RUM attributes LCP to the last one.
218
+
219
+ RUM never sends a rating. The gateway rates each vital against the
220
+ thresholds the spec publishes.
221
+
222
+ A browser that does not support a vital records nothing for it. Firefox
223
+ and WebKit, for example, report no CLS. A page load whose navigation entry
224
+ reports a response start of zero records no TTFB, because `web-vitals`
225
+ treats that value as unknown. Firefox reports zero at times.
226
+
227
+ On a navigation away, browsers fire `pagehide` before the page is hidden,
228
+ and RUM takes the values at `pagehide`. An interaction that the browser has
229
+ not yet reported by then, such as the click that started the navigation,
230
+ is not in INP.
231
+
232
+ ### `resources()`
233
+
234
+ `resources()` records a span for each script, stylesheet, image, font,
235
+ media file and frame the page loads, from the browser's resource timing
236
+ entries. The span is named `resource <type>`, such as `resource script`,
237
+ and carries `o11y.rum.resource.type`, `url.full` without the query
238
+ parameters you did not allow, `server.address`, the status code and the
239
+ encoded body size when the browser exposes them. A cross-origin server
240
+ must send `Timing-Allow-Origin` for those details.
241
+
242
+ - Requests made with `fetch`, XHR or `sendBeacon` get no resource span,
243
+ because they have client spans of their own. RUM's own OTLP requests and
244
+ the URLs in `instrumentations.ignoreUrls` are left out too.
245
+ - A resource that started during the page load is a child of `app_load`.
246
+ A later resource is a root span linked to the span of its view.
247
+ - The type comes from the initiator. A font or an image that a stylesheet
248
+ loads is typed by its file extension.
249
+ - When the response has a `Server-Timing` header, a `traceparent` entry
250
+ links the span to the server span that served it. Every other entry
251
+ becomes a `server_timing` span event with `o11y.rum.server_timing.name`
252
+ and `o11y.rum.server_timing.duration` in seconds.
253
+ - At most 150 resource spans per view. Change it with
254
+ `resources({ maxPerView })`.
255
+
256
+ A page hidden before `app_load` is known records the resources of its load
257
+ as root spans at once, so leaving a slow page still records them.
258
+
259
+ Resource spans are detail, so only kept sessions send them. They are not
260
+ requests of the view, so they do not count in `o11y.rum.summary.requests`.
261
+
262
+ ### `longAnimationFrames()`
263
+
264
+ `longAnimationFrames()` counts the browser's long animation frames into
265
+ the view summary as `o11y.rum.summary.long_animation_frames`. Only
266
+ Chromium-based browsers report long animation frames today. Elsewhere it
267
+ records nothing. It does not fall back to long tasks, which measure
268
+ something else, so the gateway's `o11y.rum.browser.long_animation_frames`
269
+ metric reflects Chromium-based browsers only.
270
+
271
+ ## The `rum` handle
272
+
273
+ `telemetry.rum` has these methods. Each records nothing while consent is not
274
+ granted, or while remote configuration has switched RUM off.
275
+
276
+ - `startView({ name })` ends the current view and starts a soft view.
277
+ - `setViewName(name)` names the current view, such as with its route
278
+ template.
279
+ - `viewRendered()` marks the current view rendered. Its span ends at the
280
+ next paint.
281
+ - `addAction(name)` records a custom action, such as a programmatic save.
282
+ - `addError(error, { source, componentStack })` records an error your app
283
+ caught. Pass `source: "boundary"` and the component stack from a UI
284
+ framework's error boundary.
285
+
286
+ `startView`, `setViewName` and `viewRendered` are remembered while consent
287
+ is not granted, so a router adapter can report the route before consent.
288
+ When consent is granted, the view RUM starts takes the last name the
289
+ adapter set and, if the route had rendered, counts as rendered. This
290
+ applies only while the URL path is still the one the adapter reported. The
291
+ initial view's span then ends when the route rendered, and a later view's
292
+ span at the next paint.
293
+
294
+ ## Remote configuration
295
+
296
+ `rum.remoteConfig: remoteConfig()` lets the RUM gateway change a few
297
+ settings without a deploy. It is off unless you pass it, and a bundle
298
+ without it does not carry its code.
299
+
300
+ ```ts
301
+ import { actions, errors, remoteConfig, setupRum, views } from "@libo11y/rum";
302
+
303
+ await setupRum({
304
+ // ...
305
+ endpoint: "/_o11y",
306
+ rum: {
307
+ sessionSampleRate: 0.1,
308
+ collectors: [views(), actions(), errors()],
309
+ remoteConfig: remoteConfig({ limits: { sessionSampleRate: [0.01, 0.5] } }),
310
+ },
311
+ });
312
+ ```
313
+
314
+ Once consent is granted, RUM fetches
315
+ `GET <endpoint>/v1/config?service=<service.name>`, such as
316
+ `/_o11y/v1/config`, with `client_token` when `rum.clientToken` is set.
317
+ Pass `remoteConfig({ url })` for another URL. The request uses the
318
+ uninstrumented `fetch`, sends no credentials, and sends `If-None-Match`
319
+ with the cached ETag, so an unchanged document costs a `304`. RUM looks
320
+ again every 5 minutes while the page is visible (`refreshMillis`). A
321
+ `404` means the app has no remote configuration, and a failure keeps what
322
+ RUM has.
323
+
324
+ The gateway answers `{"version": "<16 hex>", "config": {...}}`. RUM reads
325
+ three keys inside `config` and ignores the rest:
326
+
327
+ | Key | Type | Effect |
328
+ | ------------------- | ------------------ | -------------------------------------------------------------------------------------------------- |
329
+ | `enabled` | boolean | `false` switches RUM off at once: the collectors stop and the view ends. `true` starts them again. |
330
+ | `sessionSampleRate` | number, 0 to 1 | The head-sampling rate of new sessions, kept within `limits.sessionSampleRate`. |
331
+ | `collectors` | object of booleans | `false` switches off a collector you installed. `true` never adds one you did not install. |
332
+
333
+ Code sets the limits. Without `limits.sessionSampleRate`, the range is
334
+ `[rate, rate]`, so the rate does not move. A document applies to the next
335
+ session, never to the running one, except for `enabled: false`. The
336
+ newest document and the one before it are cached in `localStorage` under
337
+ `libo11y.rum.config`, so a page that resumes a session keeps the document
338
+ that session started under. A new session takes the newest. Each session
339
+ records the version it started under as `o11y.rum.config.version` on its
340
+ `o11y.rum.session.start` event and its view summaries. Revoking consent
341
+ removes the cache.
342
+
343
+ ## Loading
344
+
345
+ RUM is large next to the code a page needs to render, so load it in two
346
+ parts. `@libo11y/rum/bootstrap` is under 1 KiB minified and gzip-compressed
347
+ and imports nothing else. Put it in your entry chunk and import the rest
348
+ after the page loaded:
349
+
350
+ ```ts
351
+ import { afterLoad, installRumBootstrap } from "@libo11y/rum/bootstrap";
352
+
353
+ installRumBootstrap({ consent: knownConsent });
354
+ afterLoad(() => import("./rum.ts"));
355
+ ```
356
+
357
+ `./rum.ts` calls `setupRum` as usual. `afterLoad` runs its callback once
358
+ the page's `load` event has fired, in an idle callback where the browser
359
+ has one.
360
+
361
+ `installRumBootstrap` takes the consent state you will pass to
362
+ `setupRum`. With `"pending"`, the default, it records nothing at all. With
363
+ `"granted"`, it holds early uncaught errors, unhandled rejections, CSP
364
+ violations and clicks in memory, never in storage, up to 100 of them
365
+ (`maxEntries`), and stops listening after 30 seconds. When `setupRum`
366
+ starts with consent granted, the collectors you installed record these with
367
+ their original times: `errors()` the errors, `actions()` the clicks. A
368
+ page whose `setupRum` starts with consent pending discards them, even if
369
+ consent is granted later.
370
+
371
+ ## Extensions
372
+
373
+ `@libo11y/rum/webext` records RUM in Manifest V3 extensions, on top of
374
+ [`@libo11y/webext`](https://github.com/jamesainslie/libo11y/tree/main/ts/packages/webext).
375
+ Extension pages and content scripts record. The service worker sends
376
+ their records to the gateway, so they need no endpoint.
377
+
378
+ In the service worker, call `setupRumWorker` on every wake, as you would
379
+ `setupWorker`:
380
+
381
+ ```ts
382
+ import { setupRumWorker } from "@libo11y/rum/webext";
383
+
384
+ setupRumWorker({
385
+ serviceName: "capture",
386
+ environment: "production",
387
+ endpoint: "https://app.example/_o11y",
388
+ consent: { initial: "pending" },
389
+ rum: { clientToken: "pub-capture" },
390
+ }).then((t) => t.onMessage(handle));
391
+ ```
392
+
393
+ It posts with the gateway's `sent_at` and `client_token` parameters and
394
+ exports app metrics with delta temporality. It also opens
395
+ `chrome.storage.session` to content scripts, so they share the
396
+ extension's session. A worker set up with `setupWorker` directly calls
397
+ `allowRumSessionInContentScripts(chrome)` for that instead. Opening the
398
+ area lets content scripts read everything in `chrome.storage.session`, so
399
+ keep nothing there that the pages a content script runs on must not
400
+ reach. The extension needs the `storage` permission.
401
+
402
+ In a popup, an options page or a side panel, call `setupRumExtension`
403
+ with `context: "page"`:
404
+
405
+ ```ts
406
+ import { actions, errors, views } from "@libo11y/rum";
407
+ import { setupRumExtension } from "@libo11y/rum/webext";
408
+
409
+ const telemetry = await setupRumExtension({
410
+ context: "page",
411
+ serviceName: "capture",
412
+ environment: "production",
413
+ rum: { collectors: [views(), actions(), errors()] },
414
+ });
415
+ ```
416
+
417
+ A page behaves as `setupRum` does. Its views are named from its own URL,
418
+ such as `/sidepanel.html`, and its retention buffer is in IndexedDB at the
419
+ extension's origin.
420
+
421
+ In a content script, pass `context: "content"` and the root of the UI the
422
+ extension adds to the page:
423
+
424
+ ```ts
425
+ const telemetry = await setupRumExtension({
426
+ context: "content",
427
+ serviceName: "capture",
428
+ environment: "production",
429
+ rum: { collectors: [views(), actions(), errors()] },
430
+ content: { uiRoot: shadowHost, viewName: "capture-overlay" },
431
+ });
432
+ ```
433
+
434
+ A content script shares the host page's document, so RUM records only
435
+ what is the extension's own:
436
+
437
+ - One view, named `content.viewName` or `content-script`, never named
438
+ from the URL. It starts when RUM starts and its span ends at the next
439
+ paint. The span carries the host page's `url.domain` and no other URL.
440
+ - Actions only on events whose composed path holds `content.uiRoot`.
441
+ Without `uiRoot`, no actions. For a closed shadow root, pass its host
442
+ element.
443
+ - Errors only from the extension's own scripts: an error event's
444
+ filename, or the first frame of its stack, starts with
445
+ `chrome.runtime.getURL("")`.
446
+ - No `vitals()`, `resources()`, `longAnimationFrames()` or `documentLoad`.
447
+ Each would measure the host page, so `setupRumExtension` refuses it
448
+ with `O11yError` `INVALID_OPTION`.
449
+ - A retention buffer in memory, because the content script's IndexedDB
450
+ is the host page's.
451
+
452
+ Every context records with platform `webext` and shares consent with the
453
+ whole extension, as `@libo11y/webext` does. Remote configuration works in
454
+ every context. Pass `remoteConfig({ url })` with an absolute URL, because
455
+ an extension context has no gateway origin of its own. Its cache is in
456
+ `chrome.storage.local`, never a page's `localStorage`, so every context
457
+ reads the document any of them fetched. An extension page fetches it under
458
+ the extension's host permissions, so list the gateway's host in
459
+ `host_permissions`. A content script's request carries the host page's
460
+ origin, without a referrer, so the gateway answers it only when that
461
+ origin is in its CORS list. Otherwise the content script keeps the cached
462
+ document the extension's pages fetched.