@log-drop/react-native 2.1.1 → 2.1.2-alpha1

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.
@@ -22,5 +22,6 @@ if respond_to?(:install_modules_dependencies, true)
22
22
  else
23
23
  s.dependency "React-Core"
24
24
  end
25
- s.dependency 'LogDrop', '2.1.10'
25
+ # Tracing (traceparent propagation and OTLP export) needs the first native release after 2.1.10.
26
+ s.dependency 'LogDrop', '2.1.11-alpha1'
26
27
  end
package/README.md CHANGED
@@ -320,7 +320,7 @@ Add LogDrop to the extension target and run `pod install`:
320
320
 
321
321
  ```ruby
322
322
  target 'LogDropNotificationServiceExtension' do
323
- pod 'LogDrop', '2.1.10'
323
+ pod 'LogDrop', '2.1.11-alpha1'
324
324
  end
325
325
  ```
326
326
 
@@ -356,6 +356,27 @@ Forces the SDK to send any cached logs immediately.
356
356
 
357
357
  ---
358
358
 
359
+ ### `LogDrop.flushOtlpTracing(timeoutMs?: number): Promise<boolean>`
360
+ Asks the native SDK to send the HTTP client spans it has queued (see
361
+ [End-to-end tracing](#-end-to-end-tracing)) and waits at most `timeoutMs`
362
+ milliseconds (1–5000, default 2000).
363
+ - Resolves `true` when nothing is left in the native queue and no span was
364
+ dropped since the previous flush.
365
+ - Resolves `false` on timeout, while delivery is still pending (for example a
366
+ batch the server asked to retry later, which the SDK resends in the
367
+ background), after spans were dropped, with native SDKs that predate the
368
+ exporter (2.1.10 and older), and on platforms other than Android and iOS. It
369
+ never rejects.
370
+ - The result does not tell you whether tracing is on.
371
+ - Optional: the SDK sends queued spans in the background on its own. Use it, for
372
+ example, before a test ends or before the user signs out.
373
+
374
+ ```ts
375
+ const delivered = await LogDrop.flushOtlpTracing(3000);
376
+ ```
377
+
378
+ ---
379
+
359
380
  ### `LogDrop.trackCustomEvent(eventName: string, properties?: Record<string, unknown>): void`
360
381
  Tracks an application-specific event with an optional JSON-compatible
361
382
  properties object. Event and property codes shown in the panel are managed by
@@ -540,6 +561,45 @@ const subscription = AppState.addEventListener('change', (state) => {
540
561
 
541
562
  ---
542
563
 
564
+ ## 🧭 End-to-end tracing
565
+
566
+ The native LogDrop Android and iOS SDKs trace the HTTP requests your app makes
567
+ with `fetch`, `XMLHttpRequest` and libraries built on them (such as axios). For
568
+ each request they add a W3C `traceparent` header and record one client span, so
569
+ the request and the backend spans it causes appear as one trace in LogDrop.
570
+ There is nothing to configure in JavaScript and no OpenTelemetry package to add:
571
+ the React Native SDK creates, queues and sends no spans of its own.
572
+
573
+ > **Native versions:** tracing needs the first LogDrop Android and iOS SDK
574
+ > releases after 2.1.10. With 2.1.10 (what this version of the React Native SDK
575
+ > depends on) no header is added and `flushOtlpTracing` resolves `false`.
576
+
577
+ - **When it runs:** only while HTTP tracking is turned on for your LogDrop
578
+ project and the SDK is enabled. Otherwise no header is added and no span is
579
+ recorded. On the first launch after install, tracing starts once the SDK has
580
+ received your project's settings from LogDrop; requests sent before that carry
581
+ no header.
582
+ - **Your own trace context:** a valid `traceparent` you set yourself is kept,
583
+ sampled or not, and LogDrop sends no span for that request: the tracer that
584
+ set it owns that span. A missing, malformed or all-zero one is replaced.
585
+ - **Not traced:** requests to LogDrop's own endpoints.
586
+ - **What a span contains:** method, scheme, host and port, status code or error
587
+ class, timing, trace and span IDs, and your app's identifier and version. No
588
+ paths, query strings, headers or bodies.
589
+ - **Delivery:** spans are stored encrypted on the device and sent to your LogDrop
590
+ base URL in the background, with your app ID. Changing the app ID with
591
+ `LogDrop.setAppId` drops the spans queued for the previous one.
592
+ `LogDrop.flushOtlpTracing()` sends them right away.
593
+ - **Android requirement:** apply `io.logdrop.gradle.plugin` (see
594
+ [Android Setup](#-android-setup)). It adds the LogDrop interceptor to every
595
+ OkHttp client in the app, including the one React Native's networking uses.
596
+ - **iOS requirement:** none beyond `LogDrop.init`. React Native's networking uses
597
+ the default `URLSession` configuration, which the SDK instruments.
598
+ - **Your backend** must read `traceparent` (for example an OpenTelemetry-instrumented
599
+ service or the LogDrop Java agent) for its spans to join the trace.
600
+
601
+ ---
602
+
543
603
  ## 🔑 API Keys
544
604
 
545
605
  You can create and manage your API keys in the LogDrop Dashboard.
@@ -77,5 +77,5 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
77
77
  dependencies {
78
78
  implementation "com.facebook.react:react-android"
79
79
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
80
- implementation "io.logdrop:sdk:2.1.10"
80
+ implementation "io.logdrop:sdk:${getExtOrDefault('logdropSdkVersion')}"
81
81
  }
@@ -3,3 +3,6 @@ LogdropReactNative_minSdkVersion=24
3
3
  LogdropReactNative_targetSdkVersion=34
4
4
  LogdropReactNative_compileSdkVersion=35
5
5
  LogdropReactNative_ndkVersion=27.1.12297006
6
+ # Native LogDrop Android SDK; an app can override it with `ext.logdropSdkVersion`. Tracing
7
+ # (traceparent propagation and OTLP export) needs the first native release after 2.1.10.
8
+ LogdropReactNative_logdropSdkVersion=2.1.11-alpha1
@@ -5,6 +5,9 @@ import com.facebook.react.bridge.ReactMethod
5
5
  import com.facebook.react.bridge.ReadableMap
6
6
  import com.facebook.react.bridge.Promise
7
7
  import io.logdrop.sdk.LogDrop
8
+ import java.lang.reflect.Method
9
+ import java.util.concurrent.ExecutorService
10
+ import java.util.concurrent.Executors
8
11
 
9
12
  class LogDropReactNativeModule(reactContext: ReactApplicationContext) :
10
13
  ReactContextBaseJavaModule(reactContext) {
@@ -51,6 +54,30 @@ class LogDropReactNativeModule(reactContext: ReactApplicationContext) :
51
54
  LogDrop.sendLogs()
52
55
  }
53
56
 
57
+ /**
58
+ * Waits up to [timeoutMs] for the native span queue to drain. The native call blocks, so it runs
59
+ * off the React Native module queue, each call on its own pooled thread so concurrent flushes do
60
+ * not wait for each other. Always resolves, with false instead of rejecting, and false when the
61
+ * native SDK predates the exporter.
62
+ */
63
+ @ReactMethod
64
+ fun flushOtlpTracing(timeoutMs: Double, promise: Promise) {
65
+ val flush = nativeTraceFlush
66
+ if (flush == null) {
67
+ promise.resolve(false)
68
+ return
69
+ }
70
+ val timeoutMillis = traceFlushTimeoutMillis(timeoutMs)
71
+ traceFlushExecutor.execute {
72
+ val delivered = try {
73
+ flush.invoke(LogDrop, timeoutMillis) == true
74
+ } catch (_: Throwable) {
75
+ false
76
+ }
77
+ promise.resolve(delivered)
78
+ }
79
+ }
80
+
54
81
  @ReactMethod
55
82
  fun trackCustomEvent(eventName: String, properties: ReadableMap?) {
56
83
  LogDrop.trackCustomEvent(eventName, properties?.toHashMap() ?: emptyMap())
@@ -116,5 +143,25 @@ class LogDropReactNativeModule(reactContext: ReactApplicationContext) :
116
143
 
117
144
  companion object {
118
145
  const val NAME = "LogDropReactNative"
146
+
147
+ /**
148
+ * Native `LogDrop.flushOtlpTracing(Long): Boolean`, looked up by reflection so the module still
149
+ * builds against native SDKs released before the exporter (2.1.10 and older). The native SDK's
150
+ * consumer R8 rules keep the public members of `io.logdrop.sdk.LogDrop`.
151
+ */
152
+ private val nativeTraceFlush: Method? by lazy {
153
+ try {
154
+ LogDrop::class.java.getMethod("flushOtlpTracing", java.lang.Long.TYPE)
155
+ } catch (_: Exception) {
156
+ null
157
+ }
158
+ }
159
+
160
+ // Each flush is bounded by its native timeout (at most 5 s); idle threads end after 60 s.
161
+ private val traceFlushExecutor: ExecutorService by lazy {
162
+ Executors.newCachedThreadPool { runnable ->
163
+ Thread(runnable, "LogDrop-RN-TraceFlush").apply { isDaemon = true }
164
+ }
165
+ }
119
166
  }
120
167
  }
@@ -16,3 +16,14 @@ fun readableMapToLogFlow(logFlowMap: ReadableMap?): LogFlow? {
16
16
 
17
17
  return LogFlow(name = name, id = id, customAttributes = customAttributes)
18
18
  }
19
+
20
+ internal const val DEFAULT_TRACE_FLUSH_TIMEOUT_MILLIS = 2_000L
21
+ internal const val MAX_TRACE_FLUSH_TIMEOUT_MILLIS = 5_000L
22
+
23
+ /** Clamps a JavaScript timeout to the 1..5000 ms range `LogDrop.flushOtlpTracing` accepts. */
24
+ internal fun traceFlushTimeoutMillis(timeoutMs: Double): Long =
25
+ if (timeoutMs.isNaN() || timeoutMs.isInfinite()) {
26
+ DEFAULT_TRACE_FLUSH_TIMEOUT_MILLIS
27
+ } else {
28
+ Math.round(timeoutMs).coerceIn(1L, MAX_TRACE_FLUSH_TIMEOUT_MILLIS)
29
+ }
@@ -18,9 +18,13 @@ RCT_EXTERN_METHOD(userUpdate:(NSString *)userUuid)
18
18
  RCT_EXTERN_METHOD(setCustomAttributes:(NSDictionary *)attributes)
19
19
  RCT_EXTERN_METHOD(removeCustomAttribute:(NSString *)key)
20
20
  RCT_EXTERN_METHOD(sendLogs)
21
+ RCT_EXTERN_METHOD(flushOtlpTracing:(nonnull NSNumber *)timeoutMs
22
+ resolve:(RCTPromiseResolveBlock)resolve
23
+ reject:(RCTPromiseRejectBlock)reject)
21
24
  RCT_EXTERN_METHOD(trackCustomEvent:(NSString *)eventName
22
25
  properties:(NSDictionary * _Nullable)properties)
23
26
  RCT_EXTERN_METHOD(trackDeepLink:(NSString *)urlString)
27
+ RCT_EXTERN_METHOD(setAppId:(NSString *)appId)
24
28
  RCT_EXTERN_METHOD(saveCustomCrashReport:(NSString *)threadName
25
29
  stackTrace:(NSString *)stackTrace
26
30
  crashType:(NSString *)crashType)
@@ -6,6 +6,11 @@ class LogDropReactNative: NSObject {
6
6
 
7
7
  @objc
8
8
  func initLogDrop(_ config: NSDictionary) {
9
+ // React Native creates its one URLSession from the default configuration on its first
10
+ // request. Install the SDK's configuration hook now rather than in the main-queue block
11
+ // below, so a request sent right after init still gets the LogDrop URL protocol. The
12
+ // protocol handles nothing until the SDK is initialized and tracking is on.
13
+ URLSessionConfiguration.enableConfigurationSwizzle()
9
14
  DispatchQueue.main.async {
10
15
  let builder = LogDropConfig.Builder()
11
16
 
@@ -133,6 +138,28 @@ class LogDropReactNative: NSObject {
133
138
  LogDrop.sendLogs()
134
139
  }
135
140
 
141
+ /// Resolves with the native flush result, or false once `timeoutMs` (1...5000) passes first.
142
+ /// The native drain keeps running after a timeout; only the wait is bounded. Resolves false
143
+ /// at once when the native SDK predates the exporter (2.1.10 and older).
144
+ @objc
145
+ func flushOtlpTracing(
146
+ _ timeoutMs: NSNumber,
147
+ resolve: @escaping RCTPromiseResolveBlock,
148
+ reject: RCTPromiseRejectBlock
149
+ ) {
150
+ guard let flush = TraceFlushSettlement.nativeFlush() else {
151
+ resolve(false)
152
+ return
153
+ }
154
+ let settlement = TraceFlushSettlement(resolve)
155
+ flush { delivered in settlement.settle(delivered.boolValue) }
156
+ DispatchQueue.global(qos: .utility).asyncAfter(
157
+ deadline: .now() + .milliseconds(TraceFlushSettlement.timeoutMillis(timeoutMs))
158
+ ) {
159
+ settlement.settle(false)
160
+ }
161
+ }
162
+
136
163
  @objc
137
164
  func trackCustomEvent(_ eventName: String, properties: NSDictionary?) {
138
165
  LogDrop.trackCustomEvent(
@@ -168,3 +195,41 @@ class LogDropReactNative: NSObject {
168
195
  crashType: crashType)
169
196
  }
170
197
  }
198
+
199
+ /// Resolves a React Native promise exactly once, from whichever of flush or timeout finishes first.
200
+ final class TraceFlushSettlement {
201
+ static let defaultTimeoutMillis = 2_000
202
+ static let maxTimeoutMillis = 5_000
203
+
204
+ private let lock = NSLock()
205
+ private var resolve: RCTPromiseResolveBlock?
206
+
207
+ init(_ resolve: @escaping RCTPromiseResolveBlock) {
208
+ self.resolve = resolve
209
+ }
210
+
211
+ func settle(_ delivered: Bool) {
212
+ lock.lock()
213
+ let pending = resolve
214
+ resolve = nil
215
+ lock.unlock()
216
+ pending?(delivered)
217
+ }
218
+
219
+ /// The native `+[LogDrop logDropFlushOtlpTracing:]`, found at run time so the bridge still
220
+ /// builds against native SDKs released before the exporter.
221
+ static func nativeFlush() -> ((@escaping @convention(block) (NSNumber) -> Void) -> Void)? {
222
+ let selector = NSSelectorFromString("logDropFlushOtlpTracing:")
223
+ let native: AnyClass = LogDrop.self
224
+ guard let method = class_getClassMethod(native, selector) else { return nil }
225
+ typealias Flush = @convention(c) (AnyClass, Selector, @convention(block) (NSNumber) -> Void) -> Void
226
+ let implementation = unsafeBitCast(method_getImplementation(method), to: Flush.self)
227
+ return { completion in implementation(native, selector, completion) }
228
+ }
229
+
230
+ static func timeoutMillis(_ value: NSNumber) -> Int {
231
+ let millis = value.doubleValue
232
+ guard millis.isFinite else { return defaultTimeoutMillis }
233
+ return Int(min(Double(maxTimeoutMillis), max(1, millis.rounded())))
234
+ }
235
+ }
@@ -13,6 +13,12 @@ export let LogDropPopupShowResult = /*#__PURE__*/function (LogDropPopupShowResul
13
13
  LogDropPopupShowResult["NotInitialized"] = "notInitialized";
14
14
  return LogDropPopupShowResult;
15
15
  }({});
16
+
17
+ /** Default wait for {@link LogDrop.flushOtlpTracing}. */
18
+ const DEFAULT_TRACE_FLUSH_TIMEOUT_MS = 2_000;
19
+ /** Longest wait the native SDKs accept for one explicit trace flush. */
20
+ const MAX_TRACE_FLUSH_TIMEOUT_MS = 5_000;
21
+ const traceFlushTimeout = timeoutMs => Number.isFinite(timeoutMs) ? Math.min(MAX_TRACE_FLUSH_TIMEOUT_MS, Math.max(1, Math.round(timeoutMs))) : DEFAULT_TRACE_FLUSH_TIMEOUT_MS;
16
22
  export default class LogDrop {
17
23
  static init = config => {
18
24
  if (Platform.OS === 'ios' || Platform.OS === 'android') {
@@ -68,6 +74,33 @@ export default class LogDrop {
68
74
  LogDropReactNative.sendLogs();
69
75
  };
70
76
 
77
+ /**
78
+ * Asks the native SDK to send the HTTP client spans it has queued and waits at
79
+ * most `timeoutMs` (1–5000 ms, default 2000).
80
+ *
81
+ * Resolves `true` when nothing is left in the native queue and no span was
82
+ * dropped since the previous flush. Resolves `false` on timeout, while delivery
83
+ * is still pending, after spans were dropped, with native SDKs that predate the
84
+ * exporter (2.1.10 and older), and on platforms other than Android and iOS.
85
+ * Never rejects. The result does not say whether tracing is on.
86
+ *
87
+ * Spans come only from the native HTTP trackers, which also add the
88
+ * `traceparent` header to requests made with `fetch`, `XMLHttpRequest` and
89
+ * libraries built on them. The JavaScript layer creates, queues and sends no
90
+ * spans of its own.
91
+ */
92
+ static flushOtlpTracing = async (timeoutMs = DEFAULT_TRACE_FLUSH_TIMEOUT_MS) => {
93
+ if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
94
+ return false;
95
+ }
96
+ try {
97
+ const delivered = await LogDropReactNative.flushOtlpTracing(traceFlushTimeout(timeoutMs));
98
+ return delivered === true;
99
+ } catch {
100
+ return false;
101
+ }
102
+ };
103
+
71
104
  /** Tracks a customer-defined event with JSON-compatible properties. */
72
105
  static trackCustomEvent = (eventName, properties = {}) => {
73
106
  LogDropReactNative.trackCustomEvent(eventName, properties);
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","LogDropErrorTracking","LogDropReactNative","LogDropPopupShowResult","LogDrop","init","config","OS","initLogDrop","start","onRemoteMessageReceived","message","onNewFcmPushToken","token","onNewHmsPushToken","onNewApnsToken","isLogDropPush","showPendingPushPopup","NotInitialized","result","Shown","NothingToShow","sendLogs","trackCustomEvent","eventName","properties","trackDeepLink","url","setAppId","appId","userUpdate","userId","setCustomAttributes","attributes","removeCustomAttribute","key","e","tag","logFlow","d","i","w"],"sourceRoot":"../../src","sources":["LogDrop.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,oBAAoB,QAAQ,iCAA8B;AAGnE,SAASC,kBAAkB,QAAQ,yBAAsB;AAEzD,WAAYC,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAMlC,eAAe,MAAMC,OAAO,CAAC;EAC3B,OAAOC,IAAI,GAAIC,MAAqB,IAAW;IAC7C,IAAIN,QAAQ,CAACO,EAAE,KAAK,KAAK,IAAIP,QAAQ,CAACO,EAAE,KAAK,SAAS,EAAE;MACtDL,kBAAkB,CAACM,WAAW,GAAGF,MAAM,CAAC;MACxCL,oBAAoB,CAACQ,KAAK,CAAC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GAAG,EAAE1B,OAAO,EAAE2B,OAAO,CAAC;EAC7C,CAAC;EAED,OAAOE,CAAC,GAAGA,CAACH,GAAW,EAAE1B,OAAe,EAAE2B,OAAiB,KAAW;IACpEpC,kBAAkB,CAACsC,CAAC,CAACH,GAAG,EAAE1B,OAAO,EAAE2B,OAAO,CAAC;EAC7C,CAAC;EAED,OAAOG,CAAC,GAAGA,CAACJ,GAAW,EAAE1B,OAAe,EAAE2B,OAAiB,KAAW;IACpEpC,kBAAkB,CAACuC,CAAC,CAACJ,GAAG,EAAE1B,OAAO,EAAE2B,OAAO,CAAC;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["Platform","LogDropErrorTracking","LogDropReactNative","LogDropPopupShowResult","DEFAULT_TRACE_FLUSH_TIMEOUT_MS","MAX_TRACE_FLUSH_TIMEOUT_MS","traceFlushTimeout","timeoutMs","Number","isFinite","Math","min","max","round","LogDrop","init","config","OS","initLogDrop","start","onRemoteMessageReceived","message","onNewFcmPushToken","token","onNewHmsPushToken","onNewApnsToken","isLogDropPush","showPendingPushPopup","NotInitialized","result","Shown","NothingToShow","sendLogs","flushOtlpTracing","delivered","trackCustomEvent","eventName","properties","trackDeepLink","url","setAppId","appId","userUpdate","userId","setCustomAttributes","attributes","removeCustomAttribute","key","e","tag","logFlow","d","i","w"],"sourceRoot":"../../src","sources":["LogDrop.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,oBAAoB,QAAQ,iCAA8B;AAGnE,SAASC,kBAAkB,QAAQ,yBAAsB;AAEzD,WAAYC,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;;AAMlC;AACA,MAAMC,8BAA8B,GAAG,KAAK;AAC5C;AACA,MAAMC,0BAA0B,GAAG,KAAK;AAExC,MAAMC,iBAAiB,GAAIC,SAAiB,IAC1CC,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hD,kBAAkB,CAACmD,CAAC,CAACJ,GAAG,EAAE5B,OAAO,EAAE6B,OAAO,CAAC;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -19,6 +19,22 @@ export default class LogDrop {
19
19
  }) => Promise<boolean>;
20
20
  static showPendingPushPopup: () => Promise<LogDropPopupShowResult>;
21
21
  static sendLogs: () => void;
22
+ /**
23
+ * Asks the native SDK to send the HTTP client spans it has queued and waits at
24
+ * most `timeoutMs` (1–5000 ms, default 2000).
25
+ *
26
+ * Resolves `true` when nothing is left in the native queue and no span was
27
+ * dropped since the previous flush. Resolves `false` on timeout, while delivery
28
+ * is still pending, after spans were dropped, with native SDKs that predate the
29
+ * exporter (2.1.10 and older), and on platforms other than Android and iOS.
30
+ * Never rejects. The result does not say whether tracing is on.
31
+ *
32
+ * Spans come only from the native HTTP trackers, which also add the
33
+ * `traceparent` header to requests made with `fetch`, `XMLHttpRequest` and
34
+ * libraries built on them. The JavaScript layer creates, queues and sends no
35
+ * spans of its own.
36
+ */
37
+ static flushOtlpTracing: (timeoutMs?: number) => Promise<boolean>;
22
38
  /** Tracks a customer-defined event with JSON-compatible properties. */
23
39
  static trackCustomEvent: (eventName: string, properties?: Record<string, unknown>) => void;
24
40
  static trackDeepLink: (url: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"LogDrop.d.ts","sourceRoot":"","sources":["../../../src/LogDrop.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,OAAO,MAAM,WAAW,CAAC;AAGhC,oBAAY,sBAAsB;IAChC,KAAK,UAAU;IACf,aAAa,kBAAkB;IAC/B,cAAc,mBAAmB;CAClC;AAED,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,MAAM,CAAC,IAAI,GAAI,QAAQ,aAAa,KAAG,IAAI,CAKzC;IAEF,MAAM,CAAC,uBAAuB,GAAI,SAAS;QACzC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM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MAAM,EAAE,OAAO,CAAM,KACvC,IAAI,CAEL;IAEF,MAAM,CAAC,aAAa,GAAI,KAAK,MAAM,KAAG,IAAI,CAExC;IAEF,MAAM,CAAC,QAAQ,GAAI,OAAO,MAAM,KAAG,IAAI,CAErC;IAEF,MAAM,CAAC,UAAU,GAAI,QAAQ,MAAM,KAAG,IAAI,CAExC;IAEF,yEAAyE;IACzE,MAAM,CAAC,mBAAmB,GAAI,YAAY,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,IAAI,CAErE;IAEF,kEAAkE;IAClE,MAAM,CAAC,qBAAqB,GAAI,KAAK,MAAM,KAAG,IAAI,CAEhD;IAEF,MAAM,CAAC,CAAC,GAAI,KAAK,MAAM,EAAE,SAAS,MAAM,EAAE,UAAU,OAAO,KAAG,IAAI,CAEhE;IAEF,MAAM,CAAC,CAAC,GAAI,KAAK,MAAM,EAAE,SAAS,MAAM,EAAE,UAAU,OAAO,KAAG,IAAI,CAEhE;IAEF,MAAM,CAAC,CAAC,GAAI,KAAK,MAAM,EAAE,SAAS,MAAM,EAAE,UAAU,OAAO,KAAG,IAAI,CAEhE;IAEF,MAAM,CAAC,CAAC,GAAI,KAAK,MAAM,EAAE,SAAS,MAAM,EAAE,UAAU,OAAO,KAAG,IAAI,CAEhE;CACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@log-drop/react-native",
3
- "version": "2.1.1",
3
+ "version": "2.1.2-alpha1",
4
4
  "description": "LogDrop React Native SDK",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
package/src/LogDrop.ts CHANGED
@@ -14,6 +14,16 @@ export enum LogDropPopupShowResult {
14
14
  NotInitialized = 'notInitialized',
15
15
  }
16
16
 
17
+ /** Default wait for {@link LogDrop.flushOtlpTracing}. */
18
+ const DEFAULT_TRACE_FLUSH_TIMEOUT_MS = 2_000;
19
+ /** Longest wait the native SDKs accept for one explicit trace flush. */
20
+ const MAX_TRACE_FLUSH_TIMEOUT_MS = 5_000;
21
+
22
+ const traceFlushTimeout = (timeoutMs: number): number =>
23
+ Number.isFinite(timeoutMs)
24
+ ? Math.min(MAX_TRACE_FLUSH_TIMEOUT_MS, Math.max(1, Math.round(timeoutMs)))
25
+ : DEFAULT_TRACE_FLUSH_TIMEOUT_MS;
26
+
17
27
  export default class LogDrop {
18
28
  static init = (config: LogDropConfig): void => {
19
29
  if (Platform.OS === 'ios' || Platform.OS === 'android') {
@@ -81,6 +91,38 @@ export default class LogDrop {
81
91
  LogDropReactNative.sendLogs();
82
92
  };
83
93
 
94
+ /**
95
+ * Asks the native SDK to send the HTTP client spans it has queued and waits at
96
+ * most `timeoutMs` (1–5000 ms, default 2000).
97
+ *
98
+ * Resolves `true` when nothing is left in the native queue and no span was
99
+ * dropped since the previous flush. Resolves `false` on timeout, while delivery
100
+ * is still pending, after spans were dropped, with native SDKs that predate the
101
+ * exporter (2.1.10 and older), and on platforms other than Android and iOS.
102
+ * Never rejects. The result does not say whether tracing is on.
103
+ *
104
+ * Spans come only from the native HTTP trackers, which also add the
105
+ * `traceparent` header to requests made with `fetch`, `XMLHttpRequest` and
106
+ * libraries built on them. The JavaScript layer creates, queues and sends no
107
+ * spans of its own.
108
+ */
109
+ static flushOtlpTracing = async (
110
+ timeoutMs: number = DEFAULT_TRACE_FLUSH_TIMEOUT_MS
111
+ ): Promise<boolean> => {
112
+ if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
113
+ return false;
114
+ }
115
+
116
+ try {
117
+ const delivered = await LogDropReactNative.flushOtlpTracing(
118
+ traceFlushTimeout(timeoutMs)
119
+ );
120
+ return delivered === true;
121
+ } catch {
122
+ return false;
123
+ }
124
+ };
125
+
84
126
  /** Tracks a customer-defined event with JSON-compatible properties. */
85
127
  static trackCustomEvent = (
86
128
  eventName: string,