Wrong metadata in metrickit exceptions
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
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.
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
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.