@logbrew/react-native 0.1.39 → 0.1.41
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 +3 -3
- package/android-native-diagnostics.d.ts +15 -5
- package/android-native-diagnostics.js +170 -94
- package/apollo.cjs +435 -226
- package/apollo.d.cts +2 -70
- package/apollo.d.ts +24 -12
- package/apollo.js +438 -221
- package/apple-native-diagnostics-config.js +176 -0
- package/apple-native-diagnostics-context.js +232 -0
- package/apple-native-diagnostics-module.js +229 -0
- package/apple-native-diagnostics.d.ts +42 -11
- package/apple-native-diagnostics.js +60 -389
- package/expo.cjs +29 -16
- package/expo.d.ts +10 -9
- package/expo.js +4 -3
- package/fatal-admission.cjs +113 -0
- package/fatal-record.cjs +317 -0
- package/fatal-replay.cjs +297 -508
- package/global-errors-capture.cjs +369 -0
- package/global-errors-event.cjs +174 -0
- package/global-errors-support.cjs +128 -0
- package/global-errors.cjs +75 -351
- package/global-errors.d.cts +29 -278
- package/global-errors.d.ts +57 -27
- package/global-errors.js +7 -2
- package/global-errors.native.js +83 -48
- package/index-breadcrumbs.cjs +139 -0
- package/index-errors.cjs +167 -0
- package/index-events.cjs +365 -0
- package/index-navigation.cjs +327 -0
- package/index-random.cjs +120 -0
- package/index-react.cjs +189 -0
- package/index-spans.cjs +190 -0
- package/index-trace-fetch.cjs +322 -0
- package/index-trace.cjs +335 -0
- package/index-transport.cjs +201 -0
- package/index-values.cjs +232 -0
- package/index.cjs +97 -1245
- package/index.d.cts +2 -505
- package/index.d.ts +130 -469
- package/index.native.d.ts +146 -22
- package/index.native.js +184 -159
- package/instrumentation-fetch.cjs +113 -0
- package/instrumentation-install.cjs +241 -0
- package/instrumentation-runtime.cjs +65 -0
- package/instrumentation-teardown.cjs +93 -0
- package/instrumentation-values.cjs +282 -0
- package/instrumentation-xhr-request.cjs +298 -0
- package/instrumentation-xhr.cjs +233 -0
- package/instrumentation.cjs +110 -599
- package/instrumentation.d.cts +2 -84
- package/instrumentation.d.ts +22 -8
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +1 -1
- package/lifecycle.cjs +181 -78
- package/lifecycle.d.cts +1 -50
- package/lifecycle.d.ts +17 -6
- package/metadata.cjs +279 -114
- package/metro-debug-id.cjs +296 -0
- package/metro-serializer.cjs +219 -0
- package/metro.cjs +153 -297
- package/metro.d.cts +2 -57
- package/metro.d.ts +27 -13
- package/metro.js +2 -3
- package/native-bridge-async.cjs +165 -0
- package/native-bridge-scope.cjs +148 -0
- package/native-bridge.cjs +83 -186
- package/native-bridge.d.cts +2 -94
- package/native-bridge.d.ts +28 -15
- package/native-client-bindings.js +230 -0
- package/native-diagnostics-values.js +120 -0
- package/native-module-lookup.js +31 -0
- package/native-null.js +3 -0
- package/null-value.cjs +4 -0
- package/package.json +43 -1
- package/persistent-delivery-store.js +247 -0
- package/persistent-delivery.native.js +183 -261
- package/promise-rejection-handlers.cjs +368 -0
- package/promise-rejections.cjs +169 -361
- package/react-native.config.js +3 -1
- package/release-artifacts-files.cjs +94 -0
- package/release-artifacts-options.cjs +182 -0
- package/release-artifacts.cjs +278 -207
- package/release-artifacts.d.cts +2 -55
- package/release-artifacts.d.ts +18 -7
- package/release-artifacts.js +2 -4
- package/resource-fetch-graphql.cjs +265 -0
- package/resource-fetch-size.cjs +156 -0
- package/resource-fetch.cjs +227 -428
- package/resource-fetch.d.cts +1 -60
- package/resource-fetch.d.ts +17 -6
- package/scripts/sync-apple-native-sources.mjs +101 -53
- package/types/capture.d.ts +95 -0
- package/types/config.d.ts +85 -0
- package/types/defaults.d.ts +55 -0
- package/types/events.d.ts +203 -0
- package/types/provider.d.ts +81 -0
- package/types/trace.d.ts +104 -0
package/index-random.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const { SdkError } = require("@logbrew/sdk");
|
|
2
|
+
const { readField } = require("./index-values.cjs");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{ readonly getRandomValues: (bytes: Uint8Array) => Uint8Array }} RandomSource
|
|
6
|
+
* @typedef {(length: number) => ArrayLike<number>} RandomValues
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const NATIVE_RANDOM_HEX = Symbol.for("co.logbrew.react-native.secure-random-hex");
|
|
10
|
+
const HEX_RADIX = 16;
|
|
11
|
+
const BYTE_HEX_WIDTH = 2;
|
|
12
|
+
const MIN_BYTE = 0;
|
|
13
|
+
const MAX_BYTE = 255;
|
|
14
|
+
const EVENT_ID_BYTES = 16;
|
|
15
|
+
const NATIVE_HEX_RE = /^[0-9a-f]+$/iu;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {unknown} value
|
|
19
|
+
* @returns {value is RandomSource}
|
|
20
|
+
*/
|
|
21
|
+
function isRandomSource(value) {
|
|
22
|
+
return typeof readField(value, "getRandomValues") === "function";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {unknown} value
|
|
27
|
+
* @returns {value is (length: number) => unknown}
|
|
28
|
+
*/
|
|
29
|
+
function isNativeRandom(value) {
|
|
30
|
+
return typeof value === "function";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {unknown} value
|
|
35
|
+
* @returns {value is RandomValues}
|
|
36
|
+
*/
|
|
37
|
+
function isRandomValues(value) {
|
|
38
|
+
return typeof value === "function";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @returns {SdkError}
|
|
43
|
+
*/
|
|
44
|
+
function secureRandomError() {
|
|
45
|
+
return new SdkError("configuration_error", "React Native secure random values are unavailable");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {(length: number) => unknown} nativeRandom
|
|
50
|
+
* @param {number} length
|
|
51
|
+
* @returns {unknown}
|
|
52
|
+
*/
|
|
53
|
+
function callNativeRandom(nativeRandom, length) {
|
|
54
|
+
try {
|
|
55
|
+
return nativeRandom(length);
|
|
56
|
+
} catch {
|
|
57
|
+
throw secureRandomError();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {number} length
|
|
63
|
+
* @returns {Uint8Array}
|
|
64
|
+
*/
|
|
65
|
+
function nativeRandomValues(length) {
|
|
66
|
+
/** @type {unknown} */
|
|
67
|
+
const nativeRandom = Reflect.get(globalThis, NATIVE_RANDOM_HEX);
|
|
68
|
+
if (!isNativeRandom(nativeRandom)) {
|
|
69
|
+
throw secureRandomError();
|
|
70
|
+
}
|
|
71
|
+
const nativeHex = callNativeRandom(nativeRandom, length);
|
|
72
|
+
if (typeof nativeHex !== "string" || nativeHex.length !== length * BYTE_HEX_WIDTH || !NATIVE_HEX_RE.test(nativeHex)) {
|
|
73
|
+
throw secureRandomError();
|
|
74
|
+
}
|
|
75
|
+
return Uint8Array.from({ length }, (_byte, index) => Number.parseInt(nativeHex.slice(index * BYTE_HEX_WIDTH, index * BYTE_HEX_WIDTH + BYTE_HEX_WIDTH), HEX_RADIX));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {number} length
|
|
80
|
+
* @returns {Uint8Array}
|
|
81
|
+
*/
|
|
82
|
+
function defaultRandomValues(length) {
|
|
83
|
+
const bytes = new Uint8Array(length);
|
|
84
|
+
const cryptoObject = readField(globalThis, "crypto");
|
|
85
|
+
if (isRandomSource(cryptoObject)) {
|
|
86
|
+
return cryptoObject.getRandomValues(bytes);
|
|
87
|
+
}
|
|
88
|
+
const expoCrypto = readField(readField(readField(globalThis, "expo"), "modules"), "ExpoCrypto");
|
|
89
|
+
if (isRandomSource(expoCrypto)) {
|
|
90
|
+
expoCrypto.getRandomValues(bytes);
|
|
91
|
+
return bytes;
|
|
92
|
+
}
|
|
93
|
+
return nativeRandomValues(length);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {number} length
|
|
98
|
+
* @param {unknown} randomValues
|
|
99
|
+
* @returns {string}
|
|
100
|
+
*/
|
|
101
|
+
function randomHex(length, randomValues) {
|
|
102
|
+
if (!isRandomValues(randomValues)) {
|
|
103
|
+
throw new SdkError("configuration_error", "randomValues must be a function");
|
|
104
|
+
}
|
|
105
|
+
const bytes = Array.from(randomValues(length), value => value);
|
|
106
|
+
if (bytes.length !== length || bytes.some(value => !Number.isInteger(value) || value < MIN_BYTE || value > MAX_BYTE)) {
|
|
107
|
+
throw new SdkError("configuration_error", "randomValues must return byte values for the requested length");
|
|
108
|
+
}
|
|
109
|
+
return bytes.map(value => value.toString(HEX_RADIX).padStart(BYTE_HEX_WIDTH, "0")).join("");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} kind
|
|
114
|
+
* @returns {string}
|
|
115
|
+
*/
|
|
116
|
+
function defaultEventId(kind) {
|
|
117
|
+
return `evt_native_${kind}_${randomHex(EVENT_ID_BYTES, defaultRandomValues)}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { defaultEventId, defaultRandomValues, randomHex };
|
package/index-react.cjs
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
const React = require("react");
|
|
2
|
+
const { SdkError } = require("@logbrew/sdk");
|
|
3
|
+
const { NULL_VALUE } = require("./null-value.cjs");
|
|
4
|
+
const { captureReactNativeError } = require("./index-errors.cjs");
|
|
5
|
+
const {
|
|
6
|
+
captureAppStateChange,
|
|
7
|
+
captureReactNativeAction,
|
|
8
|
+
captureReactNativeNetwork,
|
|
9
|
+
captureScreenView
|
|
10
|
+
} = require("./index-events.cjs");
|
|
11
|
+
const { captureReactNativeNavigationSpan, captureReactNativeResourceSpan } = require("./index-spans.cjs");
|
|
12
|
+
const { getActiveLogBrewTrace, getReactNativeTraceMetadata, resolveTraceContext } = require("./index-trace.cjs");
|
|
13
|
+
const { compactMetadata, readField, requireClient } = require("./index-values.cjs");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @import { ReactNode } from "react"
|
|
17
|
+
* @import { ActionEvent, ActionInput, CaptureAppStateChangeOptions, CaptureScreenViewOptions, NetworkInput } from "./index-events.cjs"
|
|
18
|
+
* @import { ErrorEvent, ErrorEventOptions } from "./index-errors.cjs"
|
|
19
|
+
* @import { NavigationSpanInput, ResourceSpanInput, SpanEvent } from "./index-spans.cjs"
|
|
20
|
+
* @import { AppStateLike, ClientEventMethod, ClientLike, LooseRecord, PlatformLike, TraceContext } from "./index-values.cjs"
|
|
21
|
+
* @typedef {{
|
|
22
|
+
* readonly client: ClientLike,
|
|
23
|
+
* readonly platform: PlatformLike | null | undefined,
|
|
24
|
+
* readonly appState: AppStateLike | null | undefined,
|
|
25
|
+
* readonly trace: TraceContext | undefined
|
|
26
|
+
* }} NativeContextValue
|
|
27
|
+
* @typedef {{
|
|
28
|
+
* readonly client: ClientLike,
|
|
29
|
+
* readonly platform?: PlatformLike | null | undefined,
|
|
30
|
+
* readonly appState?: AppStateLike | null | undefined,
|
|
31
|
+
* readonly trace?: unknown,
|
|
32
|
+
* readonly children?: ReactNode
|
|
33
|
+
* }} ProviderProps
|
|
34
|
+
* @typedef {{
|
|
35
|
+
* readonly release: ClientEventMethod,
|
|
36
|
+
* readonly environment: ClientEventMethod,
|
|
37
|
+
* readonly issue: ClientEventMethod,
|
|
38
|
+
* readonly log: ClientEventMethod,
|
|
39
|
+
* readonly span: ClientEventMethod,
|
|
40
|
+
* readonly action: ClientEventMethod,
|
|
41
|
+
* readonly flush: () => Promise<unknown>,
|
|
42
|
+
* readonly shutdown: () => Promise<unknown>,
|
|
43
|
+
* readonly deliveryHealth: () => unknown,
|
|
44
|
+
* readonly droppedEvents: () => unknown,
|
|
45
|
+
* readonly pendingBytes: () => unknown,
|
|
46
|
+
* readonly previewJson: () => unknown,
|
|
47
|
+
* readonly pendingEvents: () => unknown,
|
|
48
|
+
* readonly trace: TraceContext | undefined,
|
|
49
|
+
* readonly captureScreenView: (screenName: unknown, options?: CaptureScreenViewOptions) => void,
|
|
50
|
+
* readonly captureAppStateChange: (state: unknown, options?: CaptureAppStateChangeOptions) => void,
|
|
51
|
+
* readonly captureReactNativeAction: (input?: ActionInput) => ActionEvent,
|
|
52
|
+
* readonly captureReactNativeNetwork: (input?: NetworkInput) => ActionEvent,
|
|
53
|
+
* readonly captureReactNativeNavigationSpan: (input?: NavigationSpanInput) => SpanEvent,
|
|
54
|
+
* readonly captureReactNativeResourceSpan: (input?: ResourceSpanInput) => SpanEvent,
|
|
55
|
+
* readonly captureReactNativeError: (error: unknown, options?: ErrorEventOptions) => ErrorEvent
|
|
56
|
+
* }} NativeActions
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @returns {NativeContextValue | null}
|
|
61
|
+
*/
|
|
62
|
+
function emptyNativeContext() {
|
|
63
|
+
return NULL_VALUE;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const LogBrewNativeContext = React.createContext(emptyNativeContext());
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {unknown} value
|
|
70
|
+
* @returns {value is NativeContextValue}
|
|
71
|
+
*/
|
|
72
|
+
function hasNativeClient(value) {
|
|
73
|
+
return Boolean(readField(value, "client"));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {unknown} value
|
|
78
|
+
* @returns {object | undefined}
|
|
79
|
+
*/
|
|
80
|
+
function metadataSource(value) {
|
|
81
|
+
return (typeof value === "object" && value !== null) || typeof value === "function" ? value : undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {LooseRecord} attributes
|
|
86
|
+
* @param {TraceContext | undefined} trace
|
|
87
|
+
* @returns {LooseRecord}
|
|
88
|
+
*/
|
|
89
|
+
function attributesWithTrace(attributes, trace) {
|
|
90
|
+
const context = resolveTraceContext(trace) ?? getActiveLogBrewTrace();
|
|
91
|
+
if (!context) {
|
|
92
|
+
return attributes;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
...attributes,
|
|
96
|
+
metadata: compactMetadata({
|
|
97
|
+
...metadataSource(readField(attributes, "metadata")),
|
|
98
|
+
...getReactNativeTraceMetadata(context)
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @template {object} T
|
|
105
|
+
* @param {NativeContextValue} context
|
|
106
|
+
* @param {T} options
|
|
107
|
+
* @returns {T & Omit<NativeContextValue, "client">}
|
|
108
|
+
*/
|
|
109
|
+
function scoped({ platform, appState, trace }, options) {
|
|
110
|
+
return {
|
|
111
|
+
platform,
|
|
112
|
+
|
|
113
|
+
appState,
|
|
114
|
+
trace,
|
|
115
|
+
...options
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {ProviderProps} props
|
|
121
|
+
* @returns {ReactNode}
|
|
122
|
+
*/
|
|
123
|
+
function LogBrewNativeProvider({ client, platform, appState, trace, children }) {
|
|
124
|
+
requireClient(client);
|
|
125
|
+
const value = React.useMemo(() => ({
|
|
126
|
+
client,
|
|
127
|
+
platform,
|
|
128
|
+
|
|
129
|
+
appState,
|
|
130
|
+
trace: resolveTraceContext(trace)
|
|
131
|
+
}), [appState, client, platform, trace]);
|
|
132
|
+
return React.createElement(LogBrewNativeContext.Provider, { value }, children);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @returns {NativeContextValue}
|
|
137
|
+
*/
|
|
138
|
+
function useLogBrewNative() {
|
|
139
|
+
const value = React.useContext(LogBrewNativeContext);
|
|
140
|
+
if (!hasNativeClient(value)) {
|
|
141
|
+
throw new SdkError("configuration_error", "useLogBrewNative must be used inside LogBrewNativeProvider");
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @returns {NativeActions}
|
|
148
|
+
*/
|
|
149
|
+
function useLogBrewNativeActions() {
|
|
150
|
+
const context = useLogBrewNative();
|
|
151
|
+
const { client, trace } = context;
|
|
152
|
+
return {
|
|
153
|
+
release: client.release.bind(client),
|
|
154
|
+
|
|
155
|
+
environment: client.environment.bind(client),
|
|
156
|
+
issue: (id, timestamp, attributes) => client.issue(id, timestamp, attributesWithTrace(attributes, trace)),
|
|
157
|
+
log: (id, timestamp, attributes) => client.log(id, timestamp, attributesWithTrace(attributes, trace)),
|
|
158
|
+
span: client.span.bind(client),
|
|
159
|
+
|
|
160
|
+
action: (id, timestamp, attributes) => client.action(id, timestamp, attributesWithTrace(attributes, trace)),
|
|
161
|
+
flush: client.flush.bind(client),
|
|
162
|
+
shutdown: client.shutdown.bind(client),
|
|
163
|
+
|
|
164
|
+
deliveryHealth: client.deliveryHealth.bind(client),
|
|
165
|
+
droppedEvents: client.droppedEvents.bind(client),
|
|
166
|
+
pendingBytes: client.pendingBytes.bind(client),
|
|
167
|
+
previewJson: client.previewJson.bind(client),
|
|
168
|
+
|
|
169
|
+
pendingEvents: client.pendingEvents.bind(client),
|
|
170
|
+
trace,
|
|
171
|
+
|
|
172
|
+
captureScreenView: (screenName, options = {}) => {
|
|
173
|
+
captureScreenView(client, screenName, scoped(context, options));
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
captureAppStateChange: (state, options = {}) => {
|
|
177
|
+
captureAppStateChange(client, state, scoped(context, options));
|
|
178
|
+
},
|
|
179
|
+
captureReactNativeAction: (input = {}) => captureReactNativeAction(client, scoped(context, input)),
|
|
180
|
+
captureReactNativeNetwork: (input = {}) => captureReactNativeNetwork(client, scoped(context, input)),
|
|
181
|
+
|
|
182
|
+
captureReactNativeNavigationSpan: (input = {}) => captureReactNativeNavigationSpan(client, scoped(context, input)),
|
|
183
|
+
captureReactNativeResourceSpan: (input = {}) => captureReactNativeResourceSpan(client, scoped(context, input)),
|
|
184
|
+
|
|
185
|
+
captureReactNativeError: (error, options = {}) => captureReactNativeError(client, error, scoped(context, options))
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = { LogBrewNativeProvider, useLogBrewNative, useLogBrewNativeActions };
|
package/index-spans.cjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const { recordIssueBreadcrumb } = require("./index-breadcrumbs.cjs");
|
|
2
|
+
const { defaultEventId } = require("./index-random.cjs");
|
|
3
|
+
const {
|
|
4
|
+
createReactNativeSpanAttributes,
|
|
5
|
+
createReactNativeTraceContext,
|
|
6
|
+
getActiveLogBrewTrace,
|
|
7
|
+
resolveTraceContext
|
|
8
|
+
} = require("./index-trace.cjs");
|
|
9
|
+
const {
|
|
10
|
+
getReactNativeContext,
|
|
11
|
+
requireClient,
|
|
12
|
+
spanStatusFromStatusCode,
|
|
13
|
+
stripQueryAndHash,
|
|
14
|
+
textOf
|
|
15
|
+
} = require("./index-values.cjs");
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @import { ClientLike, ContextOptions } from "./index-values.cjs"
|
|
19
|
+
* @typedef {ContextOptions & {
|
|
20
|
+
* readonly actionType?: unknown,
|
|
21
|
+
* readonly durationMs?: unknown,
|
|
22
|
+
* readonly id?: string | undefined,
|
|
23
|
+
* readonly idFactory?: (context: { readonly routeName: string | undefined, readonly routePath: string | undefined, readonly screen: string | undefined }) => string,
|
|
24
|
+
* readonly includeRouteKey?: boolean | undefined,
|
|
25
|
+
* readonly name?: unknown,
|
|
26
|
+
* readonly now?: () => string,
|
|
27
|
+
* readonly previousRouteKey?: unknown,
|
|
28
|
+
* readonly previousRouteName?: unknown,
|
|
29
|
+
* readonly routeKey?: unknown,
|
|
30
|
+
* readonly routeName?: string | undefined,
|
|
31
|
+
* readonly routePath?: unknown,
|
|
32
|
+
* readonly screen?: string | undefined,
|
|
33
|
+
* readonly status?: unknown,
|
|
34
|
+
* readonly timestamp?: string | undefined,
|
|
35
|
+
* readonly trace?: unknown
|
|
36
|
+
* }} NavigationSpanInput
|
|
37
|
+
* @typedef {ContextOptions & {
|
|
38
|
+
* readonly durationMs?: unknown,
|
|
39
|
+
* readonly id?: string | undefined,
|
|
40
|
+
* readonly idFactory?: (context: { readonly method: string | undefined, readonly routeTemplate: string | undefined, readonly screen: unknown }) => string,
|
|
41
|
+
* readonly kind?: unknown,
|
|
42
|
+
* readonly method?: unknown,
|
|
43
|
+
* readonly name?: unknown,
|
|
44
|
+
* readonly now?: () => string,
|
|
45
|
+
* readonly responseSizeBytes?: unknown,
|
|
46
|
+
* readonly routeTemplate?: unknown,
|
|
47
|
+
* readonly screen?: unknown,
|
|
48
|
+
* readonly sessionId?: unknown,
|
|
49
|
+
* readonly status?: unknown,
|
|
50
|
+
* readonly statusCode?: unknown,
|
|
51
|
+
* readonly timestamp?: string | undefined,
|
|
52
|
+
* readonly trace?: unknown
|
|
53
|
+
* }} ResourceSpanInput
|
|
54
|
+
* @typedef {{ readonly id: string, readonly timestamp: string, readonly attributes: Record<string, unknown> }} SpanEvent
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
function currentTimestamp() {
|
|
61
|
+
return new Date().toISOString();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
function defaultNavigationSpanEventId() {
|
|
68
|
+
return defaultEventId("navigation");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @returns {string}
|
|
73
|
+
*/
|
|
74
|
+
function defaultResourceSpanEventId() {
|
|
75
|
+
return defaultEventId("resource");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {NavigationSpanInput} [input]
|
|
80
|
+
* @returns {SpanEvent}
|
|
81
|
+
*/
|
|
82
|
+
function createReactNativeNavigationSpanEvent({
|
|
83
|
+
actionType, durationMs, id, idFactory = defaultNavigationSpanEventId, includeRouteKey = false, metadata = {},
|
|
84
|
+
name, now = currentTimestamp, platform, appState, previousRouteKey, previousRouteName,
|
|
85
|
+
routeKey, routeName, routePath, screen, status = "ok", timestamp, trace
|
|
86
|
+
} = {}) {
|
|
87
|
+
const safeRoutePath = stripQueryAndHash(routePath);
|
|
88
|
+
const spanName = name ?? `navigation:${routeName ?? safeRoutePath ?? screen ?? "route"}`;
|
|
89
|
+
const context = resolveTraceContext(trace) ?? getActiveLogBrewTrace() ?? createReactNativeTraceContext();
|
|
90
|
+
return {
|
|
91
|
+
id: id ?? idFactory({ routeName, routePath: safeRoutePath, screen }),
|
|
92
|
+
timestamp: timestamp ?? now(),
|
|
93
|
+
|
|
94
|
+
attributes: createReactNativeSpanAttributes({
|
|
95
|
+
name: spanName,
|
|
96
|
+
status,
|
|
97
|
+
|
|
98
|
+
durationMs,
|
|
99
|
+
trace: context,
|
|
100
|
+
|
|
101
|
+
metadata: {
|
|
102
|
+
...getReactNativeContext({ appState, platform }),
|
|
103
|
+
source: "react-native.navigation",
|
|
104
|
+
|
|
105
|
+
actionType,
|
|
106
|
+
previousRouteName,
|
|
107
|
+
routeName,
|
|
108
|
+
routePath: safeRoutePath,
|
|
109
|
+
screen: screen ?? routeName,
|
|
110
|
+
...(includeRouteKey ? { previousRouteKey, routeKey } : {}),
|
|
111
|
+
...metadata
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @param {ClientLike} client
|
|
119
|
+
* @param {NavigationSpanInput} [input]
|
|
120
|
+
* @returns {SpanEvent}
|
|
121
|
+
*/
|
|
122
|
+
function captureReactNativeNavigationSpan(client, input = {}) {
|
|
123
|
+
requireClient(client);
|
|
124
|
+
const event = createReactNativeNavigationSpanEvent(input);
|
|
125
|
+
client.span(event.id, event.timestamp, event.attributes);
|
|
126
|
+
recordIssueBreadcrumb(client, event, { category: "navigation", type: "navigation" });
|
|
127
|
+
return event;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @param {ResourceSpanInput} [input]
|
|
132
|
+
* @returns {SpanEvent}
|
|
133
|
+
*/
|
|
134
|
+
function createReactNativeResourceSpanEvent({
|
|
135
|
+
durationMs, id, idFactory = defaultResourceSpanEventId, kind = "fetch", metadata = {}, method, name,
|
|
136
|
+
now = currentTimestamp, platform, appState, responseSizeBytes, routeTemplate, screen,
|
|
137
|
+
sessionId, status, statusCode, timestamp, trace
|
|
138
|
+
} = {}) {
|
|
139
|
+
const safeRouteTemplate = stripQueryAndHash(routeTemplate);
|
|
140
|
+
const safeMethod = method === undefined ? undefined : textOf(method).toUpperCase();
|
|
141
|
+
const defaultName = [safeMethod, safeRouteTemplate].filter(Boolean).join(" ");
|
|
142
|
+
const spanName = name ?? (defaultName || "mobile.resource");
|
|
143
|
+
const context = resolveTraceContext(trace) ?? getActiveLogBrewTrace() ?? createReactNativeTraceContext();
|
|
144
|
+
return {
|
|
145
|
+
id: id ?? idFactory({ method: safeMethod, routeTemplate: safeRouteTemplate, screen }),
|
|
146
|
+
timestamp: timestamp ?? now(),
|
|
147
|
+
|
|
148
|
+
attributes: createReactNativeSpanAttributes({
|
|
149
|
+
name: spanName,
|
|
150
|
+
status: status ?? spanStatusFromStatusCode(statusCode),
|
|
151
|
+
|
|
152
|
+
durationMs,
|
|
153
|
+
trace: context,
|
|
154
|
+
|
|
155
|
+
metadata: {
|
|
156
|
+
...getReactNativeContext({ appState, platform }),
|
|
157
|
+
source: "react-native.resource",
|
|
158
|
+
|
|
159
|
+
durationMs,
|
|
160
|
+
method: safeMethod,
|
|
161
|
+
resourceKind: kind,
|
|
162
|
+
responseSizeBytes,
|
|
163
|
+
routeTemplate: safeRouteTemplate,
|
|
164
|
+
screen,
|
|
165
|
+
sessionId,
|
|
166
|
+
statusCode,
|
|
167
|
+
...metadata
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @param {ClientLike} client
|
|
175
|
+
* @param {ResourceSpanInput} [input]
|
|
176
|
+
* @returns {SpanEvent}
|
|
177
|
+
*/
|
|
178
|
+
function captureReactNativeResourceSpan(client, input = {}) {
|
|
179
|
+
requireClient(client);
|
|
180
|
+
const event = createReactNativeResourceSpanEvent(input);
|
|
181
|
+
client.span(event.id, event.timestamp, event.attributes);
|
|
182
|
+
return event;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
module.exports = {
|
|
186
|
+
captureReactNativeNavigationSpan,
|
|
187
|
+
captureReactNativeResourceSpan,
|
|
188
|
+
createReactNativeNavigationSpanEvent,
|
|
189
|
+
createReactNativeResourceSpanEvent
|
|
190
|
+
};
|