@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/global-errors.native.js
CHANGED
|
@@ -3,39 +3,62 @@ import {
|
|
|
3
3
|
installLogBrewReactNativeGlobalErrorHandler as installPlatformNeutralHandler,
|
|
4
4
|
installLogBrewReactNativePromiseRejectionTracker as installPlatformNeutralTracker
|
|
5
5
|
} from "./global-errors.js";
|
|
6
|
+
import support from "./global-errors-support.cjs";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* @import { UnknownFunction } from "./global-errors-support.cjs"
|
|
10
|
+
* @typedef {Readonly<{ enable: (options: unknown) => unknown }>} HermesTrackerAdapter
|
|
11
|
+
* @typedef {Readonly<{ forwarded: Readonly<Record<string, unknown>>, injected: boolean }>} ForwardedOptions
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { isFunction, isObjectLike } = support;
|
|
15
|
+
/** @type {(value: unknown) => boolean} */
|
|
16
|
+
const isTruthy = Boolean;
|
|
10
17
|
|
|
18
|
+
/** @type {WeakMap<object, HermesTrackerAdapter>} */
|
|
11
19
|
const hermesTrackerAdapters = new WeakMap();
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @returns {Readonly<{ enable: UnknownFunction, hermes: object }> | undefined}
|
|
23
|
+
*/
|
|
24
|
+
function activeHermesTracker() {
|
|
17
25
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
/** @type {unknown} */
|
|
27
|
+
const hermes = Reflect.get(globalThis, "HermesInternal");
|
|
28
|
+
if (!isObjectLike(hermes)) {
|
|
21
29
|
return undefined;
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
/** @type {unknown} */
|
|
32
|
+
const enable = Reflect.get(hermes, "enablePromiseRejectionTracker");
|
|
33
|
+
/** @type {unknown} */
|
|
34
|
+
const hasPromise = Reflect.get(hermes, "hasPromise");
|
|
35
|
+
if (!isFunction(enable) || !isFunction(hasPromise) || hasPromise.call(hermes) !== true) {
|
|
28
36
|
return undefined;
|
|
29
37
|
}
|
|
38
|
+
return { enable, hermes };
|
|
30
39
|
} catch {
|
|
31
40
|
return undefined;
|
|
32
41
|
}
|
|
42
|
+
}
|
|
33
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @returns {HermesTrackerAdapter | undefined}
|
|
46
|
+
*/
|
|
47
|
+
function defaultPromiseRejectionTracker() {
|
|
48
|
+
const active = activeHermesTracker();
|
|
49
|
+
if (!active) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const { enable, hermes } = active;
|
|
34
53
|
const existing = hermesTrackerAdapters.get(hermes);
|
|
35
54
|
if (existing) {
|
|
36
55
|
return existing;
|
|
37
56
|
}
|
|
38
57
|
const adapter = Object.freeze({
|
|
58
|
+
/**
|
|
59
|
+
* @param {unknown} options
|
|
60
|
+
* @returns {unknown}
|
|
61
|
+
*/
|
|
39
62
|
enable(options) {
|
|
40
63
|
return enable.call(hermes, options);
|
|
41
64
|
}
|
|
@@ -44,46 +67,53 @@ function defaultPromiseRejectionTracker() {
|
|
|
44
67
|
return adapter;
|
|
45
68
|
}
|
|
46
69
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
/**
|
|
71
|
+
* @param {unknown} options
|
|
72
|
+
* @param {string} key
|
|
73
|
+
* @returns {ForwardedOptions}
|
|
74
|
+
*/
|
|
75
|
+
function forwardedOptions(options, key) {
|
|
76
|
+
let injected = false;
|
|
50
77
|
try {
|
|
51
|
-
const input = options
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: {};
|
|
55
|
-
hasInjectedStore = Object.prototype.hasOwnProperty.call(input, "fatalStore");
|
|
56
|
-
forwarded = { ...input };
|
|
78
|
+
const input = isObjectLike(options) ? options : {};
|
|
79
|
+
injected = Object.getOwnPropertyDescriptor(input, key) !== undefined;
|
|
80
|
+
return { forwarded: { ...input }, injected };
|
|
57
81
|
} catch {
|
|
58
|
-
forwarded
|
|
82
|
+
return { forwarded: {}, injected };
|
|
59
83
|
}
|
|
60
|
-
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {unknown} [options]
|
|
88
|
+
* @returns {unknown}
|
|
89
|
+
*/
|
|
90
|
+
function installLogBrewReactNativeGlobalErrorHandler(options = {}) {
|
|
91
|
+
const { forwarded, injected } = forwardedOptions(options, "fatalStore");
|
|
92
|
+
/** @type {unknown} */
|
|
93
|
+
const installation = Reflect.apply(installPlatformNeutralHandler, undefined, [{
|
|
61
94
|
...forwarded,
|
|
62
|
-
fatalStore:
|
|
63
|
-
});
|
|
95
|
+
fatalStore: injected ? forwarded["fatalStore"] : undefined
|
|
96
|
+
}]);
|
|
97
|
+
return installation;
|
|
64
98
|
}
|
|
65
99
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
100
|
+
/**
|
|
101
|
+
* @param {unknown} [options]
|
|
102
|
+
* @returns {unknown}
|
|
103
|
+
*/
|
|
104
|
+
function installLogBrewReactNativePromiseRejectionTracker(options = {}) {
|
|
105
|
+
const { forwarded, injected } = forwardedOptions(options, "tracker");
|
|
106
|
+
const tracker = injected ? forwarded["tracker"] : defaultPromiseRejectionTracker();
|
|
107
|
+
/** @type {"custom" | "hermes" | undefined} */
|
|
108
|
+
let trackerKind = undefined;
|
|
109
|
+
if (injected) {
|
|
110
|
+
trackerKind = "custom";
|
|
111
|
+
} else if (isTruthy(tracker)) {
|
|
112
|
+
trackerKind = "hermes";
|
|
78
113
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return installPlatformNeutralTracker({
|
|
83
|
-
...forwarded,
|
|
84
|
-
tracker,
|
|
85
|
-
trackerKind: hasInjectedTracker ? "custom" : tracker ? "hermes" : undefined
|
|
86
|
-
});
|
|
114
|
+
/** @type {unknown} */
|
|
115
|
+
const installation = Reflect.apply(installPlatformNeutralTracker, undefined, [{ ...forwarded, tracker, trackerKind }]);
|
|
116
|
+
return installation;
|
|
87
117
|
}
|
|
88
118
|
|
|
89
119
|
const logBrewReactNativeGlobalErrors = {
|
|
@@ -92,4 +122,9 @@ const logBrewReactNativeGlobalErrors = {
|
|
|
92
122
|
installLogBrewReactNativePromiseRejectionTracker
|
|
93
123
|
};
|
|
94
124
|
|
|
125
|
+
export { createLogBrewReactNativePromiseRejectionHandlers } from "./global-errors.js";
|
|
126
|
+
export {
|
|
127
|
+
installLogBrewReactNativeGlobalErrorHandler,
|
|
128
|
+
installLogBrewReactNativePromiseRejectionTracker
|
|
129
|
+
};
|
|
95
130
|
export default logBrewReactNativeGlobalErrors;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const { PRODUCT_ANALYTICS_SCHEMA_VERSION } = require("@logbrew/sdk");
|
|
2
|
+
const { readField, textOf } = require("./index-values.cjs");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import { LooseRecord } from "./index-values.cjs"
|
|
6
|
+
* @typedef {{ readonly timestamp: unknown, readonly attributes: LooseRecord }} BreadcrumbEvent
|
|
7
|
+
* @typedef {{ readonly category: string, readonly type: string }} BreadcrumbKind
|
|
8
|
+
* @typedef {{ readonly addBreadcrumb: (breadcrumb: LooseRecord, timestamp: unknown) => unknown }} BreadcrumbClient
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const LAST_ROUTE = Symbol.for("co.logbrew.react-native.last-route");
|
|
12
|
+
const MAX_ACTION_NAME_LENGTH = 64;
|
|
13
|
+
const MAX_BREADCRUMB_MESSAGE_LENGTH = 512;
|
|
14
|
+
const MAX_PRODUCT_ANALYTICS_SURFACE_LENGTH = 256;
|
|
15
|
+
const SCREEN_ACTION_PREFIX = "screen:";
|
|
16
|
+
const LAST_C0_CONTROL = 31;
|
|
17
|
+
const FIRST_C1_CONTROL = 127;
|
|
18
|
+
const LAST_C1_CONTROL = 159;
|
|
19
|
+
const START = 0;
|
|
20
|
+
const ACTION_NAME_RE = /^[A-Za-z0-9_.:-]+$/u;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {unknown} client
|
|
24
|
+
* @returns {client is BreadcrumbClient}
|
|
25
|
+
*/
|
|
26
|
+
function hasAddBreadcrumb(client) {
|
|
27
|
+
return typeof readField(client, "addBreadcrumb") === "function";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {readonly string[]} characters
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
34
|
+
function hasControlCharacter(characters) {
|
|
35
|
+
return characters.some(character => {
|
|
36
|
+
const code = character.codePointAt(START);
|
|
37
|
+
return code !== undefined && (code <= LAST_C0_CONTROL || (code >= FIRST_C1_CONTROL && code <= LAST_C1_CONTROL));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {unknown} value
|
|
43
|
+
* @returns {string | undefined}
|
|
44
|
+
*/
|
|
45
|
+
function boundedBreadcrumbMessage(value) {
|
|
46
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const characters = [...value];
|
|
50
|
+
if (characters.length > MAX_BREADCRUMB_MESSAGE_LENGTH || hasControlCharacter(characters)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {unknown} client
|
|
58
|
+
* @param {BreadcrumbEvent} event
|
|
59
|
+
* @param {BreadcrumbKind} kind
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/
|
|
62
|
+
function recordIssueBreadcrumb(client, event, { category, type }) {
|
|
63
|
+
if (!hasAddBreadcrumb(client)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const rawStatus = event.attributes["status"];
|
|
67
|
+
const status = typeof rawStatus === "string" ? rawStatus : undefined;
|
|
68
|
+
const message = boundedBreadcrumbMessage(event.attributes["name"]);
|
|
69
|
+
client.addBreadcrumb({
|
|
70
|
+
category,
|
|
71
|
+
type,
|
|
72
|
+
|
|
73
|
+
level: status === "failure" || status === "error" ? "error" : "info",
|
|
74
|
+
...(message === undefined ? {} : { message }),
|
|
75
|
+
...(status === undefined ? {} : { data: { status } })
|
|
76
|
+
}, event.timestamp);
|
|
77
|
+
if (category === "navigation" && message !== undefined) {
|
|
78
|
+
Reflect.set(client, LAST_ROUTE, message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {unknown} value
|
|
84
|
+
* @returns {string}
|
|
85
|
+
*/
|
|
86
|
+
function slugify(value) {
|
|
87
|
+
return textOf(value)
|
|
88
|
+
.toLowerCase()
|
|
89
|
+
.replaceAll(/[^a-z0-9]+/gu, "_")
|
|
90
|
+
.replaceAll(/^_+|_+$/gu, "") || "event";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} screenName
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
function screenActionName(screenName) {
|
|
98
|
+
const directName = `${SCREEN_ACTION_PREFIX}${screenName}`;
|
|
99
|
+
if (directName.length <= MAX_ACTION_NAME_LENGTH && ACTION_NAME_RE.test(directName)) {
|
|
100
|
+
return directName;
|
|
101
|
+
}
|
|
102
|
+
const maxScreenSegmentLength = MAX_ACTION_NAME_LENGTH - SCREEN_ACTION_PREFIX.length;
|
|
103
|
+
const screenSegment = slugify(screenName)
|
|
104
|
+
.slice(START, maxScreenSegmentLength)
|
|
105
|
+
.replace(/_+$/u, "") || "event";
|
|
106
|
+
return `${SCREEN_ACTION_PREFIX}${screenSegment}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {unknown} surface
|
|
111
|
+
* @returns {string | undefined}
|
|
112
|
+
*/
|
|
113
|
+
function boundedProductAnalyticsSurface(surface) {
|
|
114
|
+
if (typeof surface !== "string") {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const normalized = surface.trim();
|
|
118
|
+
const characters = [...normalized];
|
|
119
|
+
if (normalized === "" || characters.length > MAX_PRODUCT_ANALYTICS_SURFACE_LENGTH || hasControlCharacter(characters)) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return normalized;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {string} kind
|
|
127
|
+
* @param {unknown} surface
|
|
128
|
+
* @returns {{ analyticsSchemaVersion: number, analyticsKind: string, analyticsSurface: string | undefined }}
|
|
129
|
+
*/
|
|
130
|
+
function productAnalyticsMetadata(kind, surface) {
|
|
131
|
+
return {
|
|
132
|
+
analyticsSchemaVersion: PRODUCT_ANALYTICS_SCHEMA_VERSION,
|
|
133
|
+
|
|
134
|
+
analyticsKind: kind,
|
|
135
|
+
analyticsSurface: boundedProductAnalyticsSurface(surface)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = { productAnalyticsMetadata, recordIssueBreadcrumb, screenActionName };
|
package/index-errors.cjs
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const { createIssueAttributesFromError } = require("@logbrew/sdk");
|
|
2
|
+
const {
|
|
3
|
+
runtimeReactNativeDebugIdMap,
|
|
4
|
+
sanitizeReactNativeIssueExceptionChain,
|
|
5
|
+
sanitizeReactNativeIssueMetadata,
|
|
6
|
+
sanitizeReactNativeIssueStackFrames
|
|
7
|
+
} = require("./metadata.cjs");
|
|
8
|
+
const { defaultEventId } = require("./index-random.cjs");
|
|
9
|
+
const { getActiveLogBrewTrace, resolveTraceContext } = require("./index-trace.cjs");
|
|
10
|
+
const { compactMetadata, getReactNativeContext, readField, requireClient, textOf } = require("./index-values.cjs");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import { IssueAttributes } from "@logbrew/sdk"
|
|
14
|
+
* @import { ClientLike, ContextOptions } from "./index-values.cjs"
|
|
15
|
+
* @typedef {ContextOptions & {
|
|
16
|
+
* readonly debugIdMap?: unknown,
|
|
17
|
+
* readonly evidence?: unknown,
|
|
18
|
+
* readonly environment?: unknown,
|
|
19
|
+
* readonly fingerprint?: unknown,
|
|
20
|
+
* readonly handled?: unknown,
|
|
21
|
+
* readonly id?: string | undefined,
|
|
22
|
+
* readonly idFactory?: (context: { readonly error: unknown, readonly message: string, readonly screen: string | undefined }) => string,
|
|
23
|
+
* readonly includeStack?: unknown,
|
|
24
|
+
* readonly level?: unknown,
|
|
25
|
+
* readonly mechanism?: unknown,
|
|
26
|
+
* readonly now?: () => string,
|
|
27
|
+
* readonly release?: unknown,
|
|
28
|
+
* readonly runtime?: unknown,
|
|
29
|
+
* readonly screen?: string | undefined,
|
|
30
|
+
* readonly service?: unknown,
|
|
31
|
+
* readonly timestamp?: string | undefined,
|
|
32
|
+
* readonly trace?: unknown
|
|
33
|
+
* }} ErrorEventOptions
|
|
34
|
+
* @typedef {{ readonly id: string, readonly timestamp: string, readonly attributes: IssueAttributes }} ErrorEvent
|
|
35
|
+
* @typedef {{ readonly message: string, readonly valueType: string }} ErrorDetails
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** @type {(error: unknown, options: object) => IssueAttributes} */
|
|
39
|
+
const createIssueAttributes = createIssueAttributesFromError;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
function currentTimestamp() {
|
|
45
|
+
return new Date().toISOString();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
function defaultErrorEventId() {
|
|
52
|
+
return defaultEventId("error");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {unknown} error
|
|
57
|
+
* @returns {unknown}
|
|
58
|
+
*/
|
|
59
|
+
function errorCandidate(error) {
|
|
60
|
+
return readField(error, "reason") ?? readField(error, "error") ?? error;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {unknown} error
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
function errorMessage(error) {
|
|
68
|
+
if (error instanceof Error && typeof error.message === "string" && error.message.trim() !== "") {
|
|
69
|
+
return error.message;
|
|
70
|
+
}
|
|
71
|
+
const message = readField(error, "message");
|
|
72
|
+
if (typeof message === "string" && message.trim() !== "") {
|
|
73
|
+
return message;
|
|
74
|
+
}
|
|
75
|
+
if (typeof error === "string" && error.trim() !== "") {
|
|
76
|
+
return error;
|
|
77
|
+
}
|
|
78
|
+
return textOf(error ?? "unknown error");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {unknown} error
|
|
83
|
+
* @returns {ErrorDetails}
|
|
84
|
+
*/
|
|
85
|
+
function errorDetails(error) {
|
|
86
|
+
const candidate = errorCandidate(error);
|
|
87
|
+
return {
|
|
88
|
+
message: errorMessage(candidate),
|
|
89
|
+
valueType: candidate === null ? "null" : typeof candidate
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {IssueAttributes} attributes
|
|
95
|
+
* @param {string} message
|
|
96
|
+
* @returns {IssueAttributes}
|
|
97
|
+
*/
|
|
98
|
+
function reactNativeIssueAttributes(attributes, message) {
|
|
99
|
+
const stackFrames = sanitizeReactNativeIssueStackFrames(attributes.stackFrames);
|
|
100
|
+
const exceptionChain = sanitizeReactNativeIssueExceptionChain(attributes.exceptionChain);
|
|
101
|
+
return {
|
|
102
|
+
...attributes,
|
|
103
|
+
...(exceptionChain === undefined ? {} : { exceptionChain }),
|
|
104
|
+
...(stackFrames === undefined ? {} : { stackFrames }),
|
|
105
|
+
title: `React Native error: ${message}`,
|
|
106
|
+
|
|
107
|
+
message,
|
|
108
|
+
metadata: sanitizeReactNativeIssueMetadata(attributes.metadata, compactMetadata, stackFrames)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {unknown} error
|
|
114
|
+
* @param {ErrorEventOptions} [options]
|
|
115
|
+
* @returns {ErrorEvent}
|
|
116
|
+
*/
|
|
117
|
+
function createReactNativeErrorEvent(error, {
|
|
118
|
+
debugIdMap, evidence, environment, fingerprint, handled = true, id, idFactory = defaultErrorEventId,
|
|
119
|
+
includeStack = false, level = "error", mechanism = "react-native.error", metadata = {}, now = currentTimestamp,
|
|
120
|
+
platform, appState, release, runtime, screen, service, timestamp, trace
|
|
121
|
+
} = {}) {
|
|
122
|
+
const details = errorDetails(error);
|
|
123
|
+
const traceContext = resolveTraceContext(trace ?? getActiveLogBrewTrace());
|
|
124
|
+
const attributes = createIssueAttributes(errorCandidate(error), {
|
|
125
|
+
debugIdMap: debugIdMap === undefined ? runtimeReactNativeDebugIdMap() : debugIdMap,
|
|
126
|
+
evidence,
|
|
127
|
+
|
|
128
|
+
environment,
|
|
129
|
+
fingerprint,
|
|
130
|
+
handled,
|
|
131
|
+
includeErrorStack: includeStack,
|
|
132
|
+
level,
|
|
133
|
+
mechanism,
|
|
134
|
+
metadata: {
|
|
135
|
+
...getReactNativeContext({ appState, platform }),
|
|
136
|
+
errorValueType: details.valueType,
|
|
137
|
+
screen,
|
|
138
|
+
...metadata
|
|
139
|
+
},
|
|
140
|
+
release,
|
|
141
|
+
runtime,
|
|
142
|
+
service,
|
|
143
|
+
source: "react-native.error",
|
|
144
|
+
trace: traceContext
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
id: id ?? idFactory({ error, message: details.message, screen }),
|
|
148
|
+
timestamp: timestamp ?? now(),
|
|
149
|
+
|
|
150
|
+
attributes: reactNativeIssueAttributes(attributes, details.message)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {ClientLike} client
|
|
156
|
+
* @param {unknown} error
|
|
157
|
+
* @param {ErrorEventOptions} [options]
|
|
158
|
+
* @returns {ErrorEvent}
|
|
159
|
+
*/
|
|
160
|
+
function captureReactNativeError(client, error, options = {}) {
|
|
161
|
+
requireClient(client);
|
|
162
|
+
const event = createReactNativeErrorEvent(error, options);
|
|
163
|
+
client.issue(event.id, event.timestamp, event.attributes);
|
|
164
|
+
return event;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
module.exports = { captureReactNativeError, createReactNativeErrorEvent };
|