Skip to content

Commit

Permalink
Adding missing s.ri key (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoEmbrace authored Apr 19, 2024
1 parent a5b7dfd commit cabfc73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/EmbraceCore/Payload/SessionInfoPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct SessionInfoPayload: Codable {
let appTerminated: Bool
let cleanExit: Bool
let coldStart: Bool
let crashReportId: String?
let properties: [String: String]

enum CodingKeys: String, CodingKey {
Expand All @@ -30,6 +31,7 @@ struct SessionInfoPayload: Codable {
case appTerminated = "tr"
case cleanExit = "ce"
case coldStart = "cs"
case crashReportId = "ri"
case properties = "sp"
}

Expand All @@ -44,6 +46,7 @@ struct SessionInfoPayload: Codable {
self.appTerminated = sessionRecord.appTerminated
self.cleanExit = sessionRecord.cleanExit
self.coldStart = sessionRecord.coldStart
self.crashReportId = sessionRecord.crashReportId
self.properties = metadata.reduce(into: [:]) { result, record in
guard UserResourceKey(rawValue: record.key) == nil else {
// prevent UserResource keys from appearing in properties
Expand Down
5 changes: 4 additions & 1 deletion Tests/EmbraceCoreTests/Payload/SessionInfoPayloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ final class SessionInfoPayloadTests: XCTestCase {
spanId: .random(),
startTime: Date(),
endTime: Date(timeIntervalSinceNow: 2),
lastHeartbeatTime: Date(timeIntervalSinceNow: 1.5) )
lastHeartbeatTime: Date(timeIntervalSinceNow: 1.5),
crashReportId: "test"
)

let metadata = [
MetadataRecord(
Expand All @@ -45,6 +47,7 @@ final class SessionInfoPayloadTests: XCTestCase {
XCTAssertEqual(sessionInfoPayload.appTerminated, record.appTerminated)
XCTAssertEqual(sessionInfoPayload.cleanExit, record.cleanExit)
XCTAssertEqual(sessionInfoPayload.coldStart, record.coldStart)
XCTAssertEqual(sessionInfoPayload.crashReportId, "test")
XCTAssertEqual(sessionInfoPayload.properties.count, metadata.count)
XCTAssertEqual(sessionInfoPayload.properties, ["foo": "bar"])
}
Expand Down
9 changes: 7 additions & 2 deletions Tests/EmbraceCoreTests/Payload/SessionPayloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ final class SessionPayloadTests: XCTestCase {
spanId: TestConstants.spanId,
startTime: Date(timeIntervalSince1970: 10),
endTime: Date(timeIntervalSince1970: 40),
crashReportId: "test",
coldStart: true,
cleanExit: true,
appTerminated: false)
appTerminated: false
)
}

func test_properties() {
Expand All @@ -193,6 +195,7 @@ final class SessionPayloadTests: XCTestCase {
XCTAssertEqual(payload.sessionInfo.appTerminated, false)
XCTAssertEqual(payload.sessionInfo.cleanExit, true)
XCTAssertEqual(payload.sessionInfo.coldStart, true)
XCTAssertEqual(payload.sessionInfo.crashReportId, "test")
}

func test_highLevelKeys() throws {
Expand Down Expand Up @@ -237,6 +240,7 @@ final class SessionPayloadTests: XCTestCase {
XCTAssertEqual(sessionInfo["tr"] as! Bool, false)
XCTAssertEqual(sessionInfo["ce"] as! Bool, true)
XCTAssertEqual(sessionInfo["cs"] as! Bool, true)
XCTAssertEqual(sessionInfo["ri"] as! String, "test")
}

func test_sessionInfoKeys_withSessionProperties() throws {
Expand All @@ -258,7 +262,7 @@ final class SessionPayloadTests: XCTestCase {

// then the session payload contains the necessary keys
let sessionInfo = json["s"] as! [String: Any]
XCTAssertEqual(sessionInfo.keys.count, 11)
XCTAssertEqual(sessionInfo.keys.count, 12)
XCTAssertEqual(sessionInfo["id"] as! String, sessionRecord.id.toString)
XCTAssertEqual(sessionInfo["st"] as! Int, sessionRecord.startTime.millisecondsSince1970Truncated)
XCTAssertEqual(sessionInfo["et"] as? Int, sessionRecord.endTime?.millisecondsSince1970Truncated)
Expand All @@ -269,6 +273,7 @@ final class SessionPayloadTests: XCTestCase {
XCTAssertEqual(sessionInfo["tr"] as! Bool, false)
XCTAssertEqual(sessionInfo["ce"] as! Bool, true)
XCTAssertEqual(sessionInfo["cs"] as! Bool, true)
XCTAssertEqual(sessionInfo["ri"] as! String, "test")
XCTAssertEqual(sessionInfo["sp"] as! [String: String], ["foo": "bar"])
}

Expand Down

0 comments on commit cabfc73

Please sign in to comment.