Skip to content

Commit

Permalink
Merge pull request #1007 from dfed/dfed--DDNoop-loud-978
Browse files Browse the repository at this point in the history
Warn when DDNoopRUMMonitor is sent any DDRUMMonitor methods
  • Loading branch information
maxep authored Sep 21, 2022
2 parents 6ab6b3b + c4ae85f commit 77fc236
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 1 deletion.
158 changes: 158 additions & 0 deletions Sources/Datadog/RUM/RUMMonitor/DDNoopRUMMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,169 @@ internal class DDNoopRUMMonitor: DDRUMMonitor {
warn()
}

override func stopView(
viewController: UIViewController,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func startView(
key: String,
name: String? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func stopView(
key: String,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func addTiming(
name: String
) {
warn()
}

override func addError(
message: String,
type: String? = nil,
source: RUMErrorSource = .custom,
stack: String? = nil,
attributes: [AttributeKey: AttributeValue] = [:],
file: StaticString? = #file,
line: UInt? = #line
) {
warn()
}

override func addError(
error: Error,
source: RUMErrorSource = .custom,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func startResourceLoading(
resourceKey: String,
request: URLRequest,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func startResourceLoading(
resourceKey: String,
url: URL,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func startResourceLoading(
resourceKey: String,
httpMethod: RUMMethod,
urlString: String,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func addResourceMetrics(
resourceKey: String,
metrics: URLSessionTaskMetrics,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func addResourceMetrics(
resourceKey: String,
fetch: (start: Date, end: Date),
redirection: (start: Date, end: Date)?,
dns: (start: Date, end: Date)?,
connect: (start: Date, end: Date)?,
ssl: (start: Date, end: Date)?,
firstByte: (start: Date, end: Date)?,
download: (start: Date, end: Date)?,
responseSize: Int64?,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func stopResourceLoading(
resourceKey: String,
response: URLResponse,
size: Int64? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func stopResourceLoading(
resourceKey: String,
statusCode: Int?,
kind: RUMResourceType,
size: Int64? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func stopResourceLoadingWithError(
resourceKey: String,
error: Error,
response: URLResponse? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func stopResourceLoadingWithError(
resourceKey: String,
errorMessage: String,
type: String? = nil,
response: URLResponse? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func startUserAction(
type: RUMUserActionType,
name: String,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func stopUserAction(
type: RUMUserActionType,
name: String? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func addUserAction(
type: RUMUserActionType,
name: String,
attributes: [AttributeKey: AttributeValue] = [:]
) {
warn()
}

override func addAttribute(forKey key: AttributeKey, value: AttributeValue) {
warn()
}

override func removeAttribute(forKey key: AttributeKey) {
warn()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ class DDNoopRUMMonitorTests: XCTestCase {
noop.startView(key: "view-key", name: "View")
noop.stopView(viewController: mockView)
noop.stopView(key: "view-key")
noop.addTiming(name: #function)
noop.addError(message: #function)
noop.addError(error: ProgrammerError(description: #function))
noop.startResourceLoading(resourceKey: #function, request: .mockAny())
noop.startResourceLoading(resourceKey: #function, url: .mockRandom())
noop.startResourceLoading(resourceKey: #function, httpMethod: .mockAny(), urlString: #function)
noop.addResourceMetrics(resourceKey: #function, metrics: .mockAny())
noop.addResourceMetrics(resourceKey: #function, fetch: (start: .mockAny(), end: .mockAny()), redirection: nil, dns: nil, connect: nil, ssl: nil, firstByte: nil, download: nil, responseSize: nil)
noop.stopResourceLoading(resourceKey: #function, response: .mockAny())
noop.stopResourceLoading(resourceKey: #function, statusCode: nil, kind: .mockAny())
noop.stopResourceLoadingWithError(resourceKey: #function, error: ProgrammerError(description: #function))
noop.stopResourceLoadingWithError(resourceKey: #function, errorMessage: #function)
noop.startUserAction(type: .click, name: #function)
noop.stopUserAction(type: .click, name: #function)
noop.addUserAction(type: .click, name: #function)
noop.addAttribute(forKey: .mockAny(), value: #function)
noop.removeAttribute(forKey: .mockAny())

// Then
let expectedWarningMessage = """
Expand All @@ -28,7 +45,7 @@ class DDNoopRUMMonitorTests: XCTestCase {
See https://docs.datadoghq.com/real_user_monitoring/ios
"""

XCTAssertEqual(dd.logger.criticalLogs.count, 2)
XCTAssertEqual(dd.logger.criticalLogs.count, 21)
dd.logger.criticalLogs.forEach { log in
XCTAssertEqual(log.message, expectedWarningMessage)
}
Expand Down

0 comments on commit 77fc236

Please sign in to comment.