@@ -17,6 +17,7 @@ limitations under the License.
17
17
18
18
import Foundation
19
19
import Network
20
+ import SplunkCommon
20
21
import OpenTelemetryApi
21
22
22
23
public class NetworkInfo {
@@ -28,11 +29,13 @@ public class NetworkInfo {
28
29
case lost
29
30
}
30
31
32
+ /// An instance of the Agent shared state object, which is used to obtain agent's state, e.g. a session id.
33
+ public unowned var sharedState : AgentSharedState ?
34
+
31
35
public static let shared = NetworkInfo ( )
32
36
33
37
private let monitor = NWPathMonitor ( )
34
38
private let queue = DispatchQueue ( label: " NetworkMonitorQueue " )
35
- private var tracer : Tracer
36
39
37
40
public private( set) var isConnected : Bool = false
38
41
public private( set) var connectionType : ConnectionType = . lost
@@ -43,9 +46,7 @@ public class NetworkInfo {
43
46
// MARK: - Initialization
44
47
45
48
// Module conformance
46
- public required init ( ) {
47
- self . tracer = OpenTelemetry . instance. tracerProvider. get ( instrumentationName: " NetworkInfo " , instrumentationVersion: " 1.0 " )
48
- }
49
+ public required init ( ) { }
49
50
50
51
public func startDetection( ) {
51
52
monitor. pathUpdateHandler = { [ weak self] path in
@@ -83,10 +84,20 @@ public class NetworkInfo {
83
84
}
84
85
85
86
private func sendNetworkChangeSpan( ) {
86
- let span = tracer. spanBuilder ( spanName: " network.change " ) . startSpan ( )
87
+
88
+ let tracer = OpenTelemetry . instance
89
+ . tracerProvider
90
+ . get (
91
+ instrumentationName: " NetworkInfo " ,
92
+ instrumentationVersion: sharedState? . agentVersion
93
+ )
94
+
95
+ let span = tracer. spanBuilder ( spanName: " network.change " )
96
+ . setStartTime ( time: Date ( ) )
97
+ . startSpan ( )
87
98
span. setAttribute ( key: " network.connected " , value: isConnected)
88
99
span. setAttribute ( key: " network.connection.type " , value: connectionType. rawValue)
89
100
span. setAttribute ( key: " network.vpn " , value: isVPNActive)
90
- span. end ( )
101
+ span. end ( time : Date ( ) )
91
102
}
92
103
}
0 commit comments