<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetricKit",
  "identifier" : "/documentation/MetricKit/DiagnosticReport",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "MetricKit"
    ],
    "preciseIdentifier" : "s:9MetricKit16DiagnosticReportV"
  },
  "title" : "DiagnosticReport"
}
-->

# DiagnosticReport

A report describing a single diagnostic event.

```
struct DiagnosticReport
```

## Discussion

Each iteration of [`diagnosticReports`](/documentation/MetricKit/MetricManager/diagnosticReports) yields one report. Access the diagnostic event through [`result`](/documentation/MetricKit/DiagnosticReport/result), which is a [`DiagnosticResult`](/documentation/MetricKit/DiagnosticResult) enum. Switch over the result to handle each diagnostic type:

```swift
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`](/documentation/MetricKit/DiagnosticReport/environment-swift.property) property contains device and app metadata, [`states`](/documentation/MetricKit/DiagnosticReport/Environment-swift.struct/states), and any [`signpostData`](/documentation/MetricKit/DiagnosticReport/Environment-swift.struct/signpostData) associated with the event. The states array contains the [`MetricManager.ReportedState`](/documentation/MetricKit/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

[`let timeRange: DateInterval`](/documentation/MetricKit/DiagnosticReport/timeRange)

The date interval this report covers.

[`let environment: DiagnosticReport.Environment`](/documentation/MetricKit/DiagnosticReport/environment-swift.property)

Environment context for the device and app.

### Diagnostic event

[`let result: DiagnosticResult`](/documentation/MetricKit/DiagnosticReport/result)

The diagnostic result for this report.

### Structures

[`struct Environment`](/documentation/MetricKit/DiagnosticReport/Environment-swift.struct)

Device, app, and state metadata associated with a diagnostic report.

## Relationships

### Conforms To

[`Encodable`](/documentation/Swift/Encodable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Decodable`](/documentation/Swift/Decodable)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)