Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(example): fix crash on reporting non fetal crash #1254

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v13.2.0...dev)

### Fixed

- Fix an OOM (out-of-memory) crash while saving network logs on Android ([#1244](https://github.com/Instabug/Instabug-React-Native/pull/1244)).

## [13.2.0](https://github.com/Instabug/Instabug-React-Native/compare/v13.1.1...v13.2.0) (July 7, 2024)

### Changed
@@ -58,6 +64,11 @@

- Adds symbol files upload script ([#1137](https://github.com/Instabug/Instabug-React-Native/pull/1137))
- Support enabling NDK crash capturing on Android ([#1132](https://github.com/Instabug/Instabug-React-Native/pull/1132)).
- Add support for App Flows APIs `APM.startFlow`, `APM.setFlowAttribute` and `APM.endFlow` ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).

### Deprecated

- Deprecate execution traces APIs `APM.startExecutionTrace`, `Trace.end` and `Trace.setFlowAttribute` in favor of the new app flow APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).

### Deprecated

@@ -84,6 +95,10 @@

- Bump Instabug Android SDK to v12.8.0 ([#1149](https://github.com/Instabug/Instabug-React-Native/pull/1149)). [See release notes](https://github.com/Instabug/android/releases/tag/v12.8.0).

### Deprecated

- Deprecate Execution Traces APIs `APM.startExecutionTrace`, `Trace.end` and `Trace.setAttribute` in favor of the new App Flows APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).

## [12.7.1](https://github.com/Instabug/Instabug-React-Native/compare/v12.7.0...v12.7.1) (February 15, 2024)

### Changed
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -312,56 +314,58 @@ public void run() {
});
}

/**
* Send Apm network log by Reflection
*/
@ReactMethod
public void networkLog(String networkData) throws JSONException {
try{
APMNetworkLogger apmNetworkLogger = new APMNetworkLogger();
JSONObject jsonObject = new JSONObject(networkData);
final String requestUrl = (String) jsonObject.get("url");
final String requestBody = (String) jsonObject.get("requestBody");
final String responseBody = (String) jsonObject.get("responseBody");
final String requestMethod = (String) jsonObject.get("method");
//--------------------------------------------
final String requestContentType = (String) jsonObject.get("requestContentType");
final String responseContentType = (String) jsonObject.get("contentType");
//--------------------------------------------
final long requestBodySize = ((Number) jsonObject.get("requestBodySize")).longValue();
final long responseBodySize = ((Number) jsonObject.get("responseBodySize")).longValue();
//--------------------------------------------
final String errorDomain = (String) jsonObject.get("errorDomain");
final Integer statusCode = (Integer) jsonObject.get("responseCode");
final long requestDuration = ((Number) jsonObject.get("duration")).longValue();
final long requestStartTime = ((Number) jsonObject.get("startTime")).longValue() * 1000;
final String requestHeaders = (String) jsonObject.get("requestHeaders").toString();
final String responseHeaders = (String) jsonObject.get("responseHeaders").toString();
final String errorMessage;
if(errorDomain.equals("")) {
errorMessage = null;
} else {
errorMessage = errorDomain;
}
//--------------------------------------------
String gqlQueryName = null;
if(jsonObject.has("gqlQueryName")){
gqlQueryName = (String) jsonObject.get("gqlQueryName");
}
final String serverErrorMessage = (String) jsonObject.get("serverErrorMessage");
private void networkLogAndroid(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 String gqlQueryName,
@Nullable final String serverErrorMessage) {
try {
APMNetworkLogger networkLogger = new APMNetworkLogger();

final boolean hasError = errorDomain != null && !errorDomain.isEmpty();
final String errorMessage = hasError ? errorDomain : null;

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);
if (method != null) {
method.invoke(apmNetworkLogger, requestStartTime, requestDuration, requestHeaders, requestBody, requestBodySize, requestMethod, requestUrl, requestContentType, responseHeaders, responseBody, responseBodySize, statusCode, responseContentType, errorMessage, gqlQueryName, serverErrorMessage);
method.invoke(
networkLogger,
requestStartTime,
requestDuration,
requestHeaders,
requestBody,
requestBodySize,
requestMethod,
requestUrl,
requestContentType,
responseHeaders,
responseBody,
responseBodySize,
statusCode,
responseContentType,
errorMessage,
gqlQueryName,
serverErrorMessage
);
} else {
Log.e("IB-CP-Bridge", "apmNetworkLogByReflection was not found by reflection");
Log.e("IB-CP-Bridge", "APMNetworkLogger.log was not found by reflection");
}
} catch (Throwable e) {
e.printStackTrace();
}
}
catch(Throwable e) {
} catch(Throwable e) {
e.printStackTrace();
}
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import android.app.Application;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Log;
import android.view.View;

import androidx.annotation.UiThread;
@@ -34,6 +35,7 @@
import com.instabug.library.model.NetworkLog;
import com.instabug.library.model.Report;
import com.instabug.library.ui.onboarding.WelcomeMessage;
import com.instabug.library.util.InstabugSDKLogger;
import com.instabug.reactlibrary.utils.ArrayUtil;
import com.instabug.reactlibrary.utils.EventEmitterModule;
import com.instabug.reactlibrary.utils.MainThreadHandler;
@@ -60,7 +62,7 @@
*/
public class RNInstabugReactnativeModule extends EventEmitterModule {

private static final String TAG = RNInstabugReactnativeModule.class.getSimpleName();
private static final String TAG = "IBG-RN-Core";

private InstabugCustomTextPlaceHolder placeHolders;
private static Report currentReport;
@@ -895,27 +897,38 @@ public void run() {
});
}

/**
* Extracts HTTP connection properties. Request method, Headers, Date, Url and Response code
*
* @param jsonObject the JSON object containing all HTTP connection properties
* @throws JSONException
*/
@ReactMethod
public void networkLog(String jsonObject) throws JSONException {
NetworkLog networkLog = new NetworkLog();
String date = System.currentTimeMillis()+"";
networkLog.setDate(date);
JSONObject newJSONObject = new JSONObject(jsonObject);
networkLog.setUrl(newJSONObject.getString("url"));
networkLog.setRequest(newJSONObject.getString("requestBody"));
networkLog.setResponse(newJSONObject.getString("responseBody"));
networkLog.setMethod(newJSONObject.getString("method"));
networkLog.setResponseCode(newJSONObject.getInt("responseCode"));
networkLog.setRequestHeaders(newJSONObject.getString("requestHeaders"));
networkLog.setResponseHeaders(newJSONObject.getString("responseHeaders"));
networkLog.setTotalDuration(newJSONObject.getLong("duration"));
networkLog.insert();
public void networkLogAndroid(final String url,
final String requestBody,
final String responseBody,
final String method,
final double responseCode,
final String requestHeaders,
final String responseHeaders,
final double duration) {
try {
final String date = String.valueOf(System.currentTimeMillis());

NetworkLog networkLog = new NetworkLog();
networkLog.setDate(date);
networkLog.setUrl(url);
networkLog.setMethod(method);
networkLog.setResponseCode((int) responseCode);
networkLog.setTotalDuration((long) duration);

try {
networkLog.setRequest(requestBody);
networkLog.setResponse(responseBody);
networkLog.setRequestHeaders(requestHeaders);
networkLog.setResponseHeaders(responseHeaders);
} catch (OutOfMemoryError | Exception exception) {
Log.d(TAG, "Error: " + exception.getMessage() + "while trying to set network log contents (request body, response body, request headers, and response headers).");
}

networkLog.insert();
} catch (OutOfMemoryError | Exception exception) {
Log.d(TAG, "Error: " + exception.getMessage() + "while trying to insert a network log");
}
}

@UiThread
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public String getName() {
}

@ReactMethod
public void sendNativeNonFatal(final String exceptionObject) {
public void sendNativeNonFatal() {
final IBGNonFatalException exception = new IBGNonFatalException.Builder(new IllegalStateException("Test exception"))
.build();
CrashReporting.report(exception);
56 changes: 56 additions & 0 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
#import <Instabug/IBGTypes.h>
#import "IBGConstants.h"
#import "RNInstabug.h"
#import <RNInstabug/IBGNetworkLogger+CP.h>

@protocol InstabugCPTestProtocol <NSObject>
/**
@@ -313,6 +314,61 @@ - (void)testSetWelcomeMessageMode {
OCMVerify([mock setWelcomeMessageMode:welcomeMessageMode]);
}

- (void)testNetworkLogIOS {
id mIBGNetworkLogger = OCMClassMock([IBGNetworkLogger class]);

NSString *url = @"https://api.instabug.com";
NSString *method = @"GET";
NSString *requestBody = @"requestBody";
double requestBodySize = 10;
NSString *responseBody = @"responseBody";
double responseBodySize = 15;
double responseCode = 200;
NSDictionary *requestHeaders = @{ @"accept": @"application/json" };
NSDictionary *responseHeaders = @{ @"cache-control": @"no-store" };
NSString *contentType = @"application/json";
double errorCode = 0;
NSString *errorDomain = nil;
double startTime = 1719847101199;
double duration = 150;
NSString *gqlQueryName = nil;
NSString *serverErrorMessage = nil;

[self.instabugBridge networkLogIOS:url
method:method
requestBody:requestBody
requestBodySize:requestBodySize
responseBody:responseBody
responseBodySize:responseBodySize
responseCode:responseCode
requestHeaders:requestHeaders
responseHeaders:responseHeaders
contentType:contentType
errorDomain:errorDomain
errorCode:errorCode
startTime:startTime
duration:duration
gqlQueryName:gqlQueryName
serverErrorMessage:serverErrorMessage];

OCMVerify([mIBGNetworkLogger addNetworkLogWithUrl:url
method:method
requestBody:requestBody
requestBodySize:requestBodySize
responseBody:responseBody
responseBodySize:responseBodySize
responseCode:responseCode
requestHeaders:requestHeaders
responseHeaders:responseHeaders
contentType:contentType
errorDomain:errorDomain
errorCode:errorCode
startTime:startTime * 1000
duration:duration * 1000
gqlQueryName:gqlQueryName
serverErrorMessage:serverErrorMessage]);
}

- (void)testSetFileAttachment {
id mock = OCMClassMock([Instabug class]);
NSString *fileLocation = @"test";
12 changes: 12 additions & 0 deletions examples/default/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -404,6 +404,8 @@ PODS:
- React-jsinspector (0.72.3)
- React-logger (0.72.3):
- glog
- react-native-background-timer (2.4.1):
- React-Core
- react-native-config (1.5.1):
- react-native-config/App (= 1.5.1)
- react-native-config/App (1.5.1):
@@ -528,6 +530,8 @@ PODS:
- React-jsi (= 0.72.3)
- React-logger (= 0.72.3)
- React-perflogger (= 0.72.3)
- RNCClipboard (1.5.1):
- React-Core
- RNGestureHandler (2.13.4):
- RCT-Folly (= 2021.07.22.00)
- React-Core
@@ -623,6 +627,7 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-background-timer (from `../node_modules/react-native-background-timer`)
- react-native-config (from `../node_modules/react-native-config`)
- react-native-google-maps (from `../node_modules/react-native-maps`)
- react-native-maps (from `../node_modules/react-native-maps`)
@@ -645,6 +650,7 @@ DEPENDENCIES:
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNInstabug (from `../node_modules/instabug-reactnative`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
@@ -720,6 +726,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-background-timer:
:path: "../node_modules/react-native-background-timer"
react-native-config:
:path: "../node_modules/react-native-config"
react-native-google-maps:
@@ -764,6 +772,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/react/utils"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNCClipboard:
:path: "../node_modules/@react-native-community/clipboard"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNInstabug:
@@ -818,6 +828,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 59d1eb03af7d30b7d66589c410f13151271e8006
React-jsinspector: b511447170f561157547bc0bef3f169663860be7
React-logger: c5b527272d5f22eaa09bb3c3a690fee8f237ae95
react-native-background-timer: 17ea5e06803401a379ebf1f20505b793ac44d0fe
react-native-config: 86038147314e2e6d10ea9972022aa171e6b1d4d8
react-native-google-maps: 1bcc1f9f13f798fcf230db7fe476f3566d0bc0a3
react-native-maps: 72a8a903f8a1b53e2c777ba79102078ab502e0bf
@@ -840,6 +851,7 @@ SPEC CHECKSUMS:
React-runtimescheduler: 837c1bebd2f84572db17698cd702ceaf585b0d9a
React-utils: bcb57da67eec2711f8b353f6e3d33bd8e4b2efa3
ReactCommon: 3ccb8fb14e6b3277e38c73b0ff5e4a1b8db017a9
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
RNGestureHandler: 6e46dde1f87e5f018a54fe5d40cd0e0b942b49ee
RNInstabug: 6fa68cd181533f83154df2ebba000d0c47ca7ba3
RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87
Loading