Skip to content
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

Warn when DDNoopRUMMonitor is sent any DDRUMMonitor methods #1007

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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