Closed hajducak closed 8 months ago
Hi @hajducak i am kerollos nabil iOS developer at instabug thank you for communicating with us
at your snippet of code
let hostCollection = [
"https://www.google.com/"
// ... more different hosts alowing to log in instabug
]
let requestPredicate = NSPredicate(format: "URL.host IN %@", hostCollection)
NetworkLogger.setNetworkLoggingRequestFilterPredicate(requestPredicate, responseFilterPredicate: nil)
you are writing the host in the hostCollection list like that "https://www.google.com" and we are running this predicate against an object of type NSURLRequest
and the NSURL
object inside NSURLRequest
(URL) breaks this link into
so when we run the predicate he try to find the host " www.Google.com" in your list of hosts it fails to find it so you only need to remove "https://" from the list of hosts to be like that
let hostCollection = [
"www.google.com"
// ... more different hosts alowing to log in instabug
]
let requestPredicate = NSPredicate(format: "URL.host IN %@", hostCollection)
NetworkLogger.setNetworkLoggingRequestFilterPredicate(requestPredicate, responseFilterPredicate: nil)
this will work as expected
and for the tests you just need to use the predicate against NSURLRequest
object instead of URL
this test for the path will pass
func test_Predicate_1() {
let path = "/products"
let predicate = NSPredicate(format: "URL.path MATCHES %@", path)
let testURL: URL = URL(string: "https://www.google.com/products")!
let urlRequest = NSURLRequest(url: testURL)
let evaluatedUrl: Bool = predicate.evaluate(with: urlRequest)
XCTAssertTrue(evaluatedUrl)
expectation(for: predicate, evaluatedWith: urlRequest, handler: nil)
waitForExpectations(timeout: 10) { error in
if let error = error {
print("expectations has not been fulfullied. Failed with error \(error)")
} else {
print("expectations has been fullfilled.")
}
}
}
and this test for hosts will pass as well
func test_predicate_2() {
let hostCollection = [
"www.google.com"
// ... more different hosts alowing to log in instabug
]
let predicate = NSPredicate(format: "URL.host IN %@", hostCollection)
let testURL: URL = URL(string: "https://www.google.com/products")!
let urlRequest = NSURLRequest(url: testURL)
let evaluatedUrl: Bool = predicate.evaluate(with: urlRequest)
XCTAssertTrue(evaluatedUrl)
expectation(for: predicate, evaluatedWith: urlRequest, handler: nil)
waitForExpectations(timeout: 10) { error in
if let error = error {
print("expectations has not been fulfullied. Failed with error \(error)")
} else {
print("expectations has been fullfilled.")
}
}
}
Hello @KerollosNabil thanks for explanation. Unfortunately after editing the code Instabug still logging hosts which we don't want to log. Yeah test passes correctly as you write. This is my code I am sending to Instabug:
static func setOmittingRequests() {
let hostCollection = [
"login-ppt-a-moje.o2.cz",
"login-a-moje.o2.cz",
"login-e3-a-moje.o2.cz",
"api-ppt-a-moje.o2.cz",
"api-a-moje.o2.cz",
"api-e3-a-moje.o2.cz",
"api-eme-ppt-a-moje.o2.cz",
"api-eme-a-moje.o2.cz",
"api-eme-e3-a-moje.o2.cz",
"api-az-a-moje.o2.cz",
"api-az-ppt-a-moje.o2.cz",
"api-az-e3-a-moje.o2.cz"
]
let predicateFormat = "URL.host IN %@"
let predicate = NSPredicate(format: predicateFormat, argumentArray: hostCollection)
NetworkLogger.setNetworkLoggingRequestFilterPredicate(predicate, responseFilterPredicate: nil)
}
I checked if the code is calling at the beginning of our app. It is. I don't know what is wrong in this case. Can you help with this also?
This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.
@KerollosNabil Instabug SDK still not working in this issue, pls reopen this issue. I would love to see repair from your side. Thanks
@hajducak Could you kindly get in touch with our customer support team so that they can assist you in initiating a ticket for you to able to investigate more in your problem
This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.
@KerollosNabil I contact customer support 3 days ago, nobody send me any response.
This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed due to inactivity.
Steps to Reproduce the Problem
https://docs.instabug.com/reference/network-logging-ios#omitting-requests-from-logs Based on your documentation, implement this code
Expected Behavior
The logs should contain just api calls with UrlPath "/products"
Actual Behavior
All api calls are logged
Instabug integration code
We are sending only token as I see in code.
SDK Version
11.13.3
iOS Version
iOS 16.4
Device Model
iPhone14 Pro
My code
On project we need omitting requests based on URL host, we have collection of host that are allowed to log into instabug. So I came up with this predicate :
let predicate = NSPredicate(format: "URL.host IN %@", hostCollection)
where hostCollection is just array of url hosts.This code is not working, after making instabug, I check logs and there are all request as before implementation. I try even your approach in documentation and try filtering jut path. Either not working.
Then I tried make some tests for NSPredicate to test my Predicates if there were wrong. Of course they where. First I tried test path filtering:
Evaluation error: test_Predicate_1(): [<NSURL 0x600000bdee60> valueForUndefinedKey:]: this class is not key value coding-compliant for the key URL. (NSUnknownKeyException)
Then I try the host In sollution:
Same error occurs as first time. Okey that error should said that the URL is not compatible with my predicate. As I looking for answer I found out that the NSPredicate doesn't support URL so I tried another approach with no URL inside predicate.
This test was successful and correct. So I implanted inside our instabug and try it.
Instabug I created after implementing this code was omitting all request as before without any changes. After this steps I assume that framework have issue. I can't see inside your code so I don't know what you are doing with that NSPredicate.
Thanks for any suggestions further.