Skip to content

Commit 175bd1b

Browse files
committed
RUM-9035 Address Simao CR comments
1 parent 6b3c2d0 commit 175bd1b

File tree

11 files changed

+33
-50
lines changed

11 files changed

+33
-50
lines changed

Datadog/Datadog.xcodeproj/xcshareddata/xcschemes/DatadogRUM iOS.xcscheme

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,6 @@
212212
debugDocumentVersioning = "YES"
213213
debugServiceExtension = "internal"
214214
allowLocationSimulation = "YES">
215-
<CommandLineArguments>
216-
<CommandLineArgument
217-
argument = "DD_DEBUG"
218-
isEnabled = "NO">
219-
</CommandLineArgument>
220-
</CommandLineArguments>
221215
</LaunchAction>
222216
<ProfileAction
223217
buildConfiguration = "Release"

DatadogCore/Tests/DatadogObjc/DDRUMConfigurationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class DDRUMConfigurationTests: XCTestCase {
131131
func testEventMappers() {
132132
let swiftViewEvent: RUMViewEvent = .mockRandom()
133133
let swiftResourceEvent: RUMResourceEvent = .mockRandom()
134-
let swiftActionEvent: RUMActionEvent = .mockRandom()
134+
let swiftActionEvent: RUMActionEvent = .mockAny()
135135
let swiftErrorEvent: RUMErrorEvent = .mockRandom()
136136
let swiftLongTaskEvent: RUMLongTaskEvent = .mockRandom()
137137

DatadogCore/Tests/DatadogObjc/RUM/RUMDataModels+objcTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class RUMDataModels_objcTests: XCTestCase {
5757
let expectedUserInfoAttributes: [String: Any] = mockRandomAttributes()
5858

5959
// Given
60-
var swiftAction: RUMActionEvent = .mockRandom()
60+
var swiftAction: RUMActionEvent = .mockAny()
6161
swiftAction.context?.contextInfo = expectedContextAttributes.dd.swiftAttributes
6262
swiftAction.usr?.usrInfo = expectedUserInfoAttributes.dd.swiftAttributes
6363

DatadogRUM/Sources/RUMMonitor/Scopes/RUMUserActionScope.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ internal class RUMUserActionScope: RUMScope, RUMContextProvider {
203203

204204
if let event = dependencies.eventBuilder.build(from: actionEvent) {
205205
writer.write(value: event)
206+
207+
// Track action in session ended metric
208+
dependencies.sessionEndedMetric.track(
209+
action: event,
210+
instrumentationType: instrumentation,
211+
in: self.context.sessionID
212+
)
213+
206214
onActionEventSent(event)
207215

208216
if let activeViewID = self.context.activeViewID {

DatadogRUM/Sources/RUMMonitor/Scopes/RUMViewScope.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,6 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
414414
actionsCount += 1
415415
frustrationCount += event.action.frustration?.type.count.toInt64 ?? 0
416416
needsViewUpdate = true
417-
418-
// Track action in session ended metric
419-
if let userActionScope = userActionScope {
420-
dependencies.sessionEndedMetric.track(
421-
action: event,
422-
instrumentationType: userActionScope.instrumentation,
423-
in: self.context.sessionID
424-
)
425-
}
426417
}
427418

428419
private func addDiscreteUserAction(on command: RUMAddUserActionCommand) {

DatadogRUM/Sources/SDKMetrics/SessionEndedMetric.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,24 @@ internal class SessionEndedMetric {
174174
/// - Parameters:
175175
/// - action: the action event to track
176176
/// - instrumentationType: the type of instrumentation used to start this action
177-
func track(action: RUMActionEvent, instrumentationType: InstrumentationType?) {
177+
func track(action: RUMActionEvent, instrumentationType: InstrumentationType) {
178178
guard action.session.id == sessionID.toRUMDataFormat else {
179179
return
180180
}
181181

182-
if let instrumentationType = instrumentationType {
183-
trackedActions[instrumentationType.metricKey] = (trackedActions[instrumentationType.metricKey] ?? 0) + 1
184-
}
182+
trackedActions[instrumentationType.metricKey, default: 0] += 1
185183
}
186184

187185
/// Tracks the kind of SDK error that occurred during the session.
188186
/// - Parameter sdkErrorKind: the kind of SDK error
189187
func track(sdkErrorKind: String) {
190-
if let count = trackedSDKErrors[sdkErrorKind] {
191-
trackedSDKErrors[sdkErrorKind] = count + 1
192-
} else {
193-
trackedSDKErrors[sdkErrorKind] = 1
194-
}
188+
trackedSDKErrors[sdkErrorKind, default: 0] += 1
195189
}
196190

197191
/// Tracks an event missed due to absence of an active view.
198192
/// - Parameter missedEventType: the type of an event that was missed
199193
func track(missedEventType: MissedEventType) {
200-
if let count = missedEvents[missedEventType] {
201-
missedEvents[missedEventType] = count + 1
202-
} else {
203-
missedEvents[missedEventType] = 1
204-
}
194+
missedEvents[missedEventType, default: 0] += 1
205195
}
206196

207197
/// Signals that the session was stopped with `stopSession()` API.
@@ -410,7 +400,7 @@ internal class SessionEndedMetric {
410400
var byInstrumentationViewsCount: [String: Int] = [:]
411401
trackedViews.values.forEach {
412402
if let instrumentationType = $0.instrumentationType {
413-
byInstrumentationViewsCount[instrumentationType.metricKey] = (byInstrumentationViewsCount[instrumentationType.metricKey] ?? 0) + 1
403+
byInstrumentationViewsCount[instrumentationType.metricKey, default: 0] += 1
414404
}
415405
}
416406
let totalActionsCount = trackedActions.values.reduce(0, +)

DatadogRUM/Sources/SDKMetrics/SessionEndedMetricController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal final class SessionEndedMetricController {
7272
/// - sessionID: session ID to track this action in (pass `nil` to track it for the last started session)
7373
func track(
7474
action: RUMActionEvent,
75-
instrumentationType: InstrumentationType?,
75+
instrumentationType: InstrumentationType,
7676
in sessionID: RUMUUID?
7777
) {
7878
updateMetric(for: sessionID) { $0?.track(action: action, instrumentationType: instrumentationType) }

DatadogRUM/Tests/RUMEvent/RUMEventSanitizerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import DatadogInternal
1111
class RUMEventSanitizerTests: XCTestCase {
1212
private let viewEvent: RUMViewEvent = .mockRandom()
1313
private let resourceEvent: RUMResourceEvent = .mockRandom()
14-
private let actionEvent: RUMActionEvent = .mockRandom()
14+
private let actionEvent: RUMActionEvent = .mockAny()
1515
private let errorEvent: RUMErrorEvent = .mockRandom()
1616
private let longTaskEvent: RUMLongTaskEvent = .mockRandom()
1717

DatadogRUM/Tests/SDKMetrics/SessionEndedMetricTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class SessionEndedMetricTests: XCTestCase {
419419
// When
420420
(0..<actionCount).forEach { _ in
421421
metric.track(
422-
action: .mockRandomWith(sessionID: sessionID.rawValue),
422+
action: .mockWith(sessionID: sessionID.rawValue),
423423
instrumentationType: .manual
424424
)
425425
}
@@ -442,25 +442,25 @@ class SessionEndedMetricTests: XCTestCase {
442442
// When
443443
(0..<manualActionsCount).forEach { _ in
444444
metric.track(
445-
action: .mockRandomWith(sessionID: sessionID.rawValue),
445+
action: .mockWith(sessionID: sessionID.rawValue),
446446
instrumentationType: .manual
447447
)
448448
}
449449
(0..<swiftuiActionsCount).forEach { _ in
450450
metric.track(
451-
action: .mockRandomWith(sessionID: sessionID.rawValue),
451+
action: .mockWith(sessionID: sessionID.rawValue),
452452
instrumentationType: .swiftui
453453
)
454454
}
455455
(0..<uikitPredicateActionsCount).forEach { _ in
456456
metric.track(
457-
action: .mockRandomWith(sessionID: sessionID.rawValue),
457+
action: .mockWith(sessionID: sessionID.rawValue),
458458
instrumentationType: .uikit
459459
)
460460
}
461461
(0..<swiftuiAutomaticPredicateActionsCount).forEach { _ in
462462
metric.track(
463-
action: .mockRandomWith(sessionID: sessionID.rawValue),
463+
action: .mockWith(sessionID: sessionID.rawValue),
464464
instrumentationType: .swiftuiAutomatic
465465
)
466466
}
@@ -488,8 +488,8 @@ class SessionEndedMetricTests: XCTestCase {
488488
let metric = SessionEndedMetric.with(sessionID: sessionID)
489489

490490
// When
491-
metric.track(action: .mockRandom(), instrumentationType: .manual)
492-
metric.track(action: .mockRandom(), instrumentationType: .manual)
491+
metric.track(action: .mockAny(), instrumentationType: .manual)
492+
metric.track(action: .mockAny(), instrumentationType: .manual)
493493
let attributes = metric.asMetricAttributes()
494494

495495
// Then

DatadogRUM/Tests/Scrubbing/RUMEventsMapperTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class RUMEventsMapperTests: XCTestCase {
2020
let originalResourceEvent: RUMResourceEvent = .mockRandom()
2121
let modifiedResourceEvent: RUMResourceEvent = .mockRandom()
2222

23-
let originalActionEvent: RUMActionEvent = .mockRandom()
24-
let modifiedActionEvent: RUMActionEvent = .mockRandom()
23+
let originalActionEvent: RUMActionEvent = .mockAny()
24+
let modifiedActionEvent: RUMActionEvent = .mockAny()
2525

2626
let originalLongTaskEvent: RUMLongTaskEvent = .mockRandom()
2727
let modifiedLongTaskEvent: RUMLongTaskEvent = .mockRandom()
@@ -68,7 +68,7 @@ class RUMEventsMapperTests: XCTestCase {
6868
func testGivenMappersEnabled_whenDroppingEvents_itReturnsNil() {
6969
let originalErrorEvent: RUMErrorEvent = .mockRandom()
7070
let originalResourceEvent: RUMResourceEvent = .mockRandom()
71-
let originalActionEvent: RUMActionEvent = .mockRandom()
71+
let originalActionEvent: RUMActionEvent = .mockAny()
7272
let originalLongTaskEvent: RUMLongTaskEvent = .mockRandom()
7373

7474
// Given
@@ -108,7 +108,7 @@ class RUMEventsMapperTests: XCTestCase {
108108
let originalViewEvent: RUMViewEvent = .mockRandom()
109109
let originalErrorEvent: RUMErrorEvent = .mockRandom()
110110
let originalResourceEvent: RUMResourceEvent = .mockRandom()
111-
let originalActionEvent: RUMActionEvent = .mockRandom()
111+
let originalActionEvent: RUMActionEvent = .mockAny()
112112
let originalLongTaskEvent: RUMLongTaskEvent = .mockRandom()
113113

114114
// Given

TestUtilities/Sources/Mocks/DatadogInternal/RUMDataModelMocks.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public func randomRUMEvent() -> RUMDataModel {
4141
// swiftlint:disable opening_brace
4242
return oneOf([
4343
{ RUMViewEvent.mockRandom() },
44-
{ RUMActionEvent.mockRandom() },
44+
{ RUMActionEvent.mockAny() },
4545
{ RUMResourceEvent.mockRandom() },
4646
{ RUMErrorEvent.mockRandom() },
4747
{ RUMLongTaskEvent.mockRandom() },
@@ -369,12 +369,12 @@ extension RUMActionEvent.DD.Configuration: RandomMockable {
369369
}
370370
}
371371

372-
extension RUMActionEvent: RandomMockable {
373-
public static func mockRandom() -> RUMActionEvent {
374-
return mockRandomWith()
372+
extension RUMActionEvent: AnyMockable {
373+
public static func mockAny() -> RUMActionEvent {
374+
.mockWith()
375375
}
376376

377-
public static func mockRandomWith(
377+
public static func mockWith(
378378
sessionID: UUID = .mockRandom()
379379
) -> RUMActionEvent {
380380
return RUMActionEvent(

0 commit comments

Comments
 (0)