Skip to content

Commit 6277e4e

Browse files
committed
DEMRUM-773 Connect Module to SharedAppState
1 parent 877915b commit 6277e4e

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

SplunkAgent/Sources/SplunkAgent/Agent/Modules/SplunkRum+Modules.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Foundation
1919
internal import CiscoSessionReplay
2020
internal import SplunkAppStart
2121
internal import SplunkNetwork
22+
internal import SplunkNetworkInfo
2223

2324
#if canImport(SplunkCrashReports)
2425
internal import SplunkCrashReports
@@ -53,6 +54,7 @@ extension SplunkRum {
5354
customizeSessionReplay()
5455
customizeNetwork()
5556
customizeAppStart()
57+
customizeNetworkInfo()
5658
customizeWebViewInstrumentation()
5759
}
5860

@@ -113,6 +115,13 @@ extension SplunkRum {
113115
appStartModule?.sharedState = sharedState
114116
}
115117

118+
/// Configure NetworkInfo module
119+
private func customizeNetworkInfo() {
120+
let networkInfoModule = modulesManager?.module(ofType: SplunkNetworkInfo.NetworkInfo.self)
121+
122+
networkInfoModule?.sharedState = sharedState
123+
}
124+
116125
/// Configure WebView intrumentation module
117126
private func customizeWebViewInstrumentation() {
118127
// Get WebViewInstrumentation module, set its sharedState

SplunkNetworkInfo/Sources/SplunkNetworkInfo/NetworkInfo.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717

1818
import Foundation
1919
import Network
20+
import SplunkCommon
2021
import OpenTelemetryApi
2122

2223
public class NetworkInfo {
@@ -28,11 +29,13 @@ public class NetworkInfo {
2829
case lost
2930
}
3031

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+
3135
public static let shared = NetworkInfo()
3236

3337
private let monitor = NWPathMonitor()
3438
private let queue = DispatchQueue(label: "NetworkMonitorQueue")
35-
private var tracer: Tracer
3639

3740
public private(set) var isConnected: Bool = false
3841
public private(set) var connectionType: ConnectionType = .lost
@@ -43,9 +46,7 @@ public class NetworkInfo {
4346
// MARK: - Initialization
4447

4548
// Module conformance
46-
public required init() {
47-
self.tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "NetworkInfo", instrumentationVersion: "1.0")
48-
}
49+
public required init() { }
4950

5051
public func startDetection() {
5152
monitor.pathUpdateHandler = { [weak self] path in
@@ -83,10 +84,20 @@ public class NetworkInfo {
8384
}
8485

8586
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()
8798
span.setAttribute(key: "network.connected", value: isConnected)
8899
span.setAttribute(key: "network.connection.type", value: connectionType.rawValue)
89100
span.setAttribute(key: "network.vpn", value: isVPNActive)
90-
span.end()
101+
span.end(time: Date())
91102
}
92103
}

0 commit comments

Comments
 (0)