From 5224f46f685051d9200b0a680a9bfc08f26ea4cd Mon Sep 17 00:00:00 2001 From: maxep Date: Wed, 29 Sep 2021 10:27:01 +0200 Subject: [PATCH 1/2] RUMM-1668 Associate Logs and Traces with RUM Action --- Sources/Datadog/FeaturesIntegration/RUMIntegrations.swift | 2 ++ .../Datadog/FeaturesIntegration/RUMIntegrationsTests.swift | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Datadog/FeaturesIntegration/RUMIntegrations.swift b/Sources/Datadog/FeaturesIntegration/RUMIntegrations.swift index ea586d229f..860dcaa1d1 100644 --- a/Sources/Datadog/FeaturesIntegration/RUMIntegrations.swift +++ b/Sources/Datadog/FeaturesIntegration/RUMIntegrations.swift @@ -15,6 +15,7 @@ internal struct RUMContextIntegration { static let applicationID = "application_id" static let sessionID = "session_id" static let viewID = "view.id" + static let actionID = "user_action.id" } /// Returns attributes describing the current RUM context or `nil`if global `RUMMonitor` is not registered. @@ -31,6 +32,7 @@ internal struct RUMContextIntegration { Attributes.applicationID: rumContext.rumApplicationID, Attributes.sessionID: rumContext.sessionID.rawValue.uuidString.lowercased(), Attributes.viewID: rumContext.activeViewID?.rawValue.uuidString.lowercased(), + Attributes.actionID: rumContext.activeUserActionID?.rawValue.uuidString.lowercased(), ] } } diff --git a/Tests/DatadogTests/Datadog/FeaturesIntegration/RUMIntegrationsTests.swift b/Tests/DatadogTests/Datadog/FeaturesIntegration/RUMIntegrationsTests.swift index 1dd767cc51..cb6da340fa 100644 --- a/Tests/DatadogTests/Datadog/FeaturesIntegration/RUMIntegrationsTests.swift +++ b/Tests/DatadogTests/Datadog/FeaturesIntegration/RUMIntegrationsTests.swift @@ -17,18 +17,20 @@ class RUMIntegrationsTests: XCTestCase { // given Global.rum = RUMMonitor.initialize() Global.rum.startView(viewController: mockView) + Global.rum.startUserAction(type: .tap, name: .mockAny()) defer { Global.rum = DDNoopRUMMonitor() } // then let attributes = try XCTUnwrap(integration.currentRUMContextAttributes) - XCTAssertEqual(attributes.count, 3) + XCTAssertEqual(attributes.count, 4) XCTAssertEqual( attributes["application_id"] as? String, try XCTUnwrap(RUMFeature.instance?.configuration.applicationID) ) XCTAssertValidRumUUID(attributes["session_id"] as? String) XCTAssertValidRumUUID(attributes["view.id"] as? String) + XCTAssertValidRumUUID(attributes["user_action.id"] as? String) } func testGivenRUMMonitorRegistered_whenSessionIsSampled_itProvidesEmptyRUMContextAttributes() throws { From a5b0107433e32754ea67b33d2f46ef3586e46035 Mon Sep 17 00:00:00 2001 From: maxep Date: Wed, 29 Sep 2021 11:41:09 +0200 Subject: [PATCH 2/2] RUMM-1668 Assert user action id in Logger Tests --- Tests/DatadogTests/Datadog/LoggerTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/DatadogTests/Datadog/LoggerTests.swift b/Tests/DatadogTests/Datadog/LoggerTests.swift index d9703b49fd..602aabd6ee 100644 --- a/Tests/DatadogTests/Datadog/LoggerTests.swift +++ b/Tests/DatadogTests/Datadog/LoggerTests.swift @@ -506,6 +506,7 @@ class LoggerTests: XCTestCase { let logger = Logger.builder.build() Global.rum = RUMMonitor.initialize() Global.rum.startView(viewController: mockView) + Global.rum.startUserAction(type: .tap, name: .mockAny()) defer { Global.rum = DDNoopRUMMonitor() } // when @@ -525,6 +526,10 @@ class LoggerTests: XCTestCase { forKeyPath: RUMContextIntegration.Attributes.viewID, isTypeOf: String.self ) + logMatcher.assertValue( + forKeyPath: RUMContextIntegration.Attributes.actionID, + isTypeOf: String.self + ) } func testGivenBundlingWithRUMEnabledButRUMMonitorNotRegistered_whenSendingLog_itPrintsWarning() throws { @@ -561,6 +566,7 @@ class LoggerTests: XCTestCase { logMatcher.assertNoValue(forKeyPath: RUMContextIntegration.Attributes.applicationID) logMatcher.assertNoValue(forKeyPath: RUMContextIntegration.Attributes.sessionID) logMatcher.assertNoValue(forKeyPath: RUMContextIntegration.Attributes.viewID) + logMatcher.assertNoValue(forKeyPath: RUMContextIntegration.Attributes.actionID) } func testWhenSendingErrorOrCriticalLogs_itCreatesRUMErrorForCurrentView() throws {