Contents

DiagnosticReport

A report describing a single diagnostic event.

Declaration

struct DiagnosticReport

Mentioned in

Discussion

Each iteration of diagnosticReports yields one report. Access the diagnostic event through result, which is a DiagnosticResult enum. Switch over the result to handle each diagnostic type:

for await report in manager.diagnosticReports {
    switch report.result {
    case .crash(let diagnostic):
        handleCrash(diagnostic)
    case .hang(let diagnostic):
        handleHang(diagnostic)
    case .cpuException(let diagnostic):
        handleCPUException(diagnostic)
    case .diskWriteException(let diagnostic):
        handleDiskWriteException(diagnostic)
    case .appLaunch(let diagnostic):
        handleAppLaunchDiagnostic(diagnostic)
    @unknown default:
        break
    }
}

The environment property contains device and app metadata, states, and any signpostData associated with the event. The states array contains the MetricManager.ReportedState values that are active when the diagnostic event occurs.

MetricKit does not generate a DiagnosticReport for every occurrence of a diagnostic event. For example, hang diagnostics are only generated when the device has hang detection enabled or belongs to a sampling group with hang detection active.

Because DiagnosticReport conforms to Codable, you can serialize it directly with JSONEncoder.

Topics

Report details

Diagnostic event

Structures

See Also

Metric and diagnostic reports