Skip to content

Commit

Permalink
RUMM-3239 Fix RUM context in Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Apr 25, 2023
1 parent cc1ef5d commit 5d4b391
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Sources/Datadog/Logging/RemoteLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ internal final class RemoteLogger: LoggerProtocol {
var internalAttributes: [String: Encodable] = [:]
let contextAttributes = context.featuresAttributes

if self.rumContextIntegration, let attributes: [String: String] = contextAttributes["rum"]?.ids {
let attributes = attributes.compactMapValues(AnyEncodable.init)
if self.rumContextIntegration, let attributes: [String: AnyCodable?] = contextAttributes["rum"]?.ids {
let attributes = attributes.compactMapValues { $0 }
internalAttributes.merge(attributes) { $1 }
}

Expand Down
47 changes: 30 additions & 17 deletions Tests/DatadogTests/Datadog/LoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,28 +551,41 @@ class LoggerTests: XCTestCase {
// given
let logger = Logger.builder.build(in: core)
Global.rum = RUMMonitor.initialize(in: core)
Global.rum.startView(viewController: mockView)
Global.rum.startUserAction(type: .tap, name: .mockAny())
defer { Global.rum = DDNoopRUMMonitor() }

// when
logger.info("info message")
Global.rum.startView(viewController: mockView)
logger.info("message 0")
Global.rum.startUserAction(type: .tap, name: .mockAny())
logger.info("message 1")

// then
let logMatcher = try core.waitAndReturnLogMatchers()[0]
logMatcher.assertValue(
forKeyPath: RUMContextAttributes.IDs.applicationID,
equals: rum.configuration.applicationID
)
logMatcher.assertValue(
forKeyPath: RUMContextAttributes.IDs.sessionID,
isTypeOf: String.self
)
logMatcher.assertValue(
forKeyPath: RUMContextAttributes.IDs.viewID,
isTypeOf: String.self
)
logMatcher.assertValue(
let logMatchers = try core.waitAndReturnLogMatchers()
XCTAssertEqual(logMatchers.count, 2)

logMatchers.forEach {
$0.assertValue(
forKeyPath: RUMContextAttributes.IDs.applicationID,
equals: rum.configuration.applicationID
)
}
logMatchers.forEach {
$0.assertValue(
forKeyPath: RUMContextAttributes.IDs.sessionID,
isTypeOf: String.self
)
}

logMatchers.forEach {
$0.assertValue(
forKeyPath: RUMContextAttributes.IDs.viewID,
isTypeOf: String.self
)
}

logMatchers.first?.assertNoValue(forKeyPath: RUMContextAttributes.IDs.userActionID)

logMatchers.last?.assertValue(
forKeyPath: RUMContextAttributes.IDs.userActionID,
isTypeOf: String.self
)
Expand Down

0 comments on commit 5d4b391

Please sign in to comment.