4
4
import android .os .SystemClock ;
5
5
import android .util .Log ;
6
6
7
+ import androidx .annotation .NonNull ;
7
8
import com .facebook .react .bridge .Promise ;
8
9
import com .facebook .react .bridge .ReactApplicationContext ;
9
10
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
@@ -123,6 +124,84 @@ public void run() {
123
124
});
124
125
}
125
126
127
+ /**
128
+ * Starts an AppFlow with the specified name.
129
+ * <br/>
130
+ * On starting two flows with the same name the older flow will end with force abandon end reason.
131
+ * AppFlow name cannot exceed 150 characters otherwise it's truncated,
132
+ * leading and trailing whitespaces are also ignored.
133
+ *
134
+ * @param name AppFlow name. It can not be empty string or null.
135
+ * Starts a new AppFlow, if APM is enabled, feature is enabled
136
+ * and Instabug SDK is initialised.
137
+ */
138
+ @ ReactMethod
139
+ public void startFlow (@ NonNull final String name ) {
140
+ MainThreadHandler .runOnMainThread (new Runnable () {
141
+ @ Override
142
+ public void run () {
143
+ try {
144
+ APM .startFlow (name );
145
+ } catch (Exception e ) {
146
+ e .printStackTrace ();
147
+ }
148
+ }
149
+ });
150
+ }
151
+
152
+ /**
153
+ * Sets custom attributes for AppFlow with a given name.
154
+ * <br/>
155
+ * Setting an attribute value to null will remove its corresponding key if it already exists.
156
+ * <br/>
157
+ * Attribute key name cannot exceed 30 characters.
158
+ * Leading and trailing whitespaces are also ignored.
159
+ * Does not accept empty strings or null.
160
+ * <br/>
161
+ * Attribute value name cannot exceed 60 characters,
162
+ * leading and trailing whitespaces are also ignored.
163
+ * Does not accept empty strings.
164
+ * <br/>
165
+ * If a trace is ended, attributes will not be added and existing ones will not be updated.
166
+ * <br/>
167
+ *
168
+ * @param name AppFlow name. It can not be empty string or null
169
+ * @param key AppFlow attribute value. It can not be empty string or null
170
+ * @param value AppFlow attribute key. It can not be empty string. Null to remove attribute
171
+ */
172
+ @ ReactMethod
173
+ public void setFlowAttribute (@ NonNull final String name , @ NonNull final String key , final String value ) {
174
+ MainThreadHandler .runOnMainThread (new Runnable () {
175
+ @ Override
176
+ public void run () {
177
+ try {
178
+ APM .setFlowAttribute (name , key , value );
179
+ } catch (Exception e ) {
180
+ e .printStackTrace ();
181
+ }
182
+ }
183
+ });
184
+ }
185
+
186
+ /**
187
+ * Ends AppFlow with a given name.
188
+ *
189
+ * @param name AppFlow name to be ended. It can not be empty string or null
190
+ */
191
+ @ ReactMethod
192
+ public void endFlow (@ NonNull final String name ) {
193
+ MainThreadHandler .runOnMainThread (new Runnable () {
194
+ @ Override
195
+ public void run () {
196
+ try {
197
+ APM .endFlow (name );
198
+ } catch (Exception e ) {
199
+ e .printStackTrace ();
200
+ }
201
+ }
202
+ });
203
+ }
204
+
126
205
/**
127
206
* Starts an execution trace
128
207
*
@@ -234,7 +313,7 @@ public void run() {
234
313
}
235
314
236
315
/**
237
- * Send Apm network log by Reflection
316
+ * Send Apm network log by Reflection
238
317
*/
239
318
@ ReactMethod
240
319
public void networkLog (String networkData ) throws JSONException {
@@ -256,8 +335,8 @@ public void networkLog(String networkData) throws JSONException {
256
335
final Integer statusCode = (Integer ) jsonObject .get ("responseCode" );
257
336
final long requestDuration = ((Number ) jsonObject .get ("duration" )).longValue ();
258
337
final long requestStartTime = ((Number ) jsonObject .get ("startTime" )).longValue () * 1000 ;
259
- final String requestHeaders = (String ) jsonObject .get ("requestHeaders" ).toString ();
260
- final String responseHeaders = (String ) jsonObject .get ("responseHeaders" ).toString ();
338
+ final String requestHeaders = (String ) jsonObject .get ("requestHeaders" ).toString ();
339
+ final String responseHeaders = (String ) jsonObject .get ("responseHeaders" ).toString ();
261
340
final String errorMessage ;
262
341
if (errorDomain .equals ("" )) {
263
342
errorMessage = null ;
@@ -268,9 +347,9 @@ public void networkLog(String networkData) throws JSONException {
268
347
String gqlQueryName = null ;
269
348
if (jsonObject .has ("gqlQueryName" )){
270
349
gqlQueryName = (String ) jsonObject .get ("gqlQueryName" );
271
- }
350
+ }
272
351
final String serverErrorMessage = (String ) jsonObject .get ("serverErrorMessage" );
273
-
352
+
274
353
try {
275
354
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 );
276
355
if (method != null ) {
0 commit comments