@bugsee/react-native 7.0.0-beta2 → 7.0.0-beta4
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 +264 -9
- package/android/build.gradle +9 -0
- package/android/consumer-rules.pro +3 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +224 -20
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +44 -21
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +15 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +119 -5
- package/android/src/main/java/com/bugsee/reactnative/NetworkCaptureProbe.java +107 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +129 -14
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +64 -8
- package/android/src/main/java/com/bugsee/reactnative/StartupHold.java +237 -0
- package/ios/BugseeModule.mm +293 -155
- package/ios/Support/Package.resolved +2 -2
- package/ios/Support/Package.swift +1 -1
- package/ios/Support/Sources/BugseeRNSupport/BGSRNBlackout.m +14 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDeleteCollectedData.m +33 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNFilterArming.m +22 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNFilterDeadline.m +110 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +40 -6
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +1 -1
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNBlackout.h +23 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +2 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDeleteCollectedData.h +29 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNFilterArming.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNFilterDeadline.h +68 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +5 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +5 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +16 -2
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +5 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNBlackoutTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDeleteCollectedDataTests.m +135 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +5 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFilterArmingTests.m +48 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFilterDeadlineTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +5 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +86 -6
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +5 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +1 -1
- package/native-versions.json +2 -2
- package/package.json +2 -2
- package/plugin/build/dsym-script.d.ts +11 -0
- package/plugin/build/dsym-script.js +26 -3
- package/plugin/build/dsym-script.js.map +1 -1
- package/plugin/build/index.d.ts +27 -0
- package/plugin/build/index.js +33 -21
- package/plugin/build/index.js.map +1 -1
- package/plugin/build/manifest.d.ts +37 -0
- package/plugin/build/manifest.js +67 -1
- package/plugin/build/manifest.js.map +1 -1
- package/plugin/build/native-versions.baked.json +1 -1
- package/scripts/bugsee-xcode.sh +0 -0
- package/scripts/compose-then-inject.js +4 -2
- package/scripts/hermes-sourcemaps.js +40 -3
- package/scripts/hermesc-preserve-js.js +0 -0
- package/scripts/hermesc-preserve-js.sh +0 -0
- package/src/NativeBugsee.ts +39 -22
- package/src/apm/span.ts +42 -7
- package/src/breadcrumbs/filter.ts +104 -13
- package/src/breadcrumbs/types.ts +6 -4
- package/src/breadcrumbs/url-scrub.ts +75 -0
- package/src/exceptions/ErrorBoundary.tsx +4 -1
- package/src/exceptions/RootErrorReporter.tsx +1 -1
- package/src/exceptions/handlers.ts +17 -1
- package/src/exceptions/report.ts +30 -8
- package/src/index.ts +125 -33
- package/src/logs/filter.ts +19 -8
- package/src/network/filter.ts +17 -5
- package/src/options/AndroidLaunchOptions.ts +310 -24
- package/src/options/BugseeLaunchOptions.ts +463 -18
- package/src/options/IOSLaunchOptions.ts +164 -8
- package/src/options/android-options-manifest.json +63 -6
- package/src/options/enums.ts +28 -0
- package/src/options/ios-enums.json +6 -5
- package/src/options/ios-options-manifest.json +594 -0
- package/src/options/keys.ts +19 -1
- package/src/options/noAccessor.ts +16 -0
- package/src/options/option-keys.json +9 -3
- package/src/options/unknownKeys.ts +198 -0
package/src/NativeBugsee.ts
CHANGED
|
@@ -259,9 +259,10 @@ export interface Spec extends TurboModule {
|
|
|
259
259
|
* `requestId` is native-minted and never reused within a process.
|
|
260
260
|
* `eventJson` is the event (`setNetworkEventFilter`'s keep-value is the
|
|
261
261
|
* event object on both SDKs, not a string). JS answers with
|
|
262
|
-
* {@link replyNetworkFilter}.
|
|
263
|
-
*
|
|
264
|
-
* the
|
|
262
|
+
* {@link replyNetworkFilter}. An answer after 9 s is ignored. iOS: the
|
|
263
|
+
* bridge drops the event at 9 s (the SDK has no deadline). Android: the
|
|
264
|
+
* bridge stops waiting at 9 s and the SDK drops the event at 10 s.
|
|
265
|
+
* Nothing here passes the original through.
|
|
265
266
|
*/
|
|
266
267
|
readonly onNetworkFilterRequest: CodegenTypes.EventEmitter<{ requestId: string; eventJson: string }>;
|
|
267
268
|
/**
|
|
@@ -296,8 +297,9 @@ export interface Spec extends TurboModule {
|
|
|
296
297
|
*
|
|
297
298
|
* `requestId` is native-minted and never reused within a process. `line`
|
|
298
299
|
* is the text the SDK would store. JS answers with {@link replyLogFilter}.
|
|
299
|
-
*
|
|
300
|
-
*
|
|
300
|
+
* An answer after 9 s is ignored. iOS: the bridge drops the line at 9 s
|
|
301
|
+
* (the SDK has no deadline). Android: the bridge stops waiting at 9 s and
|
|
302
|
+
* the SDK drops the line at 10 s.
|
|
301
303
|
*/
|
|
302
304
|
readonly onLogFilterRequest: CodegenTypes.EventEmitter<{ requestId: string; line: string }>;
|
|
303
305
|
/**
|
|
@@ -314,8 +316,9 @@ export interface Spec extends TurboModule {
|
|
|
314
316
|
/**
|
|
315
317
|
* Answers one {@link onLogFilterRequest}. `line` is the replacement to
|
|
316
318
|
* keep; `null` drops the line. A second reply for the same `requestId` is
|
|
317
|
-
* a no-op. Not answering drops the line
|
|
318
|
-
*
|
|
319
|
+
* a no-op. Not answering drops the line (iOS: the bridge at 9 s; Android: the
|
|
320
|
+
* SDK at 10 s, the bridge having stopped waiting at 9 s), and a later
|
|
321
|
+
* reply is ignored; nothing passes the original through.
|
|
319
322
|
*/
|
|
320
323
|
replyLogFilter(requestId: string, line: string | null): void;
|
|
321
324
|
|
|
@@ -347,8 +350,9 @@ export interface Spec extends TurboModule {
|
|
|
347
350
|
* `requestId` is native-minted and never reused within a process.
|
|
348
351
|
* `crumbJson` is the snapshot: only the keys the crumb had, `level` as
|
|
349
352
|
* its name, `timestamp` when it is set. JS answers with
|
|
350
|
-
* {@link replyBreadcrumbFilter}. A request
|
|
351
|
-
*
|
|
353
|
+
* {@link replyBreadcrumbFilter}. A request not answered within 9 s is
|
|
354
|
+
* dropped by the native bridge on both platforms (neither SDK has a
|
|
355
|
+
* deadline for this filter); a later reply is ignored. The reply is never
|
|
352
356
|
* the original crumb after a failed filter.
|
|
353
357
|
*
|
|
354
358
|
* `addId` is set only on the request for the manual `addBreadcrumb` that
|
|
@@ -377,8 +381,8 @@ export interface Spec extends TurboModule {
|
|
|
377
381
|
* Answers one {@link onBreadcrumbFilterRequest}. `crumbJson` is the keep,
|
|
378
382
|
* with every writable key the snapshot sent and `level` as its name;
|
|
379
383
|
* `null` drops the crumb. A second reply for the same `requestId` is a
|
|
380
|
-
* no-op. Not answering
|
|
381
|
-
* that passes the original through.
|
|
384
|
+
* no-op. Not answering within 9 s drops the crumb, and a later reply is
|
|
385
|
+
* ignored; there is no reply that passes the original through.
|
|
382
386
|
*/
|
|
383
387
|
replyBreadcrumbFilter(requestId: string, crumbJson: string | null): void;
|
|
384
388
|
|
|
@@ -583,10 +587,12 @@ export interface Spec extends TurboModule {
|
|
|
583
587
|
* Finishes the span and releases every retained span that is now
|
|
584
588
|
* finished, including children a parent finish cancelled. `statusSet`
|
|
585
589
|
* false is the no-arg `finish` (status OK). The returned handles are
|
|
586
|
-
* the ones dropped
|
|
587
|
-
*
|
|
590
|
+
* the ones dropped, each with the status the SDK holds after the finish
|
|
591
|
+
* (`{ released: [{ handle, status }] }`). Empty means the handle was
|
|
592
|
+
* already gone. The name is `statusSet` because `explicit` is a keyword in
|
|
593
|
+
* the ObjC++ spec.
|
|
588
594
|
*/
|
|
589
|
-
spanFinish(handle: string, status: number, statusSet: boolean):
|
|
595
|
+
spanFinish(handle: string, status: number, statusSet: boolean): CodegenTypes.UnsafeObject;
|
|
590
596
|
|
|
591
597
|
/**
|
|
592
598
|
* One report color. `name` is already the platform's native key
|
|
@@ -605,14 +611,25 @@ export interface Spec extends TurboModule {
|
|
|
605
611
|
getAppearanceColor(name: string): string;
|
|
606
612
|
/**
|
|
607
613
|
* Deletes collected data on the device. `includingIntermediate` is the
|
|
608
|
-
* SDK's own flag
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
|
|
615
|
-
|
|
614
|
+
* SDK's own flag. `includingFinishedReports` also deletes the finished
|
|
615
|
+
* reports waiting for upload: Android's 3-argument
|
|
616
|
+
* `Bugsee.deleteCollectedDataOnDevice(includingIntermediate,
|
|
617
|
+
* includingBundles, callback)`, which deletes the finished bundles only;
|
|
618
|
+
* iOS has no flags form for it, so `true` calls `deleteCollectedDataOnDevice:`
|
|
619
|
+
* (everything: also crashes not yet reported and the performance baselines;
|
|
620
|
+
* `includingIntermediate` is then moot). That gap is a possible SDK
|
|
621
|
+
* follow-up. `includingIntermediate` covers the report snapshots on both
|
|
622
|
+
* platforms and, on Android, exported reports.
|
|
623
|
+
*
|
|
624
|
+
* Resolves to the SDK's completion value, however long the deletion takes.
|
|
625
|
+
* Both platforms refuse the deletion while launched and answer `false`
|
|
626
|
+
* (by design). iOS rejects with `E_DELETE_TIMEOUT` if the SDK reports
|
|
627
|
+
* nothing for 60 s; the deletion may still finish.
|
|
628
|
+
*/
|
|
629
|
+
deleteCollectedDataOnDevice(
|
|
630
|
+
includingIntermediate: boolean,
|
|
631
|
+
includingFinishedReports: boolean,
|
|
632
|
+
): Promise<boolean>;
|
|
616
633
|
}
|
|
617
634
|
|
|
618
635
|
// Before the lookup: on the legacy architecture getEnforcing does not throw,
|
package/src/apm/span.ts
CHANGED
|
@@ -93,12 +93,36 @@ function adopt(value: unknown): SpanObject | null {
|
|
|
93
93
|
return span;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
interface ReleasedSpan {
|
|
97
|
+
handle: string;
|
|
98
|
+
status: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What `spanFinish` reports: every handle native dropped and the status the SDK holds for it. */
|
|
102
|
+
function parseReleased(result: unknown): ReleasedSpan[] {
|
|
103
|
+
const list = (result as { released?: unknown } | null | undefined)?.released;
|
|
104
|
+
if (!Array.isArray(list)) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
const out: ReleasedSpan[] = [];
|
|
108
|
+
for (const item of list as unknown[]) {
|
|
109
|
+
const entry = item as { handle?: unknown; status?: unknown } | null;
|
|
110
|
+
if (entry !== null && typeof entry === 'object' && typeof entry.handle === 'string') {
|
|
111
|
+
out.push({
|
|
112
|
+
handle: entry.handle,
|
|
113
|
+
status: typeof entry.status === 'number' ? entry.status : SpanStatus.Unknown,
|
|
114
|
+
});
|
|
101
115
|
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function markReleased(released: readonly ReleasedSpan[]): void {
|
|
121
|
+
for (const { handle, status } of released) {
|
|
122
|
+
// The status is what native read from the SDK span after the finish, so
|
|
123
|
+
// a child the parent cancelled and a span the SDK finished on its own
|
|
124
|
+
// both report what the SDK recorded.
|
|
125
|
+
live.get(handle)?.markDead(status);
|
|
102
126
|
live.delete(handle);
|
|
103
127
|
}
|
|
104
128
|
}
|
|
@@ -192,7 +216,15 @@ class SpanObject {
|
|
|
192
216
|
this.guard();
|
|
193
217
|
const explicit = status !== undefined;
|
|
194
218
|
const wire = explicit ? assertStatus(status) : 0;
|
|
195
|
-
const released =
|
|
219
|
+
const released = parseReleased(
|
|
220
|
+
NativeBugsee.spanFinish(this.wire.handle, wire, explicit),
|
|
221
|
+
);
|
|
222
|
+
// Native reports the status it holds after the finish (no argument ends
|
|
223
|
+
// the span as OK and overwrites an earlier setStatus). When it reports
|
|
224
|
+
// nothing for this handle, only an explicit status is known.
|
|
225
|
+
if (explicit && !released.some((item) => item.handle === this.wire.handle)) {
|
|
226
|
+
this.status = wire;
|
|
227
|
+
}
|
|
196
228
|
markReleased(released);
|
|
197
229
|
// Dead even when native omits this handle. A later call is what throws.
|
|
198
230
|
this.markDead();
|
|
@@ -219,7 +251,10 @@ class SpanObject {
|
|
|
219
251
|
return this.attributes;
|
|
220
252
|
}
|
|
221
253
|
|
|
222
|
-
markDead(): void {
|
|
254
|
+
markDead(status?: number): void {
|
|
255
|
+
if (status !== undefined) {
|
|
256
|
+
this.status = status;
|
|
257
|
+
}
|
|
223
258
|
this.dead = true;
|
|
224
259
|
this.finishedFlag = true;
|
|
225
260
|
}
|
|
@@ -3,10 +3,13 @@ import { encodeBridgeObject } from '../bridge/json';
|
|
|
3
3
|
import { copyBreadcrumbData } from './data';
|
|
4
4
|
import { isBreadcrumbLevel } from './types';
|
|
5
5
|
import type { BreadcrumbFilter, BreadcrumbSnapshot } from './types';
|
|
6
|
+
import { defaultBreadcrumbUrlScrubber, scrubSnapshotUrl } from './url-scrub';
|
|
7
|
+
import type { BreadcrumbUrlScrubber } from './url-scrub';
|
|
6
8
|
|
|
7
9
|
const WRITABLE_STRINGS = ['category', 'message', 'type'] as const;
|
|
8
10
|
|
|
9
11
|
let current: BreadcrumbFilter | undefined;
|
|
12
|
+
let currentScrubber: BreadcrumbUrlScrubber | undefined;
|
|
10
13
|
let subscribed = false;
|
|
11
14
|
|
|
12
15
|
/**
|
|
@@ -18,20 +21,24 @@ let subscribed = false;
|
|
|
18
21
|
* An add native did not ask about is removed, so it cannot be claimed later.
|
|
19
22
|
*/
|
|
20
23
|
let nextAddId = 0;
|
|
21
|
-
const owed: Array<{
|
|
24
|
+
const owed: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
callback: BreadcrumbFilter | undefined;
|
|
27
|
+
scrubber: BreadcrumbUrlScrubber | undefined;
|
|
28
|
+
}> = [];
|
|
22
29
|
|
|
23
30
|
/**
|
|
24
31
|
* Called from `addBreadcrumb` after validation, before the native call.
|
|
25
32
|
* Returns the id native echoes on that add's filter request, or `null` when
|
|
26
|
-
*
|
|
33
|
+
* no filter and no URL scrubber is installed and there is nothing to retain.
|
|
27
34
|
*/
|
|
28
35
|
export function retainBreadcrumbFilterForAdd(): string | null {
|
|
29
|
-
if (current === undefined) {
|
|
36
|
+
if (current === undefined && currentScrubber === undefined) {
|
|
30
37
|
return null;
|
|
31
38
|
}
|
|
32
39
|
nextAddId += 1;
|
|
33
40
|
const id = String(nextAddId);
|
|
34
|
-
owed.push({ id, callback: current });
|
|
41
|
+
owed.push({ id, callback: current, scrubber: currentScrubber });
|
|
35
42
|
return id;
|
|
36
43
|
}
|
|
37
44
|
|
|
@@ -43,7 +50,9 @@ export function releaseBreadcrumbFilterForAdd(id: string): void {
|
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
|
|
46
|
-
function claimBreadcrumbFilter(
|
|
53
|
+
function claimBreadcrumbFilter(
|
|
54
|
+
id: string | undefined,
|
|
55
|
+
): { callback: BreadcrumbFilter | undefined; scrubber: BreadcrumbUrlScrubber | undefined } | undefined {
|
|
47
56
|
if (id === undefined || id.length === 0) {
|
|
48
57
|
return undefined;
|
|
49
58
|
}
|
|
@@ -52,7 +61,7 @@ function claimBreadcrumbFilter(id: string | undefined): BreadcrumbFilter | undef
|
|
|
52
61
|
return undefined;
|
|
53
62
|
}
|
|
54
63
|
const [item] = owed.splice(index, 1);
|
|
55
|
-
return item
|
|
64
|
+
return item;
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
/**
|
|
@@ -64,6 +73,16 @@ function claimBreadcrumbFilter(id: string | undefined): BreadcrumbFilter | undef
|
|
|
64
73
|
* crumb filtered on the installing turn still has a listener. The subscription
|
|
65
74
|
* stays: clearing the callback stops native from asking, and a later callback
|
|
66
75
|
* must still be able to answer.
|
|
76
|
+
*
|
|
77
|
+
* The native filter lives for the whole process, but the JavaScript side that
|
|
78
|
+
* answers it does not. After a full reload, `DevSettings.reload()`, or an OTA
|
|
79
|
+
* reload (`Updates.reloadAsync()`, CodePush `restartApp()`), the new runtime
|
|
80
|
+
* has not installed a filter yet, so native fails closed: crumbs are dropped, not recorded.
|
|
81
|
+
* That lasts until `setBreadcrumbFilter` is called again, which can be the rest of the
|
|
82
|
+
* process. Call it unconditionally at startup, on every launch of the JS
|
|
83
|
+
* runtime, not lazily or conditionally (after login or consent), and keep it
|
|
84
|
+
* in every OTA bundle. To opt out, call `setBreadcrumbFilter(null)`, which restores
|
|
85
|
+
* pass-through.
|
|
67
86
|
*/
|
|
68
87
|
export function setBreadcrumbFilter(callback?: BreadcrumbFilter | null): void {
|
|
69
88
|
if (callback != null && typeof callback !== 'function') {
|
|
@@ -72,11 +91,55 @@ export function setBreadcrumbFilter(callback?: BreadcrumbFilter | null): void {
|
|
|
72
91
|
);
|
|
73
92
|
}
|
|
74
93
|
current = callback ?? undefined;
|
|
75
|
-
|
|
94
|
+
syncNativeFilter();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Cleans `data.url` of `http` breadcrumbs before the callback of
|
|
99
|
+
* {@link setBreadcrumbFilter} sees them. `true` installs
|
|
100
|
+
* {@link defaultBreadcrumbUrlScrubber}, a function is a custom scrubber, and
|
|
101
|
+
* `false`, `null` or `undefined` turns it off (the default).
|
|
102
|
+
*
|
|
103
|
+
* Off costs nothing. On, native asks JS about every breadcrumb, not only
|
|
104
|
+
* `http` ones, exactly as it does for an installed breadcrumb filter, and the
|
|
105
|
+
* same 9 s deadline and fail-closed rules apply. It is independent of
|
|
106
|
+
* `setBreadcrumbFilter`: either one, or both, keeps the native filter
|
|
107
|
+
* installed. Like that filter it is a per-runtime setting: call it on every
|
|
108
|
+
* launch of the JS runtime, or after a reload native drops crumbs until it
|
|
109
|
+
* is called again.
|
|
110
|
+
*/
|
|
111
|
+
export function setBreadcrumbUrlScrubber(
|
|
112
|
+
scrubber?: boolean | BreadcrumbUrlScrubber | null,
|
|
113
|
+
): void {
|
|
114
|
+
if (scrubber != null && typeof scrubber !== 'boolean' && typeof scrubber !== 'function') {
|
|
115
|
+
throw new TypeError(
|
|
116
|
+
`Bugsee.setBreadcrumbUrlScrubber requires a boolean or a function, got ${typeof scrubber}`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const wasWanted = current !== undefined || currentScrubber !== undefined;
|
|
120
|
+
if (scrubber === true) {
|
|
121
|
+
currentScrubber = defaultBreadcrumbUrlScrubber;
|
|
122
|
+
} else if (typeof scrubber === 'function') {
|
|
123
|
+
currentScrubber = scrubber;
|
|
124
|
+
} else {
|
|
125
|
+
currentScrubber = undefined;
|
|
126
|
+
}
|
|
127
|
+
if (!wasWanted && currentScrubber === undefined) {
|
|
128
|
+
// Off to off: nothing to tell native, and a disable would release a hold
|
|
129
|
+
// that only the app's own setter should release.
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
syncNativeFilter();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The native filter stays installed while a callback or a scrubber needs it. */
|
|
136
|
+
function syncNativeFilter(): void {
|
|
137
|
+
const wanted = current !== undefined || currentScrubber !== undefined;
|
|
138
|
+
if (wanted && !subscribed) {
|
|
76
139
|
subscribed = true;
|
|
77
140
|
NativeBugsee.onBreadcrumbFilterRequest(onBreadcrumbFilterRequest);
|
|
78
141
|
}
|
|
79
|
-
NativeBugsee.setBreadcrumbFilterEnabled(
|
|
142
|
+
NativeBugsee.setBreadcrumbFilterEnabled(wanted);
|
|
80
143
|
}
|
|
81
144
|
|
|
82
145
|
/**
|
|
@@ -96,6 +159,10 @@ export function setBreadcrumbFilter(callback?: BreadcrumbFilter | null): void {
|
|
|
96
159
|
* settles does not reply at all. Neither path replies with the original crumb.
|
|
97
160
|
* `timestamp` is not a writable key, and a key the snapshot omitted stays
|
|
98
161
|
* omitted. `data: null` when the snapshot sent `data` clears it.
|
|
162
|
+
*
|
|
163
|
+
* With a URL scrubber installed (see {@link setBreadcrumbUrlScrubber}) the
|
|
164
|
+
* `data.url` of an `http` crumb is cleaned first. With a scrubber and no
|
|
165
|
+
* callback the cleaned crumb is what is kept.
|
|
99
166
|
*/
|
|
100
167
|
function onBreadcrumbFilterRequest(event: {
|
|
101
168
|
requestId: string;
|
|
@@ -112,16 +179,25 @@ function onBreadcrumbFilterRequest(event: {
|
|
|
112
179
|
reply(requestId, null);
|
|
113
180
|
return;
|
|
114
181
|
}
|
|
115
|
-
const callback = reserved
|
|
116
|
-
|
|
182
|
+
const callback = reserved === undefined ? current : reserved.callback;
|
|
183
|
+
const scrubber = reserved === undefined ? currentScrubber : reserved.scrubber;
|
|
184
|
+
if (callback === undefined && scrubber === undefined) {
|
|
117
185
|
reply(requestId, null);
|
|
118
186
|
return;
|
|
119
187
|
}
|
|
120
188
|
|
|
121
189
|
Promise.resolve()
|
|
122
|
-
.then(() =>
|
|
123
|
-
|
|
124
|
-
|
|
190
|
+
.then(() => {
|
|
191
|
+
// The scrubber runs first, so the app's callback only ever sees the
|
|
192
|
+
// cleaned URL. A throw here drops the crumb like a throw in the callback.
|
|
193
|
+
const seen = scrubber === undefined ? snapshot : scrubSnapshotUrl(snapshot, scrubber);
|
|
194
|
+
// The callback gets a copy: deleting a key from it must not change
|
|
195
|
+
// which keys the reply has to carry. Those come from the original.
|
|
196
|
+
const shown = { ...seen };
|
|
197
|
+
return Promise.all([seen, callback === undefined ? undefined : callback(shown)]);
|
|
198
|
+
})
|
|
199
|
+
.then(([seen, result]) => {
|
|
200
|
+
reply(requestId, callback === undefined ? echoJson(seen) : keptJson(seen, result));
|
|
125
201
|
})
|
|
126
202
|
.catch(() => {
|
|
127
203
|
reply(requestId, null);
|
|
@@ -165,6 +241,21 @@ function snapshotFromJson(json: string): BreadcrumbSnapshot | null {
|
|
|
165
241
|
return snapshot;
|
|
166
242
|
}
|
|
167
243
|
|
|
244
|
+
/**
|
|
245
|
+
* The JSON that keeps `snapshot` as it is, for the scrubber with no callback.
|
|
246
|
+
* `data` is not re-validated: the app wrote none of it, so a crumb native
|
|
247
|
+
* recorded with unusual data is not dropped for that.
|
|
248
|
+
*/
|
|
249
|
+
function echoJson(snapshot: BreadcrumbSnapshot): string {
|
|
250
|
+
const out: Record<string, unknown> = Object.create(null);
|
|
251
|
+
for (const key of [...WRITABLE_STRINGS, 'level', 'data'] as const) {
|
|
252
|
+
if (Object.hasOwn(snapshot, key)) {
|
|
253
|
+
out[key] = snapshot[key];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return encodeBridgeObject(out);
|
|
257
|
+
}
|
|
258
|
+
|
|
168
259
|
/**
|
|
169
260
|
* The JSON to send back, or `null` to drop.
|
|
170
261
|
*
|
package/src/breadcrumbs/types.ts
CHANGED
|
@@ -54,10 +54,12 @@ export interface BreadcrumbSnapshot {
|
|
|
54
54
|
* One crumb in, the crumb to keep out.
|
|
55
55
|
*
|
|
56
56
|
* Returning the crumb, or another object, keeps it. `null` and `undefined`
|
|
57
|
-
* drop it. A promise is waited on
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
57
|
+
* drop it. A promise is waited on, for 9 s: the native bridge drops the crumb
|
|
58
|
+
* if the filter has not settled by then, on both platforms, and ignores a
|
|
59
|
+
* later answer. Neither SDK has a deadline for this filter, so the bridge
|
|
60
|
+
* supplies it. This function does not add a timeout of its own: a timeout
|
|
61
|
+
* here that then passed the original crumb would leak exactly what the
|
|
62
|
+
* filter exists to remove.
|
|
61
63
|
*/
|
|
62
64
|
export type BreadcrumbFilter = (
|
|
63
65
|
crumb: BreadcrumbSnapshot,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { BreadcrumbSnapshot } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maps the URL of an `http` breadcrumb to the URL to record. It must return a
|
|
5
|
+
* string and run synchronously. A throw, or a result that is not a string,
|
|
6
|
+
* drops the crumb: the original URL is never recorded in its place.
|
|
7
|
+
*/
|
|
8
|
+
export type BreadcrumbUrlScrubber = (url: string) => string;
|
|
9
|
+
|
|
10
|
+
/** A colon before a `?` or `#`: a port or a password, which cannot be told apart. */
|
|
11
|
+
function looksLikeCredentials(beforeStop: string): boolean {
|
|
12
|
+
return beforeStop.includes(':') && !beforeStop.startsWith('[');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The built-in scrubber. Drops `user:password@` from the authority, the query
|
|
17
|
+
* string and the fragment. Kept: the scheme, host, port and path. Path
|
|
18
|
+
* segments can still carry an identifier or a token (and a `;jsessionid=...`
|
|
19
|
+
* path parameter stays): pass a custom scrubber when yours do.
|
|
20
|
+
*
|
|
21
|
+
* Plain string work, not `URL`: Hermes' `URL` is incomplete, and a value the
|
|
22
|
+
* native SDK recorded may not parse (a relative or malformed URL still has to
|
|
23
|
+
* lose its query). Leading and trailing whitespace is trimmed. When an `@`
|
|
24
|
+
* follows a `?` or `#` and a `:` comes before it (`u:pa?ss@host`, or a port
|
|
25
|
+
* with an `@` in its query), the text cannot be told apart, so everything after
|
|
26
|
+
* the scheme is replaced by `[redacted]`. A username with no `:` in that shape
|
|
27
|
+
* is read as the host. A `/` in the password ends the authority, as in a URL
|
|
28
|
+
* parser, and is not handled.
|
|
29
|
+
*/
|
|
30
|
+
export const defaultBreadcrumbUrlScrubber: BreadcrumbUrlScrubber = (url) => {
|
|
31
|
+
const trimmed = url.trim();
|
|
32
|
+
const parts = /^((?:[A-Za-z][A-Za-z0-9+.-]*:)?\/\/)([^/]*)/.exec(trimmed);
|
|
33
|
+
if (parts === null) {
|
|
34
|
+
return cutTail(trimmed);
|
|
35
|
+
}
|
|
36
|
+
const prefix = parts[1] as string;
|
|
37
|
+
const authority = parts[2] as string;
|
|
38
|
+
const head = cutTail(authority);
|
|
39
|
+
if (!head.includes('@') && looksLikeCredentials(head) && authority.includes('@')) {
|
|
40
|
+
// Whatever follows is the password's tail or the query: keep none of it.
|
|
41
|
+
return prefix + '[redacted]';
|
|
42
|
+
}
|
|
43
|
+
const host = authority.slice(head.lastIndexOf('@') + 1);
|
|
44
|
+
return prefix + cutTail(host + trimmed.slice(parts[0].length));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** `text` up to the first `?` or `#`. */
|
|
48
|
+
function cutTail(text: string): string {
|
|
49
|
+
const end = text.search(/[?#]/);
|
|
50
|
+
return end < 0 ? text : text.slice(0, end);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
54
|
+
return typeof value === 'object' && value !== null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* `snapshot` with `data.url` replaced by `scrub(url)`, when it is an `http`
|
|
59
|
+
* crumb carrying a string URL. Any other crumb comes back as it is. Throws
|
|
60
|
+
* when `scrub` throws or returns a non-string, so the caller drops the crumb.
|
|
61
|
+
*/
|
|
62
|
+
export function scrubSnapshotUrl(
|
|
63
|
+
snapshot: BreadcrumbSnapshot,
|
|
64
|
+
scrub: BreadcrumbUrlScrubber,
|
|
65
|
+
): BreadcrumbSnapshot {
|
|
66
|
+
const data = snapshot.data;
|
|
67
|
+
if (snapshot.type !== 'http' || !isPlainRecord(data) || typeof data.url !== 'string') {
|
|
68
|
+
return snapshot;
|
|
69
|
+
}
|
|
70
|
+
const scrubbed: unknown = scrub(data.url);
|
|
71
|
+
if (typeof scrubbed !== 'string') {
|
|
72
|
+
throw new TypeError('breadcrumb URL scrubber must return a string');
|
|
73
|
+
}
|
|
74
|
+
return { ...snapshot, data: { ...data, url: scrubbed } };
|
|
75
|
+
}
|
|
@@ -8,6 +8,7 @@ import React from 'react';
|
|
|
8
8
|
import type { ReactElement, ReactNode } from 'react';
|
|
9
9
|
import type { ExceptionOptions } from './options';
|
|
10
10
|
import { encodeExceptionOptions, exceptionOptionsMessage } from './options';
|
|
11
|
+
import { isCrashDetectionOptedOut } from './handlers';
|
|
11
12
|
import { markReported, reportHandled } from './report';
|
|
12
13
|
|
|
13
14
|
export interface ErrorBoundaryFallbackProps {
|
|
@@ -58,7 +59,9 @@ export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoun
|
|
|
58
59
|
);
|
|
59
60
|
options = undefined;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
// Honour com.bugsee.option.detect.crash like the root reporter and the
|
|
63
|
+
// global handlers do. The fallback and onError still run.
|
|
64
|
+
if (!isCrashDetectionOptedOut() && markReported(error)) {
|
|
62
65
|
reportHandled(error, options, { componentStack });
|
|
63
66
|
}
|
|
64
67
|
this.props.onError?.(error, componentStack);
|
|
@@ -40,7 +40,7 @@ export class RootErrorReporter extends React.Component<
|
|
|
40
40
|
override componentDidCatch(error: unknown, info: { componentStack?: string | null }): void {
|
|
41
41
|
const componentStack = info.componentStack ?? undefined;
|
|
42
42
|
|
|
43
|
-
if (isExceptionCaptureEnabled() && markReported(error)) {
|
|
43
|
+
if (isExceptionCaptureEnabled() && markReported(error, 'unhandled')) {
|
|
44
44
|
void reportUnhandled(error, { componentStack }).finally(() => {
|
|
45
45
|
this.setState({ phase: 'rethrow' });
|
|
46
46
|
});
|
|
@@ -176,7 +176,7 @@ function installErrorUtils(env: HandlerEnv): void {
|
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
try {
|
|
179
|
-
if (captureEnabled && markReported(error)) {
|
|
179
|
+
if (captureEnabled && markReported(error, isFatal === true ? 'unhandled' : 'handled')) {
|
|
180
180
|
if (isFatal === true) {
|
|
181
181
|
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
182
182
|
const timeout = new Promise<void>((resolve) => {
|
|
@@ -230,6 +230,22 @@ export function setExceptionCaptureEnabled(enabled: boolean): void {
|
|
|
230
230
|
captureEnabled = enabled;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/**
|
|
234
|
+
* The user's own `detect.crash: false`, kept apart from the transient hold
|
|
235
|
+
* `Bugsee.attach()` puts on {@link setExceptionCaptureEnabled} while it reads
|
|
236
|
+
* the options (which stays on if that read rejects). `ErrorBoundary` reads
|
|
237
|
+
* this one, so a failed read never silences it.
|
|
238
|
+
*/
|
|
239
|
+
let crashDetectionOptedOut = false;
|
|
240
|
+
|
|
241
|
+
export function setCrashDetectionOptedOut(optedOut: boolean): void {
|
|
242
|
+
crashDetectionOptedOut = optedOut;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function isCrashDetectionOptedOut(): boolean {
|
|
246
|
+
return crashDetectionOptedOut;
|
|
247
|
+
}
|
|
248
|
+
|
|
233
249
|
/** Current R7 capture flag; `RootErrorReporter` reads this rather than copying it. */
|
|
234
250
|
export function isExceptionCaptureEnabled(): boolean {
|
|
235
251
|
return captureEnabled;
|
package/src/exceptions/report.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds and crosses a JS exception payload to the TurboModule stubs.
|
|
3
3
|
*
|
|
4
|
-
* Dedupes object values through
|
|
4
|
+
* Dedupes object values through two WeakSets, one per kind (`markReported`). Handled
|
|
5
5
|
* `AggregateError`s are split (R14, first {@link EXCEPTION_MAX_AGGREGATE});
|
|
6
6
|
* unhandled ones stay one report. Never throws from `reportHandled`; never
|
|
7
7
|
* rejects from `reportUnhandled`.
|
|
@@ -34,17 +34,39 @@ export function unhandledReportWaitMs(): number {
|
|
|
34
34
|
}
|
|
35
35
|
export const EXCEPTION_MAX_AGGREGATE = 10;
|
|
36
36
|
|
|
37
|
+
/** Objects reported in any form (handled or unhandled). */
|
|
37
38
|
const reported = new WeakSet<object>();
|
|
39
|
+
/** Objects reported as a crash. A handled report does not enter this set. */
|
|
40
|
+
const reportedUnhandled = new WeakSet<object>();
|
|
38
41
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
42
|
+
/**
|
|
43
|
+
* true the first time an object is seen (WeakSet); always true for a primitive.
|
|
44
|
+
*
|
|
45
|
+
* A crash is never blocked by an earlier handled report of the same object,
|
|
46
|
+
* so `logException(e)` followed by a rethrow that ends the app still reports
|
|
47
|
+
* the crash. Anything already reported as a crash blocks every later report,
|
|
48
|
+
* handled or not. Pass `'unhandled'` from the crash routes.
|
|
49
|
+
*/
|
|
50
|
+
export function markReported(
|
|
51
|
+
error: unknown,
|
|
52
|
+
kind: 'handled' | 'unhandled' = 'handled',
|
|
53
|
+
): boolean {
|
|
41
54
|
if (error === null || (typeof error !== 'object' && typeof error !== 'function')) {
|
|
42
55
|
return true;
|
|
43
56
|
}
|
|
44
|
-
|
|
57
|
+
const key = error as object;
|
|
58
|
+
if (kind === 'unhandled') {
|
|
59
|
+
if (reportedUnhandled.has(key)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
reportedUnhandled.add(key);
|
|
63
|
+
reported.add(key);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (reported.has(key)) {
|
|
45
67
|
return false;
|
|
46
68
|
}
|
|
47
|
-
reported.add(
|
|
69
|
+
reported.add(key);
|
|
48
70
|
return true;
|
|
49
71
|
}
|
|
50
72
|
|
|
@@ -86,8 +108,8 @@ function sendHandled(
|
|
|
86
108
|
* at most {@link EXCEPTION_MAX_AGGREGATE} inner reports.
|
|
87
109
|
*
|
|
88
110
|
* Callers claim the value with {@link markReported} first. This function does
|
|
89
|
-
* not re-claim the top-level `error` (handlers and the facade share
|
|
90
|
-
*
|
|
111
|
+
* not re-claim the top-level `error` (handlers and the facade share the
|
|
112
|
+
* same WeakSets); it still marks AggregateError inners so a shared Error crosses
|
|
91
113
|
* once whichever route saw it first.
|
|
92
114
|
*/
|
|
93
115
|
export function reportHandled(
|
|
@@ -132,7 +154,7 @@ function warnUnhandledNativeFailureOnce(): void {
|
|
|
132
154
|
* {@link unhandledReportWaitMs}, whichever is first; never rejects.
|
|
133
155
|
*
|
|
134
156
|
* Callers claim the value with {@link markReported} first (same shared
|
|
135
|
-
*
|
|
157
|
+
* WeakSets as {@link reportHandled}; a prior handled claim does not block a crash).
|
|
136
158
|
*/
|
|
137
159
|
export async function reportUnhandled(
|
|
138
160
|
error: unknown,
|