11
22package com .instabug .reactlibrary ;
33
4+ import static com .instabug .reactlibrary .utils .InstabugUtil .getMethod ;
5+
46import android .os .SystemClock ;
57import android .util .Log ;
68
1618import com .instabug .apm .networking .APMNetworkLogger ;
1719import com .instabug .apm .networkinterception .cp .APMCPNetworkLog ;
1820import com .instabug .reactlibrary .utils .EventEmitterModule ;
19- import com .instabug .apm .networkinterception .cp .APMCPNetworkLog ;
2021import com .instabug .reactlibrary .utils .MainThreadHandler ;
2122
2223import java .lang .reflect .Method ;
23-
2424import java .util .HashMap ;
2525
2626import javax .annotation .Nonnull ;
2727
28- import static com .instabug .reactlibrary .utils .InstabugUtil .getMethod ;
29-
3028public class RNInstabugAPMModule extends EventEmitterModule {
3129
3230 public RNInstabugAPMModule (ReactApplicationContext reactApplicationContext ) {
@@ -211,7 +209,6 @@ public void run() {
211209 * Starts an execution trace
212210 *
213211 * @param name string name of the trace.
214- *
215212 * @deprecated see {@link #startFlow(String)}
216213 */
217214 @ Deprecated
@@ -242,7 +239,6 @@ public void run() {
242239 * @param id String id of the trace.
243240 * @param key attribute key
244241 * @param value attribute value. Null to remove attribute
245- *
246242 * @deprecated see {@link #setFlowAttribute}
247243 */
248244 @ Deprecated
@@ -264,7 +260,6 @@ public void run() {
264260 * Ends a trace
265261 *
266262 * @param id string id of the trace.
267- *
268263 * @deprecated see {@link #endFlow}
269264 */
270265 @ Deprecated
@@ -318,73 +313,73 @@ public void run() {
318313 });
319314 }
320315
321- /**
322- * The `networkLogAndroid` function logs network-related information using APMNetworkLogger in a React
323- * Native module.
324- *
325- * @param requestStartTime The `requestStartTime` parameter in the `networkLogAndroid` method
326- * represents the timestamp when the network request started. It is of type `double` and is passed as
327- * a parameter to log network-related information.
328- * @param requestDuration The `requestDuration` parameter in the `networkLogAndroid` method represents
329- * the duration of the network request in milliseconds. It indicates the time taken for the request to
330- * complete from the moment it was initiated until the response was received. This parameter helps in
331- * measuring the performance of network requests and identifying any potential
332- * @param requestHeaders requestHeaders is a string parameter that contains the headers of the network
333- * request. It typically includes information such as the content type, authorization token, and any
334- * other headers that were sent with the request.
335- * @param requestBody The `requestBody` parameter in the `networkLogAndroid` method represents the
336- * body of the HTTP request being logged. It contains the data that is sent as part of the request to
337- * the server. This could include form data, JSON payload, XML data, or any other content that is
338- * being transmitted
339- * @param requestBodySize The `requestBodySize` parameter in the `networkLogAndroid` method represents
340- * the size of the request body in bytes. It is a double value that indicates the size of the request
341- * body being sent in the network request. This parameter is used to log information related to the
342- * network request, including details
343- * @param requestMethod The `requestMethod` parameter in the `networkLogAndroid` method represents the
344- * HTTP method used in the network request, such as GET, POST, PUT, DELETE, etc. It indicates the type
345- * of operation that the client is requesting from the server.
346- * @param requestUrl The `requestUrl` parameter in the `networkLogAndroid` method represents the URL
347- * of the network request being logged. It typically contains the address of the server to which the
348- * request is being made, along with any additional path or query parameters required for the request.
349- * This URL is essential for identifying the
350- * @param requestContentType The `requestContentType` parameter in the `networkLogAndroid` method
351- * represents the content type of the request being made. This could be values like
352- * "application/json", "application/xml", "text/plain", etc., indicating the format of the data being
353- * sent in the request body. It helps in specifying
354- * @param responseHeaders The `responseHeaders` parameter in the `networkLogAndroid` method represents
355- * the headers of the response received from a network request. These headers typically include
356- * information such as content type, content length, server information, and any other metadata
357- * related to the response. The `responseHeaders` parameter is expected to
358- * @param responseBody The `responseBody` parameter in the `networkLogAndroid` method represents the
359- * body of the response received from a network request. It contains the data or content sent back by
360- * the server in response to the request made by the client. This could be in various formats such as
361- * JSON, XML, HTML
362- * @param responseBodySize The `responseBodySize` parameter in the `networkLogAndroid` method
363- * represents the size of the response body in bytes. It is a double value that indicates the size of
364- * the response body received from the network request. This parameter is used to log information
365- * related to the network request and response, including
366- * @param statusCode The `statusCode` parameter in the `networkLogAndroid` method represents the HTTP
367- * status code of the network request/response. It indicates the status of the HTTP response, such as
368- * success (200), redirection (3xx), client errors (4xx), or server errors (5xx). This parameter is
369- * @param responseContentType The `responseContentType` parameter in the `networkLogAndroid` method
370- * represents the content type of the response received from the network request. It indicates the
371- * format of the data in the response, such as JSON, XML, HTML, etc. This information is useful for
372- * understanding how to parse and handle the
373- * @param errorDomain The `errorDomain` parameter in the `networkLogAndroid` method is used to specify
374- * the domain of an error, if any occurred during the network request. If there was no error, this
375- * parameter will be `null`.
376- * @param w3cAttributes The `w3cAttributes` parameter in the `networkLogAndroid` method is a
377- * ReadableMap object that contains additional attributes related to W3C external trace. It may
378- * include the following key-value pairs:
379- * @param gqlQueryName The `gqlQueryName` parameter in the `networkLogAndroid` method represents the
380- * name of the GraphQL query being executed. It is a nullable parameter, meaning it can be null if no
381- * GraphQL query name is provided. This parameter is used to log information related to GraphQL
382- * queries in the network logging
383- * @param serverErrorMessage The `serverErrorMessage` parameter in the `networkLogAndroid` method is
384- * used to pass any error message received from the server during network communication. This message
385- * can provide additional details about any errors that occurred on the server side, helping in
386- * debugging and troubleshooting network-related issues.
387- */
316+ /**
317+ * The `networkLogAndroid` function logs network-related information using APMNetworkLogger in a React
318+ * Native module.
319+ *
320+ * @param requestStartTime The `requestStartTime` parameter in the `networkLogAndroid` method
321+ * represents the timestamp when the network request started. It is of type `double` and is passed as
322+ * a parameter to log network-related information.
323+ * @param requestDuration The `requestDuration` parameter in the `networkLogAndroid` method represents
324+ * the duration of the network request in milliseconds. It indicates the time taken for the request to
325+ * complete from the moment it was initiated until the response was received. This parameter helps in
326+ * measuring the performance of network requests and identifying any potential
327+ * @param requestHeaders requestHeaders is a string parameter that contains the headers of the network
328+ * request. It typically includes information such as the content type, authorization token, and any
329+ * other headers that were sent with the request.
330+ * @param requestBody The `requestBody` parameter in the `networkLogAndroid` method represents the
331+ * body of the HTTP request being logged. It contains the data that is sent as part of the request to
332+ * the server. This could include form data, JSON payload, XML data, or any other content that is
333+ * being transmitted
334+ * @param requestBodySize The `requestBodySize` parameter in the `networkLogAndroid` method represents
335+ * the size of the request body in bytes. It is a double value that indicates the size of the request
336+ * body being sent in the network request. This parameter is used to log information related to the
337+ * network request, including details
338+ * @param requestMethod The `requestMethod` parameter in the `networkLogAndroid` method represents the
339+ * HTTP method used in the network request, such as GET, POST, PUT, DELETE, etc. It indicates the type
340+ * of operation that the client is requesting from the server.
341+ * @param requestUrl The `requestUrl` parameter in the `networkLogAndroid` method represents the URL
342+ * of the network request being logged. It typically contains the address of the server to which the
343+ * request is being made, along with any additional path or query parameters required for the request.
344+ * This URL is essential for identifying the
345+ * @param requestContentType The `requestContentType` parameter in the `networkLogAndroid` method
346+ * represents the content type of the request being made. This could be values like
347+ * "application/json", "application/xml", "text/plain", etc., indicating the format of the data being
348+ * sent in the request body. It helps in specifying
349+ * @param responseHeaders The `responseHeaders` parameter in the `networkLogAndroid` method represents
350+ * the headers of the response received from a network request. These headers typically include
351+ * information such as content type, content length, server information, and any other metadata
352+ * related to the response. The `responseHeaders` parameter is expected to
353+ * @param responseBody The `responseBody` parameter in the `networkLogAndroid` method represents the
354+ * body of the response received from a network request. It contains the data or content sent back by
355+ * the server in response to the request made by the client. This could be in various formats such as
356+ * JSON, XML, HTML
357+ * @param responseBodySize The `responseBodySize` parameter in the `networkLogAndroid` method
358+ * represents the size of the response body in bytes. It is a double value that indicates the size of
359+ * the response body received from the network request. This parameter is used to log information
360+ * related to the network request and response, including
361+ * @param statusCode The `statusCode` parameter in the `networkLogAndroid` method represents the HTTP
362+ * status code of the network request/response. It indicates the status of the HTTP response, such as
363+ * success (200), redirection (3xx), client errors (4xx), or server errors (5xx). This parameter is
364+ * @param responseContentType The `responseContentType` parameter in the `networkLogAndroid` method
365+ * represents the content type of the response received from the network request. It indicates the
366+ * format of the data in the response, such as JSON, XML, HTML, etc. This information is useful for
367+ * understanding how to parse and handle the
368+ * @param errorDomain The `errorDomain` parameter in the `networkLogAndroid` method is used to specify
369+ * the domain of an error, if any occurred during the network request. If there was no error, this
370+ * parameter will be `null`.
371+ * @param w3cAttributes The `w3cAttributes` parameter in the `networkLogAndroid` method is a
372+ * ReadableMap object that contains additional attributes related to W3C external trace. It may
373+ * include the following key-value pairs:
374+ * @param gqlQueryName The `gqlQueryName` parameter in the `networkLogAndroid` method represents the
375+ * name of the GraphQL query being executed. It is a nullable parameter, meaning it can be null if no
376+ * GraphQL query name is provided. This parameter is used to log information related to GraphQL
377+ * queries in the network logging
378+ * @param serverErrorMessage The `serverErrorMessage` parameter in the `networkLogAndroid` method is
379+ * used to pass any error message received from the server during network communication. This message
380+ * can provide additional details about any errors that occurred on the server side, helping in
381+ * debugging and troubleshooting network-related issues.
382+ */
388383 @ ReactMethod
389384 private void networkLogAndroid (final double requestStartTime ,
390385 final double requestDuration ,
@@ -403,15 +398,15 @@ private void networkLogAndroid(final double requestStartTime,
403398 @ Nullable final ReadableMap w3cAttributes ,
404399 @ Nullable final String gqlQueryName ,
405400 @ Nullable final String serverErrorMessage
406- ) {
401+ ) {
407402 try {
408403 APMNetworkLogger networkLogger = new APMNetworkLogger ();
409404
410405 final boolean hasError = errorDomain != null && !errorDomain .isEmpty ();
411406 final String errorMessage = hasError ? errorDomain : null ;
412- Boolean isW3cHeaderFound = false ;
413- Long partialId = null ;
414- Long networkStartTimeInSeconds = null ;
407+ Boolean isW3cHeaderFound = false ;
408+ Long partialId = null ;
409+ Long networkStartTimeInSeconds = null ;
415410
416411
417412 try {
@@ -420,7 +415,7 @@ private void networkLogAndroid(final double requestStartTime,
420415 }
421416
422417 if (!w3cAttributes .isNull ("partialId" )) {
423- partialId =(long ) w3cAttributes .getDouble ("partialId" );
418+ partialId = (long ) w3cAttributes .getDouble ("partialId" );
424419 networkStartTimeInSeconds = (long ) w3cAttributes .getDouble ("networkStartTimeInSeconds" );
425420 }
426421
@@ -438,34 +433,54 @@ private void networkLogAndroid(final double requestStartTime,
438433 try {
439434 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 , APMCPNetworkLog .W3CExternalTraceAttributes .class );
440435 if (method != null ) {
441- method .invoke (
442- networkLogger ,
443- (long ) requestStartTime * 1000 ,
444- (long ) requestDuration ,
445- requestHeaders ,
446- requestBody ,
447- (long ) requestBodySize ,
448- requestMethod ,
449- requestUrl ,
450- requestContentType ,
451- responseHeaders ,
452- responseBody ,
453- (long )responseBodySize ,
454- (int ) statusCode ,
455- responseContentType ,
456- errorMessage ,
457- gqlQueryName ,
458- serverErrorMessage ,
459- w3cExternalTraceAttributes
460- );
436+ method .invoke (
437+ networkLogger ,
438+ (long ) requestStartTime * 1000 ,
439+ (long ) requestDuration ,
440+ requestHeaders ,
441+ requestBody ,
442+ (long ) requestBodySize ,
443+ requestMethod ,
444+ requestUrl ,
445+ requestContentType ,
446+ responseHeaders ,
447+ responseBody ,
448+ (long ) responseBodySize ,
449+ (int ) statusCode ,
450+ responseContentType ,
451+ errorMessage ,
452+ gqlQueryName ,
453+ serverErrorMessage ,
454+ w3cExternalTraceAttributes
455+ );
461456 } else {
462457 Log .e ("IB-CP-Bridge" , "APMNetworkLogger.log was not found by reflection" );
463458 }
464459 } catch (Throwable e ) {
465460 e .printStackTrace ();
466461 }
467- } catch (Throwable e ) {
462+ } catch (Throwable e ) {
468463 e .printStackTrace ();
469464 }
470465 }
466+
467+
468+ /**
469+ * Enables or disables screen rendering
470+ *
471+ * @param isEnabled boolean indicating enabled or disabled.
472+ */
473+ @ ReactMethod
474+ public void setScreenRenderEnabled (boolean isEnabled ) {
475+ MainThreadHandler .runOnMainThread (new Runnable () {
476+ @ Override
477+ public void run () {
478+ try {
479+ APM .setScreenRenderingEnabled (isEnabled );
480+ } catch (Exception e ) {
481+ e .printStackTrace ();
482+ }
483+ }
484+ });
485+ }
471486}
0 commit comments