Skip to content

Commit

Permalink
Merge pull request #1556 from DataDog/ncreated/fix/fix-browser-v5-eve…
Browse files Browse the repository at this point in the history
…nts-parser

[cherry-pick] Fix WebView event parser following Browser v5
  • Loading branch information
ncreated authored Nov 14, 2023
2 parents da1f1b9 + 6f3aaf4 commit e699ec9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions DatadogRUM/Sources/Integrations/WebViewEventReceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ internal final class WebViewEventReceiver: FeatureMessageReceiver {
event["session"] = session
}

if var dd = event["_dd"] as? JSON, var dd_sesion = dd["session"] as? [String: Int64] {
dd_sesion["plan"] = 1
dd["session"] = dd_sesion
if var dd = event["_dd"] as? JSON {
var session = dd["session"] as? [String: Any] ?? [:]
session["plan"] = 1
dd["session"] = session
event["_dd"] = dd
}

Expand Down
9 changes: 5 additions & 4 deletions DatadogRUM/Tests/Integrations/WebViewEventReceiverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class WebViewEventReceiverTests: XCTestCase {
let random = mockRandomAttributes() // because below we only mock partial web event, we use this random to make the test fuzzy
let webEventMock: JSON = [
// Known properties:
"_dd": ["session": ["plan": 2]],
"_dd": ["browser_sdk_version": "5.2.0"],
"application": ["id": String.mockRandom()],
"session": ["id": String.mockRandom()],
"view": ["id": "00000000-aaaa-0000-aaaa-000000000000"],
Expand All @@ -113,7 +113,10 @@ class WebViewEventReceiverTests: XCTestCase {
// Then
let expectedWebEventWritten: JSON = [
// Known properties:
"_dd": ["session": ["plan": 1]],
"_dd": [
"session": ["plan": 1],
"browser_sdk_version": "5.2.0"
] as [String: Any],
"application": ["id": rumContext.applicationID],
"session": ["id": rumContext.sessionID],
"view": ["id": "00000000-aaaa-0000-aaaa-000000000000"],
Expand All @@ -126,7 +129,6 @@ class WebViewEventReceiverTests: XCTestCase {
DDAssertJSONEqual(AnyCodable(actualWebEventWritten), AnyCodable(expectedWebEventWritten))
}

// swiftlint:disable opening_brace
func testGivenRUMContextNotAvailable_whenReceivingWebEvent_itIsDropped() throws {
let core = PassthroughCoreMock()

Expand All @@ -145,7 +147,6 @@ class WebViewEventReceiverTests: XCTestCase {
XCTAssertTrue(result, "It must accept the message")
XCTAssertTrue(core.events.isEmpty, "The event must be dropped")
}
// swiftlint:enable opening_brace

func testGivenInvalidRUMContext_whenReceivingEvent_itSendsErrorTelemetry() throws {
struct InvalidRUMContext: Codable {
Expand Down

0 comments on commit e699ec9

Please sign in to comment.