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-3239 Fix RUM Context in Logs #1264

Merged
merged 3 commits into from
Apr 25, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- [BUGFIX] Fix RUM context not being attached to log when no user action exists. See [#1264][]

# 1.18.0 / 19-04-2023
- [IMPROVEMENT] Add start reason to the session. See [#1247][]
- [IMPROVEMENT] Add ability to stop the session. See [#1219][]
Expand Down Expand Up @@ -452,6 +454,7 @@
[#1219]: https://github.com/DataDog/dd-sdk-ios/pull/1219
[#1220]: https://github.com/DataDog/dd-sdk-ios/pull/1220
[#1247]: https://github.com/DataDog/dd-sdk-ios/pull/1247
[#1264]: https://github.com/DataDog/dd-sdk-ios/pull/1264
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
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
44 changes: 27 additions & 17 deletions Tests/DatadogTests/Datadog/LoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,28 +551,38 @@ 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
)

$0.assertValue(
forKeyPath: RUMContextAttributes.IDs.sessionID,
isTypeOf: String.self
)

$0.assertValue(
forKeyPath: RUMContextAttributes.IDs.viewID,
isTypeOf: String.self
)
maxep marked this conversation as resolved.
Show resolved Hide resolved
}

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

logMatchers.last?.assertValue(
forKeyPath: RUMContextAttributes.IDs.userActionID,
isTypeOf: String.self
)
ganeshnj marked this conversation as resolved.
Show resolved Hide resolved
Expand Down