Filtering your data
Sometimes you may want to adjust or completely skip some pieces of data AppSpector gather. We have a special feature called Sanitizing for this, for now it's available only for HTTP and logs monitors, more coming.
For these two monitors you can provide a filter which allows to modify or block events before AppSpector sends them to the backend. Filter is a callback you assign to a AppSpectorConfig
property httpSanitizer
for HTTP monitor or logSanitizer
for logs monitor. Filter callback gets event as its argument and should return it.
Some examples. Let's say we want to skip our auth token from requests headers:
config.httpSanitizer.filter = { event in
if let headers = event.request?.allHTTPHeaderFields?.keys,
headers.contains("YOUR-AUTH-HEADER") {
event.request?.setValue("redacted", forHTTPHeaderField: "YOUR-AUTH-HEADER")
}
return event
}
[config.httpSanitizer setFilter:^ASHTTPEvent *(ASHTTPEvent *event) {
if ([event.request.allHTTPHeaderFields.allKeys containsObject:@"YOUR-AUTH-HEADER"]) {
[event.request setValue:@"redacted" forHTTPHeaderField:@"YOUR-AUTH-HEADER"];
}
return event;
}];
Ignore the HTTP event (note that it won't block the request itself, but it will not be processed by HTTP Monitor):
config.httpSanitizer.filter = { event in
if event.request
.allHTTPHeaderFields?
.keys
.contains("YOUR-AUTH-HEADER") == .some(true) {
event.blocked = true
}
return event
}
[config.httpSanitizer setFilter:^ASHTTPEvent *(ASHTTPEvent *event) {
if ([event.request.allHTTPHeaderFields.allKeys containsObject:@"YOUR-AUTH-HEADER"]) {
event.blocked = @YES
}
return event;
}];
Or raise log level to warning
for all messages containing word 'token':
config.logSanitizer.filter = { event in
if event.message.range(of: "token") != .none {
event.level = .warn
}
return event
}
[config.logSanitizer setFilter:^ASLogMonitorEvent *(ASLogMonitorEvent *event) {
if ([event.message rangeOfString:@"token"].location != NSNotFound) {
event.level = ASLogEventLevelWarn;
}
return event;
}];
See events headers for more info.
Updated almost 3 years ago