@libo11y/rum-expo-router 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/dist/universal-native-core.d.ts +19 -0
- package/dist/universal-native-core.js +51 -0
- package/dist/universal-native.d.ts +17 -0
- package/dist/universal-native.js +51 -0
- package/dist/universal-shared.d.ts +277 -0
- package/dist/universal-shared.js +454 -0
- package/dist/universal-web-core.d.ts +33 -0
- package/dist/universal-web-core.js +90 -0
- package/dist/universal-web.d.ts +17 -0
- package/dist/universal-web.js +46 -0
- package/dist/universal.d.ts +6 -0
- package/dist/universal.js +6 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +22 -4
package/README.md
CHANGED
|
@@ -103,11 +103,71 @@ in the app directory: groups such as `(tabs)` are left out, a trailing
|
|
|
103
103
|
`[id]` and `[...path]`. The root is `/`. Expo Router's own screens are
|
|
104
104
|
`/+not-found` and `/_sitemap`.
|
|
105
105
|
|
|
106
|
+
## Universal Expo apps (`@libo11y/rum-expo-router/universal`)
|
|
107
|
+
|
|
108
|
+
Universal Expo Router apps targeting web, iOS, and Android from one tree
|
|
109
|
+
can import `@libo11y/rum-expo-router/universal`. The package manifest
|
|
110
|
+
declares conditional exports with `"browser"` ordered before
|
|
111
|
+
`"react-native"` and `"default"`, so Metro and browser bundlers pick
|
|
112
|
+
`universal-web` on web and `universal-native` on iOS and Android without
|
|
113
|
+
pulling native modules into web bundles or browser RUM into native
|
|
114
|
+
bundles.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// app/_layout.tsx
|
|
118
|
+
import { UniversalRumProvider } from "@libo11y/rum-expo-router/universal";
|
|
119
|
+
import { Stack } from "expo-router";
|
|
120
|
+
|
|
121
|
+
export default function RootLayout() {
|
|
122
|
+
return (
|
|
123
|
+
<UniversalRumProvider
|
|
124
|
+
config={{
|
|
125
|
+
serviceName: "my-app",
|
|
126
|
+
environment: "production",
|
|
127
|
+
// Use an absolute HTTP(S) URL for shared web + native configs.
|
|
128
|
+
// Relative endpoints such as "/_o11y" work only on web.
|
|
129
|
+
endpoint: "https://o11y.example.com",
|
|
130
|
+
propagateTo: ["https://api.example.com"],
|
|
131
|
+
web: { maskRoot: true },
|
|
132
|
+
native: { clientToken: "pub-my-app", accessibilityNames: false },
|
|
133
|
+
}}
|
|
134
|
+
fallback={null}
|
|
135
|
+
>
|
|
136
|
+
<Stack />
|
|
137
|
+
</UniversalRumProvider>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
- **Web (`browser` / `default`)**: guards SSR (`typeof document === "undefined"`),
|
|
143
|
+
waits until after the first paint (`requestAnimationFrame` + `setTimeout(0)`)
|
|
144
|
+
unless `web.deferUntilFirstPaint` is `false`, dynamically imports `@libo11y/rum`
|
|
145
|
+
so the RUM and OpenTelemetry SDK splits into an async chunk outside the initial
|
|
146
|
+
bundle, sets `data-o11y-mask=""` on `document.documentElement` when
|
|
147
|
+
`web.maskRoot` is `true`, buffers up to `maxBufferedErrors` (default `20`)
|
|
148
|
+
early `addError` calls and replays them strictly through `target.rum.addError`
|
|
149
|
+
(preserving RUM's consent gate), and wraps children in `RumProvider`,
|
|
150
|
+
`RumErrorBoundary`, and `useExpoRouterRum`.
|
|
151
|
+
- **Native (`react-native`)**: calls `setupRumExpo` with `screens()`, `errors()`,
|
|
152
|
+
and `taps({ accessibilityNames: options.native?.accessibilityNames ?? true })`
|
|
153
|
+
inside a safe-mode wrapper, and wraps children in `RumTouchBoundary`,
|
|
154
|
+
`RumProvider`, `RumErrorBoundary`, and `useExpoRouterRum`.
|
|
155
|
+
- **Safe mode and hooks**: `createUniversalRum(options)` returns a lazy,
|
|
156
|
+
memoized loader that catches setup failures, logs one `console.warn`, invokes
|
|
157
|
+
`onError`, and resolves to `undefined`. `useUniversalRum()` returns
|
|
158
|
+
`{ status: "loading" | "ready", handle? }`, where `handle` exposes
|
|
159
|
+
`{ rum, consent, telemetry }`. `createBufferingRum(maxErrors)` and `darkRum`
|
|
160
|
+
are exported for custom bootstrap wiring.
|
|
161
|
+
|
|
162
|
+
Optional peer dependencies `@libo11y/rum-react` and `@libo11y/rum-react-native`
|
|
163
|
+
are installed only for the platforms you target (`@libo11y/rum-react` for both
|
|
164
|
+
web and native; `@libo11y/rum-react-native` for native).
|
|
165
|
+
|
|
106
166
|
## Status
|
|
107
167
|
|
|
108
168
|
A preview. The package first ships in `ts/v0.6.0`, with
|
|
109
|
-
`@libo11y/rum-react-native` at the same version.
|
|
110
|
-
[`ts/v0.
|
|
169
|
+
`@libo11y/rum-react-native` at the same version. `0.9.0` is published on npm and attached as a tarball to the
|
|
170
|
+
[`ts/v0.9.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.9.0):
|
|
111
171
|
|
|
112
172
|
```sh
|
|
113
173
|
npm install @libo11y/rum-react-native @libo11y/rum-expo-router
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure testable native implementation for `@libo11y/rum-expo-router/universal`.
|
|
3
|
+
* Calls `setupRumExpo` with `screens()`, `errors()`, and `taps({ accessibilityNames })` inside a
|
|
4
|
+
* lazy, memoized, safe-mode loader. Has zero runtime imports of `react-native` or Expo modules so
|
|
5
|
+
* it can be unit tested under Node and Bun.
|
|
6
|
+
*/
|
|
7
|
+
import type { RumCollector } from "@libo11y/rum";
|
|
8
|
+
import type { ReactNativeRumTelemetry, RumReactNativeSetupOptions, TapsOptions } from "@libo11y/rum-react-native";
|
|
9
|
+
import { type UniversalRumLoader, type UniversalRumOptions, type WarnLogger } from "./universal-shared.ts";
|
|
10
|
+
/** Injectable dependencies for testing universal-native without React Native or Expo modules. */
|
|
11
|
+
export interface UniversalNativeDeps {
|
|
12
|
+
readonly setupRumExpo: (options?: RumReactNativeSetupOptions) => Promise<ReactNativeRumTelemetry>;
|
|
13
|
+
readonly screens: () => RumCollector;
|
|
14
|
+
readonly errors: () => RumCollector;
|
|
15
|
+
readonly taps: (opts?: TapsOptions) => RumCollector;
|
|
16
|
+
readonly warn?: WarnLogger | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Creates the native universal RUM loader over injectable dependencies. */
|
|
19
|
+
export declare function createUniversalRumNativeWith(options: UniversalRumOptions, deps: UniversalNativeDeps): UniversalRumLoader;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createMemoizedSafeLoader, } from "./universal-shared.js";
|
|
2
|
+
/** Creates the native universal RUM loader over injectable dependencies. */
|
|
3
|
+
export function createUniversalRumNativeWith(options, deps) {
|
|
4
|
+
return createMemoizedSafeLoader(async () => {
|
|
5
|
+
const accessibilityNames = options.native?.accessibilityNames ?? true;
|
|
6
|
+
const collectors = options.native?.collectors ?? [
|
|
7
|
+
deps.screens(),
|
|
8
|
+
deps.errors(),
|
|
9
|
+
deps.taps({ accessibilityNames }),
|
|
10
|
+
];
|
|
11
|
+
const propagateTo = options.native?.instrumentations?.propagateTo ?? options.propagateTo;
|
|
12
|
+
const instrumentations = options.native?.instrumentations !== undefined || propagateTo !== undefined
|
|
13
|
+
? {
|
|
14
|
+
...options.native?.instrumentations,
|
|
15
|
+
...(propagateTo === undefined ? {} : { propagateTo }),
|
|
16
|
+
}
|
|
17
|
+
: undefined;
|
|
18
|
+
const clientToken = options.native?.clientToken ?? options.clientToken;
|
|
19
|
+
const consent = options.consent?.initial === undefined ? undefined : { initial: options.consent.initial };
|
|
20
|
+
const setupOptions = {
|
|
21
|
+
serviceName: options.serviceName,
|
|
22
|
+
environment: options.environment,
|
|
23
|
+
...(options.serviceVersion === undefined ? {} : { serviceVersion: options.serviceVersion }),
|
|
24
|
+
endpoint: options.endpoint,
|
|
25
|
+
...(consent === undefined ? {} : { consent }),
|
|
26
|
+
...(options.native?.headers === undefined ? {} : { headers: options.native.headers }),
|
|
27
|
+
...(options.native?.resourceAttributes === undefined
|
|
28
|
+
? {}
|
|
29
|
+
: { resourceAttributes: options.native.resourceAttributes }),
|
|
30
|
+
...(instrumentations === undefined ? {} : { instrumentations }),
|
|
31
|
+
rum: {
|
|
32
|
+
...options.native?.rum,
|
|
33
|
+
...(options.native?.initialViewName === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: { initialViewName: options.native.initialViewName }),
|
|
36
|
+
...(options.sessionSampleRate === undefined
|
|
37
|
+
? {}
|
|
38
|
+
: { sessionSampleRate: options.sessionSampleRate }),
|
|
39
|
+
...(clientToken === undefined ? {} : { clientToken }),
|
|
40
|
+
collectors,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const telemetry = await deps.setupRumExpo(setupOptions);
|
|
44
|
+
return { rum: telemetry.rum, consent: telemetry.consent, telemetry };
|
|
45
|
+
}, {
|
|
46
|
+
expoRouter: options.expoRouter,
|
|
47
|
+
onReady: options.onReady,
|
|
48
|
+
onError: options.onError,
|
|
49
|
+
warn: deps.warn,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type BufferingRum, createBufferingRum, darkRum, type UniversalRumConsent, type UniversalRumConsentOptions, type UniversalRumHandle, type UniversalRumLoader, type UniversalRumNativeInstrumentationOptions, type UniversalRumNativeOptions, type UniversalRumOptions, type UniversalRumOriginMatcher, type UniversalRumProviderProps, type UniversalRumState, type UniversalRumStatus, type UniversalRumTelemetry, type UniversalRumWebCollectors, type UniversalRumWebOptions, useUniversalRum } from "./universal-shared.ts";
|
|
3
|
+
export type { BufferingRum, UniversalRumConsent, UniversalRumConsentOptions, UniversalRumHandle, UniversalRumLoader, UniversalRumNativeInstrumentationOptions, UniversalRumNativeOptions, UniversalRumOptions, UniversalRumOriginMatcher, UniversalRumProviderProps, UniversalRumState, UniversalRumStatus, UniversalRumTelemetry, UniversalRumWebCollectors, UniversalRumWebOptions, };
|
|
4
|
+
export { createBufferingRum, darkRum, useUniversalRum };
|
|
5
|
+
/**
|
|
6
|
+
* Creates a lazy, memoized, safe-mode RUM loader for React Native / Expo. Calls `setupRumExpo`
|
|
7
|
+
* with `screens()`, `errors()`, and `taps({ accessibilityNames })` (defaulting `accessibilityNames`
|
|
8
|
+
* to `true` unless `native.accessibilityNames === false`) and resolves to `undefined` after logging
|
|
9
|
+
* one warning if setup fails.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createUniversalRum(options: UniversalRumOptions): UniversalRumLoader;
|
|
12
|
+
/**
|
|
13
|
+
* Universal RUM provider for Expo Router apps on native: initializes `setupRumExpo` in safe mode,
|
|
14
|
+
* buffers early errors with consent-safe replay, and wraps children in `RumTouchBoundary`,
|
|
15
|
+
* `RumProvider`, `RumErrorBoundary`, and `useExpoRouterRum`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function UniversalRumProvider(props: UniversalRumProviderProps): ReactNode;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native / Expo entry for `@libo11y/rum-expo-router/universal` (`react-native` export
|
|
3
|
+
* condition). Wraps `setupRumExpo` with `screens()`, `errors()`, and `taps()`, and renders
|
|
4
|
+
* `RumTouchBoundary`, `RumProvider`, `RumErrorBoundary`, and `useExpoRouterRum` using
|
|
5
|
+
* `React.createElement` (plain `.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import { RumErrorBoundary, RumProvider } from "@libo11y/rum-react";
|
|
8
|
+
import { errors, RumTouchBoundary, screens, taps } from "@libo11y/rum-react-native";
|
|
9
|
+
import { setupRumExpo } from "@libo11y/rum-react-native/expo";
|
|
10
|
+
import { createElement } from "react";
|
|
11
|
+
import { useExpoRouterRum } from "./hook.js";
|
|
12
|
+
import { createUniversalRumNativeWith } from "./universal-native-core.js";
|
|
13
|
+
import { createBufferingRum, darkRum, UniversalRumProviderBase, useUniversalRum, } from "./universal-shared.js";
|
|
14
|
+
export { createBufferingRum, darkRum, useUniversalRum };
|
|
15
|
+
/**
|
|
16
|
+
* Creates a lazy, memoized, safe-mode RUM loader for React Native / Expo. Calls `setupRumExpo`
|
|
17
|
+
* with `screens()`, `errors()`, and `taps({ accessibilityNames })` (defaulting `accessibilityNames`
|
|
18
|
+
* to `true` unless `native.accessibilityNames === false`) and resolves to `undefined` after logging
|
|
19
|
+
* one warning if setup fails.
|
|
20
|
+
*/
|
|
21
|
+
export function createUniversalRum(options) {
|
|
22
|
+
return createUniversalRumNativeWith(options, {
|
|
23
|
+
setupRumExpo,
|
|
24
|
+
screens,
|
|
25
|
+
errors,
|
|
26
|
+
taps,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const NATIVE_PROVIDER_DEPS = {
|
|
30
|
+
createLoader: createUniversalRum,
|
|
31
|
+
RumProvider,
|
|
32
|
+
RumErrorBoundary,
|
|
33
|
+
TouchBoundary: RumTouchBoundary,
|
|
34
|
+
useExpoRouterRum,
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Universal RUM provider for Expo Router apps on native: initializes `setupRumExpo` in safe mode,
|
|
38
|
+
* buffers early errors with consent-safe replay, and wraps children in `RumTouchBoundary`,
|
|
39
|
+
* `RumProvider`, `RumErrorBoundary`, and `useExpoRouterRum`.
|
|
40
|
+
*/
|
|
41
|
+
export function UniversalRumProvider(props) {
|
|
42
|
+
return createElement(UniversalRumProviderBase, { ...props, deps: NATIVE_PROVIDER_DEPS });
|
|
43
|
+
}
|
|
44
|
+
const _contract = {
|
|
45
|
+
createUniversalRum,
|
|
46
|
+
createBufferingRum,
|
|
47
|
+
darkRum,
|
|
48
|
+
UniversalRumProvider,
|
|
49
|
+
useUniversalRum,
|
|
50
|
+
};
|
|
51
|
+
void _contract;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types, safe-mode loader helpers, dark/buffering RUM handles, and provider wiring for
|
|
3
|
+
* `@libo11y/rum-expo-router/universal`. Keeps zero runtime imports of browser, React Native, or
|
|
4
|
+
* Expo Router packages so both universal-web.ts and universal-native.ts can share it cleanly.
|
|
5
|
+
*/
|
|
6
|
+
import type { ActionsOptions, ErrorsOptions, ResourcesOptions, Rum, RumCollector, RumSetupOptions, RumTelemetry, ViewsOptions } from "@libo11y/rum";
|
|
7
|
+
import { type ComponentType, type Context, type ReactNode } from "react";
|
|
8
|
+
/** The application's handle on consent (identical to `@libo11y/web`'s Consent). */
|
|
9
|
+
export type UniversalRumConsent = RumTelemetry["consent"];
|
|
10
|
+
/** Consent options accepted by universal setup (identical to `@libo11y/web`'s ConsentOptions). */
|
|
11
|
+
export type UniversalRumConsentOptions = NonNullable<RumSetupOptions["consent"]>;
|
|
12
|
+
/** The core Telemetry handle exposed alongside rum and consent. */
|
|
13
|
+
export type UniversalRumTelemetry = Omit<RumTelemetry, "rum" | "consent">;
|
|
14
|
+
/** An origin or URL matcher for trace propagation or ignore lists. */
|
|
15
|
+
export type UniversalRumOriginMatcher = string | RegExp;
|
|
16
|
+
/** The live universal RUM handle returned once setup completes. */
|
|
17
|
+
export interface UniversalRumHandle {
|
|
18
|
+
/** The RUM handle for views, actions, errors, and user identification. */
|
|
19
|
+
readonly rum: Rum;
|
|
20
|
+
/** The consent gate controlling recording and export. */
|
|
21
|
+
readonly consent: UniversalRumConsent;
|
|
22
|
+
/** The underlying Telemetry handle for tracers, meters, loggers, flush, and shutdown. */
|
|
23
|
+
readonly telemetry: UniversalRumTelemetry;
|
|
24
|
+
}
|
|
25
|
+
/** Lazy, memoized loader returned by createUniversalRum. Calling it starts setup at most once. */
|
|
26
|
+
export type UniversalRumLoader = () => Promise<UniversalRumHandle | undefined>;
|
|
27
|
+
/** Lifecycle status exposed by useUniversalRum. */
|
|
28
|
+
export type UniversalRumStatus = "loading" | "ready";
|
|
29
|
+
/** State returned by useUniversalRum. */
|
|
30
|
+
export interface UniversalRumState {
|
|
31
|
+
readonly status: UniversalRumStatus;
|
|
32
|
+
readonly handle?: UniversalRumHandle;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The collector constructors of `@libo11y/rum` passed to a web `collectors` factory so callers can
|
|
36
|
+
* customize web collectors without statically importing `@libo11y/rum` into the initial bundle.
|
|
37
|
+
*/
|
|
38
|
+
export interface UniversalRumWebCollectors {
|
|
39
|
+
readonly views: (opts?: ViewsOptions) => RumCollector;
|
|
40
|
+
readonly actions: (opts?: ActionsOptions) => RumCollector;
|
|
41
|
+
readonly errors: (opts?: ErrorsOptions) => RumCollector;
|
|
42
|
+
readonly vitals: () => RumCollector;
|
|
43
|
+
readonly resources: (opts?: ResourcesOptions) => RumCollector;
|
|
44
|
+
readonly longAnimationFrames: () => RumCollector;
|
|
45
|
+
}
|
|
46
|
+
/** Web-specific options for `@libo11y/rum-expo-router/universal`. */
|
|
47
|
+
export interface UniversalRumWebOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Sets the `data-o11y-mask` attribute on `document.documentElement` before setupRum starts,
|
|
50
|
+
* masking DOM text and inputs by default. Default false.
|
|
51
|
+
*/
|
|
52
|
+
readonly maskRoot?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Waits until after the first paint (`requestAnimationFrame` + `setTimeout(0)`) before
|
|
55
|
+
* dynamically importing `@libo11y/rum` and calling `setupRum`. Default true.
|
|
56
|
+
*/
|
|
57
|
+
readonly deferUntilFirstPaint?: boolean;
|
|
58
|
+
/** Public client token for the RUM gateway on web. Overrides top-level clientToken. */
|
|
59
|
+
readonly clientToken?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Collectors to run on web, or a factory invoked with the lazily imported `@libo11y/rum`
|
|
62
|
+
* collector constructors. Default: `[views(), actions(), errors(), vitals(), resources()]`.
|
|
63
|
+
*/
|
|
64
|
+
readonly collectors?: readonly RumCollector[] | ((collectors: UniversalRumWebCollectors) => readonly RumCollector[]);
|
|
65
|
+
/** Browser HTTP and document-load instrumentation options forwarded to `setupRum`. */
|
|
66
|
+
readonly instrumentations?: RumSetupOptions["instrumentations"];
|
|
67
|
+
/** Additional `setupRum` `rum` options beyond collectors, sessionSampleRate, and clientToken. */
|
|
68
|
+
readonly rum?: Omit<NonNullable<RumSetupOptions["rum"]>, "collectors" | "sessionSampleRate" | "clientToken">;
|
|
69
|
+
/** Extra headers for OTLP export requests on web. */
|
|
70
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
71
|
+
/** Extra resource attributes merged into the web resource. */
|
|
72
|
+
readonly resourceAttributes?: Readonly<Record<string, string | number | boolean>>;
|
|
73
|
+
}
|
|
74
|
+
/** React Native HTTP instrumentation options forwarded to `setupRumExpo`. */
|
|
75
|
+
export interface UniversalRumNativeInstrumentationOptions {
|
|
76
|
+
readonly fetch?: boolean;
|
|
77
|
+
readonly xhr?: boolean;
|
|
78
|
+
readonly propagateTo?: readonly UniversalRumOriginMatcher[];
|
|
79
|
+
readonly ignoreUrls?: readonly UniversalRumOriginMatcher[];
|
|
80
|
+
}
|
|
81
|
+
/** Native-specific options for `@libo11y/rum-expo-router/universal`. */
|
|
82
|
+
export interface UniversalRumNativeOptions {
|
|
83
|
+
/** Public client token for the RUM gateway on native. Overrides top-level clientToken. */
|
|
84
|
+
readonly clientToken?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Names taps from the tapped element's aria-label or accessibilityLabel when no o11yName or
|
|
87
|
+
* RumName names them. Default true (matching `@libo11y/rum-react-native` `taps()`). Set false
|
|
88
|
+
* when accessibility labels may contain user data.
|
|
89
|
+
*/
|
|
90
|
+
readonly accessibilityNames?: boolean;
|
|
91
|
+
/** Collectors to run on native. Default: `[screens(), errors(), taps({ accessibilityNames })]`. */
|
|
92
|
+
readonly collectors?: readonly RumCollector[];
|
|
93
|
+
/** React Native HTTP instrumentation options forwarded to `setupRumExpo`. */
|
|
94
|
+
readonly instrumentations?: UniversalRumNativeInstrumentationOptions;
|
|
95
|
+
/** Initial view name until Expo Router names the launch screen. */
|
|
96
|
+
readonly initialViewName?: string;
|
|
97
|
+
/** Additional `setupRumExpo` `rum` options beyond collectors, sessionSampleRate, and clientToken. */
|
|
98
|
+
readonly rum?: Omit<NonNullable<RumSetupOptions["rum"]>, "collectors" | "sessionSampleRate" | "clientToken" | "viewName">;
|
|
99
|
+
/** Extra headers for OTLP export requests on native. */
|
|
100
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
101
|
+
/** Extra resource attributes merged into the Expo resource. */
|
|
102
|
+
readonly resourceAttributes?: Readonly<Record<string, string | number | boolean>>;
|
|
103
|
+
}
|
|
104
|
+
/** Shared and platform-specific configuration for `@libo11y/rum-expo-router/universal`. */
|
|
105
|
+
export interface UniversalRumOptions {
|
|
106
|
+
/** Logical service name (`service.name`). */
|
|
107
|
+
readonly serviceName: string;
|
|
108
|
+
/** Deployment environment (`deployment.environment.name`). */
|
|
109
|
+
readonly environment: string;
|
|
110
|
+
/** Application version (`service.version`). */
|
|
111
|
+
readonly serviceVersion?: string;
|
|
112
|
+
/** OTLP/HTTP base URL for RUM export (for example, `"/_o11y"` on web or an absolute URL on native). */
|
|
113
|
+
readonly endpoint: string;
|
|
114
|
+
/** Optional public client token for the RUM gateway; overridden by platform-specific clientToken. */
|
|
115
|
+
readonly clientToken?: string;
|
|
116
|
+
/** Cross-origin destinations that receive W3C trace context on HTTP requests. */
|
|
117
|
+
readonly propagateTo?: readonly UniversalRumOriginMatcher[];
|
|
118
|
+
/** Consent configuration. Default: pending until `handle.consent.grant()`. */
|
|
119
|
+
readonly consent?: UniversalRumConsentOptions;
|
|
120
|
+
/** Share of sessions sampled from the start, 0 to 1. */
|
|
121
|
+
readonly sessionSampleRate?: number;
|
|
122
|
+
/** Maximum early errors buffered before RUM finishes loading. Default 20. */
|
|
123
|
+
readonly maxBufferedErrors?: number;
|
|
124
|
+
/** Whether UniversalRumProvider calls useExpoRouterRum automatically. Default true. */
|
|
125
|
+
readonly expoRouter?: boolean;
|
|
126
|
+
/** Called once when setup completes with the live handle. */
|
|
127
|
+
readonly onReady?: (handle: UniversalRumHandle) => void;
|
|
128
|
+
/** Called if setup fails in safe mode. */
|
|
129
|
+
readonly onError?: (error: unknown) => void;
|
|
130
|
+
/** Web-only options. Ignored on native. */
|
|
131
|
+
readonly web?: UniversalRumWebOptions;
|
|
132
|
+
/** Native-only options. Ignored on web. */
|
|
133
|
+
readonly native?: UniversalRumNativeOptions;
|
|
134
|
+
}
|
|
135
|
+
/** Props of UniversalRumProvider. */
|
|
136
|
+
export interface UniversalRumProviderProps {
|
|
137
|
+
/**
|
|
138
|
+
* Configuration for universal RUM setup, or a memoized loader from `createUniversalRum`.
|
|
139
|
+
*
|
|
140
|
+
* Ownership contract:
|
|
141
|
+
* - When an options object (`UniversalRumOptions`) is passed, the provider owns the handle's
|
|
142
|
+
* lifecycle: configuration is captured when `config` first becomes defined (subsequent object
|
|
143
|
+
* updates while `config` remains defined are ignored), removing `config` (`undefined`) or
|
|
144
|
+
* unmounting shuts down the owned handle, and supplying a new options object starts a fresh
|
|
145
|
+
* setup after the prior shutdown settles.
|
|
146
|
+
* - When a prebuilt `UniversalRumLoader` function is passed, the caller owns the handle's
|
|
147
|
+
* lifecycle: unmounting or removing `config` detaches local provider state without shutting
|
|
148
|
+
* down the handle, so remounting or toggling `config` reuses the live handle.
|
|
149
|
+
* - When omitted, telemetry remains disabled and children render with `darkRum`.
|
|
150
|
+
*/
|
|
151
|
+
readonly config?: UniversalRumOptions | UniversalRumLoader;
|
|
152
|
+
/** Rendered by RumErrorBoundary when a descendant throws during render. */
|
|
153
|
+
readonly fallback?: ReactNode | ((error: unknown) => ReactNode);
|
|
154
|
+
/** Called once when setup resolves with the live handle. */
|
|
155
|
+
readonly onReady?: (handle: UniversalRumHandle) => void;
|
|
156
|
+
/** Called if setup fails in safe mode. */
|
|
157
|
+
readonly onError?: (error: unknown) => void;
|
|
158
|
+
/** Maximum early errors buffered before RUM loads. Overrides `config.maxBufferedErrors`. Default 20. */
|
|
159
|
+
readonly maxBufferedErrors?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Whether to run `useExpoRouterRum` automatically. Overrides `config.expoRouter` for options-object
|
|
162
|
+
* configs, and inherits `expoRouter` from a prebuilt `createUniversalRum(options)` loader when
|
|
163
|
+
* omitted. When passing a prebuilt loader, set `expoRouter` on `createUniversalRum(options)` so
|
|
164
|
+
* web `views({ history })` and `ExpoRouterBridge` stay in sync. Default true.
|
|
165
|
+
*/
|
|
166
|
+
readonly expoRouter?: boolean;
|
|
167
|
+
/** Forwarded to `useExpoRouterRum` when Expo Router tracking is enabled. */
|
|
168
|
+
readonly viewRendered?: "navigation" | "screen";
|
|
169
|
+
readonly children?: ReactNode;
|
|
170
|
+
}
|
|
171
|
+
/** A Rum handle that buffers early `addError` calls up to a bound and replays them on `attach`. */
|
|
172
|
+
export interface BufferingRum extends Rum {
|
|
173
|
+
/**
|
|
174
|
+
* Attaches the live RUM handle, replaying buffered errors through `target.addError` (preserving
|
|
175
|
+
* RUM's consent gate) and forwarding all subsequent calls. Idempotent after the first call.
|
|
176
|
+
*/
|
|
177
|
+
attach(target: Rum): void;
|
|
178
|
+
/** Drops all buffered errors and routes future calls to `darkRum`. */
|
|
179
|
+
discard(): void;
|
|
180
|
+
/** Number of errors currently waiting in the buffer. */
|
|
181
|
+
pendingErrors(): number;
|
|
182
|
+
}
|
|
183
|
+
/** Internal module shape checked by both universal-web.ts and universal-native.ts via `satisfies`. */
|
|
184
|
+
export interface UniversalRumModule {
|
|
185
|
+
readonly createUniversalRum: (options: UniversalRumOptions) => UniversalRumLoader;
|
|
186
|
+
readonly createBufferingRum: (maxErrors?: number) => BufferingRum;
|
|
187
|
+
readonly darkRum: Rum;
|
|
188
|
+
readonly UniversalRumProvider: (props: UniversalRumProviderProps) => ReactNode;
|
|
189
|
+
readonly useUniversalRum: () => UniversalRumState;
|
|
190
|
+
}
|
|
191
|
+
/** A safe no-op Rum handle used when telemetry is disabled, unavailable, or in SSR. */
|
|
192
|
+
export declare const darkRum: Rum;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a bounded Rum handle that buffers early `addError` calls until `attach(target)` is
|
|
195
|
+
* called. Buffered errors are replayed strictly through `target.addError`, so `@libo11y/rum`'s
|
|
196
|
+
* consent gate (`on()`) still decides whether each error is recorded.
|
|
197
|
+
*/
|
|
198
|
+
export declare function createBufferingRum(maxErrors?: number): BufferingRum;
|
|
199
|
+
/** Context holding the nearest UniversalRumProvider's status and live handle. */
|
|
200
|
+
export declare const UniversalRumContext: Context<UniversalRumState>;
|
|
201
|
+
/** Returns `{ status: "loading" | "ready", handle? }` from the nearest UniversalRumProvider. */
|
|
202
|
+
export declare function useUniversalRum(): UniversalRumState;
|
|
203
|
+
/** Runs a callback inside safe-mode try/catch so user hooks never crash telemetry lifecycle. */
|
|
204
|
+
export declare function safeCall(fn: (() => void) | undefined): void;
|
|
205
|
+
/** Safe-mode warning logger. */
|
|
206
|
+
export type WarnLogger = (message: string, error: unknown) => void;
|
|
207
|
+
export declare const defaultWarn: WarnLogger;
|
|
208
|
+
/** Internal non-enumerable tag carrying `options.expoRouter` from `createUniversalRum` to `UniversalRumProvider`. */
|
|
209
|
+
export declare const LOADER_EXPO_ROUTER_SYMBOL: unique symbol;
|
|
210
|
+
/**
|
|
211
|
+
* Wraps a platform setup function in a lazy, memoized, safe-mode loader:
|
|
212
|
+
* - Does no work until the returned function is invoked.
|
|
213
|
+
* - Memoizes the setup promise so repeated calls share one setup attempt.
|
|
214
|
+
* - Clears the memoized promise once an explicit `handle.telemetry.shutdown()` settles, so a
|
|
215
|
+
* caller who shuts down the handle can call the loader again for a fresh setup.
|
|
216
|
+
* - Catches any sync or async failure, logs one warning, invokes `onError`, and resolves `undefined`.
|
|
217
|
+
*/
|
|
218
|
+
export declare function createMemoizedSafeLoader(run: () => Promise<UniversalRumHandle | undefined>, callbacks: {
|
|
219
|
+
readonly expoRouter?: boolean | undefined;
|
|
220
|
+
readonly onReady?: ((handle: UniversalRumHandle) => void) | undefined;
|
|
221
|
+
readonly onError?: ((error: unknown) => void) | undefined;
|
|
222
|
+
readonly warn?: WarnLogger | undefined;
|
|
223
|
+
readonly skipMemoize?: (() => boolean) | undefined;
|
|
224
|
+
}): UniversalRumLoader;
|
|
225
|
+
/** Internal provider dependencies supplied by universal-web.ts and universal-native.ts. */
|
|
226
|
+
export interface UniversalProviderDeps {
|
|
227
|
+
readonly createLoader: (options: UniversalRumOptions) => UniversalRumLoader;
|
|
228
|
+
readonly RumProvider: ComponentType<{
|
|
229
|
+
readonly rum: Rum;
|
|
230
|
+
readonly children?: ReactNode;
|
|
231
|
+
}>;
|
|
232
|
+
readonly RumErrorBoundary: ComponentType<{
|
|
233
|
+
readonly rum?: Rum;
|
|
234
|
+
readonly fallback?: ReactNode | ((error: unknown) => ReactNode);
|
|
235
|
+
readonly children?: ReactNode;
|
|
236
|
+
}>;
|
|
237
|
+
readonly TouchBoundary?: ComponentType<{
|
|
238
|
+
readonly children?: ReactNode;
|
|
239
|
+
}>;
|
|
240
|
+
readonly useExpoRouterRum: (rum: Rum | undefined, options?: {
|
|
241
|
+
readonly viewRendered?: "navigation" | "screen";
|
|
242
|
+
}) => void;
|
|
243
|
+
readonly warn?: WarnLogger | undefined;
|
|
244
|
+
}
|
|
245
|
+
/** Internal mutable refs held by UniversalRumProviderBase across committed effects. */
|
|
246
|
+
export interface ProviderLifecycleRefs {
|
|
247
|
+
buffer: BufferingRum | undefined;
|
|
248
|
+
loader: UniversalRumLoader | undefined;
|
|
249
|
+
activeLoader: UniversalRumLoader | undefined;
|
|
250
|
+
owned: boolean;
|
|
251
|
+
ownedHandle: UniversalRumHandle | undefined;
|
|
252
|
+
pendingShutdown: Promise<void>;
|
|
253
|
+
notifiedReady: boolean;
|
|
254
|
+
warnedExpoRouterMismatch: boolean;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Starts or tears down the universal RUM load for one effect cycle of UniversalRumProviderBase.
|
|
258
|
+
* - Owned handles (created from an options object) are shut down on cleanup/removal and serialized
|
|
259
|
+
* through `refs.pendingShutdown` so any subsequent setup waits for shutdown to settle.
|
|
260
|
+
* - Caller-supplied `UniversalRumLoader` handles (`owned === false`) are never shut down by the
|
|
261
|
+
* provider on cleanup/unmount.
|
|
262
|
+
* - Cancelled effect callbacks never touch a newer mount's buffer, state, or `onError`.
|
|
263
|
+
* Exported internally for deterministic lifecycle unit testing under Node and Bun.
|
|
264
|
+
*/
|
|
265
|
+
export declare function runProviderEffect(params: {
|
|
266
|
+
readonly hasConfig: boolean;
|
|
267
|
+
readonly owned: boolean;
|
|
268
|
+
readonly callerLoader?: UniversalRumLoader | undefined;
|
|
269
|
+
readonly refs: ProviderLifecycleRefs;
|
|
270
|
+
readonly setState: (update: UniversalRumState | ((prev: UniversalRumState) => UniversalRumState)) => void;
|
|
271
|
+
readonly onReady: () => ((handle: UniversalRumHandle) => void) | undefined;
|
|
272
|
+
readonly onError: () => ((error: unknown) => void) | undefined;
|
|
273
|
+
}): (() => void) | undefined;
|
|
274
|
+
/** Shared top-level provider component parameterized by platform dependencies. */
|
|
275
|
+
export declare function UniversalRumProviderBase(props: UniversalRumProviderProps & {
|
|
276
|
+
readonly deps: UniversalProviderDeps;
|
|
277
|
+
}): ReactNode;
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { createContext, createElement, Fragment, useContext, useEffect, useRef, useState, } from "react";
|
|
2
|
+
/** A safe no-op Rum handle used when telemetry is disabled, unavailable, or in SSR. */
|
|
3
|
+
export const darkRum = Object.freeze({
|
|
4
|
+
sessionId: () => undefined,
|
|
5
|
+
identify: () => { },
|
|
6
|
+
onRequestStart: () => () => { },
|
|
7
|
+
startView: () => { },
|
|
8
|
+
setViewName: () => { },
|
|
9
|
+
viewRendered: () => { },
|
|
10
|
+
addAction: () => { },
|
|
11
|
+
addError: () => { },
|
|
12
|
+
});
|
|
13
|
+
const DEFAULT_MAX_BUFFERED_ERRORS = 20;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a bounded Rum handle that buffers early `addError` calls until `attach(target)` is
|
|
16
|
+
* called. Buffered errors are replayed strictly through `target.addError`, so `@libo11y/rum`'s
|
|
17
|
+
* consent gate (`on()`) still decides whether each error is recorded.
|
|
18
|
+
*/
|
|
19
|
+
export function createBufferingRum(maxErrors = DEFAULT_MAX_BUFFERED_ERRORS) {
|
|
20
|
+
const limit = Number.isFinite(maxErrors) && maxErrors > 0 ? Math.floor(maxErrors) : 0;
|
|
21
|
+
const buffered = [];
|
|
22
|
+
let target;
|
|
23
|
+
let discarded = false;
|
|
24
|
+
return {
|
|
25
|
+
sessionId: () => target?.sessionId(),
|
|
26
|
+
identify: (userId) => {
|
|
27
|
+
target?.identify(userId);
|
|
28
|
+
},
|
|
29
|
+
onRequestStart: (hook) => (target === undefined ? () => { } : target.onRequestStart(hook)),
|
|
30
|
+
startView: (opts) => {
|
|
31
|
+
target?.startView(opts);
|
|
32
|
+
},
|
|
33
|
+
setViewName: (name) => {
|
|
34
|
+
target?.setViewName(name);
|
|
35
|
+
},
|
|
36
|
+
viewRendered: () => {
|
|
37
|
+
target?.viewRendered();
|
|
38
|
+
},
|
|
39
|
+
addAction: (name) => {
|
|
40
|
+
target?.addAction(name);
|
|
41
|
+
},
|
|
42
|
+
addError: (error, opts) => {
|
|
43
|
+
if (target !== undefined) {
|
|
44
|
+
target.addError(error, opts);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!discarded && buffered.length < limit) {
|
|
48
|
+
buffered.push({ error, opts });
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
attach: (next) => {
|
|
52
|
+
if (target !== undefined || discarded)
|
|
53
|
+
return;
|
|
54
|
+
target = next;
|
|
55
|
+
const queued = buffered.splice(0);
|
|
56
|
+
for (const entry of queued) {
|
|
57
|
+
try {
|
|
58
|
+
next.addError(entry.error, entry.opts);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Safe mode: never let a replayed error interrupt startup.
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
discard: () => {
|
|
66
|
+
if (discarded)
|
|
67
|
+
return;
|
|
68
|
+
discarded = true;
|
|
69
|
+
buffered.length = 0;
|
|
70
|
+
if (target === undefined)
|
|
71
|
+
target = darkRum;
|
|
72
|
+
},
|
|
73
|
+
pendingErrors: () => buffered.length,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const DEFAULT_STATE = Object.freeze({ status: "loading" });
|
|
77
|
+
/** Context holding the nearest UniversalRumProvider's status and live handle. */
|
|
78
|
+
export const UniversalRumContext = createContext(DEFAULT_STATE);
|
|
79
|
+
/** Returns `{ status: "loading" | "ready", handle? }` from the nearest UniversalRumProvider. */
|
|
80
|
+
export function useUniversalRum() {
|
|
81
|
+
return useContext(UniversalRumContext);
|
|
82
|
+
}
|
|
83
|
+
/** Runs a callback inside safe-mode try/catch so user hooks never crash telemetry lifecycle. */
|
|
84
|
+
export function safeCall(fn) {
|
|
85
|
+
if (fn === undefined)
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
fn();
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Safe mode: ignore callback throws.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export const defaultWarn = (message, error) => {
|
|
95
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
96
|
+
if (error === undefined) {
|
|
97
|
+
console.warn(message);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.warn(message, error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/** Internal non-enumerable tag carrying `options.expoRouter` from `createUniversalRum` to `UniversalRumProvider`. */
|
|
105
|
+
export const LOADER_EXPO_ROUTER_SYMBOL = Symbol("libo11y.rum.universal.expoRouter");
|
|
106
|
+
/**
|
|
107
|
+
* Wraps a platform setup function in a lazy, memoized, safe-mode loader:
|
|
108
|
+
* - Does no work until the returned function is invoked.
|
|
109
|
+
* - Memoizes the setup promise so repeated calls share one setup attempt.
|
|
110
|
+
* - Clears the memoized promise once an explicit `handle.telemetry.shutdown()` settles, so a
|
|
111
|
+
* caller who shuts down the handle can call the loader again for a fresh setup.
|
|
112
|
+
* - Catches any sync or async failure, logs one warning, invokes `onError`, and resolves `undefined`.
|
|
113
|
+
*/
|
|
114
|
+
export function createMemoizedSafeLoader(run, callbacks) {
|
|
115
|
+
let pending;
|
|
116
|
+
const warn = callbacks.warn ?? defaultWarn;
|
|
117
|
+
const loader = () => {
|
|
118
|
+
if (callbacks.skipMemoize?.() === true) {
|
|
119
|
+
return Promise.resolve(undefined);
|
|
120
|
+
}
|
|
121
|
+
if (pending !== undefined)
|
|
122
|
+
return pending;
|
|
123
|
+
const current = (async () => {
|
|
124
|
+
try {
|
|
125
|
+
const handle = await run();
|
|
126
|
+
if (handle !== undefined) {
|
|
127
|
+
const origShutdown = handle.telemetry.shutdown;
|
|
128
|
+
if (typeof origShutdown === "function") {
|
|
129
|
+
let cleared = false;
|
|
130
|
+
const clear = () => {
|
|
131
|
+
if (pending === current)
|
|
132
|
+
pending = undefined;
|
|
133
|
+
};
|
|
134
|
+
const wrappedShutdown = (...args) => {
|
|
135
|
+
let report;
|
|
136
|
+
try {
|
|
137
|
+
report = origShutdown.apply(handle.telemetry, args);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
if (!cleared) {
|
|
141
|
+
cleared = true;
|
|
142
|
+
clear();
|
|
143
|
+
}
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
if (!cleared) {
|
|
147
|
+
cleared = true;
|
|
148
|
+
void Promise.resolve(report).then(clear, clear);
|
|
149
|
+
}
|
|
150
|
+
return report;
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
Object.defineProperty(handle.telemetry, "shutdown", {
|
|
154
|
+
value: wrappedShutdown,
|
|
155
|
+
configurable: true,
|
|
156
|
+
writable: true,
|
|
157
|
+
enumerable: true,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Frozen telemetry mock: skip in-place shutdown wrapping.
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
safeCall(() => callbacks.onReady?.(handle));
|
|
165
|
+
}
|
|
166
|
+
return handle;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
safeCall(() => warn("o11y: rum: universal setup failed; telemetry disabled", error));
|
|
170
|
+
safeCall(() => callbacks.onError?.(error));
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
})();
|
|
174
|
+
pending = current;
|
|
175
|
+
return current;
|
|
176
|
+
};
|
|
177
|
+
Object.defineProperty(loader, LOADER_EXPO_ROUTER_SYMBOL, {
|
|
178
|
+
value: callbacks.expoRouter,
|
|
179
|
+
enumerable: false,
|
|
180
|
+
configurable: true,
|
|
181
|
+
});
|
|
182
|
+
return loader;
|
|
183
|
+
}
|
|
184
|
+
/** Top-level bridge so `useExpoRouterRum` is only mounted when `expoRouter` is enabled. */
|
|
185
|
+
function ExpoRouterBridge(props) {
|
|
186
|
+
props.useExpoRouterRum(props.rum, props.viewRendered === undefined ? {} : { viewRendered: props.viewRendered });
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function safeShutdown(handle) {
|
|
190
|
+
return Promise.resolve()
|
|
191
|
+
.then(() => handle.telemetry.shutdown())
|
|
192
|
+
.then(() => undefined, () => undefined);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Starts or tears down the universal RUM load for one effect cycle of UniversalRumProviderBase.
|
|
196
|
+
* - Owned handles (created from an options object) are shut down on cleanup/removal and serialized
|
|
197
|
+
* through `refs.pendingShutdown` so any subsequent setup waits for shutdown to settle.
|
|
198
|
+
* - Caller-supplied `UniversalRumLoader` handles (`owned === false`) are never shut down by the
|
|
199
|
+
* provider on cleanup/unmount.
|
|
200
|
+
* - Cancelled effect callbacks never touch a newer mount's buffer, state, or `onError`.
|
|
201
|
+
* Exported internally for deterministic lifecycle unit testing under Node and Bun.
|
|
202
|
+
*/
|
|
203
|
+
export function runProviderEffect(params) {
|
|
204
|
+
const { hasConfig, owned, callerLoader, refs, setState, onReady, onError } = params;
|
|
205
|
+
const loader = hasConfig ? (callerLoader ?? refs.loader) : undefined;
|
|
206
|
+
const buffer = refs.buffer;
|
|
207
|
+
if (loader === undefined) {
|
|
208
|
+
refs.activeLoader = undefined;
|
|
209
|
+
refs.loader = undefined;
|
|
210
|
+
refs.notifiedReady = false;
|
|
211
|
+
if (refs.ownedHandle !== undefined) {
|
|
212
|
+
const prev = refs.ownedHandle;
|
|
213
|
+
refs.ownedHandle = undefined;
|
|
214
|
+
refs.pendingShutdown = refs.pendingShutdown.then(() => safeShutdown(prev));
|
|
215
|
+
}
|
|
216
|
+
buffer?.discard();
|
|
217
|
+
refs.buffer = undefined;
|
|
218
|
+
setState((prev) => (prev.status === "ready" && prev.handle === undefined ? prev : { status: "ready" }));
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
setState((prev) => (prev.status === "loading" && prev.handle === undefined ? prev : { status: "loading" }));
|
|
222
|
+
refs.activeLoader = loader;
|
|
223
|
+
let cancelled = false;
|
|
224
|
+
let settled = false;
|
|
225
|
+
let markLoadDone;
|
|
226
|
+
const loadDone = new Promise((resolve) => {
|
|
227
|
+
markLoadDone = resolve;
|
|
228
|
+
});
|
|
229
|
+
const startAfter = refs.pendingShutdown;
|
|
230
|
+
void startAfter
|
|
231
|
+
.then(() => {
|
|
232
|
+
if (cancelled)
|
|
233
|
+
return undefined;
|
|
234
|
+
return loader();
|
|
235
|
+
})
|
|
236
|
+
.then((handle) => {
|
|
237
|
+
if (cancelled) {
|
|
238
|
+
if (owned && handle !== undefined && refs.ownedHandle !== handle && refs.activeLoader !== loader) {
|
|
239
|
+
return safeShutdown(handle);
|
|
240
|
+
}
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
if (handle !== undefined) {
|
|
244
|
+
if (owned)
|
|
245
|
+
refs.ownedHandle = handle;
|
|
246
|
+
buffer?.attach(handle.rum);
|
|
247
|
+
setState({ status: "ready", handle });
|
|
248
|
+
if (!refs.notifiedReady) {
|
|
249
|
+
refs.notifiedReady = true;
|
|
250
|
+
safeCall(() => onReady()?.(handle));
|
|
251
|
+
}
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
buffer?.discard();
|
|
255
|
+
setState({ status: "ready" });
|
|
256
|
+
return undefined;
|
|
257
|
+
}, (error) => {
|
|
258
|
+
if (cancelled)
|
|
259
|
+
return;
|
|
260
|
+
buffer?.discard();
|
|
261
|
+
safeCall(() => onError()?.(error));
|
|
262
|
+
setState({ status: "ready" });
|
|
263
|
+
})
|
|
264
|
+
.finally(() => {
|
|
265
|
+
settled = true;
|
|
266
|
+
markLoadDone();
|
|
267
|
+
});
|
|
268
|
+
return () => {
|
|
269
|
+
cancelled = true;
|
|
270
|
+
if (refs.activeLoader === loader) {
|
|
271
|
+
refs.activeLoader = undefined;
|
|
272
|
+
}
|
|
273
|
+
if (owned) {
|
|
274
|
+
if (refs.ownedHandle !== undefined) {
|
|
275
|
+
const prev = refs.ownedHandle;
|
|
276
|
+
refs.ownedHandle = undefined;
|
|
277
|
+
refs.pendingShutdown = refs.pendingShutdown.then(() => safeShutdown(prev));
|
|
278
|
+
}
|
|
279
|
+
else if (!settled) {
|
|
280
|
+
refs.pendingShutdown = refs.pendingShutdown.then(() => loadDone);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const LOADING_STATE = Object.freeze({ status: "loading" });
|
|
286
|
+
const READY_EMPTY_STATE = Object.freeze({ status: "ready" });
|
|
287
|
+
function createConfigSession(params) {
|
|
288
|
+
if (params.kind === "none") {
|
|
289
|
+
return {
|
|
290
|
+
kind: "none",
|
|
291
|
+
callerLoader: undefined,
|
|
292
|
+
loader: undefined,
|
|
293
|
+
buffer: undefined,
|
|
294
|
+
ownedExpoRouter: undefined,
|
|
295
|
+
onReady: params.onReady,
|
|
296
|
+
onError: params.onError,
|
|
297
|
+
configOnError: undefined,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
if (params.kind === "caller") {
|
|
301
|
+
return {
|
|
302
|
+
kind: "caller",
|
|
303
|
+
callerLoader: params.callerLoader,
|
|
304
|
+
loader: params.callerLoader,
|
|
305
|
+
buffer: createBufferingRum(params.maxErrors),
|
|
306
|
+
ownedExpoRouter: undefined,
|
|
307
|
+
onReady: params.onReady,
|
|
308
|
+
onError: params.onError,
|
|
309
|
+
configOnError: undefined,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
const initialExpoRouter = params.requestedEnableRouter;
|
|
313
|
+
const session = {
|
|
314
|
+
kind: "owned",
|
|
315
|
+
callerLoader: undefined,
|
|
316
|
+
loader: undefined,
|
|
317
|
+
buffer: createBufferingRum(params.maxErrors),
|
|
318
|
+
ownedExpoRouter: initialExpoRouter,
|
|
319
|
+
onReady: params.onReady,
|
|
320
|
+
onError: params.onError,
|
|
321
|
+
configOnError: params.configOptions?.onError,
|
|
322
|
+
};
|
|
323
|
+
let createdLoader;
|
|
324
|
+
const mergedOptions = Object.assign({}, params.configOptions, {
|
|
325
|
+
expoRouter: initialExpoRouter,
|
|
326
|
+
onError: (err) => {
|
|
327
|
+
if (!params.activeLoaderMatches(createdLoader))
|
|
328
|
+
return;
|
|
329
|
+
safeCall(() => session.configOnError?.(err));
|
|
330
|
+
safeCall(() => session.onError?.(err));
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
createdLoader = params.createLoader(mergedOptions);
|
|
334
|
+
return Object.assign(session, { loader: createdLoader });
|
|
335
|
+
}
|
|
336
|
+
/** Shared top-level provider component parameterized by platform dependencies. */
|
|
337
|
+
export function UniversalRumProviderBase(props) {
|
|
338
|
+
const { deps } = props;
|
|
339
|
+
const hasConfig = props.config !== undefined;
|
|
340
|
+
const callerLoader = typeof props.config === "function" ? props.config : undefined;
|
|
341
|
+
const configOptions = typeof props.config === "object" ? props.config : undefined;
|
|
342
|
+
const nextKind = !hasConfig
|
|
343
|
+
? "none"
|
|
344
|
+
: callerLoader !== undefined
|
|
345
|
+
? "caller"
|
|
346
|
+
: "owned";
|
|
347
|
+
const maxErrors = props.maxBufferedErrors ?? configOptions?.maxBufferedErrors ?? DEFAULT_MAX_BUFFERED_ERRORS;
|
|
348
|
+
const hasTaggedExpoRouter = callerLoader !== undefined && LOADER_EXPO_ROUTER_SYMBOL in callerLoader;
|
|
349
|
+
const taggedExpoRouter = hasTaggedExpoRouter
|
|
350
|
+
? callerLoader[LOADER_EXPO_ROUTER_SYMBOL]
|
|
351
|
+
: undefined;
|
|
352
|
+
const requestedEnableRouter = props.expoRouter ??
|
|
353
|
+
configOptions?.expoRouter ??
|
|
354
|
+
(hasTaggedExpoRouter ? (taggedExpoRouter ?? true) : true);
|
|
355
|
+
const refs = useRef({
|
|
356
|
+
buffer: undefined,
|
|
357
|
+
loader: undefined,
|
|
358
|
+
activeLoader: undefined,
|
|
359
|
+
owned: false,
|
|
360
|
+
ownedHandle: undefined,
|
|
361
|
+
pendingShutdown: Promise.resolve(),
|
|
362
|
+
notifiedReady: false,
|
|
363
|
+
warnedExpoRouterMismatch: false,
|
|
364
|
+
});
|
|
365
|
+
const buildSession = () => createConfigSession({
|
|
366
|
+
kind: nextKind,
|
|
367
|
+
callerLoader,
|
|
368
|
+
configOptions,
|
|
369
|
+
maxErrors,
|
|
370
|
+
requestedEnableRouter,
|
|
371
|
+
createLoader: deps.createLoader,
|
|
372
|
+
activeLoaderMatches: (loader) => loader !== undefined && refs.current.activeLoader === loader,
|
|
373
|
+
onReady: props.onReady,
|
|
374
|
+
onError: props.onError,
|
|
375
|
+
});
|
|
376
|
+
// Hold per-config session in React state rather than mutating lifecycle refs during render so
|
|
377
|
+
// suspended/abandoned concurrent renders never corrupt the committed config's loader or buffer.
|
|
378
|
+
const [session, setSession] = useState(buildSession);
|
|
379
|
+
const sessionMatches = session.kind === nextKind && (nextKind !== "caller" || session.callerLoader === callerLoader);
|
|
380
|
+
let activeSession = session;
|
|
381
|
+
if (!sessionMatches) {
|
|
382
|
+
activeSession = buildSession();
|
|
383
|
+
setSession(activeSession);
|
|
384
|
+
}
|
|
385
|
+
const enableRouter = activeSession.kind === "owned"
|
|
386
|
+
? (activeSession.ownedExpoRouter ?? requestedEnableRouter)
|
|
387
|
+
: requestedEnableRouter;
|
|
388
|
+
if (hasTaggedExpoRouter &&
|
|
389
|
+
props.expoRouter !== undefined &&
|
|
390
|
+
props.expoRouter !== (taggedExpoRouter ?? true) &&
|
|
391
|
+
!refs.current.warnedExpoRouterMismatch) {
|
|
392
|
+
refs.current.warnedExpoRouterMismatch = true;
|
|
393
|
+
const warn = deps.warn ?? defaultWarn;
|
|
394
|
+
safeCall(() => warn("o11y: rum: UniversalRumProvider expoRouter prop disagrees with prebuilt createUniversalRum(options); set expoRouter on createUniversalRum(options) instead", undefined));
|
|
395
|
+
}
|
|
396
|
+
const [stateEntry, setStateEntry] = useState(() => ({
|
|
397
|
+
session: activeSession,
|
|
398
|
+
state: hasConfig ? LOADING_STATE : READY_EMPTY_STATE,
|
|
399
|
+
}));
|
|
400
|
+
// Update callbacks on the committed session in a passive effect so a previous session's failure
|
|
401
|
+
// during a transition commit can never invoke the replacement session's onError callback.
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
activeSession.onReady = props.onReady;
|
|
404
|
+
activeSession.onError = props.onError;
|
|
405
|
+
activeSession.configOnError = configOptions?.onError;
|
|
406
|
+
}, [activeSession, props.onReady, props.onError, configOptions?.onError]);
|
|
407
|
+
useEffect(() => {
|
|
408
|
+
refs.current.buffer = activeSession.buffer;
|
|
409
|
+
refs.current.loader = activeSession.loader;
|
|
410
|
+
refs.current.owned = activeSession.kind === "owned";
|
|
411
|
+
refs.current.notifiedReady = false;
|
|
412
|
+
return runProviderEffect({
|
|
413
|
+
hasConfig: activeSession.kind !== "none",
|
|
414
|
+
owned: activeSession.kind === "owned",
|
|
415
|
+
callerLoader: activeSession.callerLoader,
|
|
416
|
+
refs: refs.current,
|
|
417
|
+
setState: (update) => {
|
|
418
|
+
setStateEntry((prev) => {
|
|
419
|
+
const base = prev.session === activeSession
|
|
420
|
+
? prev.state
|
|
421
|
+
: activeSession.kind === "none"
|
|
422
|
+
? READY_EMPTY_STATE
|
|
423
|
+
: LOADING_STATE;
|
|
424
|
+
const next = typeof update === "function" ? update(base) : update;
|
|
425
|
+
if (prev.session === activeSession && prev.state === next)
|
|
426
|
+
return prev;
|
|
427
|
+
return { session: activeSession, state: next };
|
|
428
|
+
});
|
|
429
|
+
},
|
|
430
|
+
onReady: () => activeSession.onReady,
|
|
431
|
+
onError: () => activeSession.onError,
|
|
432
|
+
});
|
|
433
|
+
}, [activeSession]);
|
|
434
|
+
const stateMatches = stateEntry.session === activeSession;
|
|
435
|
+
const visibleState = stateMatches
|
|
436
|
+
? stateEntry.state
|
|
437
|
+
: hasConfig
|
|
438
|
+
? LOADING_STATE
|
|
439
|
+
: READY_EMPTY_STATE;
|
|
440
|
+
const activeHandle = stateMatches ? stateEntry.state.handle : undefined;
|
|
441
|
+
const activeRum = activeHandle?.rum ?? (hasConfig ? (activeSession.buffer ?? darkRum) : darkRum);
|
|
442
|
+
const boundaryProps = props.fallback === undefined ? { rum: activeRum } : { rum: activeRum, fallback: props.fallback };
|
|
443
|
+
const inner = createElement(deps.RumProvider, { rum: activeRum }, createElement(deps.RumErrorBoundary, boundaryProps, enableRouter
|
|
444
|
+
? createElement(ExpoRouterBridge, {
|
|
445
|
+
useExpoRouterRum: deps.useExpoRouterRum,
|
|
446
|
+
rum: activeHandle?.rum,
|
|
447
|
+
viewRendered: props.viewRendered,
|
|
448
|
+
})
|
|
449
|
+
: null, props.children));
|
|
450
|
+
const wrapped = deps.TouchBoundary === undefined
|
|
451
|
+
? createElement(Fragment, null, inner)
|
|
452
|
+
: createElement(deps.TouchBoundary, null, inner);
|
|
453
|
+
return createElement(UniversalRumContext.Provider, { value: visibleState }, wrapped);
|
|
454
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure testable web implementation for `@libo11y/rum-expo-router/universal`.
|
|
3
|
+
* Guards SSR (`typeof document === "undefined"`), waits for first paint (`requestAnimationFrame` +
|
|
4
|
+
* `setTimeout(0)`) unless disabled, dynamically imports `@libo11y/rum` so the RUM + OTel SDK
|
|
5
|
+
* splits into an async chunk, applies `data-o11y-mask` on `document.documentElement` when
|
|
6
|
+
* `web.maskRoot === true`, and wraps `setupRum` in safe mode.
|
|
7
|
+
*/
|
|
8
|
+
import type { RumSetupOptions, RumTelemetry } from "@libo11y/rum";
|
|
9
|
+
import { type UniversalRumLoader, type UniversalRumOptions, type UniversalRumWebCollectors, type WarnLogger } from "./universal-shared.ts";
|
|
10
|
+
/** The slice of `@libo11y/rum` dynamically imported by the web universal entry. */
|
|
11
|
+
export interface UniversalWebRumImport extends UniversalRumWebCollectors {
|
|
12
|
+
readonly setupRum: (options?: RumSetupOptions) => Promise<RumTelemetry>;
|
|
13
|
+
}
|
|
14
|
+
/** The slice of `document` touched by the web universal entry. */
|
|
15
|
+
export interface DocumentLike {
|
|
16
|
+
readonly documentElement?: {
|
|
17
|
+
setAttribute(name: string, value: string): void;
|
|
18
|
+
} | null;
|
|
19
|
+
}
|
|
20
|
+
/** Injectable dependencies for testing universal-web without DOM globals or dynamic imports. */
|
|
21
|
+
export interface UniversalWebDeps {
|
|
22
|
+
readonly getDocument: () => DocumentLike | undefined;
|
|
23
|
+
readonly afterFirstPaint: () => Promise<void>;
|
|
24
|
+
readonly importRum: () => Promise<UniversalWebRumImport>;
|
|
25
|
+
readonly warn?: WarnLogger | undefined;
|
|
26
|
+
}
|
|
27
|
+
/** Resolves after the next animation frame and macrotask turn (`rAF` + `setTimeout(0)`). */
|
|
28
|
+
export declare function afterFirstPaint(timers?: {
|
|
29
|
+
readonly requestAnimationFrame?: ((cb: () => void) => unknown) | undefined;
|
|
30
|
+
readonly setTimeout?: ((cb: () => void, ms: number) => unknown) | undefined;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
/** Creates the web universal RUM loader over injectable dependencies. */
|
|
33
|
+
export declare function createUniversalRumWebWith(options: UniversalRumOptions, deps: UniversalWebDeps): UniversalRumLoader;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createMemoizedSafeLoader, } from "./universal-shared.js";
|
|
2
|
+
/** Resolves after the next animation frame and macrotask turn (`rAF` + `setTimeout(0)`). */
|
|
3
|
+
export function afterFirstPaint(timers) {
|
|
4
|
+
const raf = timers !== undefined
|
|
5
|
+
? timers.requestAnimationFrame
|
|
6
|
+
: typeof globalThis.requestAnimationFrame === "function"
|
|
7
|
+
? globalThis.requestAnimationFrame
|
|
8
|
+
: undefined;
|
|
9
|
+
const setTimer = timers !== undefined
|
|
10
|
+
? timers.setTimeout
|
|
11
|
+
: typeof globalThis.setTimeout === "function"
|
|
12
|
+
? globalThis.setTimeout
|
|
13
|
+
: undefined;
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const finish = () => {
|
|
16
|
+
if (setTimer !== undefined) {
|
|
17
|
+
setTimer(resolve, 0);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
resolve();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
if (raf !== undefined) {
|
|
24
|
+
raf(finish);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
finish();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Creates the web universal RUM loader over injectable dependencies. */
|
|
32
|
+
export function createUniversalRumWebWith(options, deps) {
|
|
33
|
+
return createMemoizedSafeLoader(async () => {
|
|
34
|
+
const doc = deps.getDocument();
|
|
35
|
+
if (doc === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
if (options.web?.maskRoot === true) {
|
|
38
|
+
doc.documentElement?.setAttribute("data-o11y-mask", "");
|
|
39
|
+
}
|
|
40
|
+
if (options.web?.deferUntilFirstPaint !== false) {
|
|
41
|
+
await deps.afterFirstPaint();
|
|
42
|
+
}
|
|
43
|
+
const rumMod = await deps.importRum();
|
|
44
|
+
const collectors = typeof options.web?.collectors === "function"
|
|
45
|
+
? options.web.collectors(rumMod)
|
|
46
|
+
: (options.web?.collectors ?? [
|
|
47
|
+
rumMod.views({ history: options.expoRouter === false }),
|
|
48
|
+
rumMod.actions(),
|
|
49
|
+
rumMod.errors(),
|
|
50
|
+
rumMod.vitals(),
|
|
51
|
+
rumMod.resources(),
|
|
52
|
+
]);
|
|
53
|
+
const propagateTo = options.web?.instrumentations?.propagateTo ?? options.propagateTo;
|
|
54
|
+
const instrumentations = options.web?.instrumentations !== undefined || propagateTo !== undefined
|
|
55
|
+
? {
|
|
56
|
+
...options.web?.instrumentations,
|
|
57
|
+
...(propagateTo === undefined ? {} : { propagateTo }),
|
|
58
|
+
}
|
|
59
|
+
: undefined;
|
|
60
|
+
const clientToken = options.web?.clientToken ?? options.clientToken;
|
|
61
|
+
const setupOptions = {
|
|
62
|
+
serviceName: options.serviceName,
|
|
63
|
+
environment: options.environment,
|
|
64
|
+
...(options.serviceVersion === undefined ? {} : { serviceVersion: options.serviceVersion }),
|
|
65
|
+
endpoint: options.endpoint,
|
|
66
|
+
...(options.consent === undefined ? {} : { consent: options.consent }),
|
|
67
|
+
...(options.web?.headers === undefined ? {} : { headers: options.web.headers }),
|
|
68
|
+
...(options.web?.resourceAttributes === undefined
|
|
69
|
+
? {}
|
|
70
|
+
: { resourceAttributes: options.web.resourceAttributes }),
|
|
71
|
+
...(instrumentations === undefined ? {} : { instrumentations }),
|
|
72
|
+
rum: {
|
|
73
|
+
...options.web?.rum,
|
|
74
|
+
...(options.sessionSampleRate === undefined
|
|
75
|
+
? {}
|
|
76
|
+
: { sessionSampleRate: options.sessionSampleRate }),
|
|
77
|
+
...(clientToken === undefined ? {} : { clientToken }),
|
|
78
|
+
collectors,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
const telemetry = await rumMod.setupRum(setupOptions);
|
|
82
|
+
return { rum: telemetry.rum, consent: telemetry.consent, telemetry };
|
|
83
|
+
}, {
|
|
84
|
+
expoRouter: options.expoRouter,
|
|
85
|
+
onReady: options.onReady,
|
|
86
|
+
onError: options.onError,
|
|
87
|
+
warn: deps.warn,
|
|
88
|
+
skipMemoize: () => deps.getDocument() === undefined,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type BufferingRum, createBufferingRum, darkRum, type UniversalRumConsent, type UniversalRumConsentOptions, type UniversalRumHandle, type UniversalRumLoader, type UniversalRumNativeInstrumentationOptions, type UniversalRumNativeOptions, type UniversalRumOptions, type UniversalRumOriginMatcher, type UniversalRumProviderProps, type UniversalRumState, type UniversalRumStatus, type UniversalRumTelemetry, type UniversalRumWebCollectors, type UniversalRumWebOptions, useUniversalRum } from "./universal-shared.ts";
|
|
3
|
+
export type { BufferingRum, UniversalRumConsent, UniversalRumConsentOptions, UniversalRumHandle, UniversalRumLoader, UniversalRumNativeInstrumentationOptions, UniversalRumNativeOptions, UniversalRumOptions, UniversalRumOriginMatcher, UniversalRumProviderProps, UniversalRumState, UniversalRumStatus, UniversalRumTelemetry, UniversalRumWebCollectors, UniversalRumWebOptions, };
|
|
4
|
+
export { createBufferingRum, darkRum, useUniversalRum };
|
|
5
|
+
/**
|
|
6
|
+
* Creates a lazy, memoized, safe-mode RUM loader for web. Guards SSR (`typeof document === "undefined"`),
|
|
7
|
+
* waits for first paint unless `web.deferUntilFirstPaint === false`, dynamically imports `@libo11y/rum`,
|
|
8
|
+
* applies `data-o11y-mask` on `document.documentElement` when `web.maskRoot === true`, and resolves to
|
|
9
|
+
* `undefined` after logging one warning if setup fails.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createUniversalRum(options: UniversalRumOptions): UniversalRumLoader;
|
|
12
|
+
/**
|
|
13
|
+
* Universal RUM provider for Expo Router apps on web: defers RUM initialization until after first
|
|
14
|
+
* paint, buffers early errors with consent-safe replay, and wraps children in `RumProvider`,
|
|
15
|
+
* `RumErrorBoundary`, and `useExpoRouterRum`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function UniversalRumProvider(props: UniversalRumProviderProps): ReactNode;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser / web entry for `@libo11y/rum-expo-router/universal` (`browser` and `default` export
|
|
3
|
+
* conditions). Dynamically imports `@libo11y/rum` after first paint so the RUM + OpenTelemetry SDK
|
|
4
|
+
* splits into an async chunk outside the initial bundle. Uses `React.createElement` (plain `.ts`).
|
|
5
|
+
*/
|
|
6
|
+
import { RumErrorBoundary, RumProvider } from "@libo11y/rum-react";
|
|
7
|
+
import { createElement } from "react";
|
|
8
|
+
import { useExpoRouterRum } from "./hook.js";
|
|
9
|
+
import { createBufferingRum, darkRum, UniversalRumProviderBase, useUniversalRum, } from "./universal-shared.js";
|
|
10
|
+
import { afterFirstPaint, createUniversalRumWebWith } from "./universal-web-core.js";
|
|
11
|
+
export { createBufferingRum, darkRum, useUniversalRum };
|
|
12
|
+
/**
|
|
13
|
+
* Creates a lazy, memoized, safe-mode RUM loader for web. Guards SSR (`typeof document === "undefined"`),
|
|
14
|
+
* waits for first paint unless `web.deferUntilFirstPaint === false`, dynamically imports `@libo11y/rum`,
|
|
15
|
+
* applies `data-o11y-mask` on `document.documentElement` when `web.maskRoot === true`, and resolves to
|
|
16
|
+
* `undefined` after logging one warning if setup fails.
|
|
17
|
+
*/
|
|
18
|
+
export function createUniversalRum(options) {
|
|
19
|
+
return createUniversalRumWebWith(options, {
|
|
20
|
+
getDocument: () => (typeof document === "undefined" ? undefined : document),
|
|
21
|
+
afterFirstPaint: () => afterFirstPaint(),
|
|
22
|
+
importRum: () => import("@libo11y/rum"),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const WEB_PROVIDER_DEPS = {
|
|
26
|
+
createLoader: createUniversalRum,
|
|
27
|
+
RumProvider,
|
|
28
|
+
RumErrorBoundary,
|
|
29
|
+
useExpoRouterRum,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Universal RUM provider for Expo Router apps on web: defers RUM initialization until after first
|
|
33
|
+
* paint, buffers early errors with consent-safe replay, and wraps children in `RumProvider`,
|
|
34
|
+
* `RumErrorBoundary`, and `useExpoRouterRum`.
|
|
35
|
+
*/
|
|
36
|
+
export function UniversalRumProvider(props) {
|
|
37
|
+
return createElement(UniversalRumProviderBase, { ...props, deps: WEB_PROVIDER_DEPS });
|
|
38
|
+
}
|
|
39
|
+
const _contract = {
|
|
40
|
+
createUniversalRum,
|
|
41
|
+
createBufferingRum,
|
|
42
|
+
darkRum,
|
|
43
|
+
UniversalRumProvider,
|
|
44
|
+
useUniversalRum,
|
|
45
|
+
};
|
|
46
|
+
void _contract;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public TypeScript API contract for `@libo11y/rum-expo-router/universal`.
|
|
3
|
+
* Bundlers resolve `"browser"` / `"default"` to `universal-web` and `"react-native"` to
|
|
4
|
+
* `universal-native`; both modules check runtime export assignability via `satisfies`.
|
|
5
|
+
*/
|
|
6
|
+
export { type BufferingRum, createBufferingRum, createUniversalRum, darkRum, type UniversalRumConsent, type UniversalRumConsentOptions, type UniversalRumHandle, type UniversalRumLoader, type UniversalRumNativeInstrumentationOptions, type UniversalRumNativeOptions, type UniversalRumOptions, type UniversalRumOriginMatcher, UniversalRumProvider, type UniversalRumProviderProps, type UniversalRumState, type UniversalRumStatus, type UniversalRumTelemetry, type UniversalRumWebCollectors, type UniversalRumWebOptions, useUniversalRum, } from "./universal-web.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public TypeScript API contract for `@libo11y/rum-expo-router/universal`.
|
|
3
|
+
* Bundlers resolve `"browser"` / `"default"` to `universal-web` and `"react-native"` to
|
|
4
|
+
* `universal-native`; both modules check runtime export assignability via `satisfies`.
|
|
5
|
+
*/
|
|
6
|
+
export { createBufferingRum, createUniversalRum, darkRum, UniversalRumProvider, useUniversalRum, } from "./universal-web.js";
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The `@libo11y/rum-expo-router` package version. scripts/release.ts keeps it equal to package.json. */
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.9.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The `@libo11y/rum-expo-router` package version. scripts/release.ts keeps it equal to package.json. */
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.9.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libo11y/rum-expo-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Expo Router adapter for @libo11y/rum-react-native: names screens by route template, starts a view on each new screen and marks it rendered when its navigation state is committed.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./universal": {
|
|
14
|
+
"types": "./dist/universal.d.ts",
|
|
15
|
+
"browser": "./dist/universal-web.js",
|
|
16
|
+
"react-native": "./dist/universal-native.js",
|
|
17
|
+
"default": "./dist/universal-web.js"
|
|
12
18
|
}
|
|
13
19
|
},
|
|
14
20
|
"repository": {
|
|
@@ -17,19 +23,31 @@
|
|
|
17
23
|
"directory": "ts/packages/rum-expo-router"
|
|
18
24
|
},
|
|
19
25
|
"peerDependencies": {
|
|
20
|
-
"@libo11y/rum": "0.
|
|
26
|
+
"@libo11y/rum": "0.9.0",
|
|
27
|
+
"@libo11y/rum-react": "0.9.0",
|
|
28
|
+
"@libo11y/rum-react-native": "0.9.0",
|
|
21
29
|
"expo-router": ">=58.0.0",
|
|
22
30
|
"react": "^19.0.0"
|
|
23
31
|
},
|
|
24
32
|
"peerDependenciesMeta": {
|
|
33
|
+
"@libo11y/rum-react": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"@libo11y/rum-react-native": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
25
39
|
"expo-router": {
|
|
26
40
|
"optional": true
|
|
27
41
|
}
|
|
28
42
|
},
|
|
29
43
|
"devDependencies": {
|
|
30
|
-
"@libo11y/rum": "0.
|
|
44
|
+
"@libo11y/rum": "0.9.0",
|
|
45
|
+
"@libo11y/rum-react": "0.9.0",
|
|
46
|
+
"@libo11y/rum-react-native": "0.9.0",
|
|
31
47
|
"@types/react": "19.3.0",
|
|
32
|
-
"react": "19.3.
|
|
48
|
+
"@types/react-dom": "19.3.0",
|
|
49
|
+
"react": "19.3.1",
|
|
50
|
+
"react-dom": "19.3.1"
|
|
33
51
|
},
|
|
34
52
|
"files": [
|
|
35
53
|
"dist",
|