Skip to content

Commit 7999267

Browse files
committed
RUM-8416 Add auto-tracking option for SwiftUI in RUM Configuration
1 parent 6664ae2 commit 7999267

File tree

6 files changed

+295
-131
lines changed

6 files changed

+295
-131
lines changed

DatadogRUM/Sources/Feature/RUMFeature.swift

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ internal final class RUMFeature: DatadogRemoteFeature {
160160
featureScope: featureScope,
161161
uiKitRUMViewsPredicate: configuration.uiKitViewsPredicate,
162162
uiKitRUMActionsPredicate: configuration.uiKitActionsPredicate,
163+
swiftUIRUMViewsPredicate: configuration.swiftUIViewsPredicate,
163164
longTaskThreshold: configuration.longTaskThreshold,
164165
appHangThreshold: configuration.appHangThreshold,
165166
mainQueue: configuration.mainQueue,

DatadogRUM/Sources/RUMConfiguration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extension RUM {
192192
/// and do not make any assumptions on the thread used to run it.
193193
///
194194
/// Note: This mapper ensures that all views are sent by preventing the return of `nil`. To drop certain automatically
195-
/// collected RUM views, adjust the implementation of the view predicate (see the `uiKitViewsPredicate` and `swiftUIPredicate` options).
195+
/// collected RUM views, adjust the implementations of the view predicates (see the `uiKitViewsPredicate` and `swiftUIViewsPredicate` options).
196196
///
197197
/// Default: `nil`.
198198
public var viewEventMapper: RUM.ViewEventMapper?

DatadogRUM/Tests/Instrumentation/RUMInstrumentationTests.swift

+36
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class RUMInstrumentationTests: XCTestCase {
1818
featureScope: NOPFeatureScope(),
1919
uiKitRUMViewsPredicate: UIKitRUMViewsPredicateMock(),
2020
uiKitRUMActionsPredicate: nil,
21+
swiftUIRUMViewsPredicate: nil,
2122
longTaskThreshold: nil,
2223
appHangThreshold: .mockAny(),
2324
mainQueue: .main,
@@ -46,6 +47,7 @@ class RUMInstrumentationTests: XCTestCase {
4647
featureScope: NOPFeatureScope(),
4748
uiKitRUMViewsPredicate: nil,
4849
uiKitRUMActionsPredicate: UIKitRUMActionsPredicateMock(),
50+
swiftUIRUMViewsPredicate: nil,
4951
longTaskThreshold: nil,
5052
appHangThreshold: .mockAny(),
5153
mainQueue: .main,
@@ -65,12 +67,42 @@ class RUMInstrumentationTests: XCTestCase {
6567
}
6668
}
6769

70+
func testWhenOnlySwiftUIViewsPredicateIsConfigured_itInstrumentsUIViewController() throws {
71+
// When
72+
let instrumentation = RUMInstrumentation(
73+
featureScope: NOPFeatureScope(),
74+
uiKitRUMViewsPredicate: nil,
75+
uiKitRUMActionsPredicate: nil,
76+
swiftUIRUMViewsPredicate: SwiftUIRUMViewsPredicateMock(),
77+
longTaskThreshold: nil,
78+
appHangThreshold: .mockAny(),
79+
mainQueue: .main,
80+
dateProvider: SystemDateProvider(),
81+
backtraceReporter: BacktraceReporterMock(),
82+
fatalErrorContext: FatalErrorContextNotifierMock(),
83+
processID: .mockAny(),
84+
notificationCenter: .default,
85+
watchdogTermination: .mockRandom(),
86+
memoryWarningMonitor: .mockRandom()
87+
)
88+
89+
// Then
90+
withExtendedLifetime(instrumentation) {
91+
DDAssertActiveSwizzlings([
92+
"viewDidAppear:",
93+
"viewDidDisappear:",
94+
])
95+
XCTAssertNil(instrumentation.longTasks)
96+
}
97+
}
98+
6899
func testWhenOnlyLongTasksThresholdIsConfigured_itInstrumentsRunLoop() throws {
69100
// When
70101
let instrumentation = RUMInstrumentation(
71102
featureScope: NOPFeatureScope(),
72103
uiKitRUMViewsPredicate: nil,
73104
uiKitRUMActionsPredicate: nil,
105+
swiftUIRUMViewsPredicate: nil,
74106
longTaskThreshold: 0.5,
75107
appHangThreshold: .mockAny(),
76108
mainQueue: .main,
@@ -99,6 +131,7 @@ class RUMInstrumentationTests: XCTestCase {
99131
featureScope: NOPFeatureScope(),
100132
uiKitRUMViewsPredicate: nil,
101133
uiKitRUMActionsPredicate: nil,
134+
swiftUIRUMViewsPredicate: nil,
102135
longTaskThreshold: .mockRandom(min: -100, max: 0),
103136
appHangThreshold: .mockAny(),
104137
mainQueue: .main,
@@ -123,6 +156,7 @@ class RUMInstrumentationTests: XCTestCase {
123156
featureScope: NOPFeatureScope(),
124157
uiKitRUMViewsPredicate: nil,
125158
uiKitRUMActionsPredicate: nil,
159+
swiftUIRUMViewsPredicate: nil,
126160
longTaskThreshold: .mockRandom(min: -100, max: 0),
127161
appHangThreshold: 2,
128162
mainQueue: .main,
@@ -147,6 +181,7 @@ class RUMInstrumentationTests: XCTestCase {
147181
featureScope: NOPFeatureScope(),
148182
uiKitRUMViewsPredicate: nil,
149183
uiKitRUMActionsPredicate: nil,
184+
swiftUIRUMViewsPredicate: nil,
150185
longTaskThreshold: .mockRandom(min: -100, max: 0),
151186
appHangThreshold: nil,
152187
mainQueue: .main,
@@ -171,6 +206,7 @@ class RUMInstrumentationTests: XCTestCase {
171206
featureScope: NOPFeatureScope(),
172207
uiKitRUMViewsPredicate: UIKitRUMViewsPredicateMock(),
173208
uiKitRUMActionsPredicate: UIKitRUMActionsPredicateMock(),
209+
swiftUIRUMViewsPredicate: nil,
174210
longTaskThreshold: 0.5,
175211
appHangThreshold: 2,
176212
mainQueue: .main,

0 commit comments

Comments
 (0)