Skip to content

feat(metrickit): Support fatal hang diagnostics - #9425

Draft
philprime wants to merge 1 commit into
mainfrom
feat/metrickit-ios27-hangs
Draft

philprime wants to merge 1 commit into
mainfrom
feat/metrickit-ios27-hangs

Conversation

@philprime

Copy link
Copy Markdown
Member

Description

Use the Swift MetricKit diagnostic stream on iOS 27 and the existing MX subscriber on older systems, rather than subscribing to both. Report watchdog terminations as fatal hangs and preserve diagnostic-time environment and StateReporting context when available.

Fatal hang messages stay concise, with the original termination reason in mechanism data. Flame graph mode attaches the recorded watchdog stack trees and ignores threads without stacks. The sample includes separate fatal and non-fatal hang triggers.

Motivation and Context

Watchdog terminations arrive as crash diagnostics, so treating only hang diagnostics as hangs misses fatal cases. The Swift API provides a typed watchdog category instead of requiring a match against the human-readable termination reason.

A watchdog flame graph represents the available termination snapshot, not a sampled history of the entire hang. The separate V9 app-hang tracker can still report its own event without a flame graph.

How did you test it?

Formatting, static analysis, the iOS SDK build, iOS test compilation, and focused macOS MetricKit tests passed before the final structural cleanup. iOS tests and UI tests were not executed. The latest sample build hit a shared-derived-data header conflict, and its isolated rebuild was stopped. Further validation and the lint commit hook were skipped on request.

Device events used during investigation, recorded before the final API-selection and message cleanup:

The non-fatal pair contained matching flame graph attachments. The fatal Swift report supplied the watchdog snapshot with empty threads used to reproduce the missing-attachment regression. StateReporting arrays in these device reports were empty, so populated state enrichment still needs device verification.

Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • If I added a new public API, I also added it to the SentryObjC wrapper.

Use the Swift MetricKit stream on iOS 27 and the MX subscriber on older
systems. Preserve diagnostic-time context and report watchdog hangs
without affecting the running session.

Attach available fatal stack trees in flame graph mode and retain raw
termination reasons as structured mechanism data. Add sample triggers
and regression coverage for fatality, empty stacks, and API selection.
@philprime philprime self-assigned this Oct 22, 2026
Comment thread CHANGELOG.md
### Features

- Add experimental MetricKit hang flame graph attachments via `options.experimental.metrickit.hangReportingMode = .flamegraphAttachment`, also available through `SentryObjC`. The default `.legacy` mode reports the flattened call stack tree, which is also retained when flame graph attachment creation fails (#9347, #9421)
- Report MetricKit watchdog terminations as fatal hangs with structured termination metadata. Flame graph mode also attaches the recorded watchdog stack trees, omitting threads without stacks. Use the Swift MetricKit API with diagnostic-time state context on iOS 27 and the existing subscriber on older systems (#9425)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 🚫 The changelog entry seems to be part of an already released section ## 9.31.0.
    Consider moving the entry to the ## Unreleased section, please.

@github-actions

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 0235a09

@philprime philprime added the run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request label Oct 22, 2026
@sentry

sentry Bot commented Oct 22, 2026

Copy link
Copy Markdown

Size Analysis

1 component analyzed

iOS Builds

Name Configuration Version Download Size Install Size
SDK-Size (iOS)
io.sentry.sample.SDK-Size
Release 9.31.0 (1) 1.2 MB (+1.1 KB) 3.1 MB (0 B)

Configure sentry-cocoa status check rules

@sentry

sentry Bot commented Oct 22, 2026

Copy link
Copy Markdown

📲 Install Builds

iOS

🔗 App Name App ID Version Configuration
SDK-Size io.sentry.sample.SDK-Size 9.31.0 (1) Release

⚙️ sentry-cocoa Build Distribution Settings

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant