When using URLSessionInstrumentation in SwiftUI, the app crashes on iOS with the following exception:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Cannot set task delegate after resumption'
Code Example:
self.urlSessionInstrumentation = URLSessionInstrumentation(
configuration: URLSessionInstrumentationConfiguration(
shouldInstrument: { request in
// filtering applied
}
)
)
Environment:
iOS version: 26
Swift version: 6
OpenTelemetry SDK: 2.1.0
SwiftUI app using .task on a view
Steps to Reproduce:
Initialize URLSessionInstrumentation as above.
Trigger a network request with URLSession.
App crashes with the exception.
Expected behavior:
The instrumentation should not crash the app, even if URLSession tasks are resumed/swizzled.
Additional context:
The crash seems related to swizzling and delegate reassignment.
Occurs regardless of shouldInstrument filtering.