Skip to content

Commit 5a49e0f

Browse files
Merge pull request #2154 from DataDog/maciey/RUM-7205/double-full-snapshot-bug
RUM-7205 Double full snapshot bug Co-authored-by: maciejburda <maciej.burda@datadoghq.com>
2 parents 2d785bf + fd28491 commit 5a49e0f

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
- [IMPROVEMENT] Add Datadog Configuration `backgroundTasksEnabled` ObjC API. See [#2148][]
4+
- [FIX] Prevent Session Replay to create two full snapshots in a row. See [#2154][]
45

56
# 2.21.0 / 11-12-2024
67

@@ -809,6 +810,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
809810
[#2120]: https://github.com/DataDog/dd-sdk-ios/pull/2120
810811
[#2126]: https://github.com/DataDog/dd-sdk-ios/pull/2126
811812
[#2148]: https://github.com/DataDog/dd-sdk-ios/pull/2148
813+
[#2154]: https://github.com/DataDog/dd-sdk-ios/pull/2154
812814
[@00fa9a]: https://github.com/00FA9A
813815
[@britton-earnin]: https://github.com/Britton-Earnin
814816
[@hengyu]: https://github.com/Hengyu

DatadogSessionReplay/Sources/Processor/Builders/RecordsBuilder.swift

-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ internal class RecordsBuilder {
6666
/// In case of unexpected failure, it will fallback to creating FSR instead.
6767
/// If the root wireframe has changed, we trigger a full snapshot so it is added first in the replay.
6868
func createIncrementalSnapshotRecord(from snapshot: ViewTreeSnapshot, with wireframes: [SRWireframe], lastWireframes: [SRWireframe]) -> SRRecord? {
69-
if wireframes.first?.id != lastWireframes.first?.id {
70-
return createFullSnapshotRecord(from: snapshot, wireframes: wireframes)
71-
}
7269
do {
7370
return try createIncrementalSnapshotRecord(from: snapshot, newWireframes: wireframes, lastWireframes: lastWireframes)
7471
} catch {

DatadogSessionReplay/Tests/Processor/Builders/RecordsBuilderTests.swift

+16-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class RecordsBuilderTests: XCTestCase {
4747
DDAssertReflectionEqual(mutations.adds[0].wireframe, next[2])
4848
}
4949

50-
func testWhenNextWireframesAddsNewRoot_itCreatesFullSnapshotRecord() throws {
50+
func testWhenNextWireframesAddsNewRoot_itCreatesIncrementalRecord() throws {
5151
let builder = RecordsBuilder(telemetry: TelemetryMock())
5252

5353
// Given
@@ -58,8 +58,11 @@ class RecordsBuilderTests: XCTestCase {
5858
let record = builder.createIncrementalSnapshotRecord(from: .mockAny(), with: next, lastWireframes: previous)
5959

6060
// Then
61-
let fullRecord = try XCTUnwrap(record?.fullSnapshot)
62-
DDAssertReflectionEqual(fullRecord.data.wireframes, next)
61+
let incrementalRecord = try XCTUnwrap(record?.incrementalSnapshot)
62+
guard case .mutationData = incrementalRecord.data else {
63+
XCTFail("Expected `mutationData` in incremental record, got \(incrementalRecord.data)")
64+
return
65+
}
6366
}
6467

6568
// This case does not need a full snapshot for the player to work, but adding a
@@ -68,15 +71,21 @@ class RecordsBuilderTests: XCTestCase {
6871
let builder = RecordsBuilder(telemetry: TelemetryMock())
6972

7073
// Given
71-
let previous: [SRWireframe] = [.mockRandomWith(id: 0), .mockRandomWith(id: 1)]
72-
let next: [SRWireframe] = [.mockRandomWith(id: 1)]
74+
let previous: [SRWireframe] = [
75+
.shapeWireframe(value: .mockRandomWith(id: 0)),
76+
.shapeWireframe(value: .mockRandomWith(id: 1))
77+
]
78+
let next: [SRWireframe] = [.shapeWireframe(value: .mockRandomWith(id: 1))]
7379

7480
// When
7581
let record = builder.createIncrementalSnapshotRecord(from: .mockAny(), with: next, lastWireframes: previous)
7682

7783
// Then
78-
let fullRecord = try XCTUnwrap(record?.fullSnapshot)
79-
DDAssertReflectionEqual(fullRecord.data.wireframes, next)
84+
let incrementalRecord = try XCTUnwrap(record?.incrementalSnapshot)
85+
guard case .mutationData = incrementalRecord.data else {
86+
XCTFail("Expected `mutationData` in incremental record, got \(incrementalRecord.data)")
87+
return
88+
}
8089
}
8190

8291
func testWhenWireframesAreNotConsistent_itFallbacksToFullSnapshotRecordAndSendsErrorTelemetry() throws {

DatadogSessionReplay/Tests/Processor/SnapshotProcessorTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class SnapshotProcessorTests: XCTestCase {
146146
XCTAssertTrue(enrichedRecords[0].records[1].isFocusRecord)
147147
XCTAssertTrue(enrichedRecords[0].records[2].isFullSnapshotRecord)
148148

149-
XCTAssertEqual(enrichedRecords[1].records.count, 2, "It should follow with 'full snapshot' → 'incremental snapshot' records")
150-
XCTAssertTrue(enrichedRecords[1].records[0].isFullSnapshotRecord)
149+
XCTAssertEqual(enrichedRecords[1].records.count, 2, "It should follow with 'incremental snapshot' records")
150+
XCTAssertTrue(enrichedRecords[1].records[0].isIncrementalSnapshotRecord)
151151
XCTAssertTrue(enrichedRecords[1].records[1].isIncrementalSnapshotRecord)
152152
XCTAssertEqual(enrichedRecords[1].records[1].incrementalSnapshot?.viewportResizeData?.height, 100)
153153
XCTAssertEqual(enrichedRecords[1].records[1].incrementalSnapshot?.viewportResizeData?.width, 200)

0 commit comments

Comments
 (0)