Skip to content

feat: support app flows APIs #446

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 9 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
### Added

- Add `SessionReplay.getSessionReplayLink` API which retrieves the current session's replay link ([#445](hhttps://github.com/Instabug/Instabug-Flutter/pull/445)).
- Add support for App Flows APIs `APM.startFlow`, `APM.endFlow` and `APM.setFlowAttribute` ([#446](https://github.com/Instabug/Instabug-Flutter/pull/446)).

### Deprecated

- Deprecate execution traces APIs `APM.startExecutionTrace`, `APM.setExecutionTraceAttribute`, `APM.endExecutionTrace`, `Trace.setAttribute` and `Trace.end` in favor of the new app flow APIs ([#446](https://github.com/Instabug/Instabug-Flutter/pull/446)).

## [12.7.0](https://github.com/Instabug/Instabug-Flutter/compare/v12.5.0...v12.7.0) (February 15, 2024)

Expand Down
34 changes: 29 additions & 5 deletions android/src/main/java/com/instabug/flutter/modules/ApmApi.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package com.instabug.flutter.modules;

import android.util.Log;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;
import com.instabug.apm.APM;
import com.instabug.apm.model.ExecutionTrace;
import com.instabug.apm.networking.APMNetworkLogger;
import com.instabug.flutter.generated.ApmPigeon;
import com.instabug.flutter.util.Reflection;
import com.instabug.flutter.util.ThreadManager;

import io.flutter.plugin.common.BinaryMessenger;
import org.json.JSONObject;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import io.flutter.plugin.common.BinaryMessenger;

public class ApmApi implements ApmPigeon.ApmHostApi {
private final String TAG = ApmApi.class.getName();
private final HashMap<String, ExecutionTrace> traces = new HashMap<>();
Expand Down Expand Up @@ -95,6 +92,33 @@ public void run() {
);
}

@Override
public void startFlow(@NonNull String name) {
try {
APM.startFlow(name);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void setFlowAttribute(@NonNull String name, @NonNull String key, @Nullable String value) {
try {
APM.setFlowAttribute(name, key, value);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void endFlow(@NonNull String name) {
try {
APM.endFlow(name);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void setExecutionTraceAttribute(@NonNull String id, @NonNull String key, @NonNull String value) {
try {
Expand Down
33 changes: 33 additions & 0 deletions android/src/test/java/com/instabug/flutter/ApmApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,39 @@ public void testEndExecutionTrace() {
verify(mTrace).end();
}

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

api.startFlow(appFlowName);

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

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

api.startFlow(appFlowName);

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

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


api.setFlowAttribute(appFlowName, flowAttributeKey, flowAttributeValue);

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

@Test
public void testStartUITrace() {
String name = "login";
Expand Down
29 changes: 29 additions & 0 deletions example/ios/InstabugTests/ApmApiTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,35 @@ - (void)testEndExecutionTrace {
OCMVerify([mTrace end]);
}

- (void) testStartFlow {
NSString* appFlowName = @"app-flow-name";
FlutterError *error;

[self.api startFlowName:appFlowName error:&error];

OCMVerify([self.mAPM startFlowWithName:appFlowName]);
}

- (void) testEndFlow {
NSString* appFlowName = @"app-flow-name";
FlutterError *error;

[self.api endFlowName:appFlowName error:&error];

OCMVerify([self.mAPM endFlowWithName:appFlowName]);
}

- (void) testSetFlowAttribute {
NSString* appFlowName = @"app-flow-name";
NSString* attributeKey = @"attribute-key";
NSString* attributeValue = @"attribute-value";
FlutterError *error;

[self.api setFlowAttributeName:appFlowName key:attributeKey value:attributeValue error:&error];

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

- (void)testStartUITrace {
NSString *name = @"login";
FlutterError *error;
Expand Down
98 changes: 61 additions & 37 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
sha256: "80e5141fafcb3361653ce308776cfd7d45e6e9fbb429e14eec571382c0c5fecb"
url: "https://pub.dev"
source: hosted
version: "3.3.2"
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
url: "https://pub.dev"
source: hosted
version: "2.11.0"
version: "2.10.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,10 +29,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.1"
clock:
dependency: transitive
description:
Expand All @@ -37,10 +45,18 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.0"
crypto:
dependency: transitive
description:
name: crypto
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
url: "https://pub.dev"
source: hosted
version: "3.0.2"
espresso:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -92,46 +108,54 @@ packages:
relative: true
source: path
version: "12.7.0"
js:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
matcher:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.13"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.8.2"
platform:
dependency: transitive
description:
name: platform
sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
url: "https://pub.dev"
source: hosted
version: "3.1.2"
version: "3.1.0"
process:
dependency: transitive
description:
Expand All @@ -149,26 +173,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -197,10 +221,18 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
url: "https://pub.dev"
source: hosted
version: "0.4.16"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "1.3.1"
vector_math:
dependency: transitive
description:
Expand All @@ -213,26 +245,18 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583
url: "https://pub.dev"
source: hosted
version: "11.10.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "9.4.0"
webdriver:
dependency: transitive
description:
name: webdriver
sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49"
sha256: ef67178f0cc7e32c1494645b11639dd1335f1d18814aa8435113a92e9ef9d841
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.1"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=2.18.0 <3.0.0"
flutter: ">=2.10.0"
12 changes: 12 additions & 0 deletions ios/Classes/Modules/ApmApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ - (void)endExecutionTraceId:(NSString *)id error:(FlutterError *_Nullable *_Nonn
}
}

- (void)startFlowName:(nonnull NSString *)name error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
[IBGAPM startFlowWithName:name];
}

- (void)setFlowAttributeName:(nonnull NSString *)name key:(nonnull NSString *)key value:(nullable NSString *)value error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
[IBGAPM setAttributeForFlowWithName:name key:key value:value];
}

- (void)endFlowName:(nonnull NSString *)name error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
[IBGAPM endFlowWithName:name];
}

- (void)startUITraceName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error {
[IBGAPM startUITraceWithName:name];
}
Expand Down
Loading