@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
@@ -0,0 +1,71 @@
1
+ /** Views: a page or route. performance.now() times. */
2
+ import type { RUMViewKind } from "@libo11y/spec";
3
+ import type { SpanContext } from "@opentelemetry/api";
4
+ export interface ViewState {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ readonly kind: RUMViewKind;
8
+ /** performance.now() when the view started. */
9
+ readonly startTime: number;
10
+ /** The session the view belongs to. */
11
+ readonly sessionId: string;
12
+ /** The view span's context, once the view tracker has started it. */
13
+ readonly spanContext?: SpanContext;
14
+ }
15
+ export type ViewEvent = {
16
+ readonly type: "start";
17
+ readonly view: ViewState;
18
+ readonly previous?: ViewState;
19
+ /** The action that caused the view, from ViewStartOptions.cause. */
20
+ readonly cause?: SpanContext;
21
+ /** From ViewStartOptions.rendered: the content is already on screen. */
22
+ readonly rendered?: true;
23
+ } | {
24
+ readonly type: "rename";
25
+ readonly view: ViewState;
26
+ }
27
+ /** The routed content of the view rendered (rendered()). */
28
+ | {
29
+ readonly type: "rendered";
30
+ readonly view: ViewState;
31
+ /** performance.now() it rendered at, when that was before now (a render reported before consent). */
32
+ readonly at?: number;
33
+ } | {
34
+ readonly type: "end";
35
+ readonly view: ViewState;
36
+ };
37
+ export interface ViewStartOptions {
38
+ readonly kind: RUMViewKind;
39
+ /** Default: the tracker's namer applied to location. */
40
+ readonly name?: string;
41
+ /** Default now. */
42
+ readonly startTime?: number;
43
+ /** The action that caused the view, linked from the view span. */
44
+ readonly cause?: SpanContext;
45
+ /** The view's content is already on screen, as after a session change: its span ends at the next paint. */
46
+ readonly rendered?: boolean;
47
+ }
48
+ export interface ViewTracker {
49
+ current(): ViewState | undefined;
50
+ /** The view that loaded the page (initial, prerender, or the latest bfcache_restore). Vitals attach to it. */
51
+ loadView(): ViewState | undefined;
52
+ /** Ends the current view and starts another. */
53
+ start(opts: ViewStartOptions): ViewState;
54
+ rename(name: string): void;
55
+ /**
56
+ * The routed view rendered: emits rendered for the current view, whose span ends at the next
57
+ * paint. at (performance.now()) is when it rendered, for a render that happened earlier.
58
+ */
59
+ rendered(at?: number): void;
60
+ /** The span processor reports web's documentLoad span here, so the initial view span can be its child. */
61
+ appLoadStarted(ctx: SpanContext): void;
62
+ /** The context appLoadStarted reported, once it has. */
63
+ appLoad(): SpanContext | undefined;
64
+ /** Records the view span's context on the view, so actions on the view can link to it. */
65
+ attachSpan(viewId: string, ctx: SpanContext): void;
66
+ /** Starts the load view. Called once the session exists. */
67
+ begin(): void;
68
+ /** Ends the current view without starting another (hide is not an end; revoke and shutdown are). */
69
+ end(): void;
70
+ subscribe(listener: (event: ViewEvent) => void): () => void;
71
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
1
+ /**
2
+ * setupRumCore: RUM over a platform binding. In order: settings, the
3
+ * retention buffer (opened lazily), the session manager, the bus, the summary accumulator, the
4
+ * view tracker, the span processor, then the binding, which runs the platform's setup with RUM's
5
+ * wrappers. After setup: consent wiring (collectors run only while granted), session events, hide
6
+ * handling and activity from the platform's lifecycle. The returned handle is the platform's
7
+ * telemetry extended in place with rum. setupRumWith (setup.ts) binds it to the web.
8
+ *
9
+ * Nothing here imports a browser-only module or reads a browser global; every platform part is a
10
+ * dependency (core.test.ts enforces the imports), so a platform without a DOM, such as React
11
+ * Native, can bind it.
12
+ *
13
+ * The span processor reaches core as options.spanProcessor. Core treats an injected processor as
14
+ * the traces route ("injected") and then uses no span exporter the platform builds, so RUM also
15
+ * injects a forwarding span exporter. When the binding hands RUM its platform's delivery (before
16
+ * core builds anything), RUM builds the span exporter for the route traces would have had without
17
+ * RUM: none in hermetic mode, else OTEL_TRACES_EXPORTER from the platform's env. An app that
18
+ * injects its own spanExporter keeps it, routed by session; one that injects only a spanProcessor
19
+ * keeps sole charge of span export.
20
+ *
21
+ * Only spans and log records routed to OTLP wait in the retention buffer, which sends through the
22
+ * platform's delivery. Those of the console route, and those of an exporter the app injected, wait
23
+ * in memory instead (holdingSpanExporter, holdingLogExporter) and go to their own exporter once
24
+ * their session is kept.
25
+ *
26
+ * Consent. Closing the gate stops RUM at once, in the gate listener, so a grant that follows a
27
+ * revoke before the revoke hooks finish starts RUM again. The revoke hook then removes the stored
28
+ * session, the configuration cache and the retention buffer, and waits for stores that write
29
+ * asynchronously. A start that is denied (consent.initial, or a respected privacy signal) removes
30
+ * them too, before setup resolves, so a later grant never resumes what an earlier page stored. A
31
+ * pending start touches no RUM storage.
32
+ *
33
+ * OTEL_SDK_DISABLED=true (outside hermetic mode) disables RUM as core disables its providers: no
34
+ * session, collector, remote configuration or bootstrap replay starts, on a grant or otherwise. A
35
+ * denied start and a revoke still remove what an earlier page stored.
36
+ */
37
+ import { type Telemetry } from "@libo11y/core";
38
+ import { type RUMPlatform, type RUMViewKind } from "@libo11y/spec";
39
+ import { type PersistentQueue, type QueueOptions } from "@libo11y/web/portable";
40
+ import { type RemoteConfigStorage } from "./config/remote.ts";
41
+ import type { RumBind, RumLifecycle, RumPlatformOptions } from "./contracts/binding.ts";
42
+ import type { RumRuntime, RumScope } from "./contracts/runtime.ts";
43
+ import type { SessionStore } from "./contracts/session.ts";
44
+ import type { Rum, RumOptions } from "./options.ts";
45
+ /** What setupRumCore builds on: the platform's binding and lifecycle, and RUM's own dependencies. */
46
+ export interface RumCoreDeps<O extends RumPlatformOptions, T extends Telemetry> {
47
+ /** The platform summaries, session starts and app_load record. */
48
+ readonly platform: RUMPlatform;
49
+ /** Runs the platform's setup with RUM's wrappers. */
50
+ readonly bind: RumBind<O, T>;
51
+ /** When the page or app is shown, hidden and used. */
52
+ readonly lifecycle: RumLifecycle;
53
+ readonly openRetentionQueue: (opts: QueueOptions) => Promise<PersistentQueue>;
54
+ /** The session manager first uses the store when consent is granted, so it must open nothing before. */
55
+ readonly sessionStore: () => SessionStore;
56
+ /** Epoch milliseconds. */
57
+ readonly now: () => number;
58
+ /** performance.now(). */
59
+ readonly perfNow: () => number;
60
+ /**
61
+ * The epoch milliseconds perfNow counts from. A platform whose runtime may lack
62
+ * performance.timeOrigin, as React Native, passes its own. Unset where perfNow is a fake clock:
63
+ * RumRuntime.timeOrigin is then performance.timeOrigin, and request ends are read on perfNow alone.
64
+ */
65
+ readonly timeOrigin?: number;
66
+ /** The page URL, or the app's fixed URL where there is no page. */
67
+ readonly location: () => string;
68
+ readonly prerendered: () => boolean;
69
+ readonly connection: () => string | undefined;
70
+ /** Where pageshow fires, for the view tracker's back/forward-cache restores. Unset outside a page. */
71
+ readonly window?: EventTarget | undefined;
72
+ /** The fetch remote configuration uses. Default web's pristineFetch, which is never instrumented. */
73
+ readonly fetch?: typeof fetch;
74
+ /**
75
+ * Where remote configuration is cached. Default none. Called only once consent is granted, or to
76
+ * remove the cache when consent is denied. It may resolve later, as a cache in
77
+ * chrome.storage.local does once it has read the stored value.
78
+ */
79
+ readonly storage?: () => ConfigCacheStorage | undefined | Promise<ConfigCacheStorage | undefined>;
80
+ /** The context's limits on the collectors, for a content script. With fixedView, the one view starts when RUM does and is on screen at once. */
81
+ readonly scope?: RumScope;
82
+ /**
83
+ * Takes what a bootstrap buffered before RUM loaded, at the end of setup. RUM replays it through
84
+ * the returned function when setup started with consent granted and no scope. Default none.
85
+ */
86
+ readonly bootstrap?: () => (runtime: RumRuntime) => void;
87
+ /**
88
+ * The kind of every view, for a platform with one kind of view, such as React Native's screen:
89
+ * the first view is the load view, and rum.startView's views have it too. Default the web's.
90
+ */
91
+ readonly viewKind?: RUMViewKind;
92
+ /**
93
+ * performance.now() when the first view starts, for a platform whose clock does not start at the
94
+ * page's navigation, as React Native's counts from the device's boot. Default 0, navigation start.
95
+ */
96
+ readonly initialViewStart?: () => number;
97
+ /**
98
+ * Called once with the runtime, before consent is wired, so the platform's own recorders (React
99
+ * Native's app_load) see the first grant's session start and load view, even at setup.
100
+ */
101
+ readonly onRuntime?: (runtime: RumRuntime) => void;
102
+ }
103
+ /**
104
+ * The synchronous storage remote configuration caches in. A storage that writes asynchronously, as
105
+ * chrome.storage.local does, has flush, which resolves once every earlier write reached storage and
106
+ * never rejects.
107
+ */
108
+ export type ConfigCacheStorage = RemoteConfigStorage & {
109
+ flush?(): Promise<void>;
110
+ };
111
+ /** The RUM runtime behind a RUM telemetry, for the adapter packages and the browser fixtures. */
112
+ export declare function runtimeOf(telemetry: object): RumRuntime | undefined;
113
+ /** How long a tab that ended a session waits to hear whether another tab's rotation won. */
114
+ export declare const SESSION_END_ELECTION_MILLIS = 500;
115
+ /**
116
+ * RUM over deps.bind: options are the platform's setup options, rumOptions RUM's own. Resolves with
117
+ * the platform's telemetry, with rum added.
118
+ */
119
+ export declare function setupRumCore<O extends RumPlatformOptions, T extends Telemetry>(options: O, rumOptions: RumOptions | undefined, deps: RumCoreDeps<O, T>): Promise<T & {
120
+ readonly rum: Rum;
121
+ }>;