@bugsee/react-native 0.0.0-stage → 7.0.0-beta2

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.
Files changed (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +557 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +962 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,1869 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import android.content.Context;
7
+ import android.content.pm.ApplicationInfo;
8
+ import android.content.pm.PackageManager;
9
+ import android.graphics.Point;
10
+ import android.hardware.display.DisplayManager;
11
+ import android.util.Base64;
12
+ import android.util.Log;
13
+ import android.view.Display;
14
+
15
+ import com.bugsee.library.Bugsee;
16
+ import com.bugsee.library.contracts.exchange.Breadcrumb;
17
+ import com.bugsee.library.contracts.exchange.BugseeExchangeFactory;
18
+ import com.bugsee.library.contracts.options.IssueSeverity;
19
+ import com.bugsee.library.contracts.options.Options;
20
+ import com.bugsee.library.contracts.options.OptionsContainer;
21
+ import com.bugsee.library.contracts.performance.Span;
22
+ import com.bugsee.library.contracts.performance.SpanStatus;
23
+ import com.bugsee.library.contracts.performance.Transaction;
24
+ import com.bugsee.library.contracts.reporting.Report;
25
+ import com.facebook.react.bridge.Arguments;
26
+ import com.facebook.react.bridge.Promise;
27
+ import com.facebook.react.bridge.ReactApplicationContext;
28
+ import com.facebook.react.bridge.ReadableArray;
29
+ import com.facebook.react.bridge.ReadableMap;
30
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
31
+ import com.facebook.react.bridge.ReadableType;
32
+ import com.facebook.react.bridge.WritableArray;
33
+ import com.facebook.react.bridge.UiThreadUtil;
34
+ import com.facebook.react.bridge.WritableMap;
35
+ import com.facebook.react.module.annotations.ReactModule;
36
+
37
+ import java.io.Serializable;
38
+ import java.util.ArrayList;
39
+ import java.util.Arrays;
40
+ import java.util.HashMap;
41
+ import java.util.LinkedHashMap;
42
+ import java.util.List;
43
+ import java.util.Map;
44
+ import java.util.concurrent.CountDownLatch;
45
+ import java.util.concurrent.Executors;
46
+ import java.util.concurrent.TimeUnit;
47
+ import java.util.concurrent.atomic.AtomicBoolean;
48
+ import java.util.concurrent.atomic.AtomicReference;
49
+
50
+ import org.json.JSONException;
51
+ import org.json.JSONObject;
52
+ import org.json.JSONTokener;
53
+
54
+ /**
55
+ * The Android half of the `Bugsee` TurboModule.
56
+ *
57
+ * <p>Thin on purpose. Everything that translates between the JS wire shape and
58
+ * the SDK's types lives in {@link BugseeTokens}, {@link BugseeStatusMapper},
59
+ * {@link ReportOps}, {@link ReportHandlerBridge} and {@link CreatedReports}, which are plain Java and
60
+ * unit-tested without React Native or a device; what is left here is the part
61
+ * that can only be exercised by running the app, and is covered by the example
62
+ * app's e2e instead.
63
+ */
64
+ @ReactModule(name = BugseeModule.NAME)
65
+ public class BugseeModule extends NativeBugseeSpec
66
+ implements WrapperEventBus.Sink, ReportHandlerBridge.Sink, NetworkFilterBridge.Sink,
67
+ LogFilterBridge.Sink, BreadcrumbFilterBridge.Sink {
68
+
69
+ public static final String NAME = "Bugsee";
70
+
71
+ /** The wrapper's log tag, as ReportHandlerBridge and WrapperEventBus use. */
72
+ private static final String TAG = "BugseeRN";
73
+
74
+ /** Whether a throwing log filter has been reported for {@link #log} yet. */
75
+ private static final AtomicBoolean LOG_FAULT_REPORTED = new AtomicBoolean();
76
+
77
+ /** Production adapter: the SDK's handled / unhandled entry points. */
78
+ private static final ExceptionBridge.Sdk PROD_EXCEPTION_SDK = new ExceptionBridge.Sdk() {
79
+ @Override
80
+ public void logException(final Throwable t, @Nullable final String domain) {
81
+ Bugsee.logException(t, domain, 0);
82
+ }
83
+
84
+ @Override
85
+ public void logUnhandledException(
86
+ final Throwable t,
87
+ @Nullable final Map<String, Object> options
88
+ ) {
89
+ Bugsee.logUnhandledException(t, options);
90
+ }
91
+ };
92
+
93
+ // The stable codes of src/report/errors.ts. An app matches on these.
94
+ private static final String E_REPORT_HANDLE_DEAD = "E_REPORT_HANDLE_DEAD";
95
+ private static final String E_REPORT_ATTACHMENT_REJECTED = "E_REPORT_ATTACHMENT_REJECTED";
96
+ private static final String E_REPORT_BAD_ARGUMENT = "E_REPORT_BAD_ARGUMENT";
97
+ private static final String E_REPORT_CREATE_BUSY = "E_REPORT_CREATE_BUSY";
98
+ // The stable code of src/attributes/errors.ts's AttributeErrorCode.Rejected.
99
+ private static final String E_ATTRIBUTE_REJECTED = "E_ATTRIBUTE_REJECTED";
100
+
101
+ /** Moves secure rectangles from React Native's viewport space to display pixels. */
102
+ private final ReactRootOriginTracker originTracker;
103
+
104
+ /**
105
+ * What the SDK's secure-rectangle pull calls to refresh the origin. One
106
+ * instance, held, so invalidate() can remove exactly this one.
107
+ */
108
+ private final Runnable pullRefresher;
109
+
110
+ /**
111
+ * The one {@link DataRequestBridge.Sink} this module hands to the bridge,
112
+ * held so {@code invalidate()} can detach exactly this instance -- a
113
+ * fresh {@code this::emitRequest} reference at that call site would not
114
+ * be the same object the bridge was attached with.
115
+ */
116
+ private final DataRequestBridge.Sink dataRequestSink = this::emitRequest;
117
+
118
+ /** This module's claim on the secure store (SecureRectangleStore#claimRuntime). */
119
+ private final int secureRuntime;
120
+
121
+ /** Spans this module is holding. {@link #invalidate()} drops them. */
122
+ private final SpanHandles spanHandles = new SpanHandles();
123
+
124
+ public BugseeModule(final ReactApplicationContext context) {
125
+ super(context);
126
+ // A new JS runtime: Modal surfaces the previous one left behind (a
127
+ // reload with a secure Modal open) are dropped before this one's JS
128
+ // can publish.
129
+ final int leftBehind = SecureRectangleStore.shared().nonMainSurfacesWithRectangles();
130
+ secureRuntime = SecureRectangleStore.shared().claimRuntime();
131
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
132
+ Log.d(TAG, "secure runtime claimed: dropped " + leftBehind
133
+ + " Modal surface(s) the previous runtime left");
134
+ }
135
+ originTracker = new ReactRootOriginTracker(context, SecureRectangleStore.shared(), secureRuntime);
136
+ // refreshSoon only posts to the UI thread, which is all the SDK's pull
137
+ // thread may do.
138
+ pullRefresher = originTracker::refreshSoon;
139
+ SecureRectanglePulls.shared().setRefresher(pullRefresher);
140
+ // Attached here, not on first subscribe: the SDK may emit before any JS
141
+ // has run, and a listener that only exists once JS asks for it would
142
+ // miss the launch transitions that a caller most wants.
143
+ WrapperEventBus.shared().attach(this);
144
+ ReportHandlerBridge.shared().attach(this);
145
+ DataRequestBridge.shared().attach(dataRequestSink, originTracker::currentOrigin);
146
+ NetworkFilterBridge.shared().attach(this);
147
+ LogFilterBridge.shared().attach(this);
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);
151
+ BreadcrumbFilterBridge.shared().attach(this);
152
+ }
153
+
154
+ /**
155
+ * Detaches from the event bus and the report handler bridge when the
156
+ * bridge goes away.
157
+ *
158
+ * <p>Identity-checked inside both: a reload can construct and attach the
159
+ * NEW module before this one is invalidated, and an unconditional clear
160
+ * would then silence the live bridge. Emitting into a dead module is the
161
+ * classic React Native leak, so this is not optional.
162
+ */
163
+ @Override
164
+ public void invalidate() {
165
+ WrapperEventBus.shared().detach(this);
166
+ // Also completes every report handle this module's JS was given: the
167
+ // next runtime cannot know them, so the reports must not wait out
168
+ // their deadlines.
169
+ ReportHandlerBridge.shared().detach(this);
170
+ // The next runtime cannot know a created-report handle. Drop it and
171
+ // free the one slot before that runtime reserves its own.
172
+ CreatedReports.shared().clear();
173
+ // Same for any outstanding vh request, and disables the view tree:
174
+ // the next runtime's anchor has not mounted yet.
175
+ DataRequestBridge.shared().detach(dataRequestSink);
176
+ NetworkFilterBridge.shared().detach(this);
177
+ // Drops every log-filter request this module was given. An unanswered
178
+ // one would otherwise sit until the SDK's timeout, and a reply into
179
+ // this module after it is gone has nowhere to land.
180
+ LogFilterBridge.shared().detach(this);
181
+ // Drops every breadcrumb-filter request this module was given. An
182
+ // unanswered one is not recorded; a reply into this module after it
183
+ // is gone has nowhere to land.
184
+ BreadcrumbFilterBridge.shared().detach(this);
185
+ // The next runtime cannot know these handles. Drop them without
186
+ // finishing: a reload must not close a transaction the SDK still has.
187
+ spanHandles.releaseAll();
188
+ SecureRectanglePulls.shared().clearRefresher(pullRefresher);
189
+ originTracker.dispose();
190
+ // This runtime's Modal surfaces cannot be cleared by its JS any more.
191
+ // A no-op when the next module has already claimed the store.
192
+ final int open = SecureRectangleStore.shared().nonMainSurfacesWithRectangles();
193
+ SecureRectangleStore.shared().releaseRuntime(secureRuntime);
194
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
195
+ Log.d(TAG, "secure runtime released: " + open + " Modal surface(s) held, "
196
+ + SecureRectangleStore.shared().nonMainSurfacesWithRectangles() + " left");
197
+ }
198
+ super.invalidate();
199
+ }
200
+
201
+ @Override
202
+ public void onLifecycleEvent(@NonNull final String name, @Nullable final String reportId) {
203
+ final WritableMap payload = Arguments.createMap();
204
+ payload.putString("name", name);
205
+ // Present only for the events that carry one, rather than null for the
206
+ // rest: the JS type marks it optional, and a null would force every
207
+ // caller to distinguish "absent" from "explicitly nothing".
208
+ if (reportId != null) {
209
+ payload.putString("reportId", reportId);
210
+ }
211
+ emitOnLifecycleEvent(payload);
212
+ }
213
+
214
+ @NonNull
215
+ @Override
216
+ public String getName() {
217
+ return NAME;
218
+ }
219
+
220
+ @Override
221
+ public void launch(final String token, final ReadableMap options, final Promise promise) {
222
+ if (!BugseeTokens.isUsable(token)) {
223
+ promise.reject("E_TOKEN", "Bugsee.launch requires a non-empty app token");
224
+ return;
225
+ }
226
+ // The Application, not the React context: the SDK registers activity
227
+ // lifecycle callbacks on it and outlives any single React instance.
228
+ Bugsee.launch(
229
+ getReactApplicationContext().getApplicationContext(),
230
+ token,
231
+ withConfiguredEndpoint(toOptions(options)),
232
+ // The SDK reports whether it actually started. Declining — it
233
+ // is already running, or the token was rejected — is a normal
234
+ // outcome, so it resolves false rather than rejecting.
235
+ launched -> {
236
+ // launch can replace the log filter. Put the pass-through
237
+ // (or the user filter, if one is already on) back.
238
+ LogFilterBridge.shared().ensureInstalled();
239
+ promise.resolve(Boolean.TRUE.equals(launched));
240
+ });
241
+ }
242
+
243
+ @Override
244
+ public void relaunch(final ReadableMap options, final Promise promise) {
245
+ Bugsee.relaunch(withConfiguredEndpoint(toOptions(options)), relaunched -> {
246
+ LogFilterBridge.shared().ensureInstalled();
247
+ promise.resolve(Boolean.TRUE.equals(relaunched));
248
+ });
249
+ }
250
+
251
+ @Override
252
+ public void stop(final Promise promise) {
253
+ Bugsee.stop(() -> promise.resolve(true));
254
+ }
255
+
256
+ @Override
257
+ public void getStatus(final Promise promise) {
258
+ promise.resolve(BugseeStatusMapper.toWire(Bugsee.getStatus()));
259
+ }
260
+
261
+ @Override
262
+ public void setWrapperInfo(final ReadableMap identity) {
263
+ if (identity == null) {
264
+ WrapperRegistrar.register(null);
265
+ return;
266
+ }
267
+ final ReadableMap context = identity.hasKey("context")
268
+ ? identity.getMap("context")
269
+ : null;
270
+ // A new instance, so the SDK hands it a fresh channel and retires the
271
+ // provider's. Through the registrar: the provider registered on
272
+ // another thread, and the spec forbids registrations overlapping.
273
+ WrapperRegistrar.register(new BugseeReactNativeWrapper(
274
+ string(identity, "type", "unknown"),
275
+ string(identity, "version", "unknown"),
276
+ identity.hasKey("build") ? identity.getString("build") : null,
277
+ toStringMap(context)));
278
+ }
279
+
280
+ @Override
281
+ public void setSecureRectangles(final double display, final ReadableArray coordinates) {
282
+ publishSecure(display, SecureRectangleStore.MAIN_SURFACE, coordinates);
283
+ }
284
+
285
+ @Override
286
+ public void setSecureRectanglesOnSurface(
287
+ final double display, final double surface, final ReadableArray coordinates) {
288
+ publishSecure(display, (int) Math.round(surface), coordinates);
289
+ }
290
+
291
+ private void publishSecure(final double display, final int surface, final ReadableArray coordinates) {
292
+ // A void TurboModule method: anything thrown here has no promise to
293
+ // reject and crashes the host app, over a call JS already validated.
294
+ try {
295
+ // Codegen hands numbers across as double, because that is what a
296
+ // JS number is. Rounding rather than truncating: the JS side has
297
+ // already rounded each edge outwards, and truncating -0.9999 to 0
298
+ // would pull an edge back inside the region it was widened to
299
+ // cover.
300
+ final int[] flat = new int[coordinates == null ? 0 : coordinates.size()];
301
+ for (int i = 0; i < flat.length; i++) {
302
+ flat[i] = (int) Math.round(coordinates.getDouble(i));
303
+ }
304
+ // The display's real size first: until an origin is read the
305
+ // store serves the whole display, and it must know how big that
306
+ // is. Display reads are safe off the UI thread.
307
+ recordDisplayBounds((int) display);
308
+ // Stored as measured (relative to that surface's own origin);
309
+ // the store serves them moved by that surface's display origin,
310
+ // which the tracker keeps current. Re-read now too, in case the
311
+ // window moved without a layout pass.
312
+ // Ignored once a newer runtime has claimed the store: this
313
+ // module's late writes (a reload's teardown) must not touch
314
+ // the next runtime's lanes, whose keys may be the same tags.
315
+ if (!SecureRectangleStore.shared().publishForRuntime(secureRuntime, (int) display, surface, flat)) {
316
+ return;
317
+ }
318
+ originTracker.refreshSoon();
319
+ // A <Modal>'s first rectangles: find and watch its dialog root.
320
+ // Until then they fail closed in the store. An empty publish
321
+ // (the Modal clearing on unmount) watches nothing.
322
+ if (flat.length > 0) {
323
+ originTracker.watchSurface(surface);
324
+ }
325
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
326
+ Log.d(TAG, "secure published display=" + (int) display
327
+ + " surface=" + surface
328
+ + " raw=" + Arrays.toString(flat)
329
+ + " served=" + Arrays.toString(SecureRectangleStore.shared().snapshot((int) display)));
330
+ }
331
+ } catch (RuntimeException e) {
332
+ Log.e(TAG, "setSecureRectangles failed; the previous set stays published: "
333
+ + e.getClass().getName());
334
+ }
335
+ }
336
+
337
+ /** Records {@code display}'s real size in the store, once. */
338
+ private void recordDisplayBounds(final int display) {
339
+ final SecureRectangleStore store = SecureRectangleStore.shared();
340
+ if (store.hasDisplayBounds(display)) {
341
+ return;
342
+ }
343
+ final DisplayManager displays =
344
+ (DisplayManager) getReactApplicationContext().getSystemService(Context.DISPLAY_SERVICE);
345
+ final Display found = displays == null ? null : displays.getDisplay(display);
346
+ if (found == null) {
347
+ return;
348
+ }
349
+ final Point size = new Point();
350
+ found.getRealSize(size);
351
+ store.setDisplayBounds(display, size.x, size.y);
352
+ }
353
+
354
+ /**
355
+ * The display origin {@code [x, y]} of the {@code <Modal>} whose host has
356
+ * React tag {@code surface}, for the {@code vh} walk, which asks once per
357
+ * {@code <Modal>} per walk. Answered from the tracker's cache when the
358
+ * surface is watched; otherwise read on the UI thread, waiting at most
359
+ * {@link #SURFACE_ORIGIN_WAIT_MS}. Empty when unknown: the walk then
360
+ * keeps the request's origin for that subtree.
361
+ */
362
+ @Override
363
+ public WritableArray secureSurfaceOrigin(final double surface) {
364
+ final int key = (int) Math.round(surface);
365
+ int[] origin = originTracker.cachedSurfaceOrigin(key);
366
+ if (origin == null) {
367
+ origin = readSurfaceOriginOnUiThread(key);
368
+ }
369
+ final WritableArray out = Arguments.createArray();
370
+ if (origin != null) {
371
+ out.pushDouble(origin[0]);
372
+ out.pushDouble(origin[1]);
373
+ }
374
+ return out;
375
+ }
376
+
377
+ /** Well inside the walk's own 250 ms budget. */
378
+ private static final long SURFACE_ORIGIN_WAIT_MS = 100;
379
+
380
+ @Nullable
381
+ private int[] readSurfaceOriginOnUiThread(final int key) {
382
+ if (UiThreadUtil.isOnUiThread()) {
383
+ return originTracker.surfaceOriginNow(key);
384
+ }
385
+ final AtomicReference<int[]> result = new AtomicReference<>();
386
+ final CountDownLatch done = new CountDownLatch(1);
387
+ UiThreadUtil.runOnUiThread(() -> {
388
+ try {
389
+ result.set(originTracker.surfaceOriginNow(key));
390
+ } catch (Throwable t) {
391
+ Log.w(TAG, "secure surface origin failed (" + t.getClass().getSimpleName() + ")");
392
+ } finally {
393
+ done.countDown();
394
+ }
395
+ });
396
+ try {
397
+ done.await(SURFACE_ORIGIN_WAIT_MS, TimeUnit.MILLISECONDS);
398
+ } catch (InterruptedException e) {
399
+ Thread.currentThread().interrupt();
400
+ }
401
+ return result.get();
402
+ }
403
+
404
+ // --- Blackout and view-hierarchy capture (design doc §4.1) -----------
405
+ // Since 7.4.0 the SDK honours startBlackout/endBlackout before launch()
406
+ // and applies the state at launch (bugsee-android#248), as iOS does.
407
+
408
+ @Override
409
+ public void startBlackout() {
410
+ Bugsee.startBlackout();
411
+ }
412
+
413
+ @Override
414
+ public void endBlackout() {
415
+ Bugsee.endBlackout();
416
+ }
417
+
418
+ @Override
419
+ public void isBlackout(final Promise promise) {
420
+ promise.resolve(Bugsee.isBlackout());
421
+ }
422
+
423
+ @Override
424
+ public void captureViewHierarchy() {
425
+ Bugsee.captureViewHierarchy();
426
+ }
427
+
428
+ // --- View-hierarchy data request (design doc, Phase 6 / Task 6.5) ------
429
+ // DataRequestBridge owns the exactly-once, within-deadline contract with
430
+ // the SDK; this is only the translation to and from its Sink/emit shape,
431
+ // mirroring ReportHandlerBridge's onReportHandlerRequest below.
432
+
433
+ /**
434
+ * Builds the {@code onDataRequest} payload and emits it. {@code
435
+ * originX}/{@code originY} cross as doubles because codegen types the
436
+ * TS event's fields as {@code number} -- there is no separate integer
437
+ * wire type.
438
+ */
439
+ private void emitRequest(final String requestId, final String type, final int originX, final int originY) {
440
+ final WritableMap payload = Arguments.createMap();
441
+ payload.putString("requestId", requestId);
442
+ payload.putString("type", type);
443
+ payload.putDouble("originX", originX);
444
+ payload.putDouble("originY", originY);
445
+ emitOnDataRequest(payload);
446
+ }
447
+
448
+ @Override
449
+ public void setViewTreeEnabled(final boolean enabled) {
450
+ DataRequestBridge.shared().setViewTreeEnabled(dataRequestSink, enabled);
451
+ }
452
+
453
+ @Override
454
+ public void replyDataRequest(final String requestId, @Nullable final String payload) {
455
+ DataRequestBridge.shared().complete(requestId, payload);
456
+ }
457
+
458
+ private static String string(
459
+ @NonNull final ReadableMap map,
460
+ @NonNull final String key,
461
+ @NonNull final String fallback
462
+ ) {
463
+ final String value = map.hasKey(key) ? map.getString(key) : null;
464
+ return value == null ? fallback : value;
465
+ }
466
+
467
+ /**
468
+ * The SDK types context as string-to-string. A non-string value would be
469
+ * dropped rather than stringified: a number rendered as "1" is
470
+ * indistinguishable from a version the wrapper actually reported.
471
+ */
472
+ private static Map<String, String> toStringMap(@Nullable final ReadableMap map) {
473
+ final Map<String, String> result = new HashMap<>();
474
+ if (map == null) {
475
+ return result;
476
+ }
477
+ final ReadableMapKeySetIterator keys = map.keySetIterator();
478
+ while (keys.hasNextKey()) {
479
+ final String key = keys.nextKey();
480
+ if (map.getType(key) == ReadableType.String) {
481
+ result.put(key, map.getString(key));
482
+ }
483
+ }
484
+ return result;
485
+ }
486
+
487
+ @Override
488
+ public void getLaunchOptions(final Promise promise) {
489
+ // Android's container is valid before launch too, in which case it
490
+ // holds the SDK's own defaults -- so this answers a getter that the
491
+ // app has not overridden, without the wrapper hardcoding anything.
492
+ promise.resolve(toWritableMap(Bugsee.getLaunchOptions().toMap()));
493
+ }
494
+
495
+ @Override
496
+ public void testCrash() {
497
+ Bugsee.testCrash();
498
+ }
499
+
500
+ /**
501
+ * A handled JS exception. Posted onto {@link ExceptionExecutors#HANDLED}:
502
+ * the SDK must not run on the native-modules thread.
503
+ */
504
+ @Override
505
+ public void logException(final String payloadJson, final @Nullable String optionsJson) {
506
+ ExceptionExecutors.HANDLED.execute(() -> {
507
+ try {
508
+ ExceptionBridge.logHandled(PROD_EXCEPTION_SDK, payloadJson, optionsJson);
509
+ Log.i(TAG, "exception handled sent bytes="
510
+ + (payloadJson == null ? 0 : payloadJson.length()));
511
+ } catch (final RuntimeException e) {
512
+ Log.e(TAG, "logException failed: " + e.getClass().getName());
513
+ }
514
+ });
515
+ }
516
+
517
+ /**
518
+ * An unhandled JS exception. Posted onto {@link ExceptionExecutors#UNHANDLED},
519
+ * not behind handled reports: JS waits at most 1500 ms. The promise
520
+ * resolves {@code null} exactly once in a {@code finally} after that
521
+ * background call returns, including when the SDK throws.
522
+ */
523
+ @Override
524
+ public void logUnhandledException(final String payloadJson, final Promise promise) {
525
+ ExceptionExecutors.UNHANDLED.execute(() -> {
526
+ try {
527
+ ExceptionBridge.logUnhandled(PROD_EXCEPTION_SDK, payloadJson);
528
+ Log.i(TAG, "exception unhandled sent bytes="
529
+ + (payloadJson == null ? 0 : payloadJson.length()));
530
+ // No wrapper deadline on Android: the SDK call returned.
531
+ Log.i(TAG, "exception unhandled completed by=sdk");
532
+ } finally {
533
+ promise.resolve(null);
534
+ }
535
+ });
536
+ }
537
+
538
+ /**
539
+ * JS has already checked the strings, the severity range and the labels.
540
+ * {@code severity} 0 and a null label list are the SDK default. A throw
541
+ * from the SDK must not escape a void method.
542
+ */
543
+ @Override
544
+ public void upload(
545
+ final String summary,
546
+ final String description,
547
+ final double severity,
548
+ @Nullable final ReadableArray labels
549
+ ) {
550
+ try {
551
+ Bugsee.upload(
552
+ summary,
553
+ description,
554
+ ReportArgs.severity((int) severity),
555
+ ReportArgs.labels(labels == null ? null : labels.toArrayList()));
556
+ } catch (final RuntimeException e) {
557
+ Log.e(TAG, "upload failed: " + e.getClass().getName());
558
+ }
559
+ }
560
+
561
+ /**
562
+ * On the UI thread: the dialog presents from there. Same argument
563
+ * mapping as {@link #upload}. Does nothing before launch -- the SDK
564
+ * logs and returns. The dialog runs {@code onBeforeReportCreated}
565
+ * before it opens.
566
+ */
567
+ @Override
568
+ public void showReportDialog(
569
+ @Nullable final String summary,
570
+ @Nullable final String description,
571
+ final double severity,
572
+ @Nullable final ReadableArray labels
573
+ ) {
574
+ try {
575
+ final IssueSeverity sev = ReportArgs.severity((int) severity);
576
+ final ArrayList<String> labelList =
577
+ ReportArgs.labels(labels == null ? null : labels.toArrayList());
578
+ UiThreadUtil.runOnUiThread(() -> {
579
+ try {
580
+ Bugsee.showReportDialog(summary, description, sev, labelList);
581
+ } catch (final RuntimeException e) {
582
+ Log.e(TAG, "showReportDialog failed: " + e.getClass().getName());
583
+ }
584
+ });
585
+ } catch (final RuntimeException e) {
586
+ Log.e(TAG, "showReportDialog failed: " + e.getClass().getName());
587
+ }
588
+ }
589
+
590
+ /**
591
+ * The app's own {@code Bugsee.log()} line, through the SDK's public
592
+ * {@code Bugsee.log} -- not the wrapper channel, which records nothing
593
+ * with {@code capture.logs} off. {@code requiresFiltering} is the app's
594
+ * choice, passed through: the app's log filter runs on the line only when
595
+ * it is {@code true}. The level maps by the channel's table.
596
+ *
597
+ * <p>When it runs, the app's filter runs on this thread, and an exception
598
+ * it throws comes back here, as on the channel
599
+ * ({@link WrapperChannelHolder#log}).
600
+ * This thread is React Native's, so it stops here and is reported once
601
+ * per process: the report is itself a logcat line, which the SDK's
602
+ * logcat capture can feed back into the same filter.
603
+ */
604
+ @Override
605
+ public void log(final String message, final double level, final boolean requiresFiltering) {
606
+ try {
607
+ Bugsee.log(message, WrapperChannelHolder.levelFor((int) level), requiresFiltering);
608
+ } catch (final Throwable e) {
609
+ if (LOG_FAULT_REPORTED.compareAndSet(false, true)) {
610
+ Log.w(TAG, "the app's log filter threw on a Bugsee.log line "
611
+ + "(reported once per process): " + e.getClass().getName());
612
+ }
613
+ }
614
+ }
615
+
616
+ /**
617
+ * One JS line into the wrapper channel. JS has already range-checked the
618
+ * level; the holder defends again, maps it by value, and keeps a throwing
619
+ * app filter from escaping onto this thread. Filtered natively only --
620
+ * JS never runs the app's filter on these lines.
621
+ */
622
+ @Override
623
+ public void wrapperLog(final String message, final double level) {
624
+ WrapperChannelHolder.shared().log(message, (int) level);
625
+ }
626
+
627
+ /**
628
+ * Arms the logcat drop for one console echo. Does not record a line.
629
+ * {@code Bugsee.log} does not call this, so it does not arm a drop.
630
+ *
631
+ * <p>Returns {@code true}. The return keeps the call on the JS thread:
632
+ * codegen queues a {@code void} method onto the native modules thread,
633
+ * and the SDK's logcat reader could then filter the echo before this
634
+ * credit existed. The console hook calls this before it writes the line.
635
+ */
636
+ @Override
637
+ public boolean noteConsoleEcho(final String message) {
638
+ LogFilterBridge.shared().noteEcho(message);
639
+ return true;
640
+ }
641
+
642
+ @Override
643
+ public void onNetworkFilterRequest(@NonNull final String requestId, @NonNull final String eventJson) {
644
+ final WritableMap payload = Arguments.createMap();
645
+ payload.putString("requestId", requestId);
646
+ payload.putString("eventJson", eventJson);
647
+ emitOnNetworkFilterRequest(payload);
648
+ }
649
+
650
+ /**
651
+ * Returns true. The return is what keeps the call on the JS thread:
652
+ * codegen queues a {@code void} TurboModule method onto the native
653
+ * modules thread, so a request started on the next line could be
654
+ * recorded before a queued install landed, unfiltered.
655
+ */
656
+ @Override
657
+ public boolean setNetworkFilterEnabled(final boolean enabled) {
658
+ NetworkFilterBridge.shared().setEnabled(enabled);
659
+ return true;
660
+ }
661
+
662
+ @Override
663
+ public void replyNetworkFilter(final String requestId, @Nullable final String eventJson) {
664
+ if (requestId == null) {
665
+ return;
666
+ }
667
+ NetworkFilterBridge.shared().reply(requestId, eventJson);
668
+ }
669
+
670
+ /**
671
+ * A network event the app recorded itself. The bridge stamps it with
672
+ * {@code BugseeExchangeFactory.currentTimestamp()}, the SDK capture
673
+ * clock, then builds the event and submits it with filtering required.
674
+ * A missing factory or a null event is logged and dropped. That clock
675
+ * is not read when the factory is missing: {@code NetworkEvents.record}
676
+ * returns {@code NO_EVENT} before {@code clock.now()}. There is no
677
+ * timeout that would pass the original through.
678
+ */
679
+ @Override
680
+ public void addNetworkEvent(final String eventJson) {
681
+ final NetworkEvents.Outcome outcome;
682
+ try {
683
+ final com.bugsee.library.contracts.exchange.BugseeExchangeFactory factory =
684
+ Bugsee.getExchangeFactory();
685
+ // A null receiver makes factory::currentTimestamp throw while the
686
+ // reference is created. record() never reads the clock in that
687
+ // case, so the stand-in is not the factory clock.
688
+ final NetworkEvents.Clock clock = factory == null ? () -> 0L : factory::currentTimestamp;
689
+ outcome = NetworkEvents.record(
690
+ eventJson,
691
+ factory == null ? null : (timestamp, stage, eventId, mechanism, method) ->
692
+ factory.createNetworkEvent(timestamp, stage, eventId, mechanism, method),
693
+ (event, requiresFiltering) -> Bugsee.addNetworkEvent(event, requiresFiltering),
694
+ clock
695
+ );
696
+ } catch (final Throwable e) {
697
+ Log.w(TAG, "addNetworkEvent dropped: the SDK made no event");
698
+ return;
699
+ }
700
+ if (outcome == NetworkEvents.Outcome.NO_EVENT) {
701
+ Log.w(TAG, "addNetworkEvent dropped: the SDK made no event");
702
+ }
703
+ }
704
+
705
+ // --- Attributes and identity ---------------------------------------
706
+ // Everything that decides a value's shape lives in AttributeBridge, which
707
+ // is plain Java and unit-tested; this is only the translation to and from
708
+ // the bridge's Promise/WritableMap shapes, and the SDK adapter.
709
+
710
+ /** The one {@link AttributeBridge.Sdk} adapter; the class itself has no state. */
711
+ private static final AttributeBridge.Sdk ATTRIBUTE_SDK = new AttributeBridge.Sdk() {
712
+ @Override
713
+ public void set(final String name, final Serializable value) {
714
+ Bugsee.setAttribute(name, value);
715
+ }
716
+
717
+ @Override
718
+ public Object getInMemory(final String name) {
719
+ return Bugsee.getAttribute(name);
720
+ }
721
+
722
+ @Override
723
+ public Map<String, Serializable> getPersisted() {
724
+ return Bugsee.getAllAttributes();
725
+ }
726
+ };
727
+
728
+ @Override
729
+ public void setAttributeString(final String name, final String value, final Promise promise) {
730
+ setAttribute(name, value, promise);
731
+ }
732
+
733
+ @Override
734
+ public void setAttributeNumber(final String name, final double value, final Promise promise) {
735
+ setAttribute(name, AttributeBridge.numberValue(value), promise);
736
+ }
737
+
738
+ @Override
739
+ public void setAttributeBoolean(final String name, final boolean value, final Promise promise) {
740
+ setAttribute(name, value, promise);
741
+ }
742
+
743
+ /**
744
+ * {@code setAttribute*}'s shared body: verify, then resolve or reject.
745
+ * Neither SDK's own {@code setAttribute} reports a dropped value
746
+ * truthfully, so {@link AttributeBridge#setAndVerify}'s read-back is the
747
+ * only honest signal (design doc, Phase 5).
748
+ */
749
+ private static void setAttribute(final String name, final Serializable value, final Promise promise) {
750
+ try {
751
+ if (AttributeBridge.setAndVerify(ATTRIBUTE_SDK, name, value)) {
752
+ promise.resolve(null);
753
+ } else {
754
+ promise.reject(E_ATTRIBUTE_REJECTED,
755
+ "attribute \"" + name + "\" was not kept by the SDK");
756
+ }
757
+ } catch (final RuntimeException e) {
758
+ rejectAttributeFailure(promise, "setAttribute", e);
759
+ }
760
+ }
761
+
762
+ /**
763
+ * Rejects {@code E_ATTRIBUTE_REJECTED} after an attribute or identity
764
+ * operation throws. The message names the operation only
765
+ * ({@link AttributeBridge#failureMessage}); the exception's message can
766
+ * echo the attribute name or value that made the SDK throw, so only its
767
+ * class name is logged.
768
+ */
769
+ private static void rejectAttributeFailure(
770
+ final Promise promise, final String operation, final RuntimeException e) {
771
+ Log.e(TAG, operation + " failed: " + e.getClass().getName());
772
+ promise.reject(E_ATTRIBUTE_REJECTED, AttributeBridge.failureMessage(operation));
773
+ }
774
+
775
+ @Override
776
+ public void getAttribute(final String name, final Promise promise) {
777
+ try {
778
+ promise.resolve(attributeValueMap(AttributeBridge.readOne(ATTRIBUTE_SDK, name)));
779
+ } catch (final RuntimeException e) {
780
+ rejectAttributeFailure(promise, "getAttribute", e);
781
+ }
782
+ }
783
+
784
+ @Override
785
+ public void getAllAttributes(final Promise promise) {
786
+ try {
787
+ final Map<String, Object> readable = AttributeBridge.readable(Bugsee.getAllAttributes());
788
+ final WritableMap result = Arguments.createMap();
789
+ for (final Map.Entry<String, Object> entry : readable.entrySet()) {
790
+ putAttributeValue(result, entry.getKey(), entry.getValue());
791
+ }
792
+ promise.resolve(result);
793
+ } catch (final RuntimeException e) {
794
+ rejectAttributeFailure(promise, "getAllAttributes", e);
795
+ }
796
+ }
797
+
798
+ @Override
799
+ public void clearAttribute(final String name, final Promise promise) {
800
+ try {
801
+ Bugsee.clearAttribute(name);
802
+ promise.resolve(null);
803
+ } catch (final RuntimeException e) {
804
+ rejectAttributeFailure(promise, "clearAttribute", e);
805
+ }
806
+ }
807
+
808
+ @Override
809
+ public void clearAllAttributes(final Promise promise) {
810
+ try {
811
+ Bugsee.clearAllAttributes();
812
+ promise.resolve(null);
813
+ } catch (final RuntimeException e) {
814
+ rejectAttributeFailure(promise, "clearAllAttributes", e);
815
+ }
816
+ }
817
+
818
+ @Override
819
+ public void setUserIdentifier(final String identifier) {
820
+ Bugsee.setUserIdentifier(identifier);
821
+ }
822
+
823
+ @Override
824
+ public void getUserIdentifier(final Promise promise) {
825
+ try {
826
+ final String id = AttributeBridge.identifier(Bugsee.getUserIdentifier());
827
+ final WritableMap result = Arguments.createMap();
828
+ if (id != null) {
829
+ result.putString("value", id);
830
+ }
831
+ promise.resolve(result);
832
+ } catch (final RuntimeException e) {
833
+ rejectAttributeFailure(promise, "getUserIdentifier", e);
834
+ }
835
+ }
836
+
837
+ @Override
838
+ public void clearUserIdentifier() {
839
+ Bugsee.clearUserIdentifier();
840
+ }
841
+
842
+ @Override
843
+ public void onLogFilterRequest(@NonNull final String requestId, @NonNull final String line) {
844
+ final WritableMap payload = Arguments.createMap();
845
+ payload.putString("requestId", requestId);
846
+ payload.putString("line", line);
847
+ emitOnLogFilterRequest(payload);
848
+ }
849
+
850
+ /**
851
+ * Returns true. The return is what keeps the call on the JS thread:
852
+ * codegen queues a {@code void} TurboModule method onto the native
853
+ * modules thread, so a console line written on the next line could be
854
+ * captured before a queued flag flip landed.
855
+ */
856
+ @Override
857
+ public boolean setLogFilterEnabled(final boolean enabled) {
858
+ LogFilterBridge.shared().setEnabled(enabled);
859
+ return true;
860
+ }
861
+
862
+ @Override
863
+ public void replyLogFilter(final String requestId, @Nullable final String line) {
864
+ if (requestId == null) {
865
+ return;
866
+ }
867
+ LogFilterBridge.shared().reply(requestId, line);
868
+ }
869
+
870
+ @Override
871
+ public void onBreadcrumbFilterRequest(
872
+ @NonNull final String requestId,
873
+ @NonNull final String crumbJson,
874
+ @Nullable final String addId
875
+ ) {
876
+ final WritableMap payload = Arguments.createMap();
877
+ payload.putString("requestId", requestId);
878
+ payload.putString("crumbJson", crumbJson);
879
+ if (addId != null) {
880
+ payload.putString("addId", addId);
881
+ }
882
+ emitOnBreadcrumbFilterRequest(payload);
883
+ }
884
+
885
+ /**
886
+ * Returns true. The return is what keeps the call on the JS thread:
887
+ * codegen queues a {@code void} TurboModule method onto the native
888
+ * modules thread, while {@link #addBreadcrumb} (which returns a value)
889
+ * runs inline. A queued clear could then run between a same-turn
890
+ * re-enable and the add after it, and that add recorded with no filter,
891
+ * its original value kept.
892
+ */
893
+ @Override
894
+ public boolean setBreadcrumbFilterEnabled(final boolean enabled) {
895
+ BreadcrumbFilterBridge.shared().setEnabled(enabled);
896
+ return true;
897
+ }
898
+
899
+ @Override
900
+ public void replyBreadcrumbFilter(
901
+ final String requestId,
902
+ @Nullable final String crumbJson
903
+ ) {
904
+ if (requestId == null) {
905
+ return;
906
+ }
907
+ BreadcrumbFilterBridge.shared().reply(requestId, crumbJson);
908
+ }
909
+
910
+ /**
911
+ * Builds the crumb with {@link Bugsee#getExchangeFactory()} and records
912
+ * it. The no-argument {@code createBreadcrumb} leaves the timestamp unset
913
+ * so the provider stamps it. {@code level} is the JS name;
914
+ * {@link BreadcrumbFilterBridge#levelFromName} maps it to
915
+ * {@link Breadcrumb.Level}. {@code dataJson} null leaves data unset.
916
+ *
917
+ * <p>Returns true only when a filter request for {@code addId} was
918
+ * emitted during {@link Bugsee#addBreadcrumb}. The filter runs before
919
+ * that call returns, so the id has to be visible to it for this call
920
+ * only. False means JS should drop the id.
921
+ */
922
+ @Override
923
+ public boolean addBreadcrumb(
924
+ final String category,
925
+ final String level,
926
+ final String message,
927
+ final String type,
928
+ @Nullable final String dataJson,
929
+ @Nullable final String addId
930
+ ) {
931
+ try {
932
+ // iOS still hands back a crumb when this option is false, then
933
+ // records nothing. Android's factory is null in that case. Either
934
+ // way the call has to say so.
935
+ final OptionsContainer options = Bugsee.getLaunchOptions();
936
+ final Object capture = options == null
937
+ ? Boolean.FALSE
938
+ : options.getOption(Options.CaptureBreadcrumbs, Boolean.FALSE);
939
+ if (!Boolean.TRUE.equals(capture)) {
940
+ Log.e(TAG, "addBreadcrumb dropped: capture is off or the SDK made no crumb");
941
+ return false;
942
+ }
943
+ final BugseeExchangeFactory factory = Bugsee.getExchangeFactory();
944
+ if (factory == null) {
945
+ Log.e(TAG, "addBreadcrumb dropped: capture is off or the SDK made no crumb");
946
+ return false;
947
+ }
948
+ final Breadcrumb crumb = factory.createBreadcrumb();
949
+ if (crumb == null) {
950
+ Log.e(TAG, "addBreadcrumb dropped: capture is off or the SDK made no crumb");
951
+ return false;
952
+ }
953
+ final Breadcrumb.Level parsed = BreadcrumbFilterBridge.levelFromName(level);
954
+ if (parsed == null) {
955
+ Log.e(TAG, "addBreadcrumb dropped: level is not a breadcrumb level name");
956
+ return false;
957
+ }
958
+ crumb.setCategory(category);
959
+ crumb.setLevel(parsed);
960
+ crumb.setMessage(message);
961
+ crumb.setType(type);
962
+ if (dataJson != null) {
963
+ crumb.setData(BridgeJson.parseObject(dataJson));
964
+ }
965
+ final boolean[] emitted = { false };
966
+ BreadcrumbFilterBridge.shared().withSdkLock(() -> {
967
+ if (addId != null) {
968
+ BreadcrumbFilterBridge.shared().beginManualAdd(addId);
969
+ }
970
+ try {
971
+ Bugsee.addBreadcrumb(crumb);
972
+ emitted[0] = addId != null
973
+ && BreadcrumbFilterBridge.shared().takeUnclaimedManualAdd() == null;
974
+ } finally {
975
+ BreadcrumbFilterBridge.shared().takeUnclaimedManualAdd();
976
+ }
977
+ });
978
+ return emitted[0];
979
+ } catch (final BridgeJson.BadJson e) {
980
+ Log.e(TAG, "addBreadcrumb dropped: its data is not a JSON object: " + e.getMessage());
981
+ return false;
982
+ } catch (final RuntimeException e) {
983
+ Log.e(TAG, "addBreadcrumb failed: " + e.getClass().getName());
984
+ return false;
985
+ }
986
+ }
987
+
988
+ /** {@code { value }}, typed by {@code value}'s runtime type, or empty when absent. */
989
+ private static WritableMap attributeValueMap(@Nullable final Object value) {
990
+ final WritableMap result = Arguments.createMap();
991
+ putAttributeValue(result, "value", value);
992
+ return result;
993
+ }
994
+
995
+ /**
996
+ * Writes one attribute value into {@code target}, typed as
997
+ * {@link AttributeBridge#readable} produced it: {@code String}, {@code
998
+ * Boolean}, {@code Number} (always a {@code Double} -- see {@link
999
+ * AttributeBridge#readable}) or a {@code List<String>}. Absent ({@code
1000
+ * null}) writes nothing, leaving the key out entirely.
1001
+ */
1002
+ private static void putAttributeValue(
1003
+ @NonNull final WritableMap target,
1004
+ @NonNull final String key,
1005
+ @Nullable final Object value
1006
+ ) {
1007
+ if (value instanceof String) {
1008
+ target.putString(key, (String) value);
1009
+ } else if (value instanceof Boolean) {
1010
+ target.putBoolean(key, (Boolean) value);
1011
+ } else if (value instanceof Number) {
1012
+ target.putDouble(key, ((Number) value).doubleValue());
1013
+ } else if (value instanceof List) {
1014
+ target.putArray(key, toWritableArray((List<?>) value));
1015
+ }
1016
+ }
1017
+
1018
+ /**
1019
+ * Records a named event, with optional params.
1020
+ *
1021
+ * {@code paramsJson} is the params as JSON text ({@code src/bridge/json.ts}),
1022
+ * parsed by {@link BridgeJson} -- the one transport for object payloads,
1023
+ * because iOS's object-argument conversion drops null members and this
1024
+ * one must mean the same thing on both platforms. Text that does not parse
1025
+ * drops the event, logged: a void method has no promise to reject.
1026
+ *
1027
+ * {@code null} params calls the SDK's one-argument overload rather than
1028
+ * passing an empty map: the bundle's event entry has no {@code params}
1029
+ * key at all when none were given (design doc, Phase 4 bundle facts), and
1030
+ * a {@code {}} here would produce one. JS has already validated params
1031
+ * against the accepted value domain and copied it
1032
+ * ({@code src/data/validate.ts}), so nothing here is re-checked -- only
1033
+ * guarded, since a void TurboModule method has no promise to reject and
1034
+ * an escaping exception crashes the host app.
1035
+ */
1036
+ @Override
1037
+ public void event(final String name, @Nullable final String paramsJson) {
1038
+ try {
1039
+ if (paramsJson == null) {
1040
+ Bugsee.event(name);
1041
+ } else {
1042
+ Bugsee.event(name, BridgeJson.parseObject(paramsJson));
1043
+ }
1044
+ } catch (final BridgeJson.BadJson e) {
1045
+ Log.e(TAG, "event \"" + name + "\" dropped: its params are not a JSON object: "
1046
+ + e.getMessage());
1047
+ } catch (RuntimeException e) {
1048
+ Log.e(TAG, "event failed: " + e.getClass().getName());
1049
+ }
1050
+ }
1051
+
1052
+ /** A numeric trace value. Boxed to a {@code Double}, the SDK's own {@code Object} overload. */
1053
+ @Override
1054
+ public void traceNumber(final String name, final double value) {
1055
+ try {
1056
+ Bugsee.trace(name, value);
1057
+ } catch (RuntimeException e) {
1058
+ Log.e(TAG, "traceNumber failed: " + e.getClass().getName());
1059
+ }
1060
+ }
1061
+
1062
+ /** A string trace value. */
1063
+ @Override
1064
+ public void traceString(final String name, final String value) {
1065
+ try {
1066
+ Bugsee.trace(name, value);
1067
+ } catch (RuntimeException e) {
1068
+ Log.e(TAG, "traceString failed: " + e.getClass().getName());
1069
+ }
1070
+ }
1071
+
1072
+ /**
1073
+ * A boolean trace value, boxed explicitly to a {@code Boolean} -- kept
1074
+ * apart from {@link #traceNumber} so it cannot silently arrive as
1075
+ * {@code 0}/{@code 1} on the SDK side.
1076
+ */
1077
+ @Override
1078
+ public void traceBoolean(final String name, final boolean value) {
1079
+ try {
1080
+ Bugsee.trace(name, Boolean.valueOf(value));
1081
+ } catch (RuntimeException e) {
1082
+ Log.e(TAG, "traceBoolean failed: " + e.getClass().getName());
1083
+ }
1084
+ }
1085
+
1086
+ @Override
1087
+ public void onReportHandlerRequest(
1088
+ @NonNull final String handleId,
1089
+ @NonNull final String phase,
1090
+ @NonNull final String reportId,
1091
+ @NonNull final String type,
1092
+ final double deadlineMs
1093
+ ) {
1094
+ final WritableMap payload = Arguments.createMap();
1095
+ payload.putString("handleId", handleId);
1096
+ payload.putString("phase", phase);
1097
+ payload.putString("reportId", reportId);
1098
+ payload.putString("type", type);
1099
+ payload.putDouble("deadlineMs", deadlineMs);
1100
+ emitOnReportHandlerRequest(payload);
1101
+ }
1102
+
1103
+ @Override
1104
+ public void setReportHandlerPhases(final boolean before, final boolean after) {
1105
+ ReportHandlerBridge.shared().setPhases(before, after);
1106
+ }
1107
+
1108
+ @Override
1109
+ public void completeReportHandler(final String handleId) {
1110
+ ReportHandlerBridge.shared().complete(handleId);
1111
+ }
1112
+
1113
+ // The report ops run on the calling (native-modules) thread: the SDK
1114
+ // documents Report as usable from any thread, and its collections are
1115
+ // synchronized. Each catches everything -- an exception escaping a
1116
+ // TurboModule method is a crash in a release build, and the SDK's fault
1117
+ // is not worth the app.
1118
+
1119
+ @Override
1120
+ public void reportRead(final String handleId, final Promise promise) {
1121
+ final Report report = ReportHandlerBridge.shared().reportFor(handleId);
1122
+ if (report == null) {
1123
+ rejectHandleDead(promise);
1124
+ return;
1125
+ }
1126
+ try {
1127
+ promise.resolve(snapshotToWritableMap(ReportOps.read(report)));
1128
+ } catch (final Throwable e) {
1129
+ rejectReportFailure(promise, "reportRead", e);
1130
+ }
1131
+ }
1132
+
1133
+ @Override
1134
+ public void reportUpdate(final String handleId, final String patchJson, final Promise promise) {
1135
+ final Report report = ReportHandlerBridge.shared().reportFor(handleId);
1136
+ if (report == null) {
1137
+ rejectHandleDead(promise);
1138
+ return;
1139
+ }
1140
+ try {
1141
+ // JSON text, not a ReadableMap: the transport iOS needs to keep a
1142
+ // clearing null, used here too so both platforms parse one form.
1143
+ ReportOps.applyJson(report, patchJson);
1144
+ promise.resolve(null);
1145
+ } catch (final ReportOps.BadArgument e) {
1146
+ promise.reject(E_REPORT_BAD_ARGUMENT, e.getMessage());
1147
+ } catch (final Throwable e) {
1148
+ rejectReportFailure(promise, "reportUpdate", e);
1149
+ }
1150
+ }
1151
+
1152
+ @Override
1153
+ public void reportAddFileAttachment(
1154
+ final String handleId,
1155
+ final String path,
1156
+ final String name,
1157
+ @Nullable final String mimeType,
1158
+ final boolean move,
1159
+ final Promise promise
1160
+ ) {
1161
+ final Report report = ReportHandlerBridge.shared().reportFor(handleId);
1162
+ if (report == null) {
1163
+ rejectHandleDead(promise);
1164
+ return;
1165
+ }
1166
+ try {
1167
+ settleAttachment(handleId, ReportOps.addFile(report, path, name, mimeType, move), promise);
1168
+ } catch (final Throwable e) {
1169
+ rejectReportFailure(promise, "reportAddFileAttachment", e);
1170
+ }
1171
+ }
1172
+
1173
+ @Override
1174
+ public void reportAddDataAttachment(
1175
+ final String handleId,
1176
+ final String base64,
1177
+ final String name,
1178
+ @Nullable final String mimeType,
1179
+ final Promise promise
1180
+ ) {
1181
+ final Report report = ReportHandlerBridge.shared().reportFor(handleId);
1182
+ if (report == null) {
1183
+ rejectHandleDead(promise);
1184
+ return;
1185
+ }
1186
+ final byte[] data;
1187
+ try {
1188
+ data = Base64.decode(base64, Base64.NO_WRAP);
1189
+ } catch (final IllegalArgumentException e) {
1190
+ promise.reject(E_REPORT_BAD_ARGUMENT, "data must be base64-encoded");
1191
+ return;
1192
+ }
1193
+ try {
1194
+ settleAttachment(handleId, ReportOps.addData(report, data, name, mimeType), promise);
1195
+ } catch (final Throwable e) {
1196
+ rejectReportFailure(promise, "reportAddDataAttachment", e);
1197
+ }
1198
+ }
1199
+
1200
+ /**
1201
+ * One created report at a time. The slot is reserved before the SDK is
1202
+ * asked, because {@code onCreated} arrives later, on the main thread.
1203
+ * A throw from that call ends the reservation; otherwise the listener does,
1204
+ * with {@code cr-<n>} or null.
1205
+ */
1206
+ @Override
1207
+ public void createReport(final Promise promise) {
1208
+ final CreatedReports registry = CreatedReports.shared();
1209
+ final int stamp = registry.tryReserve();
1210
+ if (stamp == 0) {
1211
+ Log.i(TAG, "created report - busy");
1212
+ promise.reject(
1213
+ E_REPORT_CREATE_BUSY,
1214
+ "A created report is already outstanding.");
1215
+ return;
1216
+ }
1217
+ try {
1218
+ Bugsee.createReport(created -> deliverCreatedReport(registry, stamp, created, promise));
1219
+ } catch (final Throwable thrown) {
1220
+ // The SDK threw before the listener ran. The stamp no-ops once
1221
+ // this reservation has been cleared and another one opened.
1222
+ registry.fulfil(stamp, null);
1223
+ rejectReportFailure(promise, "createReport", thrown);
1224
+ }
1225
+ }
1226
+
1227
+ /**
1228
+ * Runs on the SDK's listener thread. A throw here would escape onto that
1229
+ * thread, so it is caught, the reservation is ended, and the promise rejects.
1230
+ * The stamp is the one captured at reserve time: a listener that arrives
1231
+ * after {@code invalidate} cleared that reservation cannot end a newer one.
1232
+ */
1233
+ private static void deliverCreatedReport(
1234
+ final CreatedReports registry,
1235
+ final int stamp,
1236
+ @Nullable final Report created,
1237
+ final Promise promise
1238
+ ) {
1239
+ String handle = null;
1240
+ try {
1241
+ handle = registry.fulfil(stamp, created);
1242
+ if (handle == null) {
1243
+ Log.i(TAG, "created report - none");
1244
+ } else {
1245
+ Log.i(TAG, "created report " + handle + " created");
1246
+ }
1247
+ promise.resolve(handle);
1248
+ } catch (final Throwable thrown) {
1249
+ if (handle != null) {
1250
+ registry.take(handle);
1251
+ } else {
1252
+ registry.fulfil(stamp, null);
1253
+ }
1254
+ rejectReportFailure(promise, "createReport", thrown);
1255
+ }
1256
+ }
1257
+
1258
+ @Override
1259
+ public void createdReportRead(final String handleId, final Promise promise) {
1260
+ final Report report = CreatedReports.shared().get(handleId);
1261
+ if (report == null) {
1262
+ rejectHandleDead(promise);
1263
+ return;
1264
+ }
1265
+ try {
1266
+ promise.resolve(snapshotToWritableMap(ReportOps.read(report)));
1267
+ } catch (final Throwable e) {
1268
+ rejectReportFailure(promise, "createdReportRead", e);
1269
+ }
1270
+ }
1271
+
1272
+ @Override
1273
+ public void createdReportUpdate(
1274
+ final String handleId,
1275
+ final String patchJson,
1276
+ final Promise promise
1277
+ ) {
1278
+ final Report report = CreatedReports.shared().get(handleId);
1279
+ if (report == null) {
1280
+ rejectHandleDead(promise);
1281
+ return;
1282
+ }
1283
+ try {
1284
+ ReportOps.applyJson(report, patchJson);
1285
+ promise.resolve(null);
1286
+ } catch (final ReportOps.BadArgument e) {
1287
+ promise.reject(E_REPORT_BAD_ARGUMENT, e.getMessage());
1288
+ } catch (final Throwable e) {
1289
+ rejectReportFailure(promise, "createdReportUpdate", e);
1290
+ }
1291
+ }
1292
+
1293
+ @Override
1294
+ public void createdReportAddDataAttachment(
1295
+ final String handleId,
1296
+ final String base64,
1297
+ final String name,
1298
+ @Nullable final String mimeType,
1299
+ final Promise promise
1300
+ ) {
1301
+ final Report report = CreatedReports.shared().get(handleId);
1302
+ if (report == null) {
1303
+ rejectHandleDead(promise);
1304
+ return;
1305
+ }
1306
+ final byte[] data;
1307
+ try {
1308
+ data = Base64.decode(base64, Base64.NO_WRAP);
1309
+ } catch (final IllegalArgumentException e) {
1310
+ promise.reject(E_REPORT_BAD_ARGUMENT, "data must be base64-encoded");
1311
+ return;
1312
+ }
1313
+ try {
1314
+ settleCreatedAttachment(
1315
+ handleId, ReportOps.addData(report, data, name, mimeType), promise);
1316
+ } catch (final Throwable e) {
1317
+ rejectReportFailure(promise, "createdReportAddDataAttachment", e);
1318
+ }
1319
+ }
1320
+
1321
+ /** Copied, not moved: a created report has no {@code move} argument. */
1322
+ @Override
1323
+ public void createdReportAddFileAttachment(
1324
+ final String handleId,
1325
+ final String path,
1326
+ final String name,
1327
+ @Nullable final String mimeType,
1328
+ final Promise promise
1329
+ ) {
1330
+ final Report report = CreatedReports.shared().get(handleId);
1331
+ if (report == null) {
1332
+ rejectHandleDead(promise);
1333
+ return;
1334
+ }
1335
+ try {
1336
+ settleCreatedAttachment(
1337
+ handleId,
1338
+ ReportOps.addFile(report, path, name, mimeType, false),
1339
+ promise);
1340
+ } catch (final Throwable e) {
1341
+ rejectReportFailure(promise, "createdReportAddFileAttachment", e);
1342
+ }
1343
+ }
1344
+
1345
+ /**
1346
+ * Takes the report first, so the slot is free whether or not the upload
1347
+ * succeeds. The handle is dead afterwards.
1348
+ */
1349
+ @Override
1350
+ public void createdReportUpload(final String handleId, final Promise promise) {
1351
+ final Report report = CreatedReports.shared().take(handleId);
1352
+ if (report == null) {
1353
+ rejectHandleDead(promise);
1354
+ return;
1355
+ }
1356
+ try {
1357
+ Bugsee.upload(report, ok -> {
1358
+ try {
1359
+ Log.i(TAG, "created report " + handleId + " uploaded ok=" + ok);
1360
+ promise.resolve(ok);
1361
+ } catch (final Throwable thrown) {
1362
+ rejectReportFailure(promise, "createdReportUpload", thrown);
1363
+ }
1364
+ });
1365
+ } catch (final Throwable thrown) {
1366
+ rejectReportFailure(promise, "createdReportUpload", thrown);
1367
+ }
1368
+ }
1369
+
1370
+ /**
1371
+ * Rejects after a report operation faults with anything it does not
1372
+ * validate itself. The code stays React Native's own default
1373
+ * ({@code EUNSPECIFIED}, what {@code reject(Throwable)} produced): an
1374
+ * unexpected fault is not one of the codes the JS contract names. The
1375
+ * message names the operation only ({@link ReportOps#failureMessage}) --
1376
+ * the fault's own message can echo report content (a summary, an
1377
+ * attribute value, a file path, an attachment name), and passing the
1378
+ * Throwable would also send its message and stack to JS. Only its class
1379
+ * name is logged.
1380
+ */
1381
+ private static void rejectReportFailure(
1382
+ final Promise promise, final String operation, final Throwable e) {
1383
+ Log.e(TAG, operation + " failed: " + e.getClass().getName());
1384
+ promise.reject((String) null, ReportOps.failureMessage(operation));
1385
+ }
1386
+
1387
+ /**
1388
+ * The SDK returns null both for a declined attachment and for a report
1389
+ * that is no longer live. The handle tells the two apart: if it died while
1390
+ * the call ran, that is the truer answer.
1391
+ */
1392
+ private static void settleAttachment(
1393
+ final String handleId,
1394
+ final boolean added,
1395
+ final Promise promise
1396
+ ) {
1397
+ if (added) {
1398
+ promise.resolve(null);
1399
+ } else if (ReportHandlerBridge.shared().reportFor(handleId) == null) {
1400
+ rejectHandleDead(promise);
1401
+ } else {
1402
+ promise.reject(E_REPORT_ATTACHMENT_REJECTED, "The SDK declined the attachment");
1403
+ }
1404
+ }
1405
+
1406
+ /** Same decision as {@link #settleAttachment}, against the created-report registry. */
1407
+ private static void settleCreatedAttachment(
1408
+ final String handleId,
1409
+ final boolean added,
1410
+ final Promise promise
1411
+ ) {
1412
+ if (added) {
1413
+ promise.resolve(null);
1414
+ } else if (CreatedReports.shared().get(handleId) == null) {
1415
+ rejectHandleDead(promise);
1416
+ } else {
1417
+ promise.reject(E_REPORT_ATTACHMENT_REJECTED, "The SDK declined the attachment");
1418
+ }
1419
+ }
1420
+
1421
+ private static void rejectHandleDead(final Promise promise) {
1422
+ promise.reject(
1423
+ E_REPORT_HANDLE_DEAD,
1424
+ "This BugseeReport handle is no longer valid: its handler has "
1425
+ + "already settled, or its deadline has passed.");
1426
+ }
1427
+
1428
+ /** {@link ReportOps#read}'s snapshot as a bridge map. */
1429
+ private static WritableMap snapshotToWritableMap(@NonNull final Map<String, Object> snapshot) {
1430
+ final WritableMap result = Arguments.createMap();
1431
+ for (final Map.Entry<String, Object> entry : snapshot.entrySet()) {
1432
+ final String key = entry.getKey();
1433
+ final Object value = entry.getValue();
1434
+ if (value == null) {
1435
+ result.putNull(key);
1436
+ } else if (value instanceof Boolean) {
1437
+ result.putBoolean(key, (Boolean) value);
1438
+ } else if (value instanceof Number) {
1439
+ result.putDouble(key, ((Number) value).doubleValue());
1440
+ } else if (value instanceof String) {
1441
+ result.putString(key, (String) value);
1442
+ } else if (value instanceof Map) {
1443
+ @SuppressWarnings("unchecked")
1444
+ final Map<String, Object> nested = (Map<String, Object>) value;
1445
+ result.putMap(key, snapshotToWritableMap(nested));
1446
+ } else if (value instanceof List) {
1447
+ result.putArray(key, toWritableArray((List<?>) value));
1448
+ }
1449
+ }
1450
+ return result;
1451
+ }
1452
+
1453
+ private static WritableArray toWritableArray(@NonNull final List<?> list) {
1454
+ final WritableArray result = Arguments.createArray();
1455
+ for (final Object value : list) {
1456
+ if (value instanceof Boolean) {
1457
+ result.pushBoolean((Boolean) value);
1458
+ } else if (value instanceof Number) {
1459
+ result.pushDouble(((Number) value).doubleValue());
1460
+ } else if (value instanceof String) {
1461
+ result.pushString((String) value);
1462
+ } else {
1463
+ result.pushNull();
1464
+ }
1465
+ }
1466
+ return result;
1467
+ }
1468
+
1469
+ /** Turns the SDK's option map into something the bridge can return. */
1470
+ private static WritableMap toWritableMap(@Nullable final Map<String, Serializable> options) {
1471
+ final WritableMap result = Arguments.createMap();
1472
+ if (options == null) {
1473
+ return result;
1474
+ }
1475
+ for (final Map.Entry<String, Serializable> entry : options.entrySet()) {
1476
+ final Serializable value = entry.getValue();
1477
+ if (value instanceof Boolean) {
1478
+ result.putBoolean(entry.getKey(), (Boolean) value);
1479
+ } else if (value instanceof Number) {
1480
+ result.putDouble(entry.getKey(), ((Number) value).doubleValue());
1481
+ } else if (value instanceof String) {
1482
+ result.putString(entry.getKey(), (String) value);
1483
+ } else if (value instanceof Enum) {
1484
+ // Enums go back as the number they arrived as -- their
1485
+ // internal value, which is what both platforms speak.
1486
+ result.putDouble(entry.getKey(), BugseeOptionEnums.wireValue(value));
1487
+ }
1488
+ // Anything else has no JS representation; omitted rather than
1489
+ // stringified, which would read as a value the app could set back.
1490
+ }
1491
+ return result;
1492
+ }
1493
+
1494
+ /**
1495
+ * Flattens the JS options map into what the SDK takes.
1496
+ *
1497
+ * <p>An unrecognised value is dropped rather than guessed at: a wrong
1498
+ * coercion would look like the option was honoured. Numbers go through
1499
+ * {@link BugseeOptionEnums}, because an enum-typed option arriving as a
1500
+ * bare number is ignored by the SDK's Map path.
1501
+ */
1502
+ /**
1503
+ * The Expo plugin's {@code endpoint} option, from this app's manifest
1504
+ * meta-data, applied when JS passed no endpoint (PluginEndpoint).
1505
+ */
1506
+ private Map<String, Serializable> withConfiguredEndpoint(final Map<String, Serializable> options) {
1507
+ return PluginEndpoint.withDefault(options, readConfiguredEndpoint());
1508
+ }
1509
+
1510
+ @Nullable
1511
+ private String readConfiguredEndpoint() {
1512
+ try {
1513
+ final Context context = getReactApplicationContext();
1514
+ final ApplicationInfo info = context.getPackageManager()
1515
+ .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
1516
+ return info.metaData == null ? null : info.metaData.getString(PluginEndpoint.META_DATA_KEY);
1517
+ } catch (Exception e) {
1518
+ // No meta-data to read is no configured endpoint: launch as JS asked.
1519
+ return null;
1520
+ }
1521
+ }
1522
+
1523
+ private static Map<String, Serializable> toOptions(@Nullable final ReadableMap options) {
1524
+ final Map<String, Serializable> result = new HashMap<>();
1525
+ if (options == null) {
1526
+ return result;
1527
+ }
1528
+ final ReadableMapKeySetIterator keys = options.keySetIterator();
1529
+ while (keys.hasNextKey()) {
1530
+ final String key = keys.nextKey();
1531
+ switch (options.getType(key)) {
1532
+ case Boolean:
1533
+ result.put(key, options.getBoolean(key));
1534
+ break;
1535
+ case Number:
1536
+ // Enum-typed keys arrive as their internal value and must
1537
+ // become enum instances: the SDK's Map path does not
1538
+ // coerce, so a bare number is ignored. null means the
1539
+ // value names no constant, and the option is dropped
1540
+ // rather than guessed at.
1541
+ final Serializable number =
1542
+ BugseeOptionEnums.numberFor(key, options.getDouble(key));
1543
+ if (number != null) {
1544
+ result.put(key, number);
1545
+ }
1546
+ break;
1547
+ case String:
1548
+ result.put(key, options.getString(key));
1549
+ break;
1550
+ default:
1551
+ break;
1552
+ }
1553
+ }
1554
+ return result;
1555
+ }
1556
+
1557
+ // --- Notify and spans ------------------------------------------------
1558
+ // Span calls stay on this thread. Both SDKs keep the active span in
1559
+ // thread-local storage, so hopping to another thread would make
1560
+ // startSpan miss the transaction startTransaction just opened.
1561
+ // The setters return a boolean for that same thread: codegen queues a
1562
+ // void TurboModule method, and a setAttribute then finish in one turn
1563
+ // would release the handle before the setter ran.
1564
+
1565
+ @Override
1566
+ public void notify(
1567
+ final String title,
1568
+ @Nullable final String body,
1569
+ final double severity,
1570
+ @Nullable final String fieldsJson,
1571
+ final boolean urgent
1572
+ ) {
1573
+ Map<String, String> fields = null;
1574
+ if (fieldsJson != null) {
1575
+ try {
1576
+ final Map<String, Object> parsed = BridgeJson.parseObject(fieldsJson);
1577
+ fields = new LinkedHashMap<>();
1578
+ for (final Map.Entry<String, Object> entry : parsed.entrySet()) {
1579
+ if (entry.getValue() instanceof String) {
1580
+ fields.put(entry.getKey(), (String) entry.getValue());
1581
+ }
1582
+ }
1583
+ } catch (final BridgeJson.BadJson error) {
1584
+ Log.w(TAG, "notify dropped: " + error.getMessage());
1585
+ return;
1586
+ }
1587
+ }
1588
+ Bugsee.notify(title, body, ReportArgs.severity((int) severity), fields, urgent);
1589
+ }
1590
+
1591
+ @Override
1592
+ public WritableMap startTransaction(
1593
+ final String name,
1594
+ final String operation,
1595
+ @Nullable final String attributesJson
1596
+ ) {
1597
+ final Map<String, Object> attributes = attributes(attributesJson, "startTransaction");
1598
+ final Transaction transaction = attributes == null
1599
+ ? Bugsee.startTransaction(name, operation)
1600
+ : Bugsee.startTransaction(name, operation, attributes);
1601
+ if (transaction == null) {
1602
+ return noSpan();
1603
+ }
1604
+ return snapshot(spanHandles.retain(transaction, new LiveSpan(transaction)), transaction);
1605
+ }
1606
+
1607
+ @Override
1608
+ public WritableMap startSpan(final String operation, @Nullable final String description) {
1609
+ final Span span = Bugsee.startSpan(operation, description);
1610
+ if (span == null) {
1611
+ return noSpan();
1612
+ }
1613
+ return snapshot(spanHandles.retain(span, new LiveSpan(span)), span);
1614
+ }
1615
+
1616
+ @Override
1617
+ public WritableMap getActiveSpan() {
1618
+ final Span span = Bugsee.getActiveSpan();
1619
+ if (span == null) {
1620
+ return noSpan();
1621
+ }
1622
+ return snapshot(spanHandles.retain(span, new LiveSpan(span)), span);
1623
+ }
1624
+
1625
+ @Override
1626
+ public boolean spanSetName(final String handle, final String name) {
1627
+ final LiveSpan live = live(handle);
1628
+ if (live == null) {
1629
+ return false;
1630
+ }
1631
+ live.span.setName(name);
1632
+ return true;
1633
+ }
1634
+
1635
+ @Override
1636
+ public boolean spanSetDescription(final String handle, @Nullable final String description) {
1637
+ final LiveSpan live = live(handle);
1638
+ if (live == null) {
1639
+ return false;
1640
+ }
1641
+ live.span.setDescription(description);
1642
+ return true;
1643
+ }
1644
+
1645
+ @Override
1646
+ public boolean spanSetAttribute(final String handle, final String key, final String valueJson) {
1647
+ final LiveSpan live = live(handle);
1648
+ if (live == null) {
1649
+ return false;
1650
+ }
1651
+ final Object value = jsonValue(valueJson);
1652
+ if (value == null) {
1653
+ Log.w(TAG, "span attribute dropped: value is not a string, number or boolean");
1654
+ return false;
1655
+ }
1656
+ live.span.setAttribute(key, value);
1657
+ return true;
1658
+ }
1659
+
1660
+ @Override
1661
+ public boolean spanSetStatus(final String handle, final double status) {
1662
+ final LiveSpan live = live(handle);
1663
+ final SpanStatus parsed = SpanHandles.status((int) status);
1664
+ if (live == null || parsed == null) {
1665
+ if (parsed == null) {
1666
+ Log.w(TAG, "span status is outside 0..5");
1667
+ }
1668
+ return false;
1669
+ }
1670
+ live.span.setStatus(parsed);
1671
+ return true;
1672
+ }
1673
+
1674
+ @Override
1675
+ public WritableMap spanStartChild(
1676
+ final String handle,
1677
+ final String operation,
1678
+ @Nullable final String description
1679
+ ) {
1680
+ final LiveSpan live = live(handle);
1681
+ if (live == null) {
1682
+ return noSpan();
1683
+ }
1684
+ final Span child = description == null
1685
+ ? live.span.startChildSpan(operation)
1686
+ : live.span.startChildSpan(operation, description);
1687
+ if (child == null) {
1688
+ return noSpan();
1689
+ }
1690
+ return snapshot(spanHandles.retain(child, new LiveSpan(child)), child);
1691
+ }
1692
+
1693
+ @Override
1694
+ public WritableArray spanFinish(final String handle, final double status, final boolean statusSet) {
1695
+ final WritableArray released = Arguments.createArray();
1696
+ final SpanStatus parsed = statusSet ? SpanHandles.status((int) status) : null;
1697
+ if (statusSet && parsed == null) {
1698
+ Log.w(TAG, "span finish status is outside 0..5");
1699
+ return released;
1700
+ }
1701
+ for (final String id : spanHandles.finish(handle, parsed)) {
1702
+ released.pushString(id);
1703
+ }
1704
+ return released;
1705
+ }
1706
+
1707
+ @Nullable
1708
+ private LiveSpan live(final String handle) {
1709
+ final SpanHandles.Retained retained = spanHandles.get(handle);
1710
+ if (retained instanceof LiveSpan) {
1711
+ return (LiveSpan) retained;
1712
+ }
1713
+ return null;
1714
+ }
1715
+
1716
+ private static WritableMap noSpan() {
1717
+ final WritableMap map = Arguments.createMap();
1718
+ map.putString("handle", "");
1719
+ return map;
1720
+ }
1721
+
1722
+ private static WritableMap snapshot(final String handle, final Span span) {
1723
+ final WritableMap map = Arguments.createMap();
1724
+ map.putString("handle", handle);
1725
+ map.putString("spanId", span.getSpanId() == null ? "" : span.getSpanId());
1726
+ map.putString("traceId", span.getTraceId() == null ? "" : span.getTraceId());
1727
+ map.putString("operation", span.getOperation() == null ? "" : span.getOperation());
1728
+ if (span.getDescription() == null) {
1729
+ map.putNull("description");
1730
+ } else {
1731
+ map.putString("description", span.getDescription());
1732
+ }
1733
+ final SpanStatus status = span.getStatus();
1734
+ map.putInt("status", status == null ? 0 : status.ordinal());
1735
+ map.putBoolean("finished", span.isFinished());
1736
+ map.putString("attributesJson", attributesJson(span.getAttributes()));
1737
+ if (span instanceof Transaction) {
1738
+ final Transaction transaction = (Transaction) span;
1739
+ map.putString("name", transaction.getName() == null ? "" : transaction.getName());
1740
+ map.putBoolean("sampled", transaction.isSampled());
1741
+ }
1742
+ return map;
1743
+ }
1744
+
1745
+ private static String attributesJson(@Nullable final Map<String, Object> attributes) {
1746
+ if (attributes == null || attributes.isEmpty()) {
1747
+ return "{}";
1748
+ }
1749
+ final JSONObject object = new JSONObject();
1750
+ for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
1751
+ final Object value = entry.getValue();
1752
+ if (value instanceof String || value instanceof Boolean || value instanceof Number) {
1753
+ try {
1754
+ object.put(entry.getKey(), value);
1755
+ } catch (final JSONException ignored) {
1756
+ // A key the JSON writer refuses is omitted, not fatal.
1757
+ }
1758
+ }
1759
+ }
1760
+ return object.toString();
1761
+ }
1762
+
1763
+ @Nullable
1764
+ private static Map<String, Object> attributes(
1765
+ @Nullable final String json,
1766
+ final String method
1767
+ ) {
1768
+ if (json == null) {
1769
+ return null;
1770
+ }
1771
+ try {
1772
+ return BridgeJson.parseObject(json);
1773
+ } catch (final BridgeJson.BadJson error) {
1774
+ Log.w(TAG, method + " dropped attributes: " + error.getMessage());
1775
+ return null;
1776
+ }
1777
+ }
1778
+
1779
+ // --- Appearance and collected data (Phase 11) ---------------------------
1780
+ // set/get return a value so codegen runs them on the JS thread, ahead of
1781
+ // the read that follows a write in the same turn.
1782
+
1783
+ @Override
1784
+ public boolean setAppearanceColor(
1785
+ final String name,
1786
+ final double r,
1787
+ final double g,
1788
+ final double b,
1789
+ final double a
1790
+ ) {
1791
+ AppearanceBridge.setColor(
1792
+ name,
1793
+ (int) Math.round(r),
1794
+ (int) Math.round(g),
1795
+ (int) Math.round(b),
1796
+ (int) Math.round(a)
1797
+ );
1798
+ return true;
1799
+ }
1800
+
1801
+ @Override
1802
+ @NonNull
1803
+ public String getAppearanceColor(final String name) {
1804
+ return AppearanceBridge.toHex(AppearanceBridge.getColor(name));
1805
+ }
1806
+
1807
+ @Override
1808
+ public void deleteCollectedDataOnDevice(
1809
+ final boolean includingIntermediate,
1810
+ final Promise promise
1811
+ ) {
1812
+ Bugsee.deleteCollectedDataOnDevice(
1813
+ includingIntermediate,
1814
+ success -> promise.resolve(Boolean.TRUE.equals(success))
1815
+ );
1816
+ }
1817
+
1818
+ /** One JSON value, or null when it is missing, null, an object or an array. */
1819
+ @Nullable
1820
+ private static Object jsonValue(@Nullable final String json) {
1821
+ if (json == null) {
1822
+ return null;
1823
+ }
1824
+ final JSONTokener tokener = new JSONTokener(json);
1825
+ final Object value;
1826
+ try {
1827
+ value = tokener.nextValue();
1828
+ } catch (final JSONException error) {
1829
+ Log.w(TAG, "span attribute dropped: malformed JSON (" + json.length() + " characters)");
1830
+ return null;
1831
+ }
1832
+ if (value == null || value == JSONObject.NULL) {
1833
+ return null;
1834
+ }
1835
+ if (value instanceof String || value instanceof Boolean) {
1836
+ return value;
1837
+ }
1838
+ if (value instanceof Integer || value instanceof Long) {
1839
+ return value;
1840
+ }
1841
+ if (value instanceof Number) {
1842
+ return ((Number) value).doubleValue();
1843
+ }
1844
+ return null;
1845
+ }
1846
+
1847
+ /** The SDK span plus the registry's finish/isFinished surface. */
1848
+ private static final class LiveSpan implements SpanHandles.Retained {
1849
+ final Span span;
1850
+
1851
+ LiveSpan(final Span span) {
1852
+ this.span = span;
1853
+ }
1854
+
1855
+ @Override
1856
+ public void finish(@Nullable final SpanStatus status) {
1857
+ if (status == null) {
1858
+ span.finish();
1859
+ } else {
1860
+ span.finish(status);
1861
+ }
1862
+ }
1863
+
1864
+ @Override
1865
+ public boolean isFinished() {
1866
+ return span.isFinished();
1867
+ }
1868
+ }
1869
+ }