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