-
-
Notifications
You must be signed in to change notification settings - Fork 19
Improve iOS crash reports by adding scope data #491
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
Changes from 5 commits
f0e551a
4617e8c
32f05ed
7122b2a
4b38561
f2c2ed0
82fc50a
6f06f85
e845bb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ package io.sentry.kotlin.multiplatform.nsexception | |
|
|
||
| import Internal.Sentry.NSExceptionKt_SentryCrashStackCursorFromNSException | ||
| import Internal.Sentry.kSentryLevelFatal | ||
| import kotlinx.cinterop.invoke | ||
| import platform.Foundation.NSException | ||
| import platform.Foundation.NSNumber | ||
|
|
||
|
|
@@ -54,12 +55,22 @@ internal fun dropKotlinCrashEvent(event: CocoapodsSentryEvent?): CocoapodsSentry | |
| * @see wrapUnhandledExceptionHook | ||
| */ | ||
| public fun setSentryUnhandledExceptionHook(): Unit = wrapUnhandledExceptionHook { throwable -> | ||
| val envelope = throwable.asSentryEnvelope() | ||
| // The envelope will be persisted, so we can safely terminate afterwards. | ||
| // https://github.com/getsentry/sentry-cocoa/blob/678172142ac1d10f5ed7978f69d16ab03e801057/Sources/Sentry/SentryClient.m#L409 | ||
| InternalSentrySDK.storeEnvelope(envelope as objcnames.classes.SentryEnvelope) | ||
| CocoapodsSentrySDK.configureScope { scope -> | ||
| scope?.setTagValue(KOTLIN_CRASH_TAG, KOTLIN_CRASH_TAG) | ||
| val crashReporter = InternalSentryDependencyContainer.sharedInstance().crashReporter | ||
| val handler = crashReporter.uncaughtExceptionHandler | ||
|
|
||
| if (handler != null) { | ||
| // This will: | ||
| // 1. Write a crash report to disk with ALL synced scope data | ||
| // 2. Include tags, user, context, breadcrumbs, etc. | ||
| // 3. The crash will be sent on next app launch | ||
| handler.invoke(throwable.asNSException()) | ||
|
||
| } else { | ||
buenaflor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Fallback to current approach if handler not available | ||
| val envelope = throwable.asSentryEnvelope() | ||
| InternalSentrySDK.storeEnvelope(envelope as objcnames.classes.SentryEnvelope) | ||
| CocoapodsSentrySDK.configureScope { scope -> | ||
| scope?.setTagValue(KOTLIN_CRASH_TAG, KOTLIN_CRASH_TAG) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SentryCrash interface - expose the uncaughtExceptionHandler | ||
| // Based on: https://github.com/getsentry/sentry-cocoa/blob/main/Sources/Sentry/include/SentryCrash.h | ||
|
|
||
| @interface SentryCrash : NSObject | ||
|
|
||
| @property (nonatomic, assign, nullable) NSUncaughtExceptionHandler *uncaughtExceptionHandler; | ||
|
|
||
| @end |

Uh oh!
There was an error while loading. Please reload this page.