@@ -578,14 +578,16 @@ public class URLSessionInstrumentation {
578578 }
579579
580580 if InstrumentationUtils . usesUndocumentedAsyncAwaitMethods {
581- let instrumentedRequest = URLSessionLogger . processAndLogRequest ( request, sessionTaskId: taskId, instrumentation: self , shouldInjectHeaders: true )
582- task. setValue ( instrumentedRequest, forKey: " currentRequest " )
583- self . setIdKey ( value: taskId, for: task)
584-
585581 if #available( OSX 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * ) {
586- let basePriority = Task . basePriority
587- //If not inside a Task basePriority is nil
588- if basePriority != nil && task. delegate == nil {
582+ guard Task . basePriority != nil else {
583+ return
584+ }
585+ let instrumentedRequest = URLSessionLogger . processAndLogRequest ( request, sessionTaskId: taskId, instrumentation: self , shouldInjectHeaders: true )
586+ task. setValue ( instrumentedRequest, forKey: " currentRequest " )
587+ self . setIdKey ( value: taskId, for: task)
588+
589+ // If not inside a Task basePriority is nil
590+ if task. delegate == nil {
589591 task. delegate = FakeDelegate ( )
590592 }
591593 }
@@ -617,6 +619,5 @@ public class URLSessionInstrumentation {
617619}
618620
619621class FakeDelegate : NSObject , URLSessionTaskDelegate {
620- func urlSession( _ session: URLSession , task: URLSessionTask , didCompleteWithError error: Error ? ) {
621- }
622+ func urlSession( _ session: URLSession , task: URLSessionTask , didCompleteWithError error: Error ? ) { }
622623}
0 commit comments