diff --git a/Datadog/Datadog.xcodeproj/project.pbxproj b/Datadog/Datadog.xcodeproj/project.pbxproj index 1884b1e9a4..1d8b4800f0 100644 --- a/Datadog/Datadog.xcodeproj/project.pbxproj +++ b/Datadog/Datadog.xcodeproj/project.pbxproj @@ -278,6 +278,7 @@ 3C3EF2B02C1AEBAB009E9E57 /* LaunchReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C3EF2AF2C1AEBAB009E9E57 /* LaunchReport.swift */; }; 3C41693C29FBF4D50042B9D2 /* DatadogWebViewTracking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CE119FE29F7BE0100202522 /* DatadogWebViewTracking.framework */; }; 3C43A3882C188974000BFB21 /* WatchdogTerminationMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C43A3862C188970000BFB21 /* WatchdogTerminationMonitorTests.swift */; }; + B21F9B173E636896FBBF638B /* WatchdogTerminationReporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11A0F1FDC6F852757B99EF56 /* WatchdogTerminationReporterTests.swift */; }; 3C4CF9922C47BE07006DE1C0 /* MemoryWarningMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5CD8C12C3EBA1700B12303 /* MemoryWarningMonitor.swift */; }; 3C4CF9982C47CC91006DE1C0 /* MemoryWarningMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4CF9972C47CC8C006DE1C0 /* MemoryWarningMonitorTests.swift */; }; 3C4CF99B2C47DAA5006DE1C0 /* MemoryWarningMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4CF99A2C47DAA5006DE1C0 /* MemoryWarningMocks.swift */; }; @@ -2113,6 +2114,7 @@ 3C3C9E2E2C64F470003AF22F /* Data+CryptoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+CryptoTests.swift"; sourceTree = ""; }; 3C3EF2AF2C1AEBAB009E9E57 /* LaunchReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchReport.swift; sourceTree = ""; }; 3C43A3862C188970000BFB21 /* WatchdogTerminationMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchdogTerminationMonitorTests.swift; sourceTree = ""; }; + 11A0F1FDC6F852757B99EF56 /* WatchdogTerminationReporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchdogTerminationReporterTests.swift; sourceTree = ""; }; 3C4CF9972C47CC8C006DE1C0 /* MemoryWarningMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryWarningMonitorTests.swift; sourceTree = ""; }; 3C4CF99A2C47DAA5006DE1C0 /* MemoryWarningMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryWarningMocks.swift; sourceTree = ""; }; 3C5CD8C12C3EBA1700B12303 /* MemoryWarningMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryWarningMonitor.swift; sourceTree = ""; }; @@ -3957,6 +3959,7 @@ 3CFF4FA32C0E0FE5006F191D /* WatchdogTerminationCheckerTests.swift */, 3CEC57752C16FDD30042B5F2 /* AppStateManagerTests.swift */, 3C43A3862C188970000BFB21 /* WatchdogTerminationMonitorTests.swift */, + 11A0F1FDC6F852757B99EF56 /* WatchdogTerminationReporterTests.swift */, ); path = WatchdogTerminations; sourceTree = ""; @@ -9463,6 +9466,7 @@ 3C4CF99B2C47DAA5006DE1C0 /* MemoryWarningMocks.swift in Sources */, 5B1D02942E8ED6C000AB2391 /* FlagEvaluationReceiverTests.swift in Sources */, 3C43A3882C188974000BFB21 /* WatchdogTerminationMonitorTests.swift in Sources */, + B21F9B173E636896FBBF638B /* WatchdogTerminationReporterTests.swift in Sources */, D29A9F9D29DDB483005C54A4 /* ValuePublisherTests.swift in Sources */, 6174D61A2BFE449300EC7469 /* SessionEndedMetricTests.swift in Sources */, 9654971D2D774060006428EE /* SwiftUIViewNameExtractorTests.swift in Sources */, diff --git a/DatadogCore/Tests/Datadog/RUM/Integrations/CrashReportReceiverTests.swift b/DatadogCore/Tests/Datadog/RUM/Integrations/CrashReportReceiverTests.swift index ca7188bc43..768a2ee4b0 100644 --- a/DatadogCore/Tests/Datadog/RUM/Integrations/CrashReportReceiverTests.swift +++ b/DatadogCore/Tests/Datadog/RUM/Integrations/CrashReportReceiverTests.swift @@ -154,6 +154,219 @@ class CrashReportReceiverTests: XCTestCase { XCTAssertEqual(featureScope.eventsWritten(ofType: RUMErrorEvent.self).count, 1) } + func testGivenCrashDuringRUMSessionWithActiveViewCollectedLessThan4HoursAgoAndTooManyAttributes_whenSending_itSanitizesRUMErrorContext() throws { + let secondsIn4Hours: TimeInterval = 4 * 60 * 60 + let numberOfAttributes = AttributesSanitizer.Constraints.maxNumberOfAttributes * 2 + + // Given + let currentDate: Date = .mockDecember15th2019At10AMUTC() + let crashDate: Date = currentDate.secondsAgo(.random(in: 0.. Bool { diff --git a/DatadogRUM/Tests/Instrumentation/AppHangs/AppHangsMonitorTests.swift b/DatadogRUM/Tests/Instrumentation/AppHangs/AppHangsMonitorTests.swift index 19f68d62cc..fac42873d0 100644 --- a/DatadogRUM/Tests/Instrumentation/AppHangs/AppHangsMonitorTests.swift +++ b/DatadogRUM/Tests/Instrumentation/AppHangs/AppHangsMonitorTests.swift @@ -282,6 +282,80 @@ class AppHangsMonitorTests: XCTestCase { XCTAssertNil(featureScope.dataStoreMock.value(forKey: RUMDataStore.Key.fatalAppHangKey.rawValue)) } + func testGivenPendingHangWithTooManyAttributes_whenStartedInAnotherProcess_itSanitizesRUMErrorContextBeforeWriting() throws { + let numberOfAttributes = AttributesSanitizer.Constraints.maxNumberOfAttributes * 2 + let currentDate: Date = .mockDecember15th2019At10AMUTC() + let hangDate: Date = currentDate.secondsAgo(.random(in: 0...4.hours)) + var view: RUMViewEvent = .mockRandom() + view.context = RUMEventAttributes( + contextInfo: Dictionary(uniqueKeysWithValues: (0..(event: Event) where Event: RUMSanitizableEvent { @@ -84,6 +86,8 @@ class RUMEventSanitizerTests: XCTestCase { test(event: actionEvent) test(event: errorEvent) test(event: longTaskEvent) + test(event: vitalAppLaunchEvent) + test(event: vitalOperationStepEvent) } func testWhenNumberOfAttributesExceedsLimit_itDropsExtraOnes() { @@ -125,6 +129,8 @@ class RUMEventSanitizerTests: XCTestCase { test(event: actionEvent) test(event: errorEvent) test(event: longTaskEvent) + test(event: vitalAppLaunchEvent) + test(event: vitalOperationStepEvent) } // MARK: - Private diff --git a/DatadogRUM/Tests/RUMMonitor/RUMFeatureOperationManagerTests.swift b/DatadogRUM/Tests/RUMMonitor/RUMFeatureOperationManagerTests.swift index 76d60ea361..524b8cf622 100644 --- a/DatadogRUM/Tests/RUMMonitor/RUMFeatureOperationManagerTests.swift +++ b/DatadogRUM/Tests/RUMMonitor/RUMFeatureOperationManagerTests.swift @@ -98,6 +98,22 @@ class RUMFeatureOperationManagerTests: XCTestCase { XCTAssertEqual(event.dd.profiling?.quotaReason, quotaReason) } + func testFeatureOperationCommand_sanitizesContextAttributesBeforeWriting() throws { + // Given + let numberOfAttributes = AttributesSanitizer.Constraints.maxNumberOfAttributes * 2 + let attributes = Dictionary( + uniqueKeysWithValues: (0.. RUMVitalOperationStepEvent { return RUMVitalOperationStepEvent( dd: .init(), + account: .mockRandom(), application: .init(id: .mockRandom()), + context: .mockRandom(), date: .mockRandom(), session: .init(id: .mockRandom(), type: .user), + usr: .mockRandom(), view: .init(id: .mockRandom(), url: .mockRandom()), vital: .mockRandom() ) @@ -786,9 +789,12 @@ extension RUMVitalAppLaunchEvent: RandomMockable, AnyMockable { public static func mockRandom() -> Self { return RUMVitalAppLaunchEvent( dd: .init(), + account: .mockRandom(), application: .init(id: .mockRandom()), + context: .mockRandom(), date: .mockRandom(), session: .init(id: .mockRandom(), type: .user), + usr: .mockRandom(), view: .init(id: .mockRandom(), url: .mockRandom()), vital: .mockRandom() ) @@ -798,17 +804,23 @@ extension RUMVitalAppLaunchEvent: RandomMockable, AnyMockable { public static func mockWith( dd: DD = .init(), + account: RUMAccount? = .mockRandom(), application: Application = .init(id: .mockAny()), + context: RUMEventAttributes? = .mockRandom(), date: Int64 = .mockAny(), session: Session = .init(id: .mockAny(), type: .user), + usr: RUMUser? = .mockRandom(), view: View = .init(id: .mockAny(), url: .mockAny()), vital: Vital = .mockAny() ) -> Self { .init( dd: dd, + account: account, application: application, + context: context, date: date, session: session, + usr: usr, view: view, vital: vital )