44import android .os .SystemClock ;
55import android .util .Log ;
66
7+ import androidx .annotation .NonNull ;
78import com .facebook .react .bridge .Promise ;
89import com .facebook .react .bridge .ReactApplicationContext ;
910import com .facebook .react .bridge .ReactContextBaseJavaModule ;
@@ -123,14 +124,92 @@ public void run() {
123124 });
124125 }
125126
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+
126205 /**
127206 * Starts an execution trace
128207 *
129208 * @param name string name of the trace.
130209 *
131210 * @deprecated see {@link #startFlow(String)}
132211 */
133- @ Deprecated ( since = "Use `startFlow` instead." )
212+ @ Deprecated
134213 @ ReactMethod
135214 public void startExecutionTrace (final String name , final String id , final Promise promise ) {
136215 MainThreadHandler .runOnMainThread (new Runnable () {
@@ -161,7 +240,7 @@ public void run() {
161240 *
162241 * @deprecated see {@link #setFlowAttribute}
163242 */
164- @ Deprecated ( since = "Use `setFlowAttribute` instead" )
243+ @ Deprecated
165244 @ ReactMethod
166245 public void setExecutionTraceAttribute (final String id , final String key , final String value ) {
167246 MainThreadHandler .runOnMainThread (new Runnable () {
@@ -183,7 +262,7 @@ public void run() {
183262 *
184263 * @deprecated see {@link #endFlow}
185264 */
186- @ Deprecated ( since = "Use `endFlow` instead" )
265+ @ Deprecated
187266 @ ReactMethod
188267 public void endExecutionTrace (final String id ) {
189268 MainThreadHandler .runOnMainThread (new Runnable () {
@@ -234,7 +313,7 @@ public void run() {
234313 }
235314
236315 /**
237- * Send Apm network log by Reflection
316+ * Send Apm network log by Reflection
238317 */
239318 @ ReactMethod
240319 public void networkLog (String networkData ) throws JSONException {
@@ -256,8 +335,8 @@ public void networkLog(String networkData) throws JSONException {
256335 final Integer statusCode = (Integer ) jsonObject .get ("responseCode" );
257336 final long requestDuration = ((Number ) jsonObject .get ("duration" )).longValue ();
258337 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 ();
261340 final String errorMessage ;
262341 if (errorDomain .equals ("" )) {
263342 errorMessage = null ;
@@ -268,9 +347,9 @@ public void networkLog(String networkData) throws JSONException {
268347 String gqlQueryName = null ;
269348 if (jsonObject .has ("gqlQueryName" )){
270349 gqlQueryName = (String ) jsonObject .get ("gqlQueryName" );
271- }
350+ }
272351 final String serverErrorMessage = (String ) jsonObject .get ("serverErrorMessage" );
273-
352+
274353 try {
275354 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 );
276355 if (method != null ) {
0 commit comments