Skip to content

Commit

Permalink
added other AV task exceptions in NSURLSession instrumentation (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-b authored Nov 22, 2024
1 parent 7001892 commit 9332fec
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Sources/Instrumentation/URLSession/URLSessionInstrumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ struct NetworkRequestState {
private var idKey: Void?

public class URLSessionInstrumentation {
private var requestMap = [String: NetworkRequestState]()

var configuration: URLSessionInstrumentationConfiguration

private let queue = DispatchQueue(label: "io.opentelemetry.ddnetworkinstrumentation")

static var instrumentedKey = "io.opentelemetry.instrumentedCall"

static let avAssetDownloadTask: AnyClass? = NSClassFromString("__NSCFBackgroundAVAssetDownloadTask")

private var requestMap = [String: NetworkRequestState]()

var configuration: URLSessionInstrumentationConfiguration

private let queue = DispatchQueue(label: "io.opentelemetry.ddnetworkinstrumentation")

static var instrumentedKey = "io.opentelemetry.instrumentedCall"

static let AVTaskClassList : [AnyClass] = {
["__NSCFBackgroundAVAggregateAssetDownloadTask",
"__NSCFBackgroundAVAssetDownloadTask",
"__NSCFBackgroundAVAggregateAssetDownloadTaskNoChildTask" ]
.compactMap { NSClassFromString($0) }
}()

public private(set) var tracer: Tracer

public var startedRequestSpans: [Span] {
Expand Down Expand Up @@ -592,10 +597,7 @@ public class URLSessionInstrumentation {

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

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

0 comments on commit 9332fec

Please sign in to comment.