Privacy and Network traffic
Disabling network traffic collection
Network traffic collection can be disabled completely using BugseeMonitorNetworkKey launch option. See configuration for more info.
Sanitizing data
Bugsee captures network activity from the application and stores headers and in some cases body of the request and response. In order to allow you to hide user identifiable and other sensitive data from these network logs, we provide two methods for hooking your own filters, via a delegate or a block that we will call for every event about to be recorded.
Regardless of the method you chose, the principle is similar, for every event to be recorded, Bugsee will call your method and provide you with BugseeNetworkEvent object. It is your method's responsibility to clean up all user identifiable data from that structure and call decisionBlock() to pass it back to Bugsee.
Using delegate
Your class should implement BugseeDelegate protocol and it must set itself as the delegate for Bugsee.
!Objective-C
-(void)bugseeFilterNetworkEvent:(BugseeNetworkEvent *)event completionHandler:(BugseeNetworkFilterDecisionBlock)decisionBlock{
NSError * error;
// Below is an example code that will remove access_token from all URLs going through the filter.
if (event.url){
NSError * error;
NSRegularExpression * regex = [NSRegularExpression regularExpressionWithPattern:@"access_token=[0-9a-z\\-]*" options:NSRegularExpressionCaseInsensitive error:&error];
event.url = [regex stringByReplacingMatchesInString:event.url
options:0
range:NSMakeRange(0, event.url.length)
withTemplate:@""];
}
// Send the event further, call with nil if you want to omit this event altogether.
decisionBlock(event);
}
// ..somewhere within the class
[Bugsee sharedInstance].delegate = self;
!Swift
func bugseeFilterNetworkEvent(_ event: BugseeNetworkEvent, completionHandler decisionBlock: @escaping BugseeNetworkFilterDecisionBlock) {
let regex : NSRegularExpression
do {
regex = try NSRegularExpression.init(pattern: "&access_token=[0-9a-z\\-]*", options: NSRegularExpression.Options.caseInsensitive)
let range = NSMakeRange(0 , (event.url!.count))
if (event.url != nil) {
event.url = regex.stringByReplacingMatches(in: event.url!, options: .reportProgress, range: range, withTemplate: "")
}
}catch { print("Somethings went wrong!") }
decisionBlock(event);
}
// ..somewhere within the class
Bugsee.sharedInstance()?.delegate = self;
Using filter with block
Alternatively you can set up a filter by registering a block to be executed for every event.
!Objective-C
[Bugsee setNetworkEventFilter:^(BugseeNetworkEvent *event, BugseeNetworkFilterDecisionBlock decisionBlock) {
// modify BugseeNetworkEvent as you wish here
// Send the event further, call with nil if you want to omit this event altogether.
decisionBlock(event);
}
// Unregister a block before de-allocating a class in which it was registered
[Bugsee removeNetworkEventFilter];
!Swift
Bugsee.setNetworkEventFilter { (event, decisionBlock) in
// modify BugseeNetworkEvent as you wish
// Send the event further, call with nil if you want to omit this event altogether.
decisionBlock(event)
}
// always call removeNetworkEventFilter method if you de-allocate class where setNetworkEventFilter: was called
Bugsee.removeNetworkEventFilter()
Network Events
The delegate or hook is going to be called several times for each network request, depending on its life-cycle. Usually for successful requests its going to be called twice, once with the request event (request headers and body) and once after completion and will contain headers and body of the response.
Property | Description | Type | Read only | Notes |
---|---|---|---|---|
bugseeNetworkEventType | Type of network event | NSString | YES | Can be one of BugseeNetworkEventBegin, BugseeNetworkEventComplete, BugseeNetworkEventCancel or BugseeNetworkEventError |
method | HTTP Request Method | NSString | YES | 'GET', 'POST', etc... |
url | Network event URL | NSString | NO | |
redirectedFromURL | URL of Network event that we were redirected from | NSString | NO | |
body | Body | NSData | NO | Raw body of the request or response where available. |
headers | HTTP Headers | NSDictionary | NO | Key-value store of HTTP headers associated with the event. |