Skip to content

Commit fce5c32

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #381 from nachoBonafonte/urlsession-configure-delegates
2 parents fac445e + 54899bd commit fce5c32

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/Instrumentation/URLSession/URLSessionInstrumentation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class URLSessionInstrumentation {
6565
#selector(URLSessionDataDelegate.urlSession(_:dataTask:didBecome:) as (URLSessionDataDelegate) -> ((URLSession, URLSessionDataTask, URLSessionStreamTask) -> Void)?)
6666
]
6767
#endif
68-
let classes = InstrumentationUtils.objc_getClassList()
68+
let classes = configuration.delegateClassesToInstrument ?? InstrumentationUtils.objc_getClassList()
6969
let selectorsCount = selectors.count
7070
DispatchQueue.concurrentPerform(iterations: classes.count) { iteration in
7171
let theClass: AnyClass = classes[iteration]

Sources/Instrumentation/URLSession/URLSessionInstrumentationConfiguration.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public struct URLSessionInstrumentationConfiguration {
2020
injectCustomHeaders: ((inout URLRequest, Span?) -> Void)? = nil,
2121
createdRequest: ((URLRequest, Span) -> Void)? = nil,
2222
receivedResponse: ((URLResponse, DataOrFile?, Span) -> Void)? = nil,
23-
receivedError: ((Error, DataOrFile?, HTTPStatus, Span) -> Void)? = nil)
23+
receivedError: ((Error, DataOrFile?, HTTPStatus, Span) -> Void)? = nil,
24+
delegateClassesToInstrument: [AnyClass]? = nil)
2425
{
2526
self.shouldRecordPayload = shouldRecordPayload
2627
self.shouldInstrument = shouldInstrument
@@ -31,6 +32,7 @@ public struct URLSessionInstrumentationConfiguration {
3132
self.createdRequest = createdRequest
3233
self.receivedResponse = receivedResponse
3334
self.receivedError = receivedError
35+
self.delegateClassesToInstrument = delegateClassesToInstrument
3436
}
3537

3638
// Instrumentation Callbacks
@@ -65,4 +67,7 @@ public struct URLSessionInstrumentationConfiguration {
6567

6668
/// Called before the span is ended, it allows to add extra information to the Span
6769
public var receivedError: ((Error, DataOrFile?, HTTPStatus, Span) -> Void)?
70+
71+
/// The array of URLSession delegate classes that will be instrumented by the library, will autodetect if nil is passed.
72+
public var delegateClassesToInstrument: [AnyClass]?
6873
}

0 commit comments

Comments
 (0)