sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Wrong metadata in metrickit exceptions

Open noahsmartin opened this issue 3 weeks ago • 4 comments

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

latest

Xcode Version

26

Did it work on previous versions?

No response

Steps to Reproduce

Record a fatal exception with MetricKit, such as a MXCPUExceptionDiagnostic. This is sent on the next app launch after the fatal exception occurred. However, SentryMetricKitIntegration uses the app version/iOS version at the time the event was received. So to reproduce the exception needs to happen one one app version, then the app version needs to be updated before the next launch when the event is received by the SDK.

Expected Result

The sentry event recorded from metric kit should have the app version/iOS version set to the values at the time the exception occurred, rather than the time it was received.

Actual Result

The wrong values seem to be used, I don't see anywhere in the event handling code that sets these metadata fields to the values provided by MXDiagnostic.

Are you willing to submit a PR?

No response

noahsmartin avatar Nov 29 '25 17:11 noahsmartin

COCOA-1039

linear[bot] avatar Nov 29 '25 17:11 linear[bot]

Yes, that was always a big problem. We don't have a proper way of attaching the correct metadata right now. The integration simply calls captureEvent, which uses the current scope of the hub.

https://github.com/getsentry/sentry-cocoa/blob/03afb63d43c5c7a84c186341620f24d16b7a5780/Sources/Sentry/SentryMetricKitIntegration.m#L407-L420

So this isn't accurate. We also have the event.isMetricKitEvent helper method, so the SDK doesn't add screenshots and view hierarchy to metric kit events, but nothing for the scope.

I'm sorry, I thought I documented this somewhere, but I can't find it in the codebase. For context: I hacked this feature together, as we did frequently back in 2023, and we never really iterated on it, because we didn't see significant adoption.

philipphofmann avatar Dec 02 '25 14:12 philipphofmann

Makes sense @philipphofmann thanks for the context! Yeah I don't think we need to follow up with this anytime soon, it's quite an edge case, just seemed worth documenting

noahsmartin avatar Dec 02 '25 15:12 noahsmartin

Wrong app version/iOS version are an edge case, but all the other event context the client attaches isn't 100% accurate every time. So it definitely needs fixing, but not the highest priority, IMO.

philipphofmann avatar Dec 02 '25 15:12 philipphofmann