Skip to content

Commit 9332fec

Browse files
authored
added other AV task exceptions in NSURLSession instrumentation (#640)
1 parent 7001892 commit 9332fec

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Sources/Instrumentation/URLSession/URLSessionInstrumentation.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@ struct NetworkRequestState {
2626
private var idKey: Void?
2727

2828
public class URLSessionInstrumentation {
29-
private var requestMap = [String: NetworkRequestState]()
30-
31-
var configuration: URLSessionInstrumentationConfiguration
32-
33-
private let queue = DispatchQueue(label: "io.opentelemetry.ddnetworkinstrumentation")
34-
35-
static var instrumentedKey = "io.opentelemetry.instrumentedCall"
36-
37-
static let avAssetDownloadTask: AnyClass? = NSClassFromString("__NSCFBackgroundAVAssetDownloadTask")
38-
29+
private var requestMap = [String: NetworkRequestState]()
30+
31+
var configuration: URLSessionInstrumentationConfiguration
32+
33+
private let queue = DispatchQueue(label: "io.opentelemetry.ddnetworkinstrumentation")
34+
35+
static var instrumentedKey = "io.opentelemetry.instrumentedCall"
36+
37+
static let AVTaskClassList : [AnyClass] = {
38+
["__NSCFBackgroundAVAggregateAssetDownloadTask",
39+
"__NSCFBackgroundAVAssetDownloadTask",
40+
"__NSCFBackgroundAVAggregateAssetDownloadTaskNoChildTask" ]
41+
.compactMap { NSClassFromString($0) }
42+
}()
43+
3944
public private(set) var tracer: Tracer
4045

4146
public var startedRequestSpans: [Span] {
@@ -592,10 +597,7 @@ public class URLSessionInstrumentation {
592597

593598
private func urlSessionTaskWillResume(_ task: URLSessionTask) {
594599
// AV Asset Tasks cannot be auto instrumented, they dont include request attributes, skip them
595-
if let avAssetTaskClass = Self.avAssetDownloadTask,
596-
task.isKind(of: avAssetTaskClass) {
597-
return
598-
}
600+
guard !Self.AVTaskClassList.contains(where: {task.isKind(of:$0)}) else { return }
599601

600602
// We cannot instrument async background tasks because they crash if you assign a delegate
601603
if #available(OSX 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) {

0 commit comments

Comments
 (0)