Skip to content

Commit d9acd3a

Browse files
chore: add store API in Flutter side
1 parent 86cb8be commit d9acd3a

File tree

8 files changed

+204
-161
lines changed

8 files changed

+204
-161
lines changed

android/src/main/java/com/instabug/flutter/modules/ApmApi.java

Lines changed: 104 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
import com.instabug.flutter.util.Reflection;
1717
import com.instabug.flutter.util.ThreadManager;
1818

19-
import io.flutter.plugin.common.BinaryMessenger;
20-
2119
import org.json.JSONObject;
2220

2321
import java.lang.reflect.Method;
2422
import java.util.HashMap;
2523
import java.util.Map;
2624
import java.util.concurrent.Callable;
2725

26+
import io.flutter.plugin.common.BinaryMessenger;
27+
2828
public class ApmApi implements ApmPigeon.ApmHostApi {
2929
private final String TAG = ApmApi.class.getName();
3030
private final HashMap<String, ExecutionTrace> traces = new HashMap<>();
@@ -40,14 +40,14 @@ public static void init(BinaryMessenger messenger, Callable<Float> refreshRatePr
4040
ApmPigeon.ApmHostApi.setup(messenger, api);
4141
}
4242

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+
*/
5151
@Override
5252
public void setEnabled(@NonNull Boolean isEnabled) {
5353
try {
@@ -58,12 +58,12 @@ public void setEnabled(@NonNull Boolean isEnabled) {
5858
}
5959

6060
/**
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+
*/
6767
@Override
6868
public void setColdAppLaunchEnabled(@NonNull Boolean isEnabled) {
6969
try {
@@ -73,14 +73,14 @@ public void setColdAppLaunchEnabled(@NonNull Boolean isEnabled) {
7373
}
7474
}
7575

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+
*/
8484
@Override
8585
public void setAutoUITraceEnabled(@NonNull Boolean isEnabled) {
8686
try {
@@ -90,21 +90,20 @@ public void setAutoUITraceEnabled(@NonNull Boolean isEnabled) {
9090
}
9191
}
9292

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+
*/
108107
@Override
109108
public void startExecutionTrace(@NonNull String id, @NonNull String name, ApmPigeon.Result<String> result) {
110109
ThreadManager.runOnBackground(
@@ -165,7 +164,7 @@ public void startFlow(@NonNull String name) {
165164
}
166165
}
167166

168-
/**
167+
/**
169168
* Sets custom attributes for AppFlow with a given name.
170169
* <br/>
171170
* 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
194193
}
195194
}
196195

197-
/**
196+
/**
198197
* Ends AppFlow with a given name.
199198
*
200199
* @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) {
208207
}
209208
}
210209

211-
/**
210+
/**
212211
* Adds a new attribute to trace
213212
*
214213
* @param id String id of the trace.
215214
* @param key attribute key
216215
* @param value attribute value. Null to remove attribute
217-
*
218216
* @deprecated see {@link #setFlowAttribute}
219217
*/
220218
@Override
@@ -230,7 +228,6 @@ public void setExecutionTraceAttribute(@NonNull String id, @NonNull String key,
230228
* Ends a trace
231229
*
232230
* @param id string id of the trace.
233-
*
234231
* @deprecated see {@link #endFlow}
235232
*/
236233
@Override
@@ -283,7 +280,7 @@ public void endAppLaunch() {
283280

284281
/**
285282
* logs network-related information
286-
*
283+
*
287284
* @param data Map of network data object.
288285
*/
289286
@Override
@@ -349,43 +346,44 @@ public void networkLogAndroid(@NonNull Map<String, Object> data) {
349346

350347

351348
}
352-
if (data.containsKey("w3CCaughtHeader")) {
353-
w3CCaughtHeader = (String) data.get("w3CCaughtHeader");
354-
355-
}
349+
if (data.containsKey("w3CCaughtHeader")) {
350+
w3CCaughtHeader = (String) data.get("w3CCaughtHeader");
356351

352+
}
357353

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
365354

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
368362

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+
}
375365

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");
378371
}
372+
373+
} catch (Exception e) {
374+
e.printStackTrace();
379375
}
376+
}
380377

381378

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+
*/
389387
@Override
390388
public void startCpUiTrace(@NonNull String screenName, @NonNull Long microTimeStamp, @NonNull Long traceId) {
391389
try {
@@ -396,16 +394,17 @@ public void startCpUiTrace(@NonNull String screenName, @NonNull Long microTimeSt
396394
}
397395

398396

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+
*/
409408
@Override
410409
public void reportScreenLoadingCP(@NonNull Long startTimeStampMicro, @NonNull Long durationMicro, @NonNull Long uiTraceId) {
411410
try {
@@ -417,13 +416,14 @@ public void reportScreenLoadingCP(@NonNull Long startTimeStampMicro, @NonNull Lo
417416

418417

419418
/**
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+
*/
427427
@Override
428428
public void endScreenLoadingCP(@NonNull Long timeStampMicro, @NonNull Long uiTraceId) {
429429
try {
@@ -435,7 +435,7 @@ public void endScreenLoadingCP(@NonNull Long timeStampMicro, @NonNull Long uiTra
435435

436436

437437
/**
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.
439439
*/
440440
@Override
441441
public void isEndScreenLoadingEnabled(@NonNull ApmPigeon.Result<Boolean> result) {
@@ -453,9 +453,9 @@ public void isEnabled(@NonNull ApmPigeon.Result<Boolean> result) {
453453
}
454454
}
455455

456-
/**
457-
* checks whether the screen loading feature is enabled.
458-
* */
456+
/**
457+
* checks whether the screen loading feature is enabled.
458+
*/
459459
@Override
460460
public void isScreenLoadingEnabled(@NonNull ApmPigeon.Result<Boolean> result) {
461461
try {
@@ -514,4 +514,14 @@ public void deviceRefreshRate(@NonNull ApmPigeon.Result<Double> result) {
514514
}
515515
}
516516

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+
517527
}

ios/Classes/Modules/ApmApi.m

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#import "ArgsRegistry.h"
44
#import "IBGAPM+PrivateAPIs.h"
55
#import "IBGTimeIntervalUnits.h"
6-
#import "IBGFrameInfo.h"
76

87
void InitApmApi(id<FlutterBinaryMessenger> messenger) {
98
ApmApi *api = [[ApmApi alloc] init];
@@ -219,17 +218,23 @@ - (void)deviceRefreshRateWithCompletion:(void (^)(NSNumber * _Nullable, FlutterE
219218
}
220219
}
221220

222-
- (void)endScreenRenderForAutoUiTraceData:(nonnull NSDictionary<NSString *,id> *)data error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
221+
- (void)endScreenRenderForAutoUiTraceData:(nonnull NSDictionary<NSString *,id> *)data error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
223222
int traceId = [data[@"traceId"] intValue];
224-
int slowFrames = [data[@"slowFramesTotalDuration"] intValue];
225-
int frozenFrames = [data[@"frozenFramesTotalDuration"] intValue];
226-
227-
NSArray<NSArray<NSNumber *> *> *rawFrames = data[@"frameData"];
228-
229-
//complete from here
223+
int slowFrames = [data[@"slowFramesTotalDuration"] intValue];
224+
int frozenFrames = [data[@"frozenFramesTotalDuration"] intValue];
230225

231-
232-
// [IBGAPM endAutoUITraceCPWithFrames:/*<#(nullable NSArray *)#>*/]
226+
NSArray<NSArray<NSNumber *> *> *rawFrames = data[@"frameData"];
227+
NSLog(@"traceID%d" , traceId);
228+
NSLog(@"slowFrames%d" , slowFrames);
229+
NSLog(@"frozenFrames%d" , frozenFrames);
230+
if (rawFrames && [rawFrames isKindOfClass:[NSArray class]]) {
231+
for (NSArray<NSNumber *> *frameValues in rawFrames) {
232+
if ([frameValues count] == 2) {
233+
NSLog(@"startTime%lld" , [frameValues[0] longLongValue]);
234+
NSLog(@"duration%lld" , [frameValues[1] longLongValue]);
235+
}
236+
}
237+
}
233238
}
234239

235240

ios/Classes/Util/IBGAPM+PrivateAPIs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <InstabugSDK/IBGAPM.h>
1010
#import "IBGTimeIntervalUnits.h"
11-
#import "IBGFrameInfo.h"
11+
//#import "IBGFrameInfo.h"
1212

1313
@interface IBGAPM (PrivateAPIs)
1414

@@ -25,8 +25,8 @@
2525

2626
+ (BOOL)isScreenRenderingOperational;
2727

28-
+ (void)endAutoUITraceCPWithFrames:(nullable NSArray<IBGFrameInfo *> *)frames;
29-
30-
+ (void)endCustomUITraceCPWithFrames:(nullable NSArray<IBGFrameInfo *> *)frames;
28+
//+ (void)endAutoUITraceCPWithFrames:(nullable NSArray<IBGFrameInfo *> *)frames;
29+
//
30+
//+ (void)endCustomUITraceCPWithFrames:(nullable NSArray<IBGFrameInfo *> *)frames;
3131

3232
@end

0 commit comments

Comments
 (0)