Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not capturing correct backtrace of Kotlin Coroutine Crashes #4465

Open
rodolfoBee opened this issue Oct 22, 2024 · 8 comments
Open

Not capturing correct backtrace of Kotlin Coroutine Crashes #4465

rodolfoBee opened this issue Oct 22, 2024 · 8 comments

Comments

@rodolfoBee
Copy link
Member

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

8.36.0

Xcode Version

Unknown

Did it work on previous versions?

No response

Steps to Reproduce

Unclear at the moment.

Expected Result

Crashes reported by the SDK, such as SIGABRT and SIGPIPE have the Last Exception Backtrace which contain more information on the exception's cause.

Actual Result

The symbolicated event in Sentry only contains the global terminateWithUnhandledException, and to get the last exception backtrace the user needs to find the corresponding exception in Apple TestFlight.

From original investigation, the first option would be looking if it is possible to capture a CoroutineException in this case.

Are you willing to submit a PR?

No response

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 22, 2024
@kahest kahest changed the title Ios SDK not capturing Last Exception Backtrace on crashes iOS SDK not capturing Last Exception Backtrace on crashes Oct 22, 2024
@silverhammermba
Copy link

An example of this. Here's the raw stacktrace shown in Sentry:

OS Version: iOS 17.6.1 (21G93)
Report Version: 104

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 17

Application Specific Information:
0123456789abcdef0123456789ABCDEF                0000000000000000

Thread 17 Crashed:
0   libsystem_kernel.dylib          0x3bad542ec         __pthread_kill
1   libsystem_pthread.dylib         0x3e293fc08         pthread_kill
2   libsystem_c.dylib               0x3392e9b9c         abort
3   KMMUnifiedBackend               0x106a74740         konan::abort
4   KMMUnifiedBackend               0x106a7abfc         (anonymous namespace)::terminateWithUnhandledException::lambda::operator()

but when I symbolicate the same crash in Xcode it has this extra section at the top:

Last Exception Backtrace:
0   KMMUnifiedBackend             	0x101773400 kfun:com.lutron.unifiedbackend.activation.cca.CcaDeviceRepo#autoAddressLink#suspend(kotlin.collections.List<com.lutron.leap.common.model.Link>;kotlin.coroutines.Continuation<kotlin.Result<com.lutro... + 120

which shows the actual line of code that threw the exception. The crashing code is written in Kotlin multiplatform mobile, but the Xcode crash symbolicator has no official support for KMM, so I believe this is some kind of general exception backtrace that Xcode is showing.

Sentry should support these backtraces or else I cannot use it to fix crashes like this.

@philipphofmann philipphofmann changed the title iOS SDK not capturing Last Exception Backtrace on crashes Not capturing correct backtrace of Kotlin Coroutine Crashes Oct 22, 2024
@philipphofmann
Copy link
Member

Thanks for the info. If I'm not mistaken, @brustolin is currently investigating this, and will get back to you.

@brustolin
Copy link
Contributor

Yes. Im trying to figure this out. We get back to you for any news.

@buenaflor
Copy link
Contributor

@silverhammermba how are you initializing the SDK? can you show the setup

@silverhammermba
Copy link

@buenaflor Here is our function for initializing Sentry

public func enableCrashReporting(accessToken: String, environment: String?, enablePerformanceMonitoring: Bool) {
    SentrySDK.start { options in
        options.dsn         = accessToken
        options.environment = environment ?? "Public"

        // percent of events that get recorded
        options.sampleRate = 1 // error events
        if enablePerformanceMonitoring {
            options.tracesSampleRate = 1 // performance events
        }

        // auto capture extra issues
        options.enableCaptureFailedRequests = true
        options.enableAppHangTracking       = true

        options.maxBreadcrumbs = 2_000

        // declare modules as "in-app"
        options.add(inAppInclude: "KMMUnifiedBackend")
        // omitting other added modules unrelated to this crash
    }
}

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 22, 2024
@buenaflor
Copy link
Contributor

buenaflor commented Oct 22, 2024

@silverhammermba the problem is that you are initializing the SDK with the Sentry Cocoa SDK initializer. You need to use the KMP initializer because we filter the SIGABRT report and create instead a new crash event that contains the proper stacktrace etc...

If you need to set native options that we haven't exposed in the KMP layer then you should use Sentry.initWithPlatformOptions (read more here)

@brustolin
Copy link
Contributor

@silverhammermba Can you confirm if @buenaflor suggested worked for you?

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Oct 23, 2024
@brustolin brustolin moved this from Needs Discussion to Needs More Information in Mobile & Cross Platform SDK Oct 23, 2024
@silverhammermba
Copy link

@brustolin I will try it out and let you know if it works. I'm a bit busy at the moment but I'll report back when I get time to try it.

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 29, 2024
@getsantry getsantry bot moved this from Waiting for: Product Owner to Waiting for: Community in GitHub Issues with 👀 3 Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Community
Status: Needs More Information
Development

No branches or pull requests

5 participants