Skip to content

Commit c1a8e5d

Browse files
kholood-eaa7medev
andauthored
feat(ios): add session sync callback (#1282)
* feat(android): add SRSyncCallback * feat: implement and test syncCallback CP side * feat(example): use SRSyncCallback in example app * ci: fix tests * fix: export session data type * fix(example): use session data type * fix(android):remove data modifier * fix(android): add property modifiers * fix(android): update test case * fix: enhance test case * fix(ios): update network log signature * chore(ios): integrate dynamic sampling snapshot * fix:update IOS network log unit test * fix: update session metadata * feat(ios): add setSyncCallback * fix: pod.lock file * fix: update session data type * fix: add more session metadata to setSyncCallback * fix: update syncCallback test * feat: add launchType to session metadata for setSyncCallback * fix: import type * fix: enhance test case * fix: add more session metadata to setSyncCallback * fix: update syncCallback test * feat: add launchType to session metadata for setSyncCallback * fix: import type * feat(ios): add launchType metadata to session syncCallback * fix: add unknown type to launch types * fix: assert evaluate sync returns correct value * fix: import type * fix: cleanup * chore: update js doc * fix: typo * fix: follow interface naming convention * fix: update type * fix: refactor syncCallback * fix: default syncing session to true * fix: convert network logs to readable array * chore: add discriptive comment * chore: use readable map for session metadata * fix: setSyncCallback should sync in case of exception * fix: move SessionMetadata to models * fix: update SessionMetadata type import * fix: report bug e2e test * chore (ios): update snapshot * chore (ios): refactor callback * fix: return network logs * chore: update podfile.lock * chore: fix formatting * chore: revert Podfile.lock * chore: fix ci * fix: launchType typo * fix: update class sessionEvaluationCompletion atomicity * chore: enhance syncCallback formatting * chore: update evaluateSync formatting * fix: fix test SetSyncCallback * fix: update getNetworkLogsArray return value --------- Co-authored-by: Ahmed Elrefaey <[email protected]>
1 parent 1ebcf4a commit c1a8e5d

17 files changed

+140
-32
lines changed

RNInstabug.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
1616
s.source_files = "ios/**/*.{h,m,mm}"
1717

1818
s.dependency 'React-Core'
19-
use_instabug!(s)
19+
s.dependency 'Instabug'
2020
end

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ - (void)testNetworkLogIOS {
331331
double startTime = 1719847101199;
332332
double duration = 150;
333333
NSString *gqlQueryName = nil;
334-
NSString *serverErrorMessage = nil;
335334

336335
[self.instabugBridge networkLogIOS:url
337336
method:method
@@ -347,8 +346,7 @@ - (void)testNetworkLogIOS {
347346
errorCode:errorCode
348347
startTime:startTime
349348
duration:duration
350-
gqlQueryName:gqlQueryName
351-
serverErrorMessage:serverErrorMessage];
349+
gqlQueryName:gqlQueryName];
352350

353351
OCMVerify([mIBGNetworkLogger addNetworkLogWithUrl:url
354352
method:method
@@ -364,8 +362,7 @@ - (void)testNetworkLogIOS {
364362
errorCode:errorCode
365363
startTime:startTime * 1000
366364
duration:duration * 1000
367-
gqlQueryName:gqlQueryName
368-
serverErrorMessage:serverErrorMessage]);
365+
gqlQueryName:gqlQueryName]);
369366
}
370367

371368
- (void)testSetFileAttachment {

examples/default/ios/InstabugTests/InstabugSessionReplayTests.m

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ @implementation InstabugSessionReplayTests
1616

1717

1818
- (void)setUp {
19-
self.mSessionReplay = OCMClassMock([IBGSessionReplay class]);
20-
self.bridge = [[InstabugSessionReplayBridge alloc] init];
19+
self.mSessionReplay = OCMClassMock([IBGSessionReplay class]);
20+
self.bridge = [[InstabugSessionReplayBridge alloc] init];
2121
}
2222

2323
- (void)testSetEnabled {
@@ -67,7 +67,54 @@ - (void)testGetSessionReplayLink {
6767
[self.bridge getSessionReplayLink:resolve :reject];
6868
OCMVerify([self.mSessionReplay sessionReplayLink]);
6969
[self waitForExpectations:@[expectation] timeout:5.0];
70-
7170
}
7271

72+
- (void)testSetSyncCallback {
73+
id mockMetadata = OCMClassMock([IBGSessionMetadata class]);
74+
id mockNetworkLog = OCMClassMock([IBGSessionMetadataNetworkLogs class]);
75+
id partialMock = OCMPartialMock(self.bridge);
76+
77+
XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion block should be called with the expected value"];
78+
79+
BOOL expectedValue = YES;
80+
__block BOOL actualValue = NO;
81+
82+
OCMStub([mockNetworkLog url]).andReturn(@"http://example.com");
83+
OCMStub([mockNetworkLog statusCode]).andReturn(200);
84+
85+
OCMStub([mockMetadata device]).andReturn(@"ipohne");
86+
OCMStub([mockMetadata os]).andReturn(@"ios");
87+
OCMStub([mockMetadata appVersion]).andReturn(@"13.4.1");
88+
OCMStub([mockMetadata sessionDuration]).andReturn(20);
89+
OCMStub([mockMetadata hasLinkToAppReview]).andReturn(NO);
90+
OCMStub([mockMetadata launchType]).andReturn(LaunchTypeCold);
91+
OCMStub([mockMetadata launchDuration]).andReturn(20);
92+
OCMStub([mockMetadata bugsCount]).andReturn(10);
93+
OCMStub([mockMetadata fatalCrashCount]).andReturn(10);
94+
OCMStub([mockMetadata oomCrashCount]).andReturn(10);
95+
OCMStub([mockMetadata networkLogs]).andReturn(@[mockNetworkLog]);
96+
97+
SessionEvaluationCompletion sessionEvaluationCompletion = ^(BOOL shouldSync) {
98+
actualValue = shouldSync;
99+
[completionExpectation fulfill];
100+
};
101+
102+
OCMStub([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]).andDo(^(NSInvocation *invocation) {
103+
[self.bridge evaluateSync:expectedValue];
104+
});
105+
106+
OCMStub([self.mSessionReplay setSyncCallbackWithHandler:[OCMArg checkWithBlock: ^BOOL(void(^handler)(IBGSessionMetadata *metadataObject, SessionEvaluationCompletion completion)) {
107+
handler(mockMetadata, sessionEvaluationCompletion);
108+
return YES;
109+
}]]);
110+
111+
[self.bridge setSyncCallback];
112+
[self waitForExpectationsWithTimeout:1 handler:nil];
113+
114+
OCMVerify([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]);
115+
OCMVerifyAll(self.mSessionReplay);
116+
XCTAssertEqual(actualValue, expectedValue);
117+
}
118+
119+
73120
@end

examples/default/ios/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ target 'InstabugExample' do
3232
target 'InstabugTests' do
3333
inherit! :complete
3434
pod 'OCMock'
35-
# Pods for testing
36-
end
35+
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec'
36+
end
3737

3838
post_install do |installer|
3939
react_native_post_install(

examples/default/ios/Podfile.lock

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ PODS:
3838
- hermes-engine (0.72.3):
3939
- hermes-engine/Pre-built (= 0.72.3)
4040
- hermes-engine/Pre-built (0.72.3)
41-
- Instabug (13.3.0)
41+
- Instabug (13.4.0)
4242
- instabug-reactnative-ndk (0.1.0):
4343
- RCT-Folly (= 2021.07.22.00)
4444
- React-Core
4545
- libevent (2.1.12)
46-
- OCMock (3.9.3)
46+
- OCMock (3.9.4)
4747
- RCT-Folly (2021.07.22.00):
4848
- boost
4949
- DoubleConversion
@@ -476,7 +476,7 @@ PODS:
476476
- RCT-Folly (= 2021.07.22.00)
477477
- React-Core
478478
- RNInstabug (13.3.0):
479-
- Instabug (= 13.3.0)
479+
- Instabug
480480
- React-Core
481481
- RNReanimated (3.5.4):
482482
- DoubleConversion
@@ -524,6 +524,7 @@ DEPENDENCIES:
524524
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
525525
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
526526
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
527+
- Instabug (from `https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec`)
527528
- instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`)
528529
- libevent (~> 2.1.12)
529530
- OCMock
@@ -580,7 +581,6 @@ SPEC REPOS:
580581
- fmt
581582
- Google-Maps-iOS-Utils
582583
- GoogleMaps
583-
- Instabug
584584
- libevent
585585
- OCMock
586586
- SocketRocket
@@ -599,6 +599,8 @@ EXTERNAL SOURCES:
599599
hermes-engine:
600600
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
601601
:tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77
602+
Instabug:
603+
:podspec: https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec
602604
instabug-reactnative-ndk:
603605
:path: "../node_modules/instabug-reactnative-ndk"
604606
RCT-Folly:
@@ -704,10 +706,10 @@ SPEC CHECKSUMS:
704706
Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a
705707
GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac
706708
hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322
707-
Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa
709+
Instabug: 16e4c013f2ae57ddca4966ea90736e48bbcdd2d5
708710
instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17
709711
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
710-
OCMock: 300b1b1b9155cb6378660b981c2557448830bdc6
712+
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
711713
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
712714
RCTRequired: a2faf4bad4e438ca37b2040cb8f7799baa065c18
713715
RCTTypeSafety: cb09f3e4747b6d18331a15eb05271de7441ca0b3
@@ -748,14 +750,14 @@ SPEC CHECKSUMS:
748750
ReactCommon: 3ccb8fb14e6b3277e38c73b0ff5e4a1b8db017a9
749751
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
750752
RNGestureHandler: 6e46dde1f87e5f018a54fe5d40cd0e0b942b49ee
751-
RNInstabug: a4ac0bd09123f6be7d58be541dc220acbaff8dc3
753+
RNInstabug: 80b369d623a473c31ff3b8b8ea1d17daaca44132
752754
RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87
753755
RNScreens: b21dc57dfa2b710c30ec600786a3fc223b1b92e7
754756
RNSVG: 80584470ff1ffc7994923ea135a3e5ad825546b9
755757
RNVectorIcons: 8b5bb0fa61d54cd2020af4f24a51841ce365c7e9
756758
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
757759
Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce
758760

759-
PODFILE CHECKSUM: 281036e04bd4b9e7c2cc03a503b3245d3f1dd0dd
761+
PODFILE CHECKSUM: f16fc6271767fab2dc19a52068caa1ca15e29e62
760762

761763
COCOAPODS: 1.12.0

ios/RNInstabug/ArgsRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef NSDictionary<NSString*, NSNumber*> ArgsDictionary;
2222
+ (ArgsDictionary *) reproStates;
2323
+ (ArgsDictionary *) locales;
2424
+ (ArgsDictionary *)nonFatalExceptionLevel;
25+
+ (ArgsDictionary *) launchType;
2526

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

ios/RNInstabug/ArgsRegistry.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ + (NSMutableDictionary *) getAll {
2020
[all addEntriesFromDictionary:ArgsRegistry.locales];
2121
[all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel];
2222
[all addEntriesFromDictionary:ArgsRegistry.placeholders];
23+
[all addEntriesFromDictionary:ArgsRegistry.launchType];
2324

2425
return all;
2526
}
@@ -241,4 +242,12 @@ + (ArgsDictionary *)nonFatalExceptionLevel {
241242
};
242243
}
243244

245+
+ (ArgsDictionary *) launchType {
246+
return @{
247+
@"hot": @(LaunchTypeHot),
248+
@"cold": @(LaunchTypeCold),
249+
@"unknown":@(LaunchTypeUnknown)
250+
};
251+
}
252+
244253
@end

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@
120120
errorCode:(double)errorCode
121121
startTime:(double)startTime
122122
duration:(double)duration
123-
gqlQueryName:(NSString * _Nullable)gqlQueryName
124-
serverErrorMessage:(NSString * _Nullable)serverErrorMessage;
125-
123+
gqlQueryName:(NSString * _Nullable)gqlQueryName;
126124
/*
127125
+------------------------------------------------------------------------+
128126
| Experiments |

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ - (dispatch_queue_t)methodQueue {
297297
errorCode:(double)errorCode
298298
startTime:(double)startTime
299299
duration:(double)duration
300-
gqlQueryName:(NSString * _Nullable)gqlQueryName
301-
serverErrorMessage:(NSString * _Nullable)serverErrorMessage) {
300+
gqlQueryName:(NSString * _Nullable)gqlQueryName) {
302301
[IBGNetworkLogger addNetworkLogWithUrl:url
303302
method:method
304303
requestBody:requestBody
@@ -313,8 +312,7 @@ - (dispatch_queue_t)methodQueue {
313312
errorCode:errorCode
314313
startTime:startTime * 1000
315314
duration:duration * 1000
316-
gqlQueryName:gqlQueryName
317-
serverErrorMessage:serverErrorMessage];
315+
gqlQueryName:gqlQueryName];
318316
}
319317

320318
RCT_EXPORT_METHOD(addPrivateView: (nonnull NSNumber *)reactTag) {

ios/RNInstabug/InstabugSessionReplayBridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#import <React/RCTBridgeModule.h>
33
#import <React/RCTEventEmitter.h>
44
#import <Instabug/IBGTypes.h>
5+
#import <Instabug/IBGSessionReplay.h>
56

67
@interface InstabugSessionReplayBridge : RCTEventEmitter <RCTBridgeModule>
78
/*
@@ -20,6 +21,12 @@
2021

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

24+
- (void)setSyncCallback;
25+
26+
- (void)evaluateSync:(BOOL)result;
27+
28+
@property (atomic, copy) SessionEvaluationCompletion sessionEvaluationCompletion;
29+
2330
@end
2431

2532

ios/RNInstabug/InstabugSessionReplayBridge.m

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ + (BOOL)requiresMainQueueSetup
1818
}
1919

2020
- (NSArray<NSString *> *)supportedEvents {
21-
return @[];
21+
return @[
22+
@"IBGSessionReplayOnSyncCallback",
23+
];
2224
}
2325

2426
RCT_EXPORT_MODULE(IBGSessionReplay)
@@ -45,6 +47,55 @@ + (BOOL)requiresMainQueueSetup
4547
resolve(link);
4648
}
4749

50+
- (NSArray<NSDictionary *> *)getNetworkLogsArray:
51+
(NSArray<IBGSessionMetadataNetworkLogs *>*) networkLogs {
52+
NSMutableArray<NSDictionary *> *networkLogsArray = [NSMutableArray array];
53+
54+
for (IBGSessionMetadataNetworkLogs* log in networkLogs) {
55+
NSDictionary *nLog = @{@"url": log.url, @"statusCode": @(log.statusCode), @"duration": @(log.duration)};
56+
[networkLogsArray addObject:nLog];
57+
}
58+
return networkLogsArray;
59+
}
60+
61+
- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject {
62+
return @{
63+
@"appVersion": metadataObject.appVersion,
64+
@"OS": metadataObject.os,
65+
@"device": metadataObject.device,
66+
@"sessionDurationInSeconds": @(metadataObject.sessionDuration),
67+
@"hasLinkToAppReview": @(metadataObject.hasLinkToAppReview),
68+
@"launchType": @(metadataObject.launchType),
69+
@"launchDuration": @(metadataObject.launchDuration),
70+
@"bugsCount": @(metadataObject.bugsCount),
71+
@"fatalCrashCount": @(metadataObject.fatalCrashCount),
72+
@"oomCrashCount": @(metadataObject.oomCrashCount),
73+
@"networkLogs":[self getNetworkLogsArray:metadataObject.networkLogs]
74+
};
75+
}
76+
77+
RCT_EXPORT_METHOD(setSyncCallback) {
78+
[IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) {
79+
80+
[self sendEventWithName:@"IBGSessionReplayOnSyncCallback"
81+
body:[self getMetadataObjectMap:metadataObject]];
82+
83+
self.sessionEvaluationCompletion = completion;
84+
}];
85+
}
86+
87+
RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) {
88+
89+
if (self.sessionEvaluationCompletion) {
90+
91+
self.sessionEvaluationCompletion(result);
92+
93+
self.sessionEvaluationCompletion = nil;
94+
95+
}
96+
}
97+
98+
4899
@synthesize description;
49100

50101
@synthesize hash;

ios/RNInstabug/Util/IBGNetworkLogger+CP.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
1919
errorCode:(int32_t)errorCode
2020
startTime:(int64_t)startTime
2121
duration:(int64_t) duration
22-
gqlQueryName:(NSString * _Nullable)gqlQueryName
23-
serverErrorMessage:(NSString * _Nullable)serverErrorMessage;
22+
gqlQueryName:(NSString * _Nullable)gqlQueryName;
2423

2524
@end
2625

src/native/NativeConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,5 @@ interface NativeLaunchType {
194194
hot: any;
195195
cold: any;
196196
warm: any;
197+
unknown: any;
197198
}

src/native/NativeInstabug.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export interface InstabugNativeModule extends NativeModule {
6666
startTime: number,
6767
duration: number,
6868
gqlQueryName: string | undefined,
69-
serverErrorMessage: string | undefined,
7069
): void;
7170

7271
setNetworkLoggingEnabled(isEnabled: boolean): void;

src/utils/Enums.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export enum StringKey {
236236
export enum LaunchType {
237237
hot = constants.hot,
238238
cold = constants.cold,
239+
unknown = constants.unknown,
239240
/**
240241
* android only
241242
*/

src/utils/InstabugUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export function reportNetworkLog(network: NetworkData) {
191191
network.startTime,
192192
network.duration,
193193
network.gqlQueryName,
194-
network.serverErrorMessage,
195194
);
196195
}
197196
}

test/utils/InstabugUtils.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ describe('reportNetworkLog', () => {
323323
network.startTime,
324324
network.duration,
325325
network.gqlQueryName,
326-
network.serverErrorMessage,
327326
);
328327
});
329328
});

0 commit comments

Comments
 (0)