Skip to content

Commit

Permalink
fix(ios): disable auto capturing of native network logs (#1018)
Browse files Browse the repository at this point in the history
Jira ID: INSD-9944
  • Loading branch information
abdelhamid-f-nasser authored and HeshamMegid committed Sep 17, 2023
1 parent eb1ecff commit 2f91165
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import <os/log.h>
#import <Instabug/IBGTypes.h>
#import <React/RCTUIManager.h>
#import "Util/IBGNetworkLogger+CP.h"

@interface Instabug (PrivateWillSendAPI)
+ (void)setWillSendReportHandler_private:(void(^)(IBGReport *report, void(^reportCompletionHandler)(IBGReport *)))willSendReportHandler_private;
Expand Down Expand Up @@ -53,12 +54,13 @@ - (dispatch_queue_t)methodQueue {
for (NSNumber *boxedValue in invocationEventsArray) {
invocationEvents |= [boxedValue intValue];
}
[IBGNetworkLogger disableAutomaticCapturingOfNetworkLogs];
[Instabug startWithToken:token invocationEvents:invocationEvents];
[Instabug setSdkDebugLogsLevel:sdkDebugLogsLevel];

RCTAddLogFunction(InstabugReactLogFunction);
RCTSetLogThreshold(RCTLogLevelInfo);

IBGNetworkLogger.enabled = YES;

// Temporarily disabling APM hot launches
Expand All @@ -72,7 +74,7 @@ - (dispatch_queue_t)methodQueue {
[[Instabug class] performSelector:setPrivateApiSEL];
} else {
[[Instabug class] performSelector:setPrivateApiSEL withObject:param];

}
}
}
Expand Down Expand Up @@ -349,7 +351,7 @@ - (dispatch_queue_t)methodQueue {
int32_t errorCode = [networkData[@"errorCode"] integerValue];
int64_t startTime = [networkData[@"startTime"] integerValue] * 1000;
int64_t duration = [networkData[@"duration"] doubleValue] * 1000;

NSString* gqlQueryName = nil;
NSString* serverErrorMessage = nil;
if (networkData[@"gqlQueryName"] != [NSNull null]) {
Expand All @@ -360,12 +362,12 @@ - (dispatch_queue_t)methodQueue {
}

SEL networkLogSEL = NSSelectorFromString(@"addNetworkLogWithUrl:method:requestBody:requestBodySize:responseBody:responseBodySize:responseCode:requestHeaders:responseHeaders:contentType:errorDomain:errorCode:startTime:duration:gqlQueryName:serverErrorMessage:");

if([[IBGNetworkLogger class] respondsToSelector:networkLogSEL]) {
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[IBGNetworkLogger class] methodSignatureForSelector:networkLogSEL]];
[inv setSelector:networkLogSEL];
[inv setTarget:[IBGNetworkLogger class]];

[inv setArgument:&(url) atIndex:2];
[inv setArgument:&(method) atIndex:3];
[inv setArgument:&(requestBody) atIndex:4];
Expand Down Expand Up @@ -436,7 +438,7 @@ - (void) setBaseUrlForDeprecationLogs {
[inv setTarget:[Instabug class]];
IBGPlatform platform = IBGPlatformReactNative;
[inv setArgument:&(platform) atIndex:2];

[inv invoke];
}
}
Expand Down Expand Up @@ -469,7 +471,7 @@ void RNIBGLog(IBGLogLevel logLevel, NSString *format, ...) {
{
NSString *formatString = @"Instabug - REACT LOG: %@";
NSString *log = RCTFormatLog([NSDate date], level, fileName, lineNumber, message);

switch(level) {
case RCTLogLevelTrace:
RNIBGLog(IBGLogLevelVerbose, formatString, log);
Expand Down
11 changes: 11 additions & 0 deletions ios/RNInstabug/Util/IBGNetworkLogger+CP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <Instabug/Instabug.h>

NS_ASSUME_NONNULL_BEGIN

@interface IBGNetworkLogger (CP)

+ (void)disableAutomaticCapturingOfNetworkLogs;

@end

NS_ASSUME_NONNULL_END

0 comments on commit 2f91165

Please sign in to comment.