forked from DataDog/dd-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDURLSessionInstrumentation+objc.swift
73 lines (63 loc) · 2.48 KB
/
DDURLSessionInstrumentation+objc.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/
import Foundation
import DatadogCore
import DatadogInternal
/// Configuration of URLSession instrumentation.
@objc
public class DDURLSessionInstrumentationConfiguration: NSObject {
internal var swiftConfig: URLSessionInstrumentation.Configuration
@objc
public init(delegateClass: URLSessionDataDelegate.Type) {
swiftConfig = .init(delegateClass: delegateClass)
}
/// Sets additional first party hosts to consider in the interception.
@objc
public func setFirstPartyHostsTracing(_ firstPartyHostsTracing: DDURLSessionInstrumentationFirstPartyHostsTracing) {
swiftConfig.firstPartyHostsTracing = firstPartyHostsTracing.swiftType
}
/// The delegate class to be used to swizzle URLSessionTaskDelegate & URLSessionDataDelegate methods.
@objc public var delegateClass: URLSessionDataDelegate.Type {
set { swiftConfig.delegateClass = newValue }
get { swiftConfig.delegateClass }
}
}
/// Defines configuration for first-party hosts in distributed tracing.
@objc
public class DDURLSessionInstrumentationFirstPartyHostsTracing: NSObject {
internal var swiftType: URLSessionInstrumentation.FirstPartyHostsTracing
@objc
public init(hostsWithHeaderTypes: [String: Set<DDTracingHeaderType>]) {
let swiftHostsWithHeaders = hostsWithHeaderTypes.mapValues { headerTypes in
Set(headerTypes.map {
$0.swiftType
})
}
swiftType = .traceWithHeaders(hostsWithHeaders: swiftHostsWithHeaders)
}
@objc
public init(hosts: Set<String>) {
swiftType = .trace(hosts: hosts)
}
}
@objc
public class DDURLSessionInstrumentation: NSObject {
/// Enables URLSession instrumentation.
///
/// - Parameters:
/// - configuration: Configuration of the feature.
@objc
public static func enable(configuration: DDURLSessionInstrumentationConfiguration) {
URLSessionInstrumentation.enable(with: configuration.swiftConfig)
}
/// Disables URLSession instrumentation.
/// - Parameters:
/// - delegateClass: The delegate class to unbind.
@objc
public static func disable(delegateClass: URLSessionDataDelegate.Type) {
URLSessionInstrumentation.disable(delegateClass: delegateClass)
}
}