@bugsee/react-native 7.0.0-beta3 → 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 +228 -10
- 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 +1 -1
- 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/compose-then-inject.js +4 -2
- package/scripts/hermes-sourcemaps.js +40 -3
- 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
|
@@ -17,24 +17,35 @@ import java.util.HashMap;
|
|
|
17
17
|
import java.util.List;
|
|
18
18
|
import java.util.Map;
|
|
19
19
|
import java.util.concurrent.ConcurrentHashMap;
|
|
20
|
+
import java.util.concurrent.ScheduledFuture;
|
|
21
|
+
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
22
|
+
import java.util.concurrent.TimeUnit;
|
|
20
23
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
21
24
|
import java.util.concurrent.atomic.AtomicLong;
|
|
22
25
|
import java.util.concurrent.atomic.AtomicReference;
|
|
26
|
+
import java.util.function.Consumer;
|
|
27
|
+
import java.util.function.LongSupplier;
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
30
|
* The app's breadcrumb filter, as a round trip into JS.
|
|
26
31
|
*
|
|
27
32
|
* <p>Registered with {@link Bugsee#setBreadcrumbFilter}. {@link #filter}
|
|
28
33
|
* returns without waiting. The crumb the SDK lends is a pooled entry
|
|
29
|
-
* ({@code BugseeCaptureDataProviderBreadcrumb} borrows from a pool of 40)
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* ({@code BugseeCaptureDataProviderBreadcrumb} borrows from a pool of 40).
|
|
35
|
+
* Unlike {@code BugseeCaptureDataProviderLog} and the network provider, the
|
|
36
|
+
* SDK has no filter timeout and never recycles that entry: an unanswered
|
|
37
|
+
* crumb is not recorded and its entry is held for the session, and so is a
|
|
38
|
+
* crumb that is answered {@code null} (SDK 7.4.2 {@code doLogBreadcrumb}
|
|
39
|
+
* returns without recycling). That is SDK-side and not something this
|
|
40
|
+
* bridge can undo.
|
|
41
|
+
*
|
|
42
|
+
* <p>What this bridge owns is its own pending request. It forgets one that
|
|
43
|
+
* JS has not answered by {@link #DEADLINE_MS} and passes {@code null} to the
|
|
44
|
+
* SDK, which discards the crumb, failing closed. (The log and network bridges
|
|
45
|
+
* use the same 9 s, but only stop waiting then, without calling the callback:
|
|
46
|
+
* their SDK providers drop at 10 s themselves.) A timer that passed the
|
|
47
|
+
* original crumb would leak exactly what the filter exists to redact. A
|
|
48
|
+
* reply after the deadline finds nothing pending and is a no-op.
|
|
38
49
|
*
|
|
39
50
|
* <p>A missing sink, a snapshot that cannot be serialised, a failed emit,
|
|
40
51
|
* a {@code null} reply, or a reply that does not stick passes {@code null}
|
|
@@ -56,18 +67,41 @@ final class BreadcrumbFilterBridge {
|
|
|
56
67
|
);
|
|
57
68
|
}
|
|
58
69
|
|
|
70
|
+
/** Cancels a pending request's deadline. */
|
|
71
|
+
interface Cancellable {
|
|
72
|
+
void cancel();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Arms a request's deadline. Injectable so tests control time. */
|
|
76
|
+
interface Scheduler {
|
|
77
|
+
@NonNull
|
|
78
|
+
Cancellable schedule(@NonNull Runnable task, long delayMs);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* How long JS gets to answer one crumb before it is dropped. The SDK has
|
|
83
|
+
* no deadline of its own for this filter; this is the same number the
|
|
84
|
+
* log and network bridges forget at.
|
|
85
|
+
*/
|
|
86
|
+
static final long DEADLINE_MS = 9_000L;
|
|
87
|
+
|
|
59
88
|
private static final class Pending {
|
|
60
89
|
@NonNull final String id;
|
|
61
90
|
@NonNull final Breadcrumb crumb;
|
|
62
91
|
@NonNull final Callback1<Breadcrumb> callback;
|
|
63
92
|
@NonNull final Sink owner;
|
|
93
|
+
/** {@code System.nanoTime()}-style instant after which a reply is refused. */
|
|
94
|
+
final long expiresAtNanos;
|
|
95
|
+
@Nullable volatile Cancellable deadline;
|
|
64
96
|
|
|
65
97
|
Pending(
|
|
66
98
|
@NonNull final String id,
|
|
67
99
|
@NonNull final Breadcrumb crumb,
|
|
68
100
|
@NonNull final Callback1<Breadcrumb> callback,
|
|
69
|
-
@NonNull final Sink owner
|
|
101
|
+
@NonNull final Sink owner,
|
|
102
|
+
final long expiresAtNanos
|
|
70
103
|
) {
|
|
104
|
+
this.expiresAtNanos = expiresAtNanos;
|
|
71
105
|
this.id = id;
|
|
72
106
|
this.crumb = crumb;
|
|
73
107
|
this.callback = callback;
|
|
@@ -75,7 +109,7 @@ final class BreadcrumbFilterBridge {
|
|
|
75
109
|
}
|
|
76
110
|
}
|
|
77
111
|
|
|
78
|
-
private static final BreadcrumbFilterBridge SHARED = new BreadcrumbFilterBridge();
|
|
112
|
+
private static final BreadcrumbFilterBridge SHARED = new BreadcrumbFilterBridge(new DaemonScheduler(), System::nanoTime, Bugsee::setBreadcrumbFilter);
|
|
79
113
|
|
|
80
114
|
@NonNull
|
|
81
115
|
static BreadcrumbFilterBridge shared() {
|
|
@@ -86,6 +120,16 @@ final class BreadcrumbFilterBridge {
|
|
|
86
120
|
private final ConcurrentHashMap<String, Pending> pending = new ConcurrentHashMap<>();
|
|
87
121
|
private final AtomicLong ids = new AtomicLong();
|
|
88
122
|
private final AtomicBoolean installed = new AtomicBoolean();
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The module whose JS has installed its filter with
|
|
126
|
+
* {@code setEnabled(true)}, or null. Compared to the attached sink by
|
|
127
|
+
* identity, so a stale module cannot arm the new one. A reload attaches a new module whose JS has
|
|
128
|
+
* not subscribed yet, while this bridge (and the SDK's filter) outlive
|
|
129
|
+
* the old runtime. Until JS arms it again, a request would be emitted to
|
|
130
|
+
* nobody, so it is dropped at once instead: fail closed, no wait.
|
|
131
|
+
*/
|
|
132
|
+
private final AtomicReference<Sink> armedFor = new AtomicReference<>();
|
|
89
133
|
private final Object sdkLock = new Object();
|
|
90
134
|
/**
|
|
91
135
|
* The id of the manual {@code addBreadcrumb} on this thread. Set only
|
|
@@ -94,8 +138,74 @@ final class BreadcrumbFilterBridge {
|
|
|
94
138
|
*/
|
|
95
139
|
private final ThreadLocal<String> manualAddId = new ThreadLocal<>();
|
|
96
140
|
|
|
97
|
-
|
|
98
|
-
|
|
141
|
+
private final Scheduler scheduler;
|
|
142
|
+
private final LongSupplier nanoClock;
|
|
143
|
+
|
|
144
|
+
/** Tests pass a scheduler they fire themselves. Production uses {@link #shared()}. */
|
|
145
|
+
BreadcrumbFilterBridge(@NonNull final Scheduler scheduler) {
|
|
146
|
+
this(scheduler, System::nanoTime);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Tests also pass a clock, to pass the deadline without the timer having run. */
|
|
150
|
+
BreadcrumbFilterBridge(@NonNull final Scheduler scheduler, @NonNull final LongSupplier nanoClock) {
|
|
151
|
+
this(scheduler, nanoClock, installed -> { });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** As above, and the call that installs (or, with null, removes) the SDK's filter. */
|
|
155
|
+
BreadcrumbFilterBridge(
|
|
156
|
+
@NonNull final Scheduler scheduler,
|
|
157
|
+
@NonNull final LongSupplier nanoClock,
|
|
158
|
+
@NonNull final Consumer<EventFilter<Breadcrumb>> installer
|
|
159
|
+
) {
|
|
160
|
+
this.scheduler = scheduler;
|
|
161
|
+
this.nanoClock = nanoClock;
|
|
162
|
+
this.installer = installer;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private final Consumer<EventFilter<Breadcrumb>> installer;
|
|
166
|
+
|
|
167
|
+
/** True from {@link #holdUntilJs} until JS first calls {@link #setEnabled}. For the watchdog only. */
|
|
168
|
+
private final AtomicBoolean held = new AtomicBoolean();
|
|
169
|
+
|
|
170
|
+
/** Whether the startup hold is still waiting for JS to call {@code setBreadcrumbFilter}. */
|
|
171
|
+
boolean isHeld() {
|
|
172
|
+
return held.get();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Installs the filter with the SDK. A throw (the SDK not ready that early)
|
|
177
|
+
* leaves {@code installed} false, so a later {@code setEnabled(true)}
|
|
178
|
+
* installs it instead of believing it already is, and is rethrown for the
|
|
179
|
+
* caller to log.
|
|
180
|
+
*/
|
|
181
|
+
private void install() {
|
|
182
|
+
if (installed.compareAndSet(false, true)) {
|
|
183
|
+
boolean ok = false;
|
|
184
|
+
try {
|
|
185
|
+
installer.accept(filter);
|
|
186
|
+
ok = true;
|
|
187
|
+
} finally {
|
|
188
|
+
if (!ok) {
|
|
189
|
+
installed.set(false);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Installs the filter before JS has asked for it, so a manifest
|
|
197
|
+
* auto-launch does not record breadcrumbs unfiltered until
|
|
198
|
+
* {@code setBreadcrumbFilter} runs (see {@link StartupHold}). With no module
|
|
199
|
+
* attached yet the filter drops everything, and so does one whose JS has
|
|
200
|
+
* not armed it (the armed gate), so nothing waits on a reply that cannot
|
|
201
|
+
* come. {@code setEnabled(false)}, which {@code setBreadcrumbFilter(null)} sends, removes
|
|
202
|
+
* it again. A second call, or one after {@code setEnabled(true)}, is a no-op.
|
|
203
|
+
*/
|
|
204
|
+
void holdUntilJs() {
|
|
205
|
+
withSdkLock(() -> {
|
|
206
|
+
install();
|
|
207
|
+
held.set(true);
|
|
208
|
+
});
|
|
99
209
|
}
|
|
100
210
|
|
|
101
211
|
private final EventFilter<Breadcrumb> filter = new EventFilter<Breadcrumb>() {
|
|
@@ -114,7 +224,31 @@ final class BreadcrumbFilterBridge {
|
|
|
114
224
|
};
|
|
115
225
|
|
|
116
226
|
void attach(@NonNull final Sink next) {
|
|
117
|
-
sink
|
|
227
|
+
// Disarm before the sink is visible: a request in the gap must not
|
|
228
|
+
// reach a runtime that has not subscribed yet. See armedFor.
|
|
229
|
+
withSdkLock(() -> {
|
|
230
|
+
armedFor.set(null);
|
|
231
|
+
sink.set(next);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The module {@code caller}'s JS now answers requests. Ignored unless
|
|
237
|
+
* {@code caller} is still the attached module: a stale module's late
|
|
238
|
+
* enable must not arm the new runtime, which has not subscribed.
|
|
239
|
+
*/
|
|
240
|
+
void arm(@NonNull final Sink caller) {
|
|
241
|
+
if (sink.get() == caller) {
|
|
242
|
+
armedFor.set(caller);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Arms for whichever module is attached. For tests, which have no module identity of their own. */
|
|
247
|
+
void arm() {
|
|
248
|
+
final Sink current = sink.get();
|
|
249
|
+
if (current != null) {
|
|
250
|
+
armedFor.set(current);
|
|
251
|
+
}
|
|
118
252
|
}
|
|
119
253
|
|
|
120
254
|
/**
|
|
@@ -124,7 +258,10 @@ final class BreadcrumbFilterBridge {
|
|
|
124
258
|
* callback is run with {@code null}, which discards the crumb.
|
|
125
259
|
*/
|
|
126
260
|
void detach(@NonNull final Sink current) {
|
|
127
|
-
|
|
261
|
+
withSdkLock(() -> {
|
|
262
|
+
sink.compareAndSet(current, null);
|
|
263
|
+
armedFor.compareAndSet(current, null);
|
|
264
|
+
});
|
|
128
265
|
final List<Pending> owned = new ArrayList<>();
|
|
129
266
|
for (final Pending item : pending.values()) {
|
|
130
267
|
if (item.owner == current && pending.remove(item.id, item)) {
|
|
@@ -132,6 +269,7 @@ final class BreadcrumbFilterBridge {
|
|
|
132
269
|
}
|
|
133
270
|
}
|
|
134
271
|
for (final Pending item : owned) {
|
|
272
|
+
cancel(item.deadline);
|
|
135
273
|
drop(item.callback);
|
|
136
274
|
}
|
|
137
275
|
}
|
|
@@ -152,15 +290,26 @@ final class BreadcrumbFilterBridge {
|
|
|
152
290
|
|
|
153
291
|
/** Installs the filter, or removes it. A second {@code true} is a no-op. */
|
|
154
292
|
void setEnabled(final boolean enabled) {
|
|
293
|
+
setEnabled(enabled, sink.get());
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** As above, on behalf of module {@code caller}; only the attached module can arm. */
|
|
297
|
+
void setEnabled(final boolean enabled, final Sink caller) {
|
|
155
298
|
withSdkLock(() -> {
|
|
299
|
+
if (sink.get() != caller) {
|
|
300
|
+
// A superseded module must neither arm nor disable the process-wide filter.
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
held.set(false);
|
|
156
304
|
if (enabled) {
|
|
157
|
-
if (
|
|
158
|
-
|
|
305
|
+
if (caller != null) {
|
|
306
|
+
arm(caller);
|
|
159
307
|
}
|
|
308
|
+
install();
|
|
160
309
|
return;
|
|
161
310
|
}
|
|
162
311
|
if (installed.compareAndSet(true, false)) {
|
|
163
|
-
|
|
312
|
+
installer.accept(null);
|
|
164
313
|
}
|
|
165
314
|
});
|
|
166
315
|
}
|
|
@@ -177,6 +326,13 @@ final class BreadcrumbFilterBridge {
|
|
|
177
326
|
if (item == null) {
|
|
178
327
|
return;
|
|
179
328
|
}
|
|
329
|
+
cancel(item.deadline);
|
|
330
|
+
// The timer can run late: past the deadline the answer is refused even
|
|
331
|
+
// if it got here first.
|
|
332
|
+
if (nanoClock.getAsLong() - item.expiresAtNanos >= 0) {
|
|
333
|
+
drop(item.callback);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
180
336
|
try {
|
|
181
337
|
if (crumbJson == null || !apply(item.crumb, crumbJson)) {
|
|
182
338
|
drop(item.callback);
|
|
@@ -214,7 +370,7 @@ final class BreadcrumbFilterBridge {
|
|
|
214
370
|
@NonNull final Callback1<Breadcrumb> callback
|
|
215
371
|
) {
|
|
216
372
|
final Sink current = sink.get();
|
|
217
|
-
if (current == null) {
|
|
373
|
+
if (current == null || armedFor.get() != current) {
|
|
218
374
|
drop(callback);
|
|
219
375
|
return;
|
|
220
376
|
}
|
|
@@ -226,21 +382,48 @@ final class BreadcrumbFilterBridge {
|
|
|
226
382
|
return;
|
|
227
383
|
}
|
|
228
384
|
final String id = Long.toString(ids.incrementAndGet());
|
|
229
|
-
final Pending item = new Pending(
|
|
385
|
+
final Pending item = new Pending(
|
|
386
|
+
id, event, callback, current,
|
|
387
|
+
nanoClock.getAsLong() + TimeUnit.MILLISECONDS.toNanos(DEADLINE_MS));
|
|
230
388
|
pending.put(id, item);
|
|
231
389
|
final String addId = manualAddId.get();
|
|
232
390
|
try {
|
|
391
|
+
item.deadline = scheduler.schedule(() -> expire(id), DEADLINE_MS);
|
|
233
392
|
current.onBreadcrumbFilterRequest(id, json, addId);
|
|
234
393
|
if (addId != null) {
|
|
235
394
|
manualAddId.remove();
|
|
236
395
|
}
|
|
237
396
|
} catch (final Throwable e) {
|
|
238
397
|
if (pending.remove(id, item)) {
|
|
398
|
+
cancel(item.deadline);
|
|
239
399
|
drop(callback);
|
|
240
400
|
}
|
|
241
401
|
}
|
|
242
402
|
}
|
|
243
403
|
|
|
404
|
+
/**
|
|
405
|
+
* JS did not answer in time. Forget the request and drop the crumb. The
|
|
406
|
+
* SDK never recycles this entry, so a late reply has nothing to write
|
|
407
|
+
* onto: it finds no pending request and returns.
|
|
408
|
+
*/
|
|
409
|
+
private void expire(@NonNull final String id) {
|
|
410
|
+
final Pending item = pending.remove(id);
|
|
411
|
+
if (item != null) {
|
|
412
|
+
drop(item.callback);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private static void cancel(@Nullable final Cancellable deadline) {
|
|
417
|
+
if (deadline == null) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
deadline.cancel();
|
|
422
|
+
} catch (final Throwable ignored) {
|
|
423
|
+
// A timer that cannot be cancelled only finds nothing pending.
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
244
427
|
/**
|
|
245
428
|
* The crumb as JSON, with only the keys the SDK actually set.
|
|
246
429
|
* {@code level} is the JS name ({@code debug}, {@code info},
|
|
@@ -440,4 +623,25 @@ final class BreadcrumbFilterBridge {
|
|
|
440
623
|
// The SDK already treats a throw from the callback as a drop.
|
|
441
624
|
}
|
|
442
625
|
}
|
|
626
|
+
|
|
627
|
+
/** One daemon thread, started on first use, for every request's deadline. */
|
|
628
|
+
private static final class DaemonScheduler implements Scheduler {
|
|
629
|
+
private final ScheduledThreadPoolExecutor executor;
|
|
630
|
+
|
|
631
|
+
DaemonScheduler() {
|
|
632
|
+
executor = new ScheduledThreadPoolExecutor(1, runnable -> {
|
|
633
|
+
final Thread thread = new Thread(runnable, "BugseeRN-BreadcrumbFilterDeadline");
|
|
634
|
+
thread.setDaemon(true);
|
|
635
|
+
return thread;
|
|
636
|
+
});
|
|
637
|
+
executor.setRemoveOnCancelPolicy(true);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
@Override
|
|
641
|
+
@NonNull
|
|
642
|
+
public Cancellable schedule(@NonNull final Runnable task, final long delayMs) {
|
|
643
|
+
final ScheduledFuture<?> future = executor.schedule(task, delayMs, TimeUnit.MILLISECONDS);
|
|
644
|
+
return () -> future.cancel(false);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
443
647
|
}
|
|
@@ -33,6 +33,7 @@ import com.facebook.react.bridge.WritableArray;
|
|
|
33
33
|
import com.facebook.react.bridge.UiThreadUtil;
|
|
34
34
|
import com.facebook.react.bridge.WritableMap;
|
|
35
35
|
import com.facebook.react.module.annotations.ReactModule;
|
|
36
|
+
import com.facebook.react.modules.network.OkHttpClientProvider;
|
|
36
37
|
|
|
37
38
|
import java.io.Serializable;
|
|
38
39
|
import java.util.ArrayList;
|
|
@@ -144,10 +145,7 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
144
145
|
ReportHandlerBridge.shared().attach(this);
|
|
145
146
|
DataRequestBridge.shared().attach(dataRequestSink, originTracker::currentOrigin);
|
|
146
147
|
NetworkFilterBridge.shared().attach(this);
|
|
147
|
-
LogFilterBridge.shared().
|
|
148
|
-
// The echo drop is installed even when the app never calls setLogFilter.
|
|
149
|
-
// setEnabled(false) is that pass-through; it does not remove the filter.
|
|
150
|
-
LogFilterBridge.shared().setEnabled(false);
|
|
148
|
+
LogFilterBridge.shared().attachModule(this);
|
|
151
149
|
BreadcrumbFilterBridge.shared().attach(this);
|
|
152
150
|
}
|
|
153
151
|
|
|
@@ -182,9 +180,10 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
182
180
|
// unanswered one is not recorded; a reply into this module after it
|
|
183
181
|
// is gone has nowhere to land.
|
|
184
182
|
BreadcrumbFilterBridge.shared().detach(this);
|
|
185
|
-
// The next runtime cannot know these handles
|
|
186
|
-
//
|
|
187
|
-
|
|
183
|
+
// The next runtime cannot know these handles, so nothing would ever
|
|
184
|
+
// finish them and the SDK would keep the transactions open. Cancel
|
|
185
|
+
// what is still open, then drop the handles.
|
|
186
|
+
spanHandles.cancelOpenAndReleaseAll();
|
|
188
187
|
SecureRectanglePulls.shared().clearRefresher(pullRefresher);
|
|
189
188
|
originTracker.dispose();
|
|
190
189
|
// This runtime's Modal surfaces cannot be cleared by its JS any more.
|
|
@@ -223,15 +222,17 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
223
222
|
promise.reject("E_TOKEN", "Bugsee.launch requires a non-empty app token");
|
|
224
223
|
return;
|
|
225
224
|
}
|
|
225
|
+
NetworkCaptureProbe.warnOnceIfNotInstrumented(OkHttpClientProvider::createClient);
|
|
226
226
|
// The Application, not the React context: the SDK registers activity
|
|
227
227
|
// lifecycle callbacks on it and outlives any single React instance.
|
|
228
228
|
Bugsee.launch(
|
|
229
229
|
getReactApplicationContext().getApplicationContext(),
|
|
230
230
|
token,
|
|
231
231
|
withConfiguredEndpoint(toOptions(options)),
|
|
232
|
-
// The SDK reports whether it
|
|
233
|
-
// is
|
|
234
|
-
//
|
|
232
|
+
// The SDK reports whether it started. Declining (the token was
|
|
233
|
+
// rejected) is a normal outcome, so it resolves false rather
|
|
234
|
+
// than rejecting. When the SDK is already running it reports
|
|
235
|
+
// success and ignores the new options, so this resolves true.
|
|
235
236
|
launched -> {
|
|
236
237
|
// launch can replace the log filter. Put the pass-through
|
|
237
238
|
// (or the user filter, if one is already on) back.
|
|
@@ -655,7 +656,7 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
655
656
|
*/
|
|
656
657
|
@Override
|
|
657
658
|
public boolean setNetworkFilterEnabled(final boolean enabled) {
|
|
658
|
-
NetworkFilterBridge.shared().setEnabled(enabled);
|
|
659
|
+
NetworkFilterBridge.shared().setEnabled(enabled, this);
|
|
659
660
|
return true;
|
|
660
661
|
}
|
|
661
662
|
|
|
@@ -855,7 +856,7 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
855
856
|
*/
|
|
856
857
|
@Override
|
|
857
858
|
public boolean setLogFilterEnabled(final boolean enabled) {
|
|
858
|
-
LogFilterBridge.shared().setEnabled(enabled);
|
|
859
|
+
LogFilterBridge.shared().setEnabled(enabled, this);
|
|
859
860
|
return true;
|
|
860
861
|
}
|
|
861
862
|
|
|
@@ -892,7 +893,7 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
892
893
|
*/
|
|
893
894
|
@Override
|
|
894
895
|
public boolean setBreadcrumbFilterEnabled(final boolean enabled) {
|
|
895
|
-
BreadcrumbFilterBridge.shared().setEnabled(enabled);
|
|
896
|
+
BreadcrumbFilterBridge.shared().setEnabled(enabled, this);
|
|
896
897
|
return true;
|
|
897
898
|
}
|
|
898
899
|
|
|
@@ -1482,8 +1483,14 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
1482
1483
|
result.putString(entry.getKey(), (String) value);
|
|
1483
1484
|
} else if (value instanceof Enum) {
|
|
1484
1485
|
// Enums go back as the number they arrived as -- their
|
|
1485
|
-
// internal value, which is what both platforms speak
|
|
1486
|
-
|
|
1486
|
+
// internal value, which is what both platforms speak -- or, for
|
|
1487
|
+
// an enum with no number (MemoryLeakMode), as its constant name.
|
|
1488
|
+
final Object wire = BugseeOptionEnums.wireFor((Enum<?>) value);
|
|
1489
|
+
if (wire instanceof Double) {
|
|
1490
|
+
result.putDouble(entry.getKey(), (Double) wire);
|
|
1491
|
+
} else {
|
|
1492
|
+
result.putString(entry.getKey(), (String) wire);
|
|
1493
|
+
}
|
|
1487
1494
|
}
|
|
1488
1495
|
// Anything else has no JS representation; omitted rather than
|
|
1489
1496
|
// stringified, which would read as a value the app could set back.
|
|
@@ -1619,7 +1626,7 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
1619
1626
|
if (span == null) {
|
|
1620
1627
|
return noSpan();
|
|
1621
1628
|
}
|
|
1622
|
-
return snapshot(spanHandles.retain(span, new LiveSpan(span)), span);
|
|
1629
|
+
return snapshot(spanHandles.retain(span, new LiveSpan(span), false), span);
|
|
1623
1630
|
}
|
|
1624
1631
|
|
|
1625
1632
|
@Override
|
|
@@ -1691,17 +1698,24 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
1691
1698
|
}
|
|
1692
1699
|
|
|
1693
1700
|
@Override
|
|
1694
|
-
public
|
|
1701
|
+
public WritableMap spanFinish(final String handle, final double status, final boolean statusSet) {
|
|
1702
|
+
final WritableMap result = Arguments.createMap();
|
|
1695
1703
|
final WritableArray released = Arguments.createArray();
|
|
1696
1704
|
final SpanStatus parsed = statusSet ? SpanHandles.status((int) status) : null;
|
|
1697
1705
|
if (statusSet && parsed == null) {
|
|
1698
1706
|
Log.w(TAG, "span finish status is outside 0..5");
|
|
1699
|
-
|
|
1707
|
+
result.putArray("released", released);
|
|
1708
|
+
return result;
|
|
1700
1709
|
}
|
|
1701
|
-
for (final
|
|
1702
|
-
|
|
1710
|
+
for (final SpanHandles.Released item : spanHandles.finish(handle, parsed)) {
|
|
1711
|
+
final WritableMap entry = Arguments.createMap();
|
|
1712
|
+
entry.putString("handle", item.handle);
|
|
1713
|
+
entry.putInt("status", item.status);
|
|
1714
|
+
released.pushMap(entry);
|
|
1703
1715
|
}
|
|
1704
|
-
|
|
1716
|
+
// Last: putArray hands the array over, and a later push would be refused.
|
|
1717
|
+
result.putArray("released", released);
|
|
1718
|
+
return result;
|
|
1705
1719
|
}
|
|
1706
1720
|
|
|
1707
1721
|
@Nullable
|
|
@@ -1807,10 +1821,12 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
1807
1821
|
@Override
|
|
1808
1822
|
public void deleteCollectedDataOnDevice(
|
|
1809
1823
|
final boolean includingIntermediate,
|
|
1824
|
+
final boolean includingFinishedReports,
|
|
1810
1825
|
final Promise promise
|
|
1811
1826
|
) {
|
|
1812
1827
|
Bugsee.deleteCollectedDataOnDevice(
|
|
1813
1828
|
includingIntermediate,
|
|
1829
|
+
includingFinishedReports,
|
|
1814
1830
|
success -> promise.resolve(Boolean.TRUE.equals(success))
|
|
1815
1831
|
);
|
|
1816
1832
|
}
|
|
@@ -1865,5 +1881,12 @@ public class BugseeModule extends NativeBugseeSpec
|
|
|
1865
1881
|
public boolean isFinished() {
|
|
1866
1882
|
return span.isFinished();
|
|
1867
1883
|
}
|
|
1884
|
+
|
|
1885
|
+
@Override
|
|
1886
|
+
public int statusOrdinal() {
|
|
1887
|
+
final SpanStatus status = span.getStatus();
|
|
1888
|
+
// The SDK holding nothing is not OK: report Unknown, like a no-op span.
|
|
1889
|
+
return (status == null ? SpanStatus.UNKNOWN : status).ordinal();
|
|
1890
|
+
}
|
|
1868
1891
|
}
|
|
1869
1892
|
}
|
|
@@ -125,6 +125,21 @@ final class BugseeOptionEnums {
|
|
|
125
125
|
return -1;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* What an enum constant travels back to JS as: its internal value for the
|
|
130
|
+
* five numeric option enums, and its constant NAME for any other.
|
|
131
|
+
*
|
|
132
|
+
* <p>The other enums (the leak module's {@code MemoryLeakMode}) have no
|
|
133
|
+
* number, and {@link #wireValue} answers -1 for them, which JS would read as
|
|
134
|
+
* a real setting. Their constant name is also what JS sends to set them, so
|
|
135
|
+
* the value round-trips.
|
|
136
|
+
*/
|
|
137
|
+
@NonNull
|
|
138
|
+
static Object wireFor(@NonNull final Enum<?> constant) {
|
|
139
|
+
final double value = wireValue(constant);
|
|
140
|
+
return value >= 0 ? (Object) value : constant.name();
|
|
141
|
+
}
|
|
142
|
+
|
|
128
143
|
/** DirectBuffers, at 21, is the largest value any option enum carries. */
|
|
129
144
|
private static final int MAX_ENUM_VALUE = 64;
|
|
130
145
|
|