Skip to content

feat(ios): add session sync callback #1282

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 59 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
77b8993
feat(android): add SRSyncCallback
kholood-ea Aug 28, 2024
e6b816f
feat: implement and test syncCallback CP side
kholood-ea Aug 28, 2024
bad72d6
feat(example): use SRSyncCallback in example app
kholood-ea Aug 28, 2024
2b01c9d
ci: fix tests
kholood-ea Aug 28, 2024
61d6e52
fix: export session data type
kholood-ea Sep 2, 2024
849648a
fix(example): use session data type
kholood-ea Sep 2, 2024
02c621c
fix(android):remove data modifier
kholood-ea Sep 2, 2024
0d9c7f1
fix(android): add property modifiers
kholood-ea Sep 2, 2024
261aa76
fix(android): update test case
kholood-ea Sep 2, 2024
5056f58
fix: enhance test case
kholood-ea Sep 5, 2024
8d9036e
fix(ios): update network log signature
kholood-ea Sep 8, 2024
1ce3f36
chore(ios): integrate dynamic sampling snapshot
kholood-ea Sep 8, 2024
043f3df
fix:update IOS network log unit test
kholood-ea Sep 8, 2024
8a0c9cc
fix: update session metadata
kholood-ea Sep 9, 2024
65cd192
feat(ios): add setSyncCallback
kholood-ea Sep 9, 2024
36ca2ad
fix: pod.lock file
kholood-ea Sep 9, 2024
2ff447f
fix: update session data type
kholood-ea Sep 9, 2024
131a795
fix: add more session metadata to setSyncCallback
kholood-ea Sep 10, 2024
2b53766
fix: update syncCallback test
kholood-ea Sep 10, 2024
41e6b52
feat: add launchType to session metadata for setSyncCallback
kholood-ea Sep 11, 2024
c6b9173
fix: import type
kholood-ea Sep 12, 2024
5e237a0
fix: enhance test case
kholood-ea Sep 5, 2024
44901df
fix: add more session metadata to setSyncCallback
kholood-ea Sep 10, 2024
4b492dc
fix: update syncCallback test
kholood-ea Sep 10, 2024
c76ef3b
feat: add launchType to session metadata for setSyncCallback
kholood-ea Sep 11, 2024
0c0031c
fix: import type
kholood-ea Sep 12, 2024
5c75de1
feat(ios): add launchType metadata to session syncCallback
kholood-ea Sep 12, 2024
71b5585
fix: add unknown type to launch types
kholood-ea Sep 16, 2024
3b1c37b
fix: assert evaluate sync returns correct value
kholood-ea Sep 16, 2024
446e9e4
fix: import type
kholood-ea Sep 16, 2024
8187f60
fix: cleanup
kholood-ea Sep 16, 2024
d0e972c
chore: update js doc
kholood-ea Sep 16, 2024
c700600
fix: typo
kholood-ea Sep 16, 2024
38bf28f
fix: follow interface naming convention
kholood-ea Sep 16, 2024
8cef372
fix: update type
kholood-ea Sep 16, 2024
40556ec
fix: refactor syncCallback
kholood-ea Sep 16, 2024
bc4f699
fix: default syncing session to true
kholood-ea Sep 16, 2024
6eec19f
fix: convert network logs to readable array
kholood-ea Sep 16, 2024
b3c0a31
chore: add discriptive comment
kholood-ea Sep 16, 2024
e50fbef
chore: use readable map for session metadata
a7medev Sep 16, 2024
d08d84c
fix: setSyncCallback should sync in case of exception
kholood-ea Sep 18, 2024
6ee32a8
fix: move SessionMetadata to models
kholood-ea Sep 18, 2024
6bf9f32
fix: update SessionMetadata type import
kholood-ea Sep 18, 2024
df89665
fix: report bug e2e test
kholood-ea Sep 18, 2024
c60cb78
Merge remote-tracking branch 'origin/feat/session-sync-callback-andro…
kholood-ea Sep 18, 2024
23276be
chore (ios): update snapshot
kholood-ea Sep 18, 2024
3a58433
chore (ios): refactor callback
kholood-ea Sep 18, 2024
479e0de
Merge branch 'feat/session-sync-callback' into feat/session-sync-call…
kholood-ea Sep 18, 2024
fc3337c
fix: return network logs
kholood-ea Sep 19, 2024
bae6d68
chore: update podfile.lock
kholood-ea Sep 19, 2024
8fff79b
chore: fix formatting
kholood-ea Sep 19, 2024
9e69dd8
chore: revert Podfile.lock
kholood-ea Sep 19, 2024
5ea6e35
chore: fix ci
kholood-ea Sep 19, 2024
4729287
fix: launchType typo
kholood-ea Sep 23, 2024
de5c6ce
fix: update class sessionEvaluationCompletion atomicity
kholood-ea Sep 23, 2024
4d9a186
chore: enhance syncCallback formatting
kholood-ea Sep 23, 2024
6677b17
chore: update evaluateSync formatting
kholood-ea Sep 23, 2024
1afe9d3
fix: fix test SetSyncCallback
kholood-ea Sep 26, 2024
250cb94
fix: update getNetworkLogsArray return value
kholood-ea Sep 30, 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
2 changes: 1 addition & 1 deletion RNInstabug.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm}"

s.dependency 'React-Core'
use_instabug!(s)
s.dependency 'Instabug'
end
7 changes: 2 additions & 5 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ - (void)testNetworkLogIOS {
double startTime = 1719847101199;
double duration = 150;
NSString *gqlQueryName = nil;
NSString *serverErrorMessage = nil;

[self.instabugBridge networkLogIOS:url
method:method
Expand All @@ -347,8 +346,7 @@ - (void)testNetworkLogIOS {
errorCode:errorCode
startTime:startTime
duration:duration
gqlQueryName:gqlQueryName
serverErrorMessage:serverErrorMessage];
gqlQueryName:gqlQueryName];

OCMVerify([mIBGNetworkLogger addNetworkLogWithUrl:url
method:method
Expand All @@ -364,8 +362,7 @@ - (void)testNetworkLogIOS {
errorCode:errorCode
startTime:startTime * 1000
duration:duration * 1000
gqlQueryName:gqlQueryName
serverErrorMessage:serverErrorMessage]);
gqlQueryName:gqlQueryName]);
}

- (void)testSetFileAttachment {
Expand Down
53 changes: 50 additions & 3 deletions examples/default/ios/InstabugTests/InstabugSessionReplayTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ @implementation InstabugSessionReplayTests


- (void)setUp {
self.mSessionReplay = OCMClassMock([IBGSessionReplay class]);
self.bridge = [[InstabugSessionReplayBridge alloc] init];
self.mSessionReplay = OCMClassMock([IBGSessionReplay class]);
self.bridge = [[InstabugSessionReplayBridge alloc] init];
}

- (void)testSetEnabled {
Expand Down Expand Up @@ -67,7 +67,54 @@ - (void)testGetSessionReplayLink {
[self.bridge getSessionReplayLink:resolve :reject];
OCMVerify([self.mSessionReplay sessionReplayLink]);
[self waitForExpectations:@[expectation] timeout:5.0];

}

- (void)testSetSyncCallback {
id mockMetadata = OCMClassMock([IBGSessionMetadata class]);
id mockNetworkLog = OCMClassMock([IBGSessionMetadataNetworkLogs class]);
id partialMock = OCMPartialMock(self.bridge);

XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion block should be called with the expected value"];

BOOL expectedValue = YES;
__block BOOL actualValue = NO;

OCMStub([mockNetworkLog url]).andReturn(@"http://example.com");
OCMStub([mockNetworkLog statusCode]).andReturn(200);

OCMStub([mockMetadata device]).andReturn(@"ipohne");
OCMStub([mockMetadata os]).andReturn(@"ios");
OCMStub([mockMetadata appVersion]).andReturn(@"13.4.1");
OCMStub([mockMetadata sessionDuration]).andReturn(20);
OCMStub([mockMetadata hasLinkToAppReview]).andReturn(NO);
OCMStub([mockMetadata launchType]).andReturn(LaunchTypeCold);
OCMStub([mockMetadata launchDuration]).andReturn(20);
OCMStub([mockMetadata bugsCount]).andReturn(10);
OCMStub([mockMetadata fatalCrashCount]).andReturn(10);
OCMStub([mockMetadata oomCrashCount]).andReturn(10);
OCMStub([mockMetadata networkLogs]).andReturn(@[mockNetworkLog]);

SessionEvaluationCompletion sessionEvaluationCompletion = ^(BOOL shouldSync) {
actualValue = shouldSync;
[completionExpectation fulfill];
};

OCMStub([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]).andDo(^(NSInvocation *invocation) {
[self.bridge evaluateSync:expectedValue];
});

OCMStub([self.mSessionReplay setSyncCallbackWithHandler:[OCMArg checkWithBlock: ^BOOL(void(^handler)(IBGSessionMetadata *metadataObject, SessionEvaluationCompletion completion)) {
handler(mockMetadata, sessionEvaluationCompletion);
return YES;
}]]);

[self.bridge setSyncCallback];
[self waitForExpectationsWithTimeout:1 handler:nil];

OCMVerify([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]);
OCMVerifyAll(self.mSessionReplay);
XCTAssertEqual(actualValue, expectedValue);
}


@end
4 changes: 2 additions & 2 deletions examples/default/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ target 'InstabugExample' do
target 'InstabugTests' do
inherit! :complete
pod 'OCMock'
# Pods for testing
end
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec'
end

post_install do |installer|
react_native_post_install(
Expand Down
18 changes: 10 additions & 8 deletions examples/default/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ PODS:
- hermes-engine (0.72.3):
- hermes-engine/Pre-built (= 0.72.3)
- hermes-engine/Pre-built (0.72.3)
- Instabug (13.3.0)
- Instabug (13.4.0)
- instabug-reactnative-ndk (0.1.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- libevent (2.1.12)
- OCMock (3.9.3)
- OCMock (3.9.4)
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -476,7 +476,7 @@ PODS:
- RCT-Folly (= 2021.07.22.00)
- React-Core
- RNInstabug (13.3.0):
- Instabug (= 13.3.0)
- Instabug
- React-Core
- RNReanimated (3.5.4):
- DoubleConversion
Expand Down Expand Up @@ -524,6 +524,7 @@ DEPENDENCIES:
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- Instabug (from `https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec`)
- instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`)
- libevent (~> 2.1.12)
- OCMock
Expand Down Expand Up @@ -580,7 +581,6 @@ SPEC REPOS:
- fmt
- Google-Maps-iOS-Utils
- GoogleMaps
- Instabug
- libevent
- OCMock
- SocketRocket
Expand All @@ -599,6 +599,8 @@ EXTERNAL SOURCES:
hermes-engine:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
:tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77
Instabug:
:podspec: https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec
instabug-reactnative-ndk:
:path: "../node_modules/instabug-reactnative-ndk"
RCT-Folly:
Expand Down Expand Up @@ -704,10 +706,10 @@ SPEC CHECKSUMS:
Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a
GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac
hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322
Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa
Instabug: 16e4c013f2ae57ddca4966ea90736e48bbcdd2d5
instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OCMock: 300b1b1b9155cb6378660b981c2557448830bdc6
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: a2faf4bad4e438ca37b2040cb8f7799baa065c18
RCTTypeSafety: cb09f3e4747b6d18331a15eb05271de7441ca0b3
Expand Down Expand Up @@ -748,14 +750,14 @@ SPEC CHECKSUMS:
ReactCommon: 3ccb8fb14e6b3277e38c73b0ff5e4a1b8db017a9
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
RNGestureHandler: 6e46dde1f87e5f018a54fe5d40cd0e0b942b49ee
RNInstabug: a4ac0bd09123f6be7d58be541dc220acbaff8dc3
RNInstabug: 80b369d623a473c31ff3b8b8ea1d17daaca44132
RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87
RNScreens: b21dc57dfa2b710c30ec600786a3fc223b1b92e7
RNSVG: 80584470ff1ffc7994923ea135a3e5ad825546b9
RNVectorIcons: 8b5bb0fa61d54cd2020af4f24a51841ce365c7e9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce

PODFILE CHECKSUM: 281036e04bd4b9e7c2cc03a503b3245d3f1dd0dd
PODFILE CHECKSUM: f16fc6271767fab2dc19a52068caa1ca15e29e62

COCOAPODS: 1.12.0
1 change: 1 addition & 0 deletions ios/RNInstabug/ArgsRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef NSDictionary<NSString*, NSNumber*> ArgsDictionary;
+ (ArgsDictionary *) reproStates;
+ (ArgsDictionary *) locales;
+ (ArgsDictionary *)nonFatalExceptionLevel;
+ (ArgsDictionary *) launchType;

+ (NSDictionary<NSString *, NSString *> *) placeholders;

Expand Down
9 changes: 9 additions & 0 deletions ios/RNInstabug/ArgsRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ + (NSMutableDictionary *) getAll {
[all addEntriesFromDictionary:ArgsRegistry.locales];
[all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel];
[all addEntriesFromDictionary:ArgsRegistry.placeholders];
[all addEntriesFromDictionary:ArgsRegistry.launchType];

return all;
}
Expand Down Expand Up @@ -241,4 +242,12 @@ + (ArgsDictionary *)nonFatalExceptionLevel {
};
}

+ (ArgsDictionary *) launchType {
return @{
@"hot": @(LaunchTypeHot),
@"cold": @(LaunchTypeCold),
@"unknown":@(LaunchTypeUnknown)
};
}

@end
4 changes: 1 addition & 3 deletions ios/RNInstabug/InstabugReactBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@
errorCode:(double)errorCode
startTime:(double)startTime
duration:(double)duration
gqlQueryName:(NSString * _Nullable)gqlQueryName
serverErrorMessage:(NSString * _Nullable)serverErrorMessage;

gqlQueryName:(NSString * _Nullable)gqlQueryName;
/*
+------------------------------------------------------------------------+
| Experiments |
Expand Down
6 changes: 2 additions & 4 deletions ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ - (dispatch_queue_t)methodQueue {
errorCode:(double)errorCode
startTime:(double)startTime
duration:(double)duration
gqlQueryName:(NSString * _Nullable)gqlQueryName
serverErrorMessage:(NSString * _Nullable)serverErrorMessage) {
gqlQueryName:(NSString * _Nullable)gqlQueryName) {
[IBGNetworkLogger addNetworkLogWithUrl:url
method:method
requestBody:requestBody
Expand All @@ -313,8 +312,7 @@ - (dispatch_queue_t)methodQueue {
errorCode:errorCode
startTime:startTime * 1000
duration:duration * 1000
gqlQueryName:gqlQueryName
serverErrorMessage:serverErrorMessage];
gqlQueryName:gqlQueryName];
}

RCT_EXPORT_METHOD(addPrivateView: (nonnull NSNumber *)reactTag) {
Expand Down
7 changes: 7 additions & 0 deletions ios/RNInstabug/InstabugSessionReplayBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <Instabug/IBGTypes.h>
#import <Instabug/IBGSessionReplay.h>

@interface InstabugSessionReplayBridge : RCTEventEmitter <RCTBridgeModule>
/*
Expand All @@ -20,6 +21,12 @@

- (void)getSessionReplayLink:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject;

- (void)setSyncCallback;

- (void)evaluateSync:(BOOL)result;

@property (atomic, copy) SessionEvaluationCompletion sessionEvaluationCompletion;

@end


53 changes: 52 additions & 1 deletion ios/RNInstabug/InstabugSessionReplayBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ + (BOOL)requiresMainQueueSetup
}

- (NSArray<NSString *> *)supportedEvents {
return @[];
return @[
@"IBGSessionReplayOnSyncCallback",
];
}

RCT_EXPORT_MODULE(IBGSessionReplay)
Expand All @@ -45,6 +47,55 @@ + (BOOL)requiresMainQueueSetup
resolve(link);
}

- (NSArray<NSDictionary *> *)getNetworkLogsArray:
(NSArray<IBGSessionMetadataNetworkLogs *>*) networkLogs {
NSMutableArray<NSDictionary *> *networkLogsArray = [NSMutableArray array];

for (IBGSessionMetadataNetworkLogs* log in networkLogs) {
NSDictionary *nLog = @{@"url": log.url, @"statusCode": @(log.statusCode), @"duration": @(log.duration)};
[networkLogsArray addObject:nLog];
}
return networkLogsArray;
}

- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject {
return @{
@"appVersion": metadataObject.appVersion,
@"OS": metadataObject.os,
@"device": metadataObject.device,
@"sessionDurationInSeconds": @(metadataObject.sessionDuration),
@"hasLinkToAppReview": @(metadataObject.hasLinkToAppReview),
@"launchType": @(metadataObject.launchType),
@"launchDuration": @(metadataObject.launchDuration),
@"bugsCount": @(metadataObject.bugsCount),
@"fatalCrashCount": @(metadataObject.fatalCrashCount),
@"oomCrashCount": @(metadataObject.oomCrashCount),
@"networkLogs":[self getNetworkLogsArray:metadataObject.networkLogs]
};
}

RCT_EXPORT_METHOD(setSyncCallback) {
[IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) {

[self sendEventWithName:@"IBGSessionReplayOnSyncCallback"
body:[self getMetadataObjectMap:metadataObject]];

self.sessionEvaluationCompletion = completion;
}];
}

RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) {

if (self.sessionEvaluationCompletion) {

self.sessionEvaluationCompletion(result);

self.sessionEvaluationCompletion = nil;

}
}


@synthesize description;

@synthesize hash;
Expand Down
3 changes: 1 addition & 2 deletions ios/RNInstabug/Util/IBGNetworkLogger+CP.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
errorCode:(int32_t)errorCode
startTime:(int64_t)startTime
duration:(int64_t) duration
gqlQueryName:(NSString * _Nullable)gqlQueryName
serverErrorMessage:(NSString * _Nullable)serverErrorMessage;
gqlQueryName:(NSString * _Nullable)gqlQueryName;

@end

Expand Down
1 change: 1 addition & 0 deletions src/native/NativeConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,5 @@ interface NativeLaunchType {
hot: any;
cold: any;
warm: any;
unknown: any;
}
1 change: 0 additions & 1 deletion src/native/NativeInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface InstabugNativeModule extends NativeModule {
startTime: number,
duration: number,
gqlQueryName: string | undefined,
serverErrorMessage: string | undefined,
): void;

setNetworkLoggingEnabled(isEnabled: boolean): void;
Expand Down
1 change: 1 addition & 0 deletions src/utils/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export enum StringKey {
export enum LaunchType {
hot = constants.hot,
cold = constants.cold,
unknown = constants.unknown,
/**
* android only
*/
Expand Down
1 change: 0 additions & 1 deletion src/utils/InstabugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export function reportNetworkLog(network: NetworkData) {
network.startTime,
network.duration,
network.gqlQueryName,
network.serverErrorMessage,
);
}
}
Expand Down
1 change: 0 additions & 1 deletion test/utils/InstabugUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ describe('reportNetworkLog', () => {
network.startTime,
network.duration,
network.gqlQueryName,
network.serverErrorMessage,
);
});
});