Skip to content

feat(ios): Add metricKitHangReportingMode option for MetricKit hang flame graphs - #7059

Open
alwx wants to merge 2 commits into
mainfrom
alwx/feature/metrickit-hang-flamegraph
Open

alwx wants to merge 2 commits into
mainfrom
alwx/feature/metrickit-hang-flamegraph

Conversation

@alwx

@alwx alwx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Adds the experimental, iOS-only option metricKitHangReportingMode ('legacy' | 'flamegraphAttachment'). With flamegraphAttachment, sentry-cocoa attaches the aggregated call trees of a MetricKit hang diagnostic as an event.flamegraph attachment instead of a flattened stack.

React Native passes the options dictionary to the cocoa Options(dictionary:) initializer, which already reads metricKitHangReportingMode, so no native code is needed. The option also works when the native SDK starts from sentry.options.json.

💡 Motivation and Context

sentry-cocoa added MetricKit hang flame graph attachments in getsentry/sentry-cocoa#9347, but React Native users could not turn them on. Native frames in these attachments are already symbolicated by the backend.

💚 How did you test it?

  • A Jest test checks that initNativeSdk forwards the option. yarn test, yarn lint, yarn circularDepCheck, and api-report:check pass.
  • Two Swift tests in RNSentryCocoaTester check that RNSentryStart sets experimental.metrickit.hangReportingMode from the option and keeps legacy by default. The suite passes (213 tests, 0 failures).
  • Not tested with a real MetricKit payload: MetricKit does not deliver diagnostics on the simulator.

📝 Checklist

  • I added tests to verify 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.
  • All tests passing.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • No breaking changes.

🔮 Next steps

  • Check the flame graph with a real MetricKit hang on a device.

alwx added a commit that referenced this pull request Nov 17, 2026
Replace the PR link placeholder in the metricKitHangReportingMode entry with #7059.
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

⚪ None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • feat(ios): Add metricKitHangReportingMode option for MetricKit hang flame graphs by alwx in #7059
  • chore(sample): Remove unused Detox setup from the React Native sample by antonis and claude in #7072
  • ci(ios): Build TestFlight sample with Xcode 27 by philprime with sentry-junior in #7065
  • perf(android): Create SDK view managers on demand by alwx in #7049
  • fix(core): Remove web Replay and Feedback from native bundles by default by huextrat, claude and antonis in #7062
  • fix(core): Define UnsafeObject locally instead of deep importing it by alwx in #7061
  • chore(deps): update Android SDK to v8.65.0 by github-actions in #7058

🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Nov 17, 2026 •

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 75d9b44

alwx added 2 commits November 19, 2026 16:35
…lame graphs

sentry-cocoa can attach the aggregated call trees of a MetricKit hang diagnostic as an event.flamegraph attachment, which the backend symbolicates. React Native had no way to turn this on.

The new experimental metricKitHangReportingMode option accepts legacy or flamegraphAttachment. React Native passes the options dictionary to the cocoa Options(dictionary:) initializer, which reads metricKitHangReportingMode, so the option needs no native code. It also works when the native SDK starts from sentry.options.json.

A Jest test checks that initNativeSdk forwards the option, and Swift tests check that RNSentryStart sets experimental.metrickit.hangReportingMode from it and keeps legacy by default.
Replace the PR link placeholder in the metricKitHangReportingMode entry with #7059.
@alwx
alwx force-pushed the alwx/feature/metrickit-hang-flamegraph branch from dfa285d to 75d9b44 Compare November 19, 2026 15:40
@alwx
alwx marked this pull request as ready for review November 20, 2026 08:45
@alwx
alwx requested review from a team, antonis and lucas-zimerman as code owners November 20, 2026 08:45
@alwx
alwx requested review from NinjaLikesCheez, buenaflor, itaybre, markushi and runningcode and removed request for a team November 20, 2026 08:45
@alwx

alwx commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

This one simply allows to pass the option to the Cocoa SDK which allows to use flame graph attachments for MetricKit on iOS.

@alwx
alwx requested review from philprime and removed request for NinjaLikesCheez, buenaflor, itaybre, markushi and runningcode November 20, 2026 08:46
@antonis antonis added the ready-to-merge Triggers the full CI test suite label Nov 20, 2026

@antonis antonis left a comment

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 code changes LG. Let's also add a Sentry link in the description.

How does this look combined with the JS/Hermes data from #7042 ?

@sentry

sentry Bot commented Nov 20, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.36.0 (116) Release

⚙️ sentry-react-native Build Distribution Settings

alwx commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

It has nothing to do with that — MetricKit data cannot be combined with the JS hang data. This PR basically just exposes the option that was added in sentry-cocoa to make it possible to get MetricKit data in the format of flamegraph.json, nothing more, nothing less.

@alwx
alwx requested a review from antonis November 20, 2026 11:51

@antonis antonis left a comment •

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 code changes LGTM!

Let's also add a Sentry link in the description.

I've tried testing this on my personal iPad but wasn't able to get a flamegraph. Since this PR just exposes the iOS implementation it should work but please add a sentry link / screenshot on the description for future reference.

It has nothing to do with that — MetricKit data cannot be combined with the JS hang data. This PR basically just exposes the option that was added in sentry-cocoa to make it possible to get MetricKit data in the format of flamegraph.json, nothing more, nothing less.

Ok. If I get this correctly the two produce separate events, right?

@alwx

alwx commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@antonis MetricKit reports come with a delay, sometimes it could take quite a while before those appear.

From the sentry-cocoa doc:

Apple controls which hangs are reported and how much detail they contain, so not every hang produces a diagnostic.

From the official MetricKit doc:

The system delivers metric reports about the previous 24 hours to your app at most once per day.

Generally, it's better to ask @philprime or other sentry-cocoa folks regarding the specifics since this PR only passes the option to the native SDK.

@alwx

alwx commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Ok. If I get this correctly the two produce separate events, right?

Yes. Again, the reason for that is that MetricKit is basically the operating system's second opinion rather than a real-time source of data.

@itaybre

itaybre commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@antonis MetricKit reports come with a delay, sometimes it could take quite a while before those appear.

From the sentry-cocoa doc:

Apple controls which hangs are reported and how much detail they contain, so not every hang produces a diagnostic.

From the official MetricKit doc:

The system delivers metric reports about the previous 24 hours to your app at most once per day.

Generally, it's better to ask @philprime or other sentry-cocoa folks regarding the specifics since this PR only passes the option to the native SDK.

I believe @philprime had a way to trigger those events, I am not sure how to trigger them manually.

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

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants