Skip to content

Commit

Permalink
Bring back 'first crash' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Apr 11, 2024
1 parent 592068a commit e55997d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Sources/Crashes/CrashCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,37 @@ public enum CrashCollectionPlatform {
@available(iOS 13, macOS 12, *)
public final class CrashCollection {

public let platform: CrashCollectionPlatform

public var log: OSLog {
getLog()
}
private let getLog: () -> OSLog

public init(platform: CrashCollectionPlatform, log: @escaping @autoclosure () -> OSLog = .disabled) {
self.platform = platform
self.getLog = log
crashHandler = CrashHandler()
crashSender = CrashReportSender(platform: platform, log: log())
}


Check failure on line 52 in Sources/Crashes/CrashCollection.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
public func start(_ didFindCrashReports: @escaping ([[String: String]], [MXDiagnosticPayload], @escaping () -> Void) -> Void) {
let first = isFirstCrash
isFirstCrash = false

crashHandler.crashDiagnosticsPayloadHandler = { payloads in
let pixelParameters = payloads
.compactMap(\.crashDiagnostics)
.flatMap { $0 }
.map { diagnostic in
[
var params = [
"appVersion": "\(diagnostic.applicationVersion).\(diagnostic.metaData.applicationBuildVersion)",
"code": "\(diagnostic.exceptionCode ?? -1)",
"type": "\(diagnostic.exceptionType ?? -1)",
"signal": "\(diagnostic.signal ?? -1)"
]
if first {
params["first"] = "1"
}
return params
}

didFindCrashReports(pixelParameters, payloads) {
Expand All @@ -80,8 +84,22 @@ public final class CrashCollection {
MXMetricManager.shared.add(crashHandler)
}

var isFirstCrash: Bool {
get {
UserDefaults().object(forKey: Const.firstCrashKey) as? Bool ?? true
}

set {
UserDefaults().set(newValue, forKey: Const.firstCrashKey)
}
}

let crashHandler: CrashHandler
let crashSender: CrashReportSender

enum Const {
static let firstCrashKey = "CrashCollection.first"
}
}


Check failure on line 105 in Sources/Crashes/CrashCollection.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Files should have a single trailing newline (trailing_newline)

Check failure on line 105 in Sources/Crashes/CrashCollection.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)

0 comments on commit e55997d

Please sign in to comment.