Sentry for iOS uncaught exception help within NativeScript framework


#1

Hi :wave: - I’ve been working on a ‘plugin’ for NativeScript that consumes the android and iOS SDKs. Everything is working perfectly except the iOS uncaught exception logs aren’t very useful within the NativeScript framework. If you’re not familiar with NativeScript, it’s somewhat similar to React-Native but without the bridging mechanism so the consumption of native SDKs is much more direct.

The issue I’m facing lies within the actual exception that is caught and logged on the Sentry site for reviewing the crash. I’ve been in contact with the NativeScript iOS runtime team and they’re open and trying to assist in making the log provide the stack trace in the exception. Currently this is what we have logged (https://sentry.io/share/issue/2963994779d5441a9c91ab38e87d261f/) for an uncaught iOS exception. The actual stack trace is in the exception in the breadcrumbs which would be perfectly fine as this is reporting where in the JS stack the crash occurred. However it’s trimmed in the breadcrumb section so I can’t view all of it.

The developer who recently worked on throwing the exception had mentioned here (https://github.com/NativeScript/ios-runtime/pull/964#issuecomment-409501607) to see if Sentry iOS can display the reason of the exception in the logs as that would work well with how the exception is currently thrown.

Any help from the Sentry team on how to improve the log for uncaught exceptions with iOS are greatly appreciated and the NS team I imagine would be responsive enough to collaborate on how best to make this work with the framework.


#2

Just to add an example of the current android uncaught exception: https://sentry.io/share/issue/df2b921161264365ab944ce28156f5a4/ which works well making sure the stack traces are provided.

Again, the iOS uncaught exception is the one thing we’re trying to improve and then there’s no need to rely on raven or anything for JS specific tracking and the native SDKs will be integrated :tada:

If anyone interested in the iOS implementation within NS - https://github.com/bradmartin/nativescript-sentry/blob/master/src/sentry.ios.ts


#3

Hey,

wow cool stuff.
Thanks for the work you already put into this :+1: we would love to fully support native-script.
Quick question the demos in your repo work out of the box? Because it would save us some time if we actually have a quick repro case where we can try it out without setting everything up from scratch.

I think it’s not a big deal to change the iOS integration to work the same as Android.
I hope I find some time next week to look at this.


#4

Hey @HazAT - the demos do work and run using my test sentry project. However, to build them you’d need to have android build tools for android and iOS/xcode setup on your machine, along with the NativeScript CLI if you wanted a smooth build process.

Which might be a bit much to worry about. The only remaining issue is figuring out how the NSException thrown in the NativeScript runtime can be logged out well enough to understand what caused the uncaught exception. The last log output has the Exception message is being truncated around 125(?) characters. Previously we tried throwing the JS stack trace in the reason of the NSException and it also doesn’t appear to be logged by Sentry in the web site logs. Do you know anyone on the Sentry iOS/Cocoa team who can possibly chime in with optimal NSExceptions to log for uncaught errors so they’re rendered well enough in the log output?


#5

Hehe, so I wrote the Cocoa SDK, that’s why I was replying ^^

But I am not fully understanding how NativeScript calls to native functions on iOS.
We need a stacktrace, we can’t parse it from the reason of an NSException here is an example what we do for react-native: https://github.com/getsentry/sentry-cocoa/blob/1e10d4d0416f2485114204f9b36163aba0e4d6f3/Sources/Sentry/SentryJavaScriptBridgeHelper.m#L166


#6

:blush: so you do know someone :joy: really awesome stuff BTW.

Currently, I believe, this is the block for uncaught exceptions

As far as I can tell the ios-runtime team at NativeScript is open to ways to allow better logging by services like Sentry, firebase, etc. So if you have any suggestions with that feel free to ping on this issue if you’d like or I can relay anything to the team via Slack or email


#7

I can’t seem to use any github links in my reply :frowning_face: and my posts flagged as spam with sentry project urls also it seems.


#8

The latest work on trying to improve the logs on Sentry side are here

https://.com/NativeScript/ios-runtime/blob/158c95f49d447f60c012c7425a4dafd21a75b893/src/NativeScript/JSErrors.mm

Still can’t use github links so put github before the .com and you’ll see the latest on the uncaught exceptions. Really looking forward on ways to get this wrapped up nicely :smile:


#9

OK, so this link is helpful. I started to work on a PR to add support for this: https://github.com/getsentry/sentry-cocoa/pull/261

Not sure when I find time for implementing it, but it should be straightforward to do.
If you or anyone else want to help out, I am happy to provide assistance.


#10

Hi HazAT,

I actually think that you won’t need to do any special parsing for NativeScript exceptions. It seems that right now the reason field of an ObjectiveC exception is missing from the report and that the name is truncated to around 125/128 characters, but looking at the source code it seems that both are serialized without any truncation or other modification. See SentryException.

My guess is that this happens somewhere else and not in the Sentry API.