9
9
10
10
import com .facebook .react .bridge .Promise ;
11
11
import com .facebook .react .bridge .ReactApplicationContext ;
12
- import com .facebook .react .bridge .ReactContextBaseJavaModule ;
13
12
import com .facebook .react .bridge .ReactMethod ;
13
+ import com .facebook .react .bridge .ReadableMap ;
14
14
import com .instabug .apm .APM ;
15
15
import com .instabug .apm .model .ExecutionTrace ;
16
16
import com .instabug .apm .networking .APMNetworkLogger ;
17
17
import com .instabug .apm .networkinterception .cp .APMCPNetworkLog ;
18
+ import com .instabug .reactlibrary .utils .EventEmitterModule ;
19
+ import com .instabug .apm .networkinterception .cp .APMCPNetworkLog ;
18
20
import com .instabug .reactlibrary .utils .MainThreadHandler ;
19
21
20
- import org .json .JSONException ;
21
- import org .json .JSONObject ;
22
-
23
- import java .lang .reflect .InvocationTargetException ;
24
22
import java .lang .reflect .Method ;
25
23
26
24
import java .util .HashMap ;
29
27
30
28
import static com .instabug .reactlibrary .utils .InstabugUtil .getMethod ;
31
29
32
- public class RNInstabugAPMModule extends ReactContextBaseJavaModule {
30
+ public class RNInstabugAPMModule extends EventEmitterModule {
33
31
34
32
public RNInstabugAPMModule (ReactApplicationContext reactApplicationContext ) {
35
33
super (reactApplicationContext );
@@ -59,7 +57,6 @@ public void run() {
59
57
60
58
/**
61
59
* Enables or disables APM.
62
- *
63
60
* @param isEnabled boolean indicating enabled or disabled.
64
61
*/
65
62
@ ReactMethod
@@ -78,7 +75,6 @@ public void run() {
78
75
79
76
/**
80
77
* Enables or disables app launch tracking.
81
- *
82
78
* @param isEnabled boolean indicating enabled or disabled.
83
79
*/
84
80
@ ReactMethod
@@ -114,7 +110,6 @@ public void run() {
114
110
115
111
/**
116
112
* Enables or disables auto UI tracing
117
- *
118
113
* @param isEnabled boolean indicating enabled or disabled.
119
114
*/
120
115
@ ReactMethod
@@ -213,6 +208,7 @@ public void run() {
213
208
* Starts an execution trace
214
209
*
215
210
* @param name string name of the trace.
211
+ *
216
212
* @deprecated see {@link #startFlow(String)}
217
213
*/
218
214
@ Deprecated
@@ -243,6 +239,7 @@ public void run() {
243
239
* @param id String id of the trace.
244
240
* @param key attribute key
245
241
* @param value attribute value. Null to remove attribute
242
+ *
246
243
* @deprecated see {@link #setFlowAttribute}
247
244
*/
248
245
@ Deprecated
@@ -264,6 +261,7 @@ public void run() {
264
261
* Ends a trace
265
262
*
266
263
* @param id string id of the trace.
264
+ *
267
265
* @deprecated see {@link #endFlow}
268
266
*/
269
267
@ Deprecated
@@ -283,7 +281,6 @@ public void run() {
283
281
284
282
/**
285
283
* Starts a UI trace
286
- *
287
284
* @param name string name of the UI trace.
288
285
*/
289
286
@ ReactMethod
@@ -332,44 +329,71 @@ private void networkLogAndroid(final double requestStartTime,
332
329
final double statusCode ,
333
330
final String responseContentType ,
334
331
@ Nullable final String errorDomain ,
332
+ @ Nullable final ReadableMap w3cAttributes ,
335
333
@ Nullable final String gqlQueryName ,
336
- @ Nullable final String serverErrorMessage ) {
334
+ @ Nullable final String serverErrorMessage
335
+ ) {
337
336
try {
338
337
APMNetworkLogger networkLogger = new APMNetworkLogger ();
339
338
340
339
final boolean hasError = errorDomain != null && !errorDomain .isEmpty ();
341
340
final String errorMessage = hasError ? errorDomain : null ;
341
+ Boolean isW3cHeaderFound =false ;
342
+ Long partialId =null ;
343
+ Long networkStartTimeInSeconds =null ;
344
+
342
345
346
+ try {
347
+ if (!w3cAttributes .isNull ("isW3cHeaderFound" )) {
348
+ isW3cHeaderFound = w3cAttributes .getBoolean ("isW3cHeaderFound" );
349
+ }
350
+
351
+ if (!w3cAttributes .isNull ("partialId" )) {
352
+ partialId =(long ) w3cAttributes .getDouble ("partialId" );
353
+ networkStartTimeInSeconds = (long ) w3cAttributes .getDouble ("networkStartTimeInSeconds" );
354
+ }
355
+
356
+ } catch (Exception e ) {
357
+ e .printStackTrace ();
358
+ }
359
+ APMCPNetworkLog .W3CExternalTraceAttributes w3cExternalTraceAttributes =
360
+ new APMCPNetworkLog .W3CExternalTraceAttributes (
361
+ isW3cHeaderFound ,
362
+ partialId ,
363
+ networkStartTimeInSeconds ,
364
+ w3cAttributes .getString ("w3cGeneratedHeader" ),
365
+ w3cAttributes .getString ("w3cCaughtHeader" )
366
+ );
343
367
try {
344
368
Method method = getMethod (Class .forName ("com.instabug.apm.networking.APMNetworkLogger" ), "log" , long .class , long .class , String .class , String .class , long .class , String .class , String .class , String .class , String .class , String .class , long .class , int .class , String .class , String .class , String .class , String .class , APMCPNetworkLog .W3CExternalTraceAttributes .class );
345
369
if (method != null ) {
346
- method .invoke (
347
- networkLogger ,
348
- (long ) requestStartTime * 1000 ,
349
- (long ) requestDuration ,
350
- requestHeaders ,
351
- requestBody ,
352
- (long ) requestBodySize ,
353
- requestMethod ,
354
- requestUrl ,
355
- requestContentType ,
356
- responseHeaders ,
357
- responseBody ,
358
- (long ) responseBodySize ,
359
- (int ) statusCode ,
360
- responseContentType ,
361
- errorMessage ,
362
- gqlQueryName ,
363
- serverErrorMessage ,
364
- null
365
- );
370
+ method .invoke (
371
+ networkLogger ,
372
+ (long ) requestStartTime * 1000 ,
373
+ (long ) requestDuration ,
374
+ requestHeaders ,
375
+ requestBody ,
376
+ (long ) requestBodySize ,
377
+ requestMethod ,
378
+ requestUrl ,
379
+ requestContentType ,
380
+ responseHeaders ,
381
+ responseBody ,
382
+ (long )responseBodySize ,
383
+ (int ) statusCode ,
384
+ responseContentType ,
385
+ errorMessage ,
386
+ gqlQueryName ,
387
+ serverErrorMessage ,
388
+ w3cExternalTraceAttributes
389
+ );
366
390
} else {
367
391
Log .e ("IB-CP-Bridge" , "APMNetworkLogger.log was not found by reflection" );
368
392
}
369
393
} catch (Throwable e ) {
370
394
e .printStackTrace ();
371
395
}
372
- } catch (Throwable e ) {
396
+ } catch (Throwable e ) {
373
397
e .printStackTrace ();
374
398
}
375
399
}
0 commit comments