Skip to content

feat: support app flows APIs #1138

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

Merged
merged 32 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
616fa69
chore(android): deprecate execution traces APIs
abdelhamid-f-nasser Feb 19, 2024
0104d26
chore: deprecate execution traces APIs
abdelhamid-f-nasser Feb 19, 2024
20de15d
chore(ios): deprecate execution traces APIs
abdelhamid-f-nasser Feb 19, 2024
c2079ad
docs: update changelog.md
abdelhamid-f-nasser Feb 19, 2024
676e611
feat: support app flows
abdelhamid-f-nasser Feb 19, 2024
e061d55
docs: update changelog.md
abdelhamid-f-nasser Feb 21, 2024
c0e5085
chore: add eslint jsdoc plugin and update imports
abdelhamid-f-nasser Feb 21, 2024
3a1880b
docs: update changelog.md
abdelhamid-f-nasser Feb 21, 2024
18f21f0
feat: add more crash scenarios to example app (#1131)
ahmedAlaaInstabug Feb 18, 2024
289b416
feat: add setNDKCrashesEnabled API (#1132)
ahmedAlaaInstabug Feb 19, 2024
0145a38
feat:add upload symbol files command (#1137)
ahmedAlaaInstabug Feb 19, 2024
efc0dd2
feat: add runtime code push version API (#1143)
a7medev Feb 22, 2024
1b2e01d
feat: add new NDK crash scenarios to example app (#1139)
ahmedAlaaInstabug Feb 25, 2024
a500f4e
feat: add get session replay link API (#1142)
ahmedAlaaInstabug Feb 25, 2024
0173307
feat(example): add large image list example (#1145)
ahmedAlaaInstabug Feb 27, 2024
278b972
feat(example): add google maps screen (#1148)
ahmedAlaaInstabug Feb 28, 2024
a2c6b94
fix(example): fix fatal hangs and ANR crash buttons (#1154)
abdelhamid-f-nasser Feb 28, 2024
17da2fe
feat(example): survey with token actions (#1157)
ahmedAlaaInstabug Feb 28, 2024
bc7d913
feat(example): customize chat settings (#1156)
ahmedAlaaInstabug Feb 28, 2024
683747d
Merge remote-tracking branch 'origin/dev' into dev
abdelhamid-f-nasser Feb 28, 2024
66d1cb1
Merge branch 'dev' into feat/support-app-flows
abdelhamid-f-nasser Feb 28, 2024
ae275b8
chore(ios): add app flows snapshot
abdelhamid-f-nasser Feb 28, 2024
eab2af3
chore(android): add app flows snapshot
abdelhamid-f-nasser Feb 28, 2024
86f4ff0
Merge remote-tracking branch 'origin/dev' into feat/support-app-flows
abdelhamid-f-nasser Feb 29, 2024
a6d13d8
docs(android): update setFlowAttribute param docs
abdelhamid-f-nasser Mar 4, 2024
4f47756
Merge remote-tracking branch 'origin/dev' into feat/support-app-flows
abdelhamid-f-nasser Mar 6, 2024
367054b
docs: update changelog.md
abdelhamid-f-nasser Mar 6, 2024
eb676ab
Merge remote-tracking branch 'origin/dev' into feat/support-app-flows
abdelhamid-f-nasser Apr 3, 2024
91fd7ef
Update CHANGELOG.md
abdelhamid-f-nasser Apr 3, 2024
c004531
Update src/modules/APM.ts
abdelhamid-f-nasser Apr 3, 2024
642aaaa
Merge branch 'refs/heads/dev' into feat/support-app-flows
ahmedAlaaInstabug Apr 19, 2024
6aa71cb
fix: podFile issue
ahmedAlaaInstabug Apr 19, 2024
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends: '@react-native-community',
plugins: ['prettier', 'jest'],
plugins: ['prettier', 'jest', 'jsdoc'],
overrides: [
{
// Jest Overrides
Expand All @@ -27,6 +27,7 @@ module.exports = {
},
],
rules: {
'jsdoc/no-undefined-types': 'warn',
'prettier/prettier': 'error',
'prefer-const': 'error',
},
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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.setAttribute` in favor of the new App Flows APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.SystemClock;
import android.util.Log;

import androidx.annotation.NonNull;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand All @@ -29,6 +30,8 @@ public class RNInstabugAPMModule extends ReactContextBaseJavaModule {
public RNInstabugAPMModule(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
}

@Deprecated
HashMap<String, ExecutionTrace> traces = new HashMap<String, ExecutionTrace>();

@Nonnull
Expand Down Expand Up @@ -121,10 +124,92 @@ public void run() {
});
}

/**
* Starts an AppFlow with the specified name.
* <br/>
* On starting two flows with the same name the older flow will end with force abandon end reason.
* AppFlow name cannot exceed 150 characters otherwise it's truncated,
* leading and trailing whitespaces are also ignored.
*
* @param name AppFlow name. It can not be empty string or null.
* Starts a new AppFlow, if APM is enabled, feature is enabled
* and Instabug SDK is initialised.
*/
@ReactMethod
public void startFlow(@NonNull final String name) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
APM.startFlow(name);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Sets custom attributes for AppFlow with a given name.
* <br/>
* Setting an attribute value to null will remove its corresponding key if it already exists.
* <br/>
* Attribute key name cannot exceed 30 characters.
* Leading and trailing whitespaces are also ignored.
* Does not accept empty strings or null.
* <br/>
* Attribute value name cannot exceed 60 characters,
* leading and trailing whitespaces are also ignored.
* Does not accept empty strings.
* <br/>
* If a trace is ended, attributes will not be added and existing ones will not be updated.
* <br/>
*
* @param name AppFlow name. It can not be empty string or null
* @param key AppFlow attribute key. It can not be empty string or null
* @param value AppFlow attribute value. It can not be empty string. Null to remove attribute
*/
@ReactMethod
public void setFlowAttribute(@NonNull final String name, @NonNull final String key, final String value) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
APM.setFlowAttribute(name, key, value);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Ends AppFlow with a given name.
*
* @param name AppFlow name to be ended. It can not be empty string or null
*/
@ReactMethod
public void endFlow(@NonNull final String name) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
APM.endFlow(name);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Starts an execution trace
*
* @param name string name of the trace.
*
* @deprecated see {@link #startFlow(String)}
*/
@Deprecated
@ReactMethod
public void startExecutionTrace(final String name, final String id, final Promise promise) {
MainThreadHandler.runOnMainThread(new Runnable() {
Expand All @@ -148,10 +233,14 @@ public void run() {

/**
* Adds a new attribute to trace
* @param id String id of the trace.
*
* @param id String id of the trace.
* @param key attribute key
* @param value attribute value. Null to remove attribute
*
* @deprecated see {@link #setFlowAttribute}
*/
@Deprecated
@ReactMethod
public void setExecutionTraceAttribute(final String id, final String key, final String value) {
MainThreadHandler.runOnMainThread(new Runnable() {
Expand All @@ -168,8 +257,12 @@ public void run() {

/**
* Ends a trace
*
* @param id string id of the trace.
*
* @deprecated see {@link #endFlow}
*/
@Deprecated
@ReactMethod
public void endExecutionTrace(final String id) {
MainThreadHandler.runOnMainThread(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ public void givenTruesetEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
verify(promise).resolve(any());
}

@Test
public void testStartFlow() {
String appFlowName = "appFlowName";

apmModule.startFlow(appFlowName);

mockAPM.verify(() -> APM.startFlow(appFlowName));
mockAPM.verifyNoMoreInteractions();
}

@Test
public void testEndFlow() {
String appFlowName = "appFlowName";

apmModule.endFlow(appFlowName);

mockAPM.verify(() -> APM.endFlow(appFlowName));
mockAPM.verifyNoMoreInteractions();
}

@Test
public void testSetFlowAttribute() {
String appFlowName = "appFlowName";
String flowAttributeKey = "attributeKey";
String flowAttributeValue = "attributeValue";
apmModule.setFlowAttribute(appFlowName, flowAttributeKey, flowAttributeValue);

mockAPM.verify(() -> APM.setFlowAttribute(appFlowName, flowAttributeKey, flowAttributeValue));
mockAPM.verifyNoMoreInteractions();
}

// @Test
// public void givenString$setExecutionTraceAttribute_whenQuery_thenShouldCallNativeApiWithIntArgs() {
// // given
Expand Down
44 changes: 35 additions & 9 deletions examples/default/ios/InstabugTests/InstabugAPMTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ - (void) testSetAPMEnabled {
- (void) testSetAppLaunchEnabled {
id mock = OCMClassMock([IBGAPM class]);
BOOL isEnabled = YES;

OCMStub([mock setColdAppLaunchEnabled:isEnabled]);
[self.instabugBridge setAppLaunchEnabled:isEnabled];
OCMVerify([mock setColdAppLaunchEnabled:isEnabled]);
}

- (void) testEndAppLaunch {
id mock = OCMClassMock([IBGAPM class]);

OCMStub([mock endAppLaunch]);
[self.instabugBridge endAppLaunch];
OCMVerify([mock endAppLaunch]);
Expand All @@ -79,7 +79,7 @@ - (void) testEndAppLaunch {
- (void) testSetAutoUITraceEnabled {
id mock = OCMClassMock([IBGAPM class]);
BOOL isEnabled = YES;

OCMStub([mock setAutoUITraceEnabled:isEnabled]);
[self.instabugBridge setAutoUITraceEnabled:isEnabled];
OCMVerify([mock setAutoUITraceEnabled:isEnabled]);
Expand All @@ -91,7 +91,7 @@ - (void) testStartExecutionTrace {
NSString* traceKey = @"1";
RCTPromiseResolveBlock resolve = ^(id result) {};
RCTPromiseRejectBlock reject = ^(NSString *code, NSString *message, NSError *error) {};

OCMStub([mock startExecutionTraceWithName:traceName]);
[self.instabugBridge startExecutionTrace:traceName :traceKey :resolve :reject];
OCMVerify([mock startExecutionTraceWithName:traceName]);
Expand All @@ -107,10 +107,10 @@ - (void) testSetExecutionTraceAttribute {
IBGExecutionTrace * trace = [IBGExecutionTrace alloc];
id mock = OCMClassMock([IBGAPM class]);
id traceMock = OCMPartialMock(trace);

OCMStub([mock startExecutionTraceWithName:traceName]).andReturn(trace);
[self.instabugBridge startExecutionTrace:traceName :traceId :resolve :reject];

OCMStub([traceMock setAttributeWithKey:traceKey value:traceValue]);
[self.instabugBridge setExecutionTraceAttribute:traceId :traceKey :traceValue];
OCMVerify([traceMock setAttributeWithKey:traceKey value:traceValue]);
Expand All @@ -127,24 +127,50 @@ - (void) testEndExecutionTrace {

OCMStub([apmMock startExecutionTraceWithName:traceName]).andReturn(trace);
[self.instabugBridge startExecutionTrace:traceName :traceId :resolve :reject];

OCMStub([traceMock end]);
[self.instabugBridge endExecutionTrace:traceId];
OCMVerify([traceMock end]);
}

- (void) testStartFlow {
id mock = OCMClassMock([IBGAPM class]);
NSString* appFlowName = @"APP_Flow_1";

[self.instabugBridge startFlow:appFlowName];
OCMVerify([mock startFlowWithName:appFlowName]);
}

- (void) testEndFlow {
id mock = OCMClassMock([IBGAPM class]);
NSString* appFlowName = @"APP_Flow_1";

[self.instabugBridge endFlow:appFlowName];
OCMVerify([mock endFlowWithName:appFlowName]);
}

- (void) testSetFlowAttribute {
id mock = OCMClassMock([IBGAPM class]);
NSString* appFlowName = @"APP_Flow_1";
NSString* attributeKey = @"Attribute_Key_1";
NSString* attributeValue = @"Attribute_Value_1";

[self.instabugBridge setFlowAttribute:appFlowName :attributeKey :attributeValue];
OCMVerify([mock setAttributeForFlowWithName:appFlowName key:attributeKey value:attributeValue]);
}

- (void) testStartUITrace {
id mock = OCMClassMock([IBGAPM class]);
NSString* traceName = @"UITrace_1";

OCMStub([mock startUITraceWithName:traceName]);
[self.instabugBridge startUITrace:traceName];
OCMVerify([mock startUITraceWithName:traceName]);
}

- (void) testEndUITrace {
id mock = OCMClassMock([IBGAPM class]);

OCMStub([mock endUITrace]);
[self.instabugBridge endUITrace];
OCMVerify([mock endUITrace]);
Expand Down
9 changes: 6 additions & 3 deletions ios/RNInstabug/InstabugAPMBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
- (void)setAutoUITraceEnabled:(BOOL)isEnabled;
- (void)startExecutionTrace:(NSString *)name :(NSString *)id
:(RCTPromiseResolveBlock)resolve
:(RCTPromiseRejectBlock)reject;
:(RCTPromiseRejectBlock)reject DEPRECATED_MSG_ATTRIBUTE("Please use APM.startFlow instead.");
- (void)setExecutionTraceAttribute:(NSString *)id:(NSString *)key
:(NSString *)value;
- (void)endExecutionTrace:(NSString *)id;
:(NSString *)value DEPRECATED_MSG_ATTRIBUTE("Please use APM.setTraceAttribute instead.");
- (void)endExecutionTrace:(NSString *)id DEPRECATED_MSG_ATTRIBUTE("Please use APM.endFlow instead.");
- (void)startFlow:(NSString *)name;
- (void)endFlow:(NSString *)name;
- (void)setFlowAttribute:(NSString *)name :(NSString *)key :(NSString *_Nullable)value;
- (void)startUITrace:(NSString *)name;
- (void)endUITrace;

Expand Down
13 changes: 13 additions & 0 deletions ios/RNInstabug/InstabugAPMBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ - (id) init
}
}

RCT_EXPORT_METHOD(startFlow: (NSString *)name) {
[IBGAPM startFlowWithName:name];
}

RCT_EXPORT_METHOD(endFlow: (NSString *)name) {
[IBGAPM endFlowWithName:name];
}


RCT_EXPORT_METHOD(setFlowAttribute:(NSString *)name :(NSString *)key :(NSString *_Nullable)value) {
[IBGAPM setAttributeForFlowWithName:name key:key value:value];
}

RCT_EXPORT_METHOD(startUITrace:(NSString *)name) {
[IBGAPM startUITraceWithName:name];
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"commander": "^11.0.0",
"danger": "^11.2.5",
"eslint": "^8.24.0",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-prettier": "^5.0.0",
"esprima": "^4.0.1",
"form-data": "^4.0.0",
Expand Down
15 changes: 11 additions & 4 deletions src/models/Trace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NativeAPM } from '../native/NativeAPM';
import type * as APM from '../modules/APM';

export default class Trace {
constructor(
Expand All @@ -8,18 +9,24 @@ export default class Trace {
) {}

/**
* Add an attribute with key and value to the Trace to be sent.
* @param key
* @param value
* Adds an attribute with a specified key and value to the Trace to be sent.
*
* @param key - The key of the attribute.
* @param value - The value of the attribute.
*
* @deprecated Please migrate to the App Flows APIs: {@link APM.startFlow}, {@link APM.endFlow}, and {@link APM.setFlowAttribute}.
*/
setAttribute(key: string, value: string) {
NativeAPM.setExecutionTraceAttribute(this.id, key, value);
this.attributes[key] = value;
}

/**
* End Execution Trace
* Ends the execution trace.
*
* @deprecated Please migrate to the App Flows APIs: {@link APM.startFlow}, {@link APM.endFlow}, and {@link APM.setFlowAttribute}.
*/

end() {
NativeAPM.endExecutionTrace(this.id);
}
Expand Down
Loading