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

Get crash report when it crash #525

Closed
baiyidjp opened this issue Jul 4, 2024 · 5 comments
Closed

Get crash report when it crash #525

baiyidjp opened this issue Jul 4, 2024 · 5 comments
Labels

Comments

@baiyidjp
Copy link

baiyidjp commented Jul 4, 2024

I want to get the crash report when it crashes or cold starts, and upload it manually to our server. How can I do it?

The KSCrash version I use is
pod 'KSCrash', '~> 2.0.0-alpha.4'

@GLinnik21
Copy link
Collaborator

Hi!
Did you try the standard installation from the README?

@baiyidjp
Copy link
Author

baiyidjp commented Jul 5, 2024

Hi! Did you try the standard installation from the README?

    let installation = CrashInstallationConsole.shared()
    installation.printAppleFormat = true
    
    let config = KSCrashConfiguration()
    installation.install(with: config)
    
    for reportId in KSCrash.shared().reportIDs {
      guard let report = KSCrash.shared().report(for: Int64(truncating: reportId)) else {
        continue
      }
      let filter = CrashReportFilterAppleFmt(reportStyle: .unsymbolicated)
      filter.filterReports([report]) { reports, completed, error in
        if let firstReport = reports?.first, let reportString = firstReport.stringValue {
          debugPrint("KSCrash\n\r", reportString)
          KSCrash.shared().deleteReport(with: Int64(truncating: reportId))
        }
      }
    }

I found the unreported crash during cold start and converted it to a String. Because report.stringValue was nil when I directly took it, I converted it through a filter. Is this the correct procedure?

@baiyidjp
Copy link
Author

baiyidjp commented Jul 5, 2024

@GLinnik21

I can use .unsymbolicated to get unsymbolicated stringValue, but How to set it if you don't want to automatically symbolize when capturing crash?

@GLinnik21
Copy link
Collaborator

GLinnik21 commented Jul 5, 2024

Because report.stringValue was nil when I directly took it

The KSCrashReport is a new API introduced by @bamx23. It was primarily created for internal use, so exposing it in the public API might have been misleading for users.
Typically, crash reports are in a JSON-like dictionary format, so stringValue is expected to be empty. What you likely need is dictionaryValue.
Since it's in a JSON-like format, you can convert it to JSON with any converter and send it as a string to your server. You don't necessarily need to use Filters to get a string value, or the Installations module at all.
If you need this custom behavior, you might consider using just the KSCrash/Recording module and utilize the API exposed in KSCrash.h. This would give you more direct control over the crash reports.

For example, you could do something like this:

if let report = KSCrash.shared().report(for: reportId),
   let value = report.dictionaryValue,
   let jsonData = try? JSONSerialization.data(withJSONObject: value, options: []),
   let jsonString = String(data: jsonData, encoding: .utf8) {
    print(jsonString)
    // Send jsonString to your server
}

This approach should give you the raw crash report data in a string format that you can easily send to your server.

How to set it if you don't want to automatically symbolize when capturing crash?

If you need raw addresses, you can get them from dictionaryValue alongside the symbolicated values. Why don't you need symbolication?

@GLinnik21
Copy link
Collaborator

The KSCrash version I use is
pod 'KSCrash', '~> 2.0.0-alpha.4'

It's worth noting that you're using an alpha version of KSCrash. This version is not stable, and the API may change.

For production, it's recommended to use the latest stable 1.x version (currently 1.17.4):

pod 'KSCrash', '~> 1.17.4'

However, be aware that the API in 1.x versions differs slightly from the 2.0.0-alpha version. If you switch, you'll need to adjust your code for the version you're using.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants