16
16
import com .instabug .flutter .util .Reflection ;
17
17
import com .instabug .flutter .util .ThreadManager ;
18
18
19
- import io .flutter .plugin .common .BinaryMessenger ;
20
-
21
19
import org .json .JSONObject ;
22
20
23
21
import java .lang .reflect .Method ;
24
22
import java .util .HashMap ;
25
23
import java .util .Map ;
26
24
import java .util .concurrent .Callable ;
27
25
26
+ import io .flutter .plugin .common .BinaryMessenger ;
27
+
28
28
public class ApmApi implements ApmPigeon .ApmHostApi {
29
29
private final String TAG = ApmApi .class .getName ();
30
30
private final HashMap <String , ExecutionTrace > traces = new HashMap <>();
@@ -40,14 +40,14 @@ public static void init(BinaryMessenger messenger, Callable<Float> refreshRatePr
40
40
ApmPigeon .ApmHostApi .setup (messenger , api );
41
41
}
42
42
43
- /**
44
- * The function sets the enabled status of APM.
45
- *
46
- * @param isEnabled The `setEnabled` method in the code snippet is used to enable or disable a
47
- * feature, and it takes a `Boolean` parameter named `isEnabled`. When this method is called with
48
- * `true`, it enables the feature, and when called with `false`, it disables the feature. The method
49
- * internally calls
50
- */
43
+ /**
44
+ * The function sets the enabled status of APM.
45
+ *
46
+ * @param isEnabled The `setEnabled` method in the code snippet is used to enable or disable a
47
+ * feature, and it takes a `Boolean` parameter named `isEnabled`. When this method is called with
48
+ * `true`, it enables the feature, and when called with `false`, it disables the feature. The method
49
+ * internally calls
50
+ */
51
51
@ Override
52
52
public void setEnabled (@ NonNull Boolean isEnabled ) {
53
53
try {
@@ -58,12 +58,12 @@ public void setEnabled(@NonNull Boolean isEnabled) {
58
58
}
59
59
60
60
/**
61
- * Sets the cold app launch enabled status using the APM library.
62
- *
63
- * @param isEnabled The `isEnabled` parameter is a Boolean value that indicates whether cold app launch
64
- * is enabled or not. When `isEnabled` is set to `true`, cold app launch is enabled, and when it is set
65
- * to `false`, cold app launch is disabled.
66
- */
61
+ * Sets the cold app launch enabled status using the APM library.
62
+ *
63
+ * @param isEnabled The `isEnabled` parameter is a Boolean value that indicates whether cold app launch
64
+ * is enabled or not. When `isEnabled` is set to `true`, cold app launch is enabled, and when it is set
65
+ * to `false`, cold app launch is disabled.
66
+ */
67
67
@ Override
68
68
public void setColdAppLaunchEnabled (@ NonNull Boolean isEnabled ) {
69
69
try {
@@ -73,14 +73,14 @@ public void setColdAppLaunchEnabled(@NonNull Boolean isEnabled) {
73
73
}
74
74
}
75
75
76
- /**
77
- * The function sets the auto UI trace enabled status in an APM system, handling any exceptions that
78
- * may occur.
79
- *
80
- * @param isEnabled The `isEnabled` parameter is a Boolean value that indicates whether the Auto UI
81
- * trace feature should be enabled or disabled. When `isEnabled` is set to `true`, the Auto UI trace
82
- * feature is enabled, and when it is set to `false`, the feature is disabled.
83
- */
76
+ /**
77
+ * The function sets the auto UI trace enabled status in an APM system, handling any exceptions that
78
+ * may occur.
79
+ *
80
+ * @param isEnabled The `isEnabled` parameter is a Boolean value that indicates whether the Auto UI
81
+ * trace feature should be enabled or disabled. When `isEnabled` is set to `true`, the Auto UI trace
82
+ * feature is enabled, and when it is set to `false`, the feature is disabled.
83
+ */
84
84
@ Override
85
85
public void setAutoUITraceEnabled (@ NonNull Boolean isEnabled ) {
86
86
try {
@@ -90,21 +90,20 @@ public void setAutoUITraceEnabled(@NonNull Boolean isEnabled) {
90
90
}
91
91
}
92
92
93
- /**
94
- * Starts an execution trace and handles the result
95
- * using callbacks.
96
- *
97
- * @param id The `id` parameter is a non-null String that represents the identifier of the execution
98
- * trace.
99
- * @param name The `name` parameter in the `startExecutionTrace` method represents the name of the
100
- * execution trace that will be started. It is used as a reference to identify the trace during
101
- * execution monitoring.
102
- * @param result The `result` parameter in the `startExecutionTrace` method is an instance of
103
- * `ApmPigeon.Result<String>`. This parameter is used to provide the result of the execution trace
104
- * operation back to the caller. The `success` method of the `result` object is called with the
105
- *
106
- * @deprecated see {@link #startFlow}
107
- */
93
+ /**
94
+ * Starts an execution trace and handles the result
95
+ * using callbacks.
96
+ *
97
+ * @param id The `id` parameter is a non-null String that represents the identifier of the execution
98
+ * trace.
99
+ * @param name The `name` parameter in the `startExecutionTrace` method represents the name of the
100
+ * execution trace that will be started. It is used as a reference to identify the trace during
101
+ * execution monitoring.
102
+ * @param result The `result` parameter in the `startExecutionTrace` method is an instance of
103
+ * `ApmPigeon.Result<String>`. This parameter is used to provide the result of the execution trace
104
+ * operation back to the caller. The `success` method of the `result` object is called with the
105
+ * @deprecated see {@link #startFlow}
106
+ */
108
107
@ Override
109
108
public void startExecutionTrace (@ NonNull String id , @ NonNull String name , ApmPigeon .Result <String > result ) {
110
109
ThreadManager .runOnBackground (
@@ -165,7 +164,7 @@ public void startFlow(@NonNull String name) {
165
164
}
166
165
}
167
166
168
- /**
167
+ /**
169
168
* Sets custom attributes for AppFlow with a given name.
170
169
* <br/>
171
170
* Setting an attribute value to null will remove its corresponding key if it already exists.
@@ -194,7 +193,7 @@ public void setFlowAttribute(@NonNull String name, @NonNull String key, @Nullabl
194
193
}
195
194
}
196
195
197
- /**
196
+ /**
198
197
* Ends AppFlow with a given name.
199
198
*
200
199
* @param name AppFlow name to be ended. It can not be empty string or null
@@ -208,13 +207,12 @@ public void endFlow(@NonNull String name) {
208
207
}
209
208
}
210
209
211
- /**
210
+ /**
212
211
* Adds a new attribute to trace
213
212
*
214
213
* @param id String id of the trace.
215
214
* @param key attribute key
216
215
* @param value attribute value. Null to remove attribute
217
- *
218
216
* @deprecated see {@link #setFlowAttribute}
219
217
*/
220
218
@ Override
@@ -230,7 +228,6 @@ public void setExecutionTraceAttribute(@NonNull String id, @NonNull String key,
230
228
* Ends a trace
231
229
*
232
230
* @param id string id of the trace.
233
- *
234
231
* @deprecated see {@link #endFlow}
235
232
*/
236
233
@ Override
@@ -283,7 +280,7 @@ public void endAppLaunch() {
283
280
284
281
/**
285
282
* logs network-related information
286
- *
283
+ *
287
284
* @param data Map of network data object.
288
285
*/
289
286
@ Override
@@ -349,43 +346,44 @@ public void networkLogAndroid(@NonNull Map<String, Object> data) {
349
346
350
347
351
348
}
352
- if (data .containsKey ("w3CCaughtHeader" )) {
353
- w3CCaughtHeader = (String ) data .get ("w3CCaughtHeader" );
354
-
355
- }
349
+ if (data .containsKey ("w3CCaughtHeader" )) {
350
+ w3CCaughtHeader = (String ) data .get ("w3CCaughtHeader" );
356
351
352
+ }
357
353
358
- APMCPNetworkLog .W3CExternalTraceAttributes w3cExternalTraceAttributes =
359
- null ;
360
- if (isW3cHeaderFound != null ) {
361
- w3cExternalTraceAttributes = new APMCPNetworkLog .W3CExternalTraceAttributes (
362
- isW3cHeaderFound , partialId == null ? null : partialId .longValue (),
363
- networkStartTimeInSeconds == null ? null : networkStartTimeInSeconds .longValue (),
364
- w3CGeneratedHeader , w3CCaughtHeader
365
354
366
- );
367
- }
355
+ APMCPNetworkLog .W3CExternalTraceAttributes w3cExternalTraceAttributes =
356
+ null ;
357
+ if (isW3cHeaderFound != null ) {
358
+ w3cExternalTraceAttributes = new APMCPNetworkLog .W3CExternalTraceAttributes (
359
+ isW3cHeaderFound , partialId == null ? null : partialId .longValue (),
360
+ networkStartTimeInSeconds == null ? null : networkStartTimeInSeconds .longValue (),
361
+ w3CGeneratedHeader , w3CCaughtHeader
368
362
369
- Method method = Reflection .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 );
370
- if (method != null ) {
371
- method .invoke (apmNetworkLogger , requestStartTime , requestDuration , requestHeaders , requestBody , requestBodySize , requestMethod , requestUrl , requestContentType , responseHeaders , responseBody , responseBodySize , statusCode , responseContentType , errorMessage , gqlQueryName , serverErrorMessage , w3cExternalTraceAttributes );
372
- } else {
373
- Log .e (TAG , "APMNetworkLogger.log was not found by reflection" );
374
- }
363
+ );
364
+ }
375
365
376
- } catch (Exception e ){
377
- e .printStackTrace ();
366
+ Method method = Reflection .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 );
367
+ if (method != null ) {
368
+ method .invoke (apmNetworkLogger , requestStartTime , requestDuration , requestHeaders , requestBody , requestBodySize , requestMethod , requestUrl , requestContentType , responseHeaders , responseBody , responseBodySize , statusCode , responseContentType , errorMessage , gqlQueryName , serverErrorMessage , w3cExternalTraceAttributes );
369
+ } else {
370
+ Log .e (TAG , "APMNetworkLogger.log was not found by reflection" );
378
371
}
372
+
373
+ } catch (Exception e ) {
374
+ e .printStackTrace ();
379
375
}
376
+ }
380
377
381
378
382
- /**
383
- * This method is responsible for initiating a custom performance UI trace
384
- * in the APM module. It takes three parameters:
385
- * @param screenName: A string representing the name of the screen or UI element being traced.
386
- * @param microTimeStamp: A number representing the timestamp in microseconds when the trace is started.
387
- * @param traceId: A number representing the unique identifier for the trace.
388
- */
379
+ /**
380
+ * This method is responsible for initiating a custom performance UI trace
381
+ * in the APM module. It takes three parameters:
382
+ *
383
+ * @param screenName: A string representing the name of the screen or UI element being traced.
384
+ * @param microTimeStamp: A number representing the timestamp in microseconds when the trace is started.
385
+ * @param traceId: A number representing the unique identifier for the trace.
386
+ */
389
387
@ Override
390
388
public void startCpUiTrace (@ NonNull String screenName , @ NonNull Long microTimeStamp , @ NonNull Long traceId ) {
391
389
try {
@@ -396,16 +394,17 @@ public void startCpUiTrace(@NonNull String screenName, @NonNull Long microTimeSt
396
394
}
397
395
398
396
399
- /**
400
- * This method is responsible for reporting the screen
401
- * loading data from Dart side to Android side. It takes three parameters:
402
- * @param startTimeStampMicro: A number representing the start timestamp in microseconds of the screen
403
- * loading custom performance data.
404
- * @param durationMicro: A number representing the duration in microseconds of the screen loading custom
405
- * performance data.
406
- * @param uiTraceId: A number representing the unique identifier for the UI trace associated with the
407
- * screen loading.
408
- */
397
+ /**
398
+ * This method is responsible for reporting the screen
399
+ * loading data from Dart side to Android side. It takes three parameters:
400
+ *
401
+ * @param startTimeStampMicro: A number representing the start timestamp in microseconds of the screen
402
+ * loading custom performance data.
403
+ * @param durationMicro: A number representing the duration in microseconds of the screen loading custom
404
+ * performance data.
405
+ * @param uiTraceId: A number representing the unique identifier for the UI trace associated with the
406
+ * screen loading.
407
+ */
409
408
@ Override
410
409
public void reportScreenLoadingCP (@ NonNull Long startTimeStampMicro , @ NonNull Long durationMicro , @ NonNull Long uiTraceId ) {
411
410
try {
@@ -417,13 +416,14 @@ public void reportScreenLoadingCP(@NonNull Long startTimeStampMicro, @NonNull Lo
417
416
418
417
419
418
/**
420
- * This method is responsible for extend the end time if the screen loading custom
421
- * trace. It takes two parameters:
422
- * @param timeStampMicro: A number representing the timestamp in microseconds when the screen loading
423
- * custom trace is ending.
424
- * @param uiTraceId: A number representing the unique identifier for the UI trace associated with the
425
- * screen loading.
426
- */
419
+ * This method is responsible for extend the end time if the screen loading custom
420
+ * trace. It takes two parameters:
421
+ *
422
+ * @param timeStampMicro: A number representing the timestamp in microseconds when the screen loading
423
+ * custom trace is ending.
424
+ * @param uiTraceId: A number representing the unique identifier for the UI trace associated with the
425
+ * screen loading.
426
+ */
427
427
@ Override
428
428
public void endScreenLoadingCP (@ NonNull Long timeStampMicro , @ NonNull Long uiTraceId ) {
429
429
try {
@@ -435,7 +435,7 @@ public void endScreenLoadingCP(@NonNull Long timeStampMicro, @NonNull Long uiTra
435
435
436
436
437
437
/**
438
- * This method is used to check whether the end screen loading feature is enabled or not.
438
+ * This method is used to check whether the end screen loading feature is enabled or not.
439
439
*/
440
440
@ Override
441
441
public void isEndScreenLoadingEnabled (@ NonNull ApmPigeon .Result <Boolean > result ) {
@@ -453,9 +453,9 @@ public void isEnabled(@NonNull ApmPigeon.Result<Boolean> result) {
453
453
}
454
454
}
455
455
456
- /**
457
- * checks whether the screen loading feature is enabled.
458
- * */
456
+ /**
457
+ * checks whether the screen loading feature is enabled.
458
+ */
459
459
@ Override
460
460
public void isScreenLoadingEnabled (@ NonNull ApmPigeon .Result <Boolean > result ) {
461
461
try {
@@ -514,4 +514,14 @@ public void deviceRefreshRate(@NonNull ApmPigeon.Result<Double> result) {
514
514
}
515
515
}
516
516
517
+ @ Override
518
+ public void endScreenRenderForAutoUiTrace (@ NonNull Map <String , Object > data ) {
519
+
520
+ }
521
+
522
+ @ Override
523
+ public void endScreenRenderForCustomUiTrace (@ NonNull Map <String , Object > data ) {
524
+
525
+ }
526
+
517
527
}
0 commit comments