Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid processing undesired network tasks #458

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,10 @@ public class URLSessionInstrumentation {
// URLSessionTask methods
private func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
guard configuration.shouldRecordPayload?(session) ?? false else { return }
guard let taskId = objc_getAssociatedObject(dataTask, &idKey) as? String else {
return
}
let dataCopy = data
let taskId = idKeyForTask(dataTask)
queue.sync {
if (requestMap[taskId]?.request) != nil {
createRequestState(for: taskId)
Expand All @@ -512,7 +514,9 @@ public class URLSessionInstrumentation {

private func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
guard configuration.shouldRecordPayload?(session) ?? false else { return }
let taskId = idKeyForTask(dataTask)
guard let taskId = objc_getAssociatedObject(dataTask, &idKey) as? String else {
return
}
queue.sync {
if (requestMap[taskId]?.request) != nil {
createRequestState(for: taskId)
Expand All @@ -526,7 +530,9 @@ public class URLSessionInstrumentation {
}

private func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
let taskId = idKeyForTask(task)
guard let taskId = objc_getAssociatedObject(task, &idKey) as? String else {
return
}
var requestState: NetworkRequestState?
queue.sync {
requestState = requestMap[taskId]
Expand All @@ -543,13 +549,16 @@ public class URLSessionInstrumentation {
}

private func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didBecome downloadTask: URLSessionDownloadTask) {
let id = idKeyForTask(dataTask)
setIdKey(value: id, for: downloadTask)
guard let taskId = objc_getAssociatedObject(dataTask, &idKey) as? String else {
return
}
self.setIdKey(value: taskId, for: downloadTask)
}

private func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
let taskId = idKeyForTask(task)

guard let taskId = objc_getAssociatedObject(task, &idKey) as? String else {
return
}
var requestState: NetworkRequestState?
queue.sync {
requestState = requestMap[taskId]
Expand Down
Loading