Skip to content

DEMRUM-773: Network Monitor Module #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: feature/next-gen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0032966
DEMRUM-773 Initial Network Info method
SMickelsn May 20, 2025
ed48d3c
DEMRUM-773 Network Info module support
SMickelsn May 27, 2025
a36e67a
DEMRUM-773 Network Info module support
SMickelsn May 27, 2025
2f2bd1f
DEMRUM-773 Network Info module support
SMickelsn May 27, 2025
eb2073f
DEMRUM-773 Network Info module support
SMickelsn May 27, 2025
5d32b2f
DEMRUM-773 Network Info module support
SMickelsn May 27, 2025
5b46617
DEMRUM-773 Address merge conflicts
SMickelsn Jun 2, 2025
8a36b8f
DEMRUM-773 Move various files
SMickelsn Jun 2, 2025
1387c06
DEMRUM-773 Move various files
SMickelsn Jun 2, 2025
877915b
DEMRUM-773 Connect Module to default pool
SMickelsn Jun 2, 2025
6277e4e
DEMRUM-773 Connect Module to SharedAppState
SMickelsn Jun 3, 2025
338e009
DEMRUM-773 Indicate VPN as a network.connection.type
SMickelsn Jun 4, 2025
b77a0f6
DEMRUM-773 Return network.status as string rather than boolean
SMickelsn Jun 4, 2025
7ef0816
DEMRUM-773 Remove status change span at app start
SMickelsn Jun 4, 2025
3206086
DEMRUM-773 Update package.swift re review comment
SMickelsn Jun 4, 2025
886d212
DEMRUM-773 Only signal change when relevant paramters change
SMickelsn Jun 4, 2025
8f1d9fc
DEMRUM-773 Unit Test
SMickelsn Jun 4, 2025
ecdccec
Added module config. Add subtype for connection. Renamed to Network M…
aditi-s3 Jun 17, 2025
82d0a03
Updated package.swift and resolved conflicts
aditi-s3 Jun 18, 2025
8426037
Updated comments
aditi-s3 Jun 18, 2025
138965f
Resolved merge conflicts in files
aditi-s3 Jun 18, 2025
4261cdb
DEMRUM-773: Update package.swift
SMickelsn Jun 18, 2025
32c4e83
DEMRUM-773: Update package.swift
SMickelsn Jun 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func generateMainTargets() -> [Target] {
"SplunkSessionReplayProxy",
"SplunkNavigation",
"SplunkNetwork",
"SplunkNetworkMonitor",
"SplunkSlowFrameDetector",
"SplunkOpenTelemetry",
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
Expand Down Expand Up @@ -125,10 +126,27 @@ func generateMainTargets() -> [Target] {
dependencies: ["SplunkNetwork"],
path: "SplunkNetwork/Tests"
),


// MARK: - Splunk Network Monitor


.target(
name: "SplunkNetworkMonitor",
dependencies: [
"SplunkCommon",
"SplunkOpenTelemetry"
],
path: "SplunkNetworkMonitor/Sources"
),
.testTarget(
name: "SplunkNetworkMonitorTests",
dependencies: ["SplunkNetworkMonitor"],
path: "SplunkNetworkMonitor/Tests"
),


// MARK: - Splunk Common

.target(
name: "SplunkCommon",
path: "SplunkCommon/Sources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ internal import SplunkCommon
internal import SplunkNetwork
#endif

#if canImport(SplunkNetworkMonitor)
internal import SplunkNetworkMonitor
#endif

#if canImport(CiscoSessionReplay)
internal import CiscoSessionReplay
internal import SplunkSessionReplayProxy
Expand Down Expand Up @@ -79,6 +83,11 @@ class DefaultModulesPool: AgentModulesPool {
knownModules.append(NetworkInstrumentation.self)
#endif

// Network Monitor
#if canImport(SplunkNetworkMonitor)
knownModules.append(NetworkMonitor.self)
#endif

// Slow Frame Detector
#if canImport(SplunkSlowFrameDetector)
knownModules.append(SlowFrameDetector.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal import CiscoSessionReplay
internal import SplunkAppStart
internal import SplunkNavigation
internal import SplunkNetwork
internal import SplunkNetworkMonitor

#if canImport(SplunkCrashReports)
internal import SplunkCrashReports
Expand Down Expand Up @@ -55,7 +56,9 @@ extension SplunkRum {
customizeNavigation()
customizeNetwork()
customizeAppStart()
customizeNetworkMonitor()
customizeWebView()

}

/// Perform operations specific to the SessionReplay module.
Expand Down Expand Up @@ -148,6 +151,13 @@ extension SplunkRum {
appStartModule?.sharedState = sharedState
}

/// Configure NetworkMonitor module
private func customizeNetworkMonitor() {
let networkMonitorModule = modulesManager?.module(ofType: SplunkNetworkMonitor.NetworkMonitor.self)

networkMonitorModule?.sharedState = sharedState
}

/// Configure WebView Instrumentation module with shared state.
private func customizeWebView() {
// Get WebViewInstrumentation module, set its sharedState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkCommon


public struct NetworkMonitorData: ModuleEventData {}

public struct NetworkMonitorMetadata: ModuleEventMetadata {
public var timestamp = Date()
public var eventName: String = "network.change"
}

extension NetworkMonitor: Module {

// MARK: - Module types

public typealias Configuration = NetworkMonitorConfiguration
public typealias RemoteConfiguration = NetworkMonitorRemoteConfiguration

public typealias EventMetadata = NetworkMonitorMetadata
public typealias EventData = NetworkMonitorData


// MARK: - Module methods

public func install(with configuration: (any ModuleConfiguration)?, remoteConfiguration: (any RemoteModuleConfiguration)?) {
let config = configuration as? Configuration

// Start the network monitor if it's enabled or if no configuration is provided.
if config?.isEnabled ?? true {
startDetection()
}
}


// MARK: - Type transparency helpers

public func deleteData(for metadata: any ModuleEventMetadata) {}
public func onPublish(data: @escaping (NetworkMonitorMetadata, NetworkMonitorData) -> Void) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkCommon

/// NetworkMonitor module configuration, minimal configuration for module conformance.
public struct NetworkMonitorConfiguration: ModuleConfiguration {

// MARK: - Module management

/// Indicates whether the Module is enabled. Default value is `true`.
public var isEnabled: Bool = true

/// Initializes new module configuration with preconfigured values.
///
/// - Parameters:
/// - isEnabled: A `Boolean` value sets whether the module is enabled.
public init(isEnabled: Bool) {
self.isEnabled = isEnabled
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkCommon

/// NetworkMonitor remote configuration.
public struct NetworkMonitorRemoteConfiguration: RemoteModuleConfiguration {

// MARK: - Internal decoding

struct NetworkMonitor: Decodable {
let enabled: Bool
}

struct MRUMRoot: Decodable {
let NetworkMonitor: NetworkMonitor
}

struct Configuration: Decodable {
let mrum: MRUMRoot
}

struct Root: Decodable {
let configuration: Configuration
}


// MARK: - Public

public var enabled: Bool

public init?(from data: Data) {
guard let root = try? JSONDecoder().decode(Root.self, from: data) else {
return nil
}

enabled = root.configuration.mrum.NetworkMonitor.enabled
}
}
Loading