Skip to content

Commit

Permalink
fix: cocoa crash handling due to sdkInfo removal in cocoa sdk (#68)
Browse files Browse the repository at this point in the history
* remove sdkInfo from SentryEnvelopHeader init

* Update CHANGELOG.md
  • Loading branch information
buenaflor authored Apr 6, 2023
1 parent 2b14023 commit d5ecbdf
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 68 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixes

- ref: use explicit api & add code consistency ([#63](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/63))
- fix: cocoa crash handling due to sdkInfo removal in cocoa sdk ([#68](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/68))

## 0.0.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
this.maxAttachmentSize = options.maxAttachmentSize.convert()
this.maxBreadcrumbs = options.maxBreadcrumbs.convert()
this.beforeSend = { event ->
dropKotlinCrashEvent(event as NSExceptionSentryEvent?) as SentryEvent?

val cocoaName = BuildKonfig.SENTRY_COCOA_PACKAGE_NAME
val cocoaVersion = BuildKonfig.SENTRY_COCOA_VERSION

Expand All @@ -50,7 +48,7 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
sdk?.set("packages", packages)

event?.sdk = sdk
event
dropKotlinCrashEvent(event as NSExceptionSentryEvent?) as SentryEvent?
}

val sdkName = options.sdk?.name ?: BuildKonfig.SENTRY_KMP_COCOA_SDK_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import NSException.Sentry.SentryThreadInspector
import NSException.Sentry.currentHub
import NSException.Sentry.isCrashEvent
import NSException.Sentry.kSentryLevelFatal
import NSException.Sentry.options
import NSException.Sentry.prepareEvent
import NSException.Sentry.sdkInfo
import NSException.Sentry.storeEnvelope
import NSException.Sentry.threadInspector
import kotlinx.cinterop.UnsafeNumber
Expand Down Expand Up @@ -66,19 +64,19 @@ internal fun setSentryUnhandledExceptionHook(): Unit = wrapUnhandledExceptionHoo
/**
* Tag used to mark the Kotlin termination crash.
*/
private const val kotlinCrashedTag = "nsexceptionkt.kotlin_crashed"
internal const val kotlinCrashedTag = "nsexceptionkt.kotlin_crashed"

/**
* Converts `this` [Throwable] to a [SentryEnvelope].
*/
private fun Throwable.asSentryEnvelope(): SentryEnvelope {
internal fun Throwable.asSentryEnvelope(): SentryEnvelope {
val event = asSentryEvent()
val preparedEvent = SentrySDK.currentHub().let { hub ->
hub.getClient()?.prepareEvent(event, hub.scope, alwaysAttachStacktrace = false, isCrashEvent = true)
} ?: event
val item = SentryEnvelopeItem(preparedEvent)
// TODO: pass traceState when enabling performance monitoring for KMP SDK
val header = SentryEnvelopeHeader(preparedEvent.eventId, SentrySDK.options?.sdkInfo, null)
val header = SentryEnvelopeHeader(preparedEvent.eventId, null)
return SentryEnvelope(header, listOf(item))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ package io.sentry.kotlin.multiplatform.nsexception
internal val Throwable.causes: List<Throwable> get() = buildList {
val causes = mutableSetOf<Throwable>()
var cause = cause
while (cause != null && cause !in causes) {
while (cause != null && causes.add(cause)) {
add(cause)
causes.add(cause)
cause = cause.cause
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language = Objective-C
headers = SentryClient.h SentryDebugImageProvider.h SentryDebugMeta.h SentryDefines.h SentryEnvelope.h SentryEvent.h \
SentryException.h SentryHub.h SentryId.h SentryMechanism.h SentryMechanism+NSExceptionKt.h SentryOptions.h \
SentryScope.h SentrySDK.h SentrySdkInfo.h SentryStacktrace.h SentryThread.h SentryThread+NSExceptionKt.h \
Private/SentryClient.h Private/SentryCrashMonitor_NSException.h Private/SentryCrashMonitor_NSException+NSExceptionKt.h \
Private/SentryCrashStackCursor.h Private/SentryDependencyContainer.h Private/SentryEvent.h Private/SentryHook.h \
Private/SentryOptions.h Private/SentrySDK.h Private/SentryStacktraceBuilder.h Private/SentryThreadInspector.h \
Private/SentryTraceContext.h
SentryException.h SentryHub.h SentryId.h SentryMechanism.h SentryMechanism+NSExceptionKt.h SentryOptions.h \
SentryScope.h SentrySDK.h SentryStacktrace.h SentryThread.h SentryThread+NSExceptionKt.h Private/SentryClient.h \
Private/SentryCrashMonitor_NSException.h Private/SentryCrashMonitor_NSException+NSExceptionKt.h \
Private/SentryCrashStackCursor.h Private/SentryDependencyContainer.h Private/SentryEvent.h Private/SentryHook.h \
Private/SentrySDK.h Private/SentryStacktraceBuilder.h Private/SentryThreadInspector.h Private/SentryTraceContext.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
#import <Private/SentryTraceContext.h>
#import <SentryEvent.h>
#import <SentryId.h>
#import <SentrySdkInfo.h>

@interface SentryEnvelopeHeader : NSObject

- (instancetype)initWithId:(nullable SentryId *)eventId
sdkInfo:(nullable SentrySdkInfo *)sdkInfo
traceContext:(nullable SentryTraceContext *)traceContext NS_DESIGNATED_INITIALIZER;
traceContext:(nullable SentryTraceContext *)traceContext;

@end

Expand Down

This file was deleted.

0 comments on commit d5ecbdf

Please sign in to comment.