Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1668 Associate Logs and Traces with RUM Action #615

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/Datadog/FeaturesIntegration/RUMIntegrations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions Tests/DatadogTests/Datadog/LoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down