Skip to content

Commit 4e0fe6d

Browse files
authored
Merge pull request #545 from DataDog/nogorodnikov/rumm-1085/add-a-warning-when-action-is-dropped-if-another-action-is-still-active
RUMM-1085: Add a warning when action is dropped when another action is still active
2 parents baccec9 + 981ac8c commit 4e0fe6d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
146146
case let command as RUMStartUserActionCommand where isActiveView:
147147
if userActionScope == nil {
148148
startContinuousUserAction(on: command)
149+
} else {
150+
reportActionDropped(type: command.actionType, name: command.name)
149151
}
150152
case let command as RUMAddUserActionCommand where isActiveView:
151153
if userActionScope == nil {
152154
addDiscreteUserAction(on: command)
153155
} else if command.actionType == .custom {
154156
// still let it go, just instantly without any dependencies
155157
sendDiscreteCustomUserAction(on: command)
158+
} else {
159+
reportActionDropped(type: command.actionType, name: command.name)
156160
}
157161

158162
// Error command
@@ -263,6 +267,14 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
263267
)
264268
}
265269

270+
private func reportActionDropped(type: RUMUserActionType, name: String) {
271+
userLogger.warn(
272+
"""
273+
RUM Action '\(type)' on '\(name)' was dropped, because another action is still active for the same view.
274+
"""
275+
)
276+
}
277+
266278
// MARK: - Sending RUM Events
267279

268280
private func sendApplicationStartAction(on command: RUMCommand) -> Bool {

Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ class RUMViewScopeTests: XCTestCase {
433433
customTimings: [:],
434434
startTime: Date()
435435
)
436+
437+
let logOutput = LogOutputMock()
438+
userLogger = .mockWith(logOutput: logOutput)
439+
436440
XCTAssertTrue(
437441
scope.process(command: RUMStartViewCommand.mockWith(identity: mockView))
438442
)
@@ -445,10 +449,17 @@ class RUMViewScopeTests: XCTestCase {
445449
XCTAssertNotNil(scope.userActionScope)
446450
XCTAssertEqual(scope.userActionScope?.name, actionName)
447451

452+
let secondAction = RUMStartUserActionCommand.mockWith(actionType: .swipe, name: .mockRandom())
448453
XCTAssertTrue(
449-
scope.process(command: RUMStartUserActionCommand.mockWith(actionType: .swipe, name: .mockRandom()))
454+
scope.process(command: secondAction)
450455
)
451456
XCTAssertEqual(scope.userActionScope?.name, actionName, "View should ignore the next (only non-custom) UA if one is pending.")
457+
XCTAssertEqual(
458+
logOutput.recordedLog?.message,
459+
"""
460+
RUM Action '\(secondAction.actionType)' on '\(secondAction.name)' was dropped, because another action is still active for the same view.
461+
"""
462+
)
452463

453464
XCTAssertTrue(
454465
scope.process(command: RUMAddUserActionCommand.mockWith(actionType: .custom, name: .mockRandom()))
@@ -479,6 +490,10 @@ class RUMViewScopeTests: XCTestCase {
479490
customTimings: [:],
480491
startTime: currentTime
481492
)
493+
494+
let logOutput = LogOutputMock()
495+
userLogger = .mockWith(logOutput: logOutput)
496+
482497
XCTAssertTrue(
483498
scope.process(command: RUMStartViewCommand.mockWith(time: currentTime, identity: mockView))
484499
)
@@ -493,10 +508,17 @@ class RUMViewScopeTests: XCTestCase {
493508
XCTAssertNotNil(scope.userActionScope)
494509
XCTAssertEqual(scope.userActionScope?.name, actionName)
495510

511+
let secondAction = RUMAddUserActionCommand.mockWith(time: currentTime, actionType: .tap, name: .mockRandom())
496512
XCTAssertTrue(
497-
scope.process(command: RUMAddUserActionCommand.mockWith(time: currentTime, actionType: .tap, name: .mockRandom()))
513+
scope.process(command: secondAction)
498514
)
499515
XCTAssertEqual(scope.userActionScope?.name, actionName, "View should ignore the next (only non-custom) UA if one is pending.")
516+
XCTAssertEqual(
517+
logOutput.recordedLog?.message,
518+
"""
519+
RUM Action '\(secondAction.actionType)' on '\(secondAction.name)' was dropped, because another action is still active for the same view.
520+
"""
521+
)
500522

501523
XCTAssertTrue(
502524
scope.process(command: RUMAddUserActionCommand.mockWith(actionType: .custom, name: .mockRandom()))

0 commit comments

Comments
 (0)