@libo11y/react-native 0.7.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 +2 -3
- package/dist/instrumentation/network.d.ts +6 -1
- package/dist/instrumentation/network.js +18 -6
- package/dist/options.d.ts +6 -0
- package/dist/platform.js +8 -2
- package/dist/setup.js +45 -18
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -105,9 +105,8 @@ over-the-air update running on an older binary gets.
|
|
|
105
105
|
|
|
106
106
|
## Status
|
|
107
107
|
|
|
108
|
-
A preview. The package first ships in `ts/v0.4.0
|
|
109
|
-
`
|
|
110
|
-
[`ts/v0.7.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.7.0)),
|
|
108
|
+
A preview. The package first ships in `ts/v0.4.0`; `0.9.0` is published on npm and attached as a tarball to the
|
|
109
|
+
[`ts/v0.9.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.9.0),
|
|
111
110
|
and its API can change in a minor release:
|
|
112
111
|
|
|
113
112
|
```sh
|
|
@@ -24,10 +24,15 @@ export interface NetworkInstrumentation {
|
|
|
24
24
|
uninstall(): void;
|
|
25
25
|
/** fetchImpl with a client span per request; a wrapped fetch is returned as it is. */
|
|
26
26
|
traceFetch<F extends typeof fetch>(fetchImpl: F): F;
|
|
27
|
+
/**
|
|
28
|
+
* Unpatched fetch wrapped in the same synchronous depth guard that suppresses duplicate XHR spans
|
|
29
|
+
* on bare React Native (whatwg-fetch over XMLHttpRequest), without opening a libo11y fetch span.
|
|
30
|
+
*/
|
|
31
|
+
readonly untracedFetch?: typeof fetch | undefined;
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
34
|
* Patches g.fetch (g defaults to globalThis) and globalThis.XMLHttpRequest as opts says, and
|
|
30
|
-
* returns
|
|
35
|
+
* returns uninstall, traceFetch and untracedFetch.
|
|
31
36
|
*/
|
|
32
37
|
export declare function installNetworkInstrumentation(opts: NetworkInstrumentationOptions, g?: {
|
|
33
38
|
fetch?: typeof fetch;
|
|
@@ -13,15 +13,27 @@ import { installXhrInstrumentationWith, instrumentFetchWith, } from "@libo11y/we
|
|
|
13
13
|
export const RN_SCOPE = "@libo11y/react-native";
|
|
14
14
|
/**
|
|
15
15
|
* Patches g.fetch (g defaults to globalThis) and globalThis.XMLHttpRequest as opts says, and
|
|
16
|
-
* returns
|
|
16
|
+
* returns uninstall, traceFetch and untracedFetch.
|
|
17
17
|
*/
|
|
18
18
|
export function installNetworkInstrumentation(opts, g = globalThis) {
|
|
19
|
-
// How many traced fetch calls are running synchronously right now.
|
|
19
|
+
// How many traced or untraced fetch calls are running synchronously right now.
|
|
20
20
|
let depth = 0;
|
|
21
21
|
let done = false;
|
|
22
|
+
const rawFetch = typeof g.fetch === "function" ? g.fetch : undefined;
|
|
22
23
|
const xhrInternals = { scope: RN_SCOPE, skip: () => depth > 0 };
|
|
23
24
|
const wrappers = new WeakMap();
|
|
24
25
|
const wrapped = new WeakSet();
|
|
26
|
+
const untracedFetch = rawFetch === undefined
|
|
27
|
+
? undefined
|
|
28
|
+
: ((input, init) => {
|
|
29
|
+
depth++;
|
|
30
|
+
try {
|
|
31
|
+
return rawFetch(input, init);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
depth--;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
25
37
|
const traceFetch = (f) => {
|
|
26
38
|
if (wrapped.has(f))
|
|
27
39
|
return f;
|
|
@@ -45,13 +57,12 @@ export function installNetworkInstrumentation(opts, g = globalThis) {
|
|
|
45
57
|
return out;
|
|
46
58
|
};
|
|
47
59
|
const undo = [];
|
|
48
|
-
if (opts.fetch !== false &&
|
|
49
|
-
const
|
|
50
|
-
const patched = traceFetch(previous);
|
|
60
|
+
if (opts.fetch !== false && rawFetch !== undefined) {
|
|
61
|
+
const patched = traceFetch(rawFetch);
|
|
51
62
|
g.fetch = patched;
|
|
52
63
|
undo.push(() => {
|
|
53
64
|
if (g.fetch === patched)
|
|
54
|
-
g.fetch =
|
|
65
|
+
g.fetch = rawFetch;
|
|
55
66
|
});
|
|
56
67
|
}
|
|
57
68
|
if (opts.xhr !== false)
|
|
@@ -65,5 +76,6 @@ export function installNetworkInstrumentation(opts, g = globalThis) {
|
|
|
65
76
|
u();
|
|
66
77
|
},
|
|
67
78
|
traceFetch,
|
|
79
|
+
...(untracedFetch === undefined ? {} : { untracedFetch }),
|
|
68
80
|
};
|
|
69
81
|
}
|
package/dist/options.d.ts
CHANGED
|
@@ -71,6 +71,12 @@ export interface ReactNativeSetupOptions extends TelemetryOptions {
|
|
|
71
71
|
* environment. Options beat them. Ignored when hermetic is true. Default: none.
|
|
72
72
|
*/
|
|
73
73
|
readonly env?: Readonly<Record<string, string>>;
|
|
74
|
+
/**
|
|
75
|
+
* When true, also read OTEL_EXPORTER_OTLP_*_HEADERS, COMPRESSION, TIMEOUT and
|
|
76
|
+
* OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE from env. Default false (reads only endpoint
|
|
77
|
+
* and protocol from env, preserving 0.8.0 compatibility).
|
|
78
|
+
*/
|
|
79
|
+
readonly envTransportOptions?: boolean;
|
|
74
80
|
/** The consent the telemetry starts with. */
|
|
75
81
|
readonly consent?: ReactNativeConsentOptions;
|
|
76
82
|
/**
|
package/dist/platform.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The React Native Platform core builds on. */
|
|
2
2
|
import { sha1 } from "@libo11y/core";
|
|
3
|
-
import { browserEnv, createContextManager, randomUuid, } from "@libo11y/web/portable";
|
|
3
|
+
import { browserEnv, createContextManager, randomUuid, resolveMetricTemporality, } from "@libo11y/web/portable";
|
|
4
4
|
import { uuidCrypto } from "./random.js";
|
|
5
5
|
import { detectReactNativeResource } from "./resource.js";
|
|
6
6
|
/**
|
|
@@ -37,7 +37,13 @@ export function reactNativePlatform(o) {
|
|
|
37
37
|
env: () => vars,
|
|
38
38
|
detectResource: (hermetic) => detectReactNativeResource({ env: o.env, hermetic, vars }),
|
|
39
39
|
contextManager: o.exportOptions.contextManager ?? createContextManager,
|
|
40
|
-
buildExporters: (req) =>
|
|
40
|
+
buildExporters: (req) => {
|
|
41
|
+
const metricTemporality = resolveMetricTemporality(o.exportOptions, req.config?.hermetic ?? o.exportOptions.hermetic === true, vars);
|
|
42
|
+
return o.createExporterSet(req, o.delivery, o.endpoints, {
|
|
43
|
+
gate: o.gate,
|
|
44
|
+
...(metricTemporality === undefined ? {} : { metricTemporality }),
|
|
45
|
+
});
|
|
46
|
+
},
|
|
41
47
|
writeConsoleLine: (line) => log(line),
|
|
42
48
|
writeDiagnosticLine: (line) => warn(line),
|
|
43
49
|
sha1: async (data) => sha1(data),
|
package/dist/setup.js
CHANGED
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
* index.ts, passes the real ones from env.ts, the only module that loads react-native.
|
|
4
4
|
*/
|
|
5
5
|
import { createTelemetryWith, O11yError, setupWith, } from "@libo11y/core";
|
|
6
|
-
import {
|
|
6
|
+
import { resolveOtlpSignalConfig, setPropagationConfig } from "@libo11y/core/internal";
|
|
7
|
+
import { flushInBackground, isIgnored, leaseForTimeout, OTLP_SIGNALS, pristineFetch, resolveTransportOptions, shouldPropagate, shutdownWithin, WEB_ENV_PROFILE, } from "@libo11y/web/portable";
|
|
7
8
|
import { diag } from "@opentelemetry/api";
|
|
8
9
|
import { reactNativePlatform } from "./platform.js";
|
|
9
10
|
import { memoryStorage } from "./storage/memory.js";
|
|
10
11
|
/** The retry queue's mobile bounds: smaller than the browser's 5 MiB and 1000 batches. */
|
|
11
12
|
const QUEUE_DEFAULTS = { maxBytes: 2_097_152, maxEntries: 500, maxAgeMillis: 86_400_000 };
|
|
12
|
-
|
|
13
|
-
const leaseFor = (timeoutMillis) => Math.max(30_000, 3 * timeoutMillis);
|
|
13
|
+
const RN_ENV_PROFILE = { ...WEB_ENV_PROFILE, urlMode: "require-absolute" };
|
|
14
14
|
/**
|
|
15
|
-
* Refuses
|
|
16
|
-
* or https URL
|
|
15
|
+
* Refuses every configured endpoint candidate (options or, unless hermetic, env) that is not an
|
|
16
|
+
* absolute http or https URL, even when a per-signal override would otherwise shadow a relative
|
|
17
|
+
* base endpoint.
|
|
17
18
|
*/
|
|
18
19
|
function requireAbsoluteEndpoints(options, hermetic) {
|
|
19
20
|
const env = hermetic ? {} : (options.env ?? {});
|
|
@@ -41,6 +42,22 @@ function requireAbsoluteEndpoints(options, hermetic) {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
}
|
|
45
|
+
function resolveAbsoluteEndpoints(options, hermetic) {
|
|
46
|
+
requireAbsoluteEndpoints(options, hermetic);
|
|
47
|
+
const signalOpts = {
|
|
48
|
+
endpoint: options.endpoint,
|
|
49
|
+
tracesEndpoint: options.tracesEndpoint,
|
|
50
|
+
metricsEndpoint: options.metricsEndpoint,
|
|
51
|
+
logsEndpoint: options.logsEndpoint,
|
|
52
|
+
hermetic,
|
|
53
|
+
};
|
|
54
|
+
const env = options.env ?? {};
|
|
55
|
+
const out = {};
|
|
56
|
+
for (const signal of OTLP_SIGNALS) {
|
|
57
|
+
out[signal] = resolveOtlpSignalConfig(signal, signalOpts, env, RN_ENV_PROFILE).url;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
44
61
|
/** Runs each cleanup step, reporting a failure through diag and going on. */
|
|
45
62
|
async function cleanup(steps) {
|
|
46
63
|
for (const step of steps) {
|
|
@@ -73,7 +90,7 @@ async function cleanup(steps) {
|
|
|
73
90
|
export async function setupReactNativeWith(options, deps, install) {
|
|
74
91
|
const hermetic = options.hermetic === true;
|
|
75
92
|
const sdkDisabled = !hermetic && (options.env?.OTEL_SDK_DISABLED ?? "").trim().toLowerCase() === "true";
|
|
76
|
-
|
|
93
|
+
const resolvedEndpoints = resolveAbsoluteEndpoints(options, hermetic);
|
|
77
94
|
const t = options.transport ?? {};
|
|
78
95
|
// Only the initial state: respectDoNotTrack and respectGlobalPrivacyControl stay off, because a
|
|
79
96
|
// React Native runtime has no such signals.
|
|
@@ -87,7 +104,7 @@ export async function setupReactNativeWith(options, deps, install) {
|
|
|
87
104
|
});
|
|
88
105
|
const listeners = [];
|
|
89
106
|
let delivery;
|
|
90
|
-
|
|
107
|
+
const endpoints = resolvedEndpoints;
|
|
91
108
|
let telemetry;
|
|
92
109
|
let built;
|
|
93
110
|
try {
|
|
@@ -95,11 +112,9 @@ export async function setupReactNativeWith(options, deps, install) {
|
|
|
95
112
|
// grant later in this launch cannot send batches recorded before the denial. Pending keeps them.
|
|
96
113
|
if (controller.consent.state() === "denied")
|
|
97
114
|
await queue.clear();
|
|
98
|
-
|
|
115
|
+
const { transport: httpTransportOpts, leaseTimeoutMillis } = resolveTransportOptions(options, endpoints, hermetic);
|
|
99
116
|
const transport = deps.createHttpTransport({
|
|
100
|
-
|
|
101
|
-
...(options.headers === undefined ? {} : { headers: options.headers }),
|
|
102
|
-
...(t.timeoutMillis === undefined ? {} : { timeoutMillis: t.timeoutMillis }),
|
|
117
|
+
...httpTransportOpts,
|
|
103
118
|
...(pristineFetch === undefined ? {} : { fetch: pristineFetch }),
|
|
104
119
|
sendBeacon: undefined,
|
|
105
120
|
isOnline: () => true,
|
|
@@ -114,7 +129,7 @@ export async function setupReactNativeWith(options, deps, install) {
|
|
|
114
129
|
isOnline: () => true,
|
|
115
130
|
...(t.initialBackoffMillis === undefined ? {} : { initialBackoffMillis: t.initialBackoffMillis }),
|
|
116
131
|
...(t.maxBackoffMillis === undefined ? {} : { maxBackoffMillis: t.maxBackoffMillis }),
|
|
117
|
-
...(
|
|
132
|
+
...(leaseTimeoutMillis === undefined ? {} : { leaseMillis: leaseForTimeout(leaseTimeoutMillis) }),
|
|
118
133
|
});
|
|
119
134
|
const platform = reactNativePlatform({
|
|
120
135
|
exportOptions: options,
|
|
@@ -181,27 +196,39 @@ export async function setupReactNativeWith(options, deps, install) {
|
|
|
181
196
|
})();
|
|
182
197
|
return shutdownPromise;
|
|
183
198
|
};
|
|
199
|
+
const instr = options.instrumentations ?? {};
|
|
200
|
+
const propagateTo = instr.propagateTo ?? [];
|
|
201
|
+
const ignoreUrls = [
|
|
202
|
+
...(instr.ignoreUrls ?? []),
|
|
203
|
+
...OTLP_SIGNALS.flatMap((s) => (endpoints[s] === undefined ? [] : [endpoints[s]])),
|
|
204
|
+
];
|
|
205
|
+
let untracedFetch = pristineFetch;
|
|
184
206
|
if (install) {
|
|
185
207
|
try {
|
|
186
|
-
const instr = options.instrumentations ?? {};
|
|
187
208
|
const net = deps.installNetworkInstrumentation({
|
|
188
209
|
telemetry: handle,
|
|
189
|
-
propagateTo
|
|
190
|
-
ignoreUrls
|
|
191
|
-
...(instr.ignoreUrls ?? []),
|
|
192
|
-
...OTLP_SIGNALS.flatMap((s) => (endpoints[s] === undefined ? [] : [endpoints[s]])),
|
|
193
|
-
],
|
|
210
|
+
propagateTo,
|
|
211
|
+
ignoreUrls,
|
|
194
212
|
fetch: instr.fetch !== false,
|
|
195
213
|
xhr: instr.xhr !== false,
|
|
196
214
|
});
|
|
197
215
|
uninstalls.push(() => net.uninstall());
|
|
198
216
|
handle.traceFetch = net.traceFetch;
|
|
217
|
+
if (net.untracedFetch !== undefined)
|
|
218
|
+
untracedFetch = net.untracedFetch;
|
|
199
219
|
}
|
|
200
220
|
catch (err) {
|
|
201
221
|
await handle.shutdown();
|
|
202
222
|
throw err;
|
|
203
223
|
}
|
|
204
224
|
}
|
|
225
|
+
setPropagationConfig(handle, {
|
|
226
|
+
runtime: "react-native",
|
|
227
|
+
isRecording: () => !sdkDisabled && controller.recording(),
|
|
228
|
+
shouldPropagate: (url) => shouldPropagate(url, propagateTo, "null"),
|
|
229
|
+
isIgnored: (url) => isIgnored(url, ignoreUrls),
|
|
230
|
+
...(untracedFetch === undefined ? {} : { fetch: untracedFetch }),
|
|
231
|
+
});
|
|
205
232
|
void activeDelivery.drain();
|
|
206
233
|
return handle;
|
|
207
234
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The `@libo11y/react-native` 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/react-native` 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/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The libo11y React Native platform for TypeScript: setup over the OpenTelemetry JS 3.x providers on Hermes, the mobile resource, an OTLP/HTTP transport with a persistent retry queue on device storage, AppState flushing, the consent gate, and fetch and XHR spans.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"directory": "ts/packages/react-native"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@libo11y/core": "0.
|
|
41
|
-
"@libo11y/spec": "0.
|
|
42
|
-
"@libo11y/web": "0.
|
|
40
|
+
"@libo11y/core": "0.9.0",
|
|
41
|
+
"@libo11y/spec": "0.9.0",
|
|
42
|
+
"@libo11y/web": "0.9.0",
|
|
43
43
|
"@opentelemetry/core": "3.1.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@libo11y/test": "0.
|
|
68
|
+
"@libo11y/test": "0.9.0",
|
|
69
69
|
"@opentelemetry/api": "1.10.0",
|
|
70
70
|
"@opentelemetry/sdk-trace": "3.1.1",
|
|
71
71
|
"@types/react": "19.3.0",
|