---
title: "Diagnostic Reports"
description: "Capture MetricKit diagnostics, such as app hangs, CPU and disk write exceptions, as Sentry errors and investigate app hangs with symbolicated flame graph attachments."
url: https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports/
---

# App Hangs and Other Diagnostic Reports for Apple

The [MetricKit](https://docs.sentry.io/platforms/apple/metric-kit.md) integration captures the diagnostic reports of [MetricKit](https://developer.apple.com/documentation/metrickit), such as app hangs, CPU and disk write exceptions, or slow app launches, as Sentry error events.

This integration is available in SDK version 8.14.0 and later on iOS 15 and later, macOS 12 and later, and visionOS.

MetricKit controls the stack traces included in each diagnostic. Some contain only a few frames. To discard reports that aren't useful to you, filter them in [`beforeSend`](https://docs.sentry.io/platforms/apple/configuration/filtering.md#filtering-error-events).

Identify MetricKit events by their `mechanism.type`, which is listed for each report in [Choose Diagnostic Reports](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#choose-diagnostic-reports).

## [Enable MetricKit](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#enable-metrickit)

Enable the integration by setting the `enableMetricKit` option to `true`. It captures [HangDiagnostic](https://developer.apple.com/documentation/metrickit/hangdiagnostic), [DiskWriteExceptionDiagnostic](https://developer.apple.com/documentation/metrickit/diskwriteexceptiondiagnostic) and [CPUExceptionDiagnostic](https://developer.apple.com/documentation/metrickit/cpuexceptiondiagnostic):

**Swift**

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
    options.enableMetricKit = true
}
```

**Objective-C**

```objc
@import Sentry;

[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
    options.dsn = @"https://<key>@o<orgId>.ingest.sentry.io/<projectId>";
    options.enableMetricKit = YES;
}];
```

**Objective-C (SentryObjC)**

```objc
#import <SentryObjC/SentryObjC.h>

[SentryObjCSDK startWithConfigureOptions:^(SentryObjCOptions *options) {
    options.dsn = @"https://<key>@o<orgId>.ingest.sentry.io/<projectId>";
    options.enableMetricKit = YES;
}];
```

## [Hang Diagnostics](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#hang-diagnostics)

MetricKit reports periods when your app is unresponsive. Each hang diagnostic includes a hang duration and a sampled call stack tree, which can contain multiple execution paths rather than a single stack trace. Apple controls which hangs are reported and how much detail they contain, so not every hang produces a diagnostic.

We recommend MetricKit for system-provided hang diagnostics. Disabling or pausing [App Hang tracking](https://docs.sentry.io/platforms/apple/configuration/app-hangs.md) does not stop MetricKit reports, and `appHangTimeoutInterval` does not change MetricKit's detection threshold.

### [Enable Flame Graph Attachments](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#enable-flame-graph-attachments)

By default, the SDK stores the sampled call tree in the event's stack trace. Large trees are subject to stack trace limits, which can leave the flame graph incomplete. Starting with SDK version 9.31.0, send the tree as a separate attachment to preserve it independently of those limits.

Flame graph attachment reporting is available for public testing. The configuration option is experimental and may change in a future release.

Set `hangReportingMode` to `.flamegraphAttachment` when configuring the SDK. This option affects hang diagnostics only:

**Swift**

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
    options.enableMetricKit = true
    options.experimental.metrickit.hangReportingMode = .flamegraphAttachment
}
```

**Objective-C (SentryObjC)**

```objc
#import <SentryObjC/SentryObjC.h>

[SentryObjCSDK startWithConfigureOptions:^(SentryObjCOptions *options) {
    options.dsn = @"https://<key>@o<orgId>.ingest.sentry.io/<projectId>";
    options.enableMetricKit = YES;
    options.experimental.metrickit.hangReportingMode =
        SentryObjCMetricKitHangReportingModeFlamegraphAttachment;
}];
```

The SDK sends a `flamegraph.json` attachment with each hang event. Upload your app's [debug information files](https://docs.sentry.io/platforms/apple/dsym.md) so Sentry can symbolicate the flame graph using the same debug symbols as error events. Profiling does not need to be enabled.

To capture only hang diagnostics with MetricKit in Swift, replace `options.enableMetricKit = true` with `options.experimental.metrickit.enabledDiagnosticReports = [.hang]`. This requires SDK version 9.32.0 or later.

To return to default reporting, set `hangReportingMode` to `.legacy` (`SentryObjCMetricKitHangReportingModeLegacy` in Objective-C).

### [Investigate a Hang](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#investigate-a-hang)

Open a MetricKit hang event in Sentry to view its stack trace and flame graph. Sentry selects a representative stack trace from the sampled call trees for issue grouping, considering sample counts, stack depth, and in-app frames. Use this stack as a starting point for investigation, not proof of the hang's cause.

The **Flamegraph** section shows the sampled call paths, including branches outside the representative stack trace. If the diagnostic contains multiple call trees, use the tree selector to inspect them individually.

When reading the graph:

* **Width represents sample count**, including samples in a frame's descendants. Wider paths were observed more often.
* Horizontal position does not represent execution order, and frame width is not an exact duration. MetricKit provides aggregate observations, not timestamped samples.
* Some call trees aggregate samples across threads. Do not assume every tree represents a single thread or the main thread.

For a step-by-step walkthrough, see the Sentry cookbook guide to [debugging iOS hangs with MetricKit](https://sentry.io/cookbook/debug-ios-hangs-with-metrickit/).

### [Attachment Limits](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#attachment-limits)

Flame graph attachments are subject to these limits. The size and symbolication limits come from the [flame graph attachment specification](https://develop.sentry.dev/sdk/telemetry/attachments/#flame-graph-validation-and-limits):

* Attachments count toward your attachment quota, and the associated hang events count toward your error-event quota. No profiling quota is consumed. Attachment retention and access permissions apply.
* Each attachment is limited to 10 MiB. If the SDK cannot create it, for example because sample counts are invalid or the payload exceeds this limit, it falls back to storing the tree in the event's stack trace.
* Sentry symbolicates at most the first 2,500 frame entries in an attachment. Additional frames remain in the graph but may be unresolved. Missing debug information can also leave frames unresolved.

## [Choose Diagnostic Reports](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#choose-diagnostic-reports)

##### Experimental

This option is experimental and may change in future releases. It's available on Cocoa 9.32.0 and up.

Use `options.experimental.metrickit.enabledDiagnosticReports` to choose which diagnostic reports the SDK captures. A non-empty set enables the integration and captures exactly these reports, regardless of `enableMetricKit`. When the set is empty, which is the default, `enableMetricKit` decides whether the integration captures hangs, CPU exceptions and disk write exceptions.

| Report                | MetricKit diagnostic                                                                                             | `mechanism.type`           | Availability                                                  |
| --------------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------- |
| `.hang`               | [HangDiagnostic](https://developer.apple.com/documentation/metrickit/hangdiagnostic)                             | `mx_hang_diagnostic`       | All                                                           |
| `.cpuException`       | [CPUExceptionDiagnostic](https://developer.apple.com/documentation/metrickit/cpuexceptiondiagnostic)             | `mx_cpu_exception`         | All                                                           |
| `.diskWriteException` | [DiskWriteExceptionDiagnostic](https://developer.apple.com/documentation/metrickit/diskwriteexceptiondiagnostic) | `mx_disk_write_exception`  | All                                                           |
| `.appLaunch`          | [AppLaunchDiagnostic](https://developer.apple.com/documentation/metrickit/applaunchdiagnostic)                   | `mx_app_launch_diagnostic` | iOS 16 and later, visionOS 26 and earlier, macOS 27 and later |
| `.crash`              | [CrashDiagnostic](https://developer.apple.com/documentation/metrickit/crashdiagnostic)                           | `MXCrashDiagnostic`        | All                                                           |
| `.memoryException`    | [MemoryExceptionDiagnostic](https://developer.apple.com/documentation/metrickit/memoryexceptiondiagnostic)       | `mx_memory_exception`      | iOS 27 and later                                              |

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
    options.experimental.metrickit.enabledDiagnosticReports = [.hang, .cpuException, .diskWriteException, .appLaunch]
}
```

*Other available variations of the above snippet: Objective-C (SentryObjC)*

The option is available from Swift and through the [SentryObjC](https://docs.sentry.io/platforms/apple/install/swift-package-manager.md#sentryobjc-objective-c) SDK. Objective-C apps that import `Sentry` can only use `enableMetricKit`.

On iOS, macOS and visionOS 27 and later, apps built with Xcode 27 or later receive diagnostics through MetricKit's [`MetricManager`](https://developer.apple.com/documentation/metrickit/metricmanager). The SDK creates the same events as on earlier OS versions.

##### Duplicate events

MetricKit can report a crash or a termination that the SDK already reported itself. The SDK's crash handler reports crashes, which `.crash` reports as well, and its [watchdog termination tracking](https://docs.sentry.io/platforms/apple/configuration/watchdog-terminations.md) reports out-of-memory terminations, which `.memoryException` reports as well.

The SDK tries to deduplicate these events, but it can't match every MetricKit diagnostic to the event it already sent, so some crashes and terminations can show up twice in Sentry.

## [Attach the Raw Diagnostic Payload](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#attach-the-raw-diagnostic-payload)

Starting with SDK version 8.29.0, enable `enableMetricKitRawPayload` to attach the original MetricKit diagnostic payload as JSON to the event. The attachment is named `MXDiagnosticPayload.json`. On iOS, macOS and visionOS 27 and later, in apps built with Xcode 27 or later, it's named `DiagnosticReport.json`.

The raw payload is separate from `flamegraph.json` and is not required for the flame graph viewer. Enabling both options sends both attachments and consumes additional attachment quota.

**Swift**

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
    options.enableMetricKit = true
    options.enableMetricKitRawPayload = true
}
```

**Objective-C**

```objc
@import Sentry;

[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
    options.dsn = @"https://<key>@o<orgId>.ingest.sentry.io/<projectId>";
    options.enableMetricKit = YES;
    options.enableMetricKitRawPayload = YES;
}];
```

**Objective-C (SentryObjC)**

```objc
#import <SentryObjC/SentryObjC.h>

[SentryObjCSDK startWithConfigureOptions:^(SentryObjCOptions *options) {
    options.dsn = @"https://<key>@o<orgId>.ingest.sentry.io/<projectId>";
    options.enableMetricKit = YES;
    options.enableMetricKitRawPayload = YES;
}];
```

## [Delayed Data](https://docs.sentry.io/platforms/apple/metric-kit/diagnostic-reports.md#delayed-data)

MetricKit reports data after it was recorded. It can deliver a diagnostic report while the app that recorded it is still running, or on a later launch, so reports can describe both the current and earlier runs of the app. Learn more in Apple's description of the [MetricKit reporting model](https://developer.apple.com/documentation/metrickit/monitoring-app-performance-with-metrickit#Understand-the-reporting-model).

Diagnostic reports from an earlier run of the app carry the app and OS versions they were recorded with, instead of the versions running when MetricKit delivered them. Since Cocoa 9.31.0, the SDK doesn't apply the current scope to these events, so they don't get the breadcrumbs, user, tags, extras or attachments of the running app. Diagnostic reports recorded by the running process keep the scope data.

Since Cocoa 9.35.0, events from an earlier run also report the low power mode and the TestFlight state MetricKit recorded with the diagnostic, as `device.low_power_mode` and an `app.build_type` of `test`. MetricKit reports these from iOS 17 and macOS 14.

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
