diff --git a/android/native.gradle b/android/native.gradle index 7177b8c27..3241dc5f2 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '14.3.0.6752106-SNAPSHOT' + version: '14.3.0' ] dependencies { diff --git a/android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java b/android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java deleted file mode 100644 index 73befdad1..000000000 --- a/android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.instabug.apm.networking; - -import androidx.annotation.Nullable; - -import com.facebook.react.bridge.ReadableMap; -import com.instabug.apm.networking.mapping.NetworkRequestAttributes; -import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; - -public class ApmNetworkLoggerHelper { - - /// Log network request to the Android SDK using a package private API [APMNetworkLogger.log] - static public void log(final double requestStartTime, - final double requestDuration, - final String requestHeaders, - final String requestBody, - final double requestBodySize, - final String requestMethod, - final String requestUrl, - final String requestContentType, - final String responseHeaders, - final String responseBody, - final double responseBodySize, - final double statusCode, - final String responseContentType, - @Nullable final String errorDomain, - @Nullable final ReadableMap w3cAttributes, - @Nullable final String gqlQueryName, - @Nullable final String serverErrorMessage - ) { - try { - final APMNetworkLogger apmNetworkLogger = new APMNetworkLogger(); - final boolean hasError = errorDomain != null && !errorDomain.isEmpty(); - final String errorMessage = hasError ? errorDomain : null; - boolean isW3cHeaderFound = false; - Long partialId = null; - Long networkStartTimeInSeconds = null; - - - try { - if (!w3cAttributes.isNull("isW3cHeaderFound")) { - isW3cHeaderFound = w3cAttributes.getBoolean("isW3cHeaderFound"); - } - - if (!w3cAttributes.isNull("partialId")) { - partialId = (long) w3cAttributes.getDouble("partialId"); - networkStartTimeInSeconds = (long) w3cAttributes.getDouble("networkStartTimeInSeconds"); - } - - } catch (Exception e) { - e.printStackTrace(); - } - APMCPNetworkLog.W3CExternalTraceAttributes w3cExternalTraceAttributes = - new APMCPNetworkLog.W3CExternalTraceAttributes( - isW3cHeaderFound, - partialId, - networkStartTimeInSeconds, - w3cAttributes.getString("w3cGeneratedHeader"), - w3cAttributes.getString("w3cCaughtHeader") - ); - NetworkRequestAttributes requestAttributes = new NetworkRequestAttributes( - (long) requestStartTime * 1000, - (long) requestDuration, - requestHeaders, - requestBody, - (long) requestBodySize, - requestMethod, - requestUrl, - requestContentType, - responseHeaders, - responseBody, - (long) responseBodySize, - (int) statusCode, - responseContentType, - gqlQueryName, - errorMessage, - serverErrorMessage - ); - - apmNetworkLogger.log( - requestAttributes, - w3cExternalTraceAttributes - ); - } catch (Throwable e) { - e.printStackTrace(); - } - - } - -} diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java index f68f212b1..d75b4f75b 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java @@ -2,6 +2,7 @@ package com.instabug.reactlibrary; import android.os.SystemClock; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -12,14 +13,20 @@ import com.facebook.react.bridge.ReadableMap; import com.instabug.apm.APM; import com.instabug.apm.model.ExecutionTrace; -import com.instabug.apm.networking.ApmNetworkLoggerHelper; +import com.instabug.apm.networking.APMNetworkLogger; +import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; import com.instabug.reactlibrary.utils.EventEmitterModule; +import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; import com.instabug.reactlibrary.utils.MainThreadHandler; +import java.lang.reflect.Method; + import java.util.HashMap; import javax.annotation.Nonnull; +import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod; + public class RNInstabugAPMModule extends EventEmitterModule { public RNInstabugAPMModule(ReactApplicationContext reactApplicationContext) { @@ -204,6 +211,7 @@ public void run() { * Starts an execution trace * * @param name string name of the trace. + * * @deprecated see {@link #startFlow(String)} */ @Deprecated @@ -234,6 +242,7 @@ public void run() { * @param id String id of the trace. * @param key attribute key * @param value attribute value. Null to remove attribute + * * @deprecated see {@link #setFlowAttribute} */ @Deprecated @@ -255,6 +264,7 @@ public void run() { * Ends a trace * * @param id string id of the trace. + * * @deprecated see {@link #endFlow} */ @Deprecated @@ -308,73 +318,73 @@ public void run() { }); } - /** - * The `networkLogAndroid` function logs network-related information using APMNetworkLogger in a React - * Native module. - * - * @param requestStartTime The `requestStartTime` parameter in the `networkLogAndroid` method - * represents the timestamp when the network request started. It is of type `double` and is passed as - * a parameter to log network-related information. - * @param requestDuration The `requestDuration` parameter in the `networkLogAndroid` method represents - * the duration of the network request in milliseconds. It indicates the time taken for the request to - * complete from the moment it was initiated until the response was received. This parameter helps in - * measuring the performance of network requests and identifying any potential - * @param requestHeaders requestHeaders is a string parameter that contains the headers of the network - * request. It typically includes information such as the content type, authorization token, and any - * other headers that were sent with the request. - * @param requestBody The `requestBody` parameter in the `networkLogAndroid` method represents the - * body of the HTTP request being logged. It contains the data that is sent as part of the request to - * the server. This could include form data, JSON payload, XML data, or any other content that is - * being transmitted - * @param requestBodySize The `requestBodySize` parameter in the `networkLogAndroid` method represents - * the size of the request body in bytes. It is a double value that indicates the size of the request - * body being sent in the network request. This parameter is used to log information related to the - * network request, including details - * @param requestMethod The `requestMethod` parameter in the `networkLogAndroid` method represents the - * HTTP method used in the network request, such as GET, POST, PUT, DELETE, etc. It indicates the type - * of operation that the client is requesting from the server. - * @param requestUrl The `requestUrl` parameter in the `networkLogAndroid` method represents the URL - * of the network request being logged. It typically contains the address of the server to which the - * request is being made, along with any additional path or query parameters required for the request. - * This URL is essential for identifying the - * @param requestContentType The `requestContentType` parameter in the `networkLogAndroid` method - * represents the content type of the request being made. This could be values like - * "application/json", "application/xml", "text/plain", etc., indicating the format of the data being - * sent in the request body. It helps in specifying - * @param responseHeaders The `responseHeaders` parameter in the `networkLogAndroid` method represents - * the headers of the response received from a network request. These headers typically include - * information such as content type, content length, server information, and any other metadata - * related to the response. The `responseHeaders` parameter is expected to - * @param responseBody The `responseBody` parameter in the `networkLogAndroid` method represents the - * body of the response received from a network request. It contains the data or content sent back by - * the server in response to the request made by the client. This could be in various formats such as - * JSON, XML, HTML - * @param responseBodySize The `responseBodySize` parameter in the `networkLogAndroid` method - * represents the size of the response body in bytes. It is a double value that indicates the size of - * the response body received from the network request. This parameter is used to log information - * related to the network request and response, including - * @param statusCode The `statusCode` parameter in the `networkLogAndroid` method represents the HTTP - * status code of the network request/response. It indicates the status of the HTTP response, such as - * success (200), redirection (3xx), client errors (4xx), or server errors (5xx). This parameter is - * @param responseContentType The `responseContentType` parameter in the `networkLogAndroid` method - * represents the content type of the response received from the network request. It indicates the - * format of the data in the response, such as JSON, XML, HTML, etc. This information is useful for - * understanding how to parse and handle the - * @param errorDomain The `errorDomain` parameter in the `networkLogAndroid` method is used to specify - * the domain of an error, if any occurred during the network request. If there was no error, this - * parameter will be `null`. - * @param w3cAttributes The `w3cAttributes` parameter in the `networkLogAndroid` method is a - * ReadableMap object that contains additional attributes related to W3C external trace. It may - * include the following key-value pairs: - * @param gqlQueryName The `gqlQueryName` parameter in the `networkLogAndroid` method represents the - * name of the GraphQL query being executed. It is a nullable parameter, meaning it can be null if no - * GraphQL query name is provided. This parameter is used to log information related to GraphQL - * queries in the network logging - * @param serverErrorMessage The `serverErrorMessage` parameter in the `networkLogAndroid` method is - * used to pass any error message received from the server during network communication. This message - * can provide additional details about any errors that occurred on the server side, helping in - * debugging and troubleshooting network-related issues. - */ + /** + * The `networkLogAndroid` function logs network-related information using APMNetworkLogger in a React + * Native module. + * + * @param requestStartTime The `requestStartTime` parameter in the `networkLogAndroid` method + * represents the timestamp when the network request started. It is of type `double` and is passed as + * a parameter to log network-related information. + * @param requestDuration The `requestDuration` parameter in the `networkLogAndroid` method represents + * the duration of the network request in milliseconds. It indicates the time taken for the request to + * complete from the moment it was initiated until the response was received. This parameter helps in + * measuring the performance of network requests and identifying any potential + * @param requestHeaders requestHeaders is a string parameter that contains the headers of the network + * request. It typically includes information such as the content type, authorization token, and any + * other headers that were sent with the request. + * @param requestBody The `requestBody` parameter in the `networkLogAndroid` method represents the + * body of the HTTP request being logged. It contains the data that is sent as part of the request to + * the server. This could include form data, JSON payload, XML data, or any other content that is + * being transmitted + * @param requestBodySize The `requestBodySize` parameter in the `networkLogAndroid` method represents + * the size of the request body in bytes. It is a double value that indicates the size of the request + * body being sent in the network request. This parameter is used to log information related to the + * network request, including details + * @param requestMethod The `requestMethod` parameter in the `networkLogAndroid` method represents the + * HTTP method used in the network request, such as GET, POST, PUT, DELETE, etc. It indicates the type + * of operation that the client is requesting from the server. + * @param requestUrl The `requestUrl` parameter in the `networkLogAndroid` method represents the URL + * of the network request being logged. It typically contains the address of the server to which the + * request is being made, along with any additional path or query parameters required for the request. + * This URL is essential for identifying the + * @param requestContentType The `requestContentType` parameter in the `networkLogAndroid` method + * represents the content type of the request being made. This could be values like + * "application/json", "application/xml", "text/plain", etc., indicating the format of the data being + * sent in the request body. It helps in specifying + * @param responseHeaders The `responseHeaders` parameter in the `networkLogAndroid` method represents + * the headers of the response received from a network request. These headers typically include + * information such as content type, content length, server information, and any other metadata + * related to the response. The `responseHeaders` parameter is expected to + * @param responseBody The `responseBody` parameter in the `networkLogAndroid` method represents the + * body of the response received from a network request. It contains the data or content sent back by + * the server in response to the request made by the client. This could be in various formats such as + * JSON, XML, HTML + * @param responseBodySize The `responseBodySize` parameter in the `networkLogAndroid` method + * represents the size of the response body in bytes. It is a double value that indicates the size of + * the response body received from the network request. This parameter is used to log information + * related to the network request and response, including + * @param statusCode The `statusCode` parameter in the `networkLogAndroid` method represents the HTTP + * status code of the network request/response. It indicates the status of the HTTP response, such as + * success (200), redirection (3xx), client errors (4xx), or server errors (5xx). This parameter is + * @param responseContentType The `responseContentType` parameter in the `networkLogAndroid` method + * represents the content type of the response received from the network request. It indicates the + * format of the data in the response, such as JSON, XML, HTML, etc. This information is useful for + * understanding how to parse and handle the + * @param errorDomain The `errorDomain` parameter in the `networkLogAndroid` method is used to specify + * the domain of an error, if any occurred during the network request. If there was no error, this + * parameter will be `null`. + * @param w3cAttributes The `w3cAttributes` parameter in the `networkLogAndroid` method is a + * ReadableMap object that contains additional attributes related to W3C external trace. It may + * include the following key-value pairs: + * @param gqlQueryName The `gqlQueryName` parameter in the `networkLogAndroid` method represents the + * name of the GraphQL query being executed. It is a nullable parameter, meaning it can be null if no + * GraphQL query name is provided. This parameter is used to log information related to GraphQL + * queries in the network logging + * @param serverErrorMessage The `serverErrorMessage` parameter in the `networkLogAndroid` method is + * used to pass any error message received from the server during network communication. This message + * can provide additional details about any errors that occurred on the server side, helping in + * debugging and troubleshooting network-related issues. + */ @ReactMethod private void networkLogAndroid(final double requestStartTime, final double requestDuration, @@ -393,25 +403,69 @@ private void networkLogAndroid(final double requestStartTime, @Nullable final ReadableMap w3cAttributes, @Nullable final String gqlQueryName, @Nullable final String serverErrorMessage - ) { - ApmNetworkLoggerHelper.log( - requestStartTime, - requestDuration, - requestHeaders, - requestBody, - requestBodySize, - requestMethod, - requestUrl, - requestContentType, - responseHeaders, - responseBody, - responseBodySize, - statusCode, - responseContentType, - errorDomain, - w3cAttributes, - gqlQueryName, - serverErrorMessage - ); + ) { + try { + APMNetworkLogger networkLogger = new APMNetworkLogger(); + + final boolean hasError = errorDomain != null && !errorDomain.isEmpty(); + final String errorMessage = hasError ? errorDomain : null; + Boolean isW3cHeaderFound=false; + Long partialId=null; + Long networkStartTimeInSeconds=null; + + + try { + if (!w3cAttributes.isNull("isW3cHeaderFound")) { + isW3cHeaderFound = w3cAttributes.getBoolean("isW3cHeaderFound"); + } + + if (!w3cAttributes.isNull("partialId")) { + partialId =(long) w3cAttributes.getDouble("partialId"); + networkStartTimeInSeconds = (long) w3cAttributes.getDouble("networkStartTimeInSeconds"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + APMCPNetworkLog.W3CExternalTraceAttributes w3cExternalTraceAttributes = + new APMCPNetworkLog.W3CExternalTraceAttributes( + isW3cHeaderFound, + partialId, + networkStartTimeInSeconds, + w3cAttributes.getString("w3cGeneratedHeader"), + w3cAttributes.getString("w3cCaughtHeader") + ); + try { + 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); + if (method != null) { + method.invoke( + networkLogger, + (long) requestStartTime * 1000, + (long) requestDuration, + requestHeaders, + requestBody, + (long) requestBodySize, + requestMethod, + requestUrl, + requestContentType, + responseHeaders, + responseBody, + (long)responseBodySize, + (int) statusCode, + responseContentType, + errorMessage, + gqlQueryName, + serverErrorMessage, + w3cExternalTraceAttributes + ); + } else { + Log.e("IB-CP-Bridge", "APMNetworkLogger.log was not found by reflection"); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } catch(Throwable e) { + e.printStackTrace(); + } } }