Skip to content

Commit 422b27b

Browse files
Add UI Trace APIs
1 parent 5b4c7f2 commit 422b27b

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public String getName() {
3434
}
3535

3636
/**
37-
* Enables or disables the feature Chats.
37+
* Enables or disables APM.
3838
* @param isEnabled boolean indicating enabled or disabled.
3939
*/
4040
@ReactMethod
@@ -52,7 +52,7 @@ public void run() {
5252
}
5353

5454
/**
55-
* Enables or disables the feature Chats.
55+
* Enables or disables app launch tracking.
5656
* @param isEnabled boolean indicating enabled or disabled.
5757
*/
5858
@ReactMethod
@@ -89,8 +89,10 @@ public void run() {
8989
}
9090

9191
/**
92-
* Starts a trace
92+
* Adds a new attribute to trace
9393
* @param id String id of the trace.
94+
* @param key attribute key
95+
* @param value attribute value. Null to remove attribute
9496
*/
9597
@ReactMethod
9698
public void setTraceAttribute(final String id, final String key, final String value) {
@@ -107,7 +109,7 @@ public void run() {
107109
}
108110

109111
/**
110-
* Starts a trace
112+
* Ends a trace
111113
* @param id string id of the trace.
112114
*/
113115
@ReactMethod
@@ -124,5 +126,38 @@ public void run() {
124126
});
125127
}
126128

129+
/**
130+
* Starts a UI trace
131+
* @param name string name of the UI trace.
132+
*/
133+
@ReactMethod
134+
public void startUITrace(final String name) {
135+
MainThreadHandler.runOnMainThread(new Runnable() {
136+
@Override
137+
public void run() {
138+
try {
139+
APM.startUITrace(name);
140+
} catch (Exception e) {
141+
e.printStackTrace();
142+
}
143+
}
144+
});
145+
}
127146

147+
/**
148+
* Ends the current running UI trace
149+
*/
150+
@ReactMethod
151+
public void endUITrace() {
152+
MainThreadHandler.runOnMainThread(new Runnable() {
153+
@Override
154+
public void run() {
155+
try {
156+
APM.endUITrace();
157+
} catch (Exception e) {
158+
e.printStackTrace();
159+
}
160+
}
161+
});
162+
}
128163
}

index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ export namespace NetworkLogger {
125125
function setRequestFilterExpression(expression: string): void;
126126
function setProgressHandlerForRequest(handler: () => void): void;
127127
}
128+
export class Trace {
129+
constructor(id: string, name?: string, attributes?: object);
130+
setAttribute(key: string, value: string): void;
131+
end(): void;
132+
}
133+
export namespace APM {
134+
function setEnabled(isEnabled: boolean): void;
135+
function setAppLaunchEnabled(isEnabled: boolean): void;
136+
function setNetworkEnabledIOS(isEnabled: boolean): void;
137+
function setUIHangEnabled(isEnabled: boolean): void;
138+
function startTrace(name: string): Trace;
139+
function startUITrace(name: string): void;
140+
function endUITrace(): void;
141+
}
128142
export function startWithToken(
129143
token: string,
130144
invocationEvent: invocationEvent[]

ios/RNInstabug/InstabugAPMBridge.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
- (void)setEnabled:(BOOL)isEnabled;
1515
- (void)setAppLaunchEnabled:(BOOL)isEnabled;
16-
- (void)startTrace:(NSString *)name :(NSString *)id;
17-
- (void)setTraceAttribute:(NSString *)id :(NSString *)key :(NSString *)value;
16+
- (void)setUIHangEnabled:(BOOL)isEnabled;
17+
- (void)startTrace:(NSString *)name:(NSString *)id;
18+
- (void)setTraceAttribute:(NSString *)id:(NSString *)key
19+
:(NSString *)value;
1820
- (void)endTrace:(NSString *)id;
21+
- (void)startUITrace:(NSString *)name;
22+
- (void)endUITrace;
1923

2024
extern NSMutableDictionary *traces;
2125

2226
@end
23-

ios/RNInstabug/InstabugAPMBridge.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ - (id) init
4343
IBGAPM.appLaunchEnabled = isEnabled;
4444
}
4545

46+
RCT_EXPORT_METHOD(setUIHangEnabled:(BOOL)isEnabled) {
47+
IBGAPM.UIHangEnabled = isEnabled;
48+
}
49+
4650
RCT_EXPORT_METHOD(startTrace:(NSString *)name :(NSString *)id) {
4751
IBGTrace *trace = [IBGAPM startTraceWithName:name];
4852
[traces setObject: trace forKey: id];
@@ -58,6 +62,14 @@ - (id) init
5862
[trace end];
5963
}
6064

65+
RCT_EXPORT_METHOD(startUITrace:(NSString *)name) {
66+
[IBGAPM startUITraceWithName:name];
67+
}
68+
69+
RCT_EXPORT_METHOD(endUITrace) {
70+
[IBGAPM endUITrace];
71+
}
72+
6173

6274
@synthesize description;
6375

modules/APM.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export default {
3737
}
3838
},
3939

40+
/**
41+
* Enables or disables APM UI Responsivenes tracking feature
42+
* @param {boolean} isEnabled
43+
*/
44+
setUIHangEnabled(isEnabled) {
45+
if (Platform.OS === 'ios') {
46+
IBGAPM.setUIHangEnabled(isEnabled);
47+
}
48+
},
49+
4050
/**
4151
* Starts a custom trace
4252
* @param {string} name
@@ -46,4 +56,20 @@ export default {
4656
IBGAPM.startTrace(name, id);
4757
return new Trace(id, name);
4858
},
59+
60+
/**
61+
* Starts a custom trace
62+
* @param {string} name
63+
*/
64+
startUITrace(name) {
65+
IBGAPM.startUITrace(name);
66+
},
67+
68+
/**
69+
* Starts a custom trace
70+
* @param {string} name
71+
*/
72+
endUITrace() {
73+
IBGAPM.endUITrace();
74+
},
4975
};

0 commit comments

Comments
 (0)