diff --git a/CHANGELOG.md b/CHANGELOG.md index b94730a2..792807a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Improve Objc/Swift experience with @HiddenFromObjc ([#62](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/62)) +### Fixes + +- ref: use explicit api & add code consistency ([#63](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/63)) + ## 0.0.3 ### Fixes diff --git a/sentry-kotlin-multiplatform/build.gradle.kts b/sentry-kotlin-multiplatform/build.gradle.kts index 48a8a58f..a3fd38cd 100644 --- a/sentry-kotlin-multiplatform/build.gradle.kts +++ b/sentry-kotlin-multiplatform/build.gradle.kts @@ -23,6 +23,8 @@ android { } kotlin { + explicitApi() + android { publishLibraryVariants("release") } diff --git a/sentry-kotlin-multiplatform/src/androidMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt b/sentry-kotlin-multiplatform/src/androidMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt index e3052c36..8777b6eb 100644 --- a/sentry-kotlin-multiplatform/src/androidMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt +++ b/sentry-kotlin-multiplatform/src/androidMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt @@ -12,4 +12,4 @@ internal actual fun initSentry(context: Context?, configuration: OptionsConfigur } } -actual typealias Context = Context +public actual typealias Context = Context diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt index 111b9367..d69637cc 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt @@ -3,48 +3,47 @@ package io.sentry.kotlin.multiplatform import io.sentry.kotlin.multiplatform.extensions.toByteArray import io.sentry.kotlin.multiplatform.extensions.toNSData -actual class Attachment : IAttachment { +public actual class Attachment { - lateinit var cocoaAttachment: CocoaAttachment + internal lateinit var cocoaAttachment: CocoaAttachment - actual override val filename: String + public actual val filename: String get() = cocoaAttachment.filename - actual override val pathname: String? + public actual val pathname: String? get() = cocoaAttachment.path - actual override val bytes: ByteArray? + public actual val bytes: ByteArray? get() = cocoaAttachment.data?.toByteArray() - actual override val contentType: String? + public actual val contentType: String? get() = cocoaAttachment.contentType - actual companion object { - actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment { - val data = screenshotBytes.toNSData() + public actual companion object { + public actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment { return Attachment(screenshotBytes, "screenshot.png", "image/png") } } - actual constructor(pathname: String) { + public actual constructor(pathname: String) { cocoaAttachment = CocoaAttachment(pathname) } - actual constructor(pathname: String, filename: String) { + public actual constructor(pathname: String, filename: String) { cocoaAttachment = CocoaAttachment(pathname, filename) } - actual constructor(pathname: String, filename: String, contentType: String?) { + public actual constructor(pathname: String, filename: String, contentType: String?) { contentType?.let { cocoaAttachment = CocoaAttachment(pathname, filename, it) } ?: run { cocoaAttachment = CocoaAttachment(pathname, filename) } } - actual constructor(bytes: ByteArray, filename: String) { + public actual constructor(bytes: ByteArray, filename: String) { cocoaAttachment = CocoaAttachment(bytes.toNSData(), filename) } - actual constructor(bytes: ByteArray, filename: String, contentType: String?) { + public actual constructor(bytes: ByteArray, filename: String, contentType: String?) { contentType?.let { cocoaAttachment = CocoaAttachment(bytes.toNSData(), filename, it) } ?: run { cocoaAttachment = CocoaAttachment(bytes.toNSData(), filename) } diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/ScopeCocoaImpl.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/CocoaScopeProvider.kt similarity index 97% rename from sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/ScopeCocoaImpl.kt rename to sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/CocoaScopeProvider.kt index 3c900f5e..36b5d6c9 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/ScopeCocoaImpl.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/CocoaScopeProvider.kt @@ -10,7 +10,7 @@ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb import io.sentry.kotlin.multiplatform.protocol.User import Scope.Sentry.SentryScope as PrivateCocoaScope -internal class ScopeCocoaImpl(private val scope: CocoaScope) : ISentryScope { +internal class CocoaScopeProvider(private val scope: CocoaScope) : ScopeProvider { /* This bridge exposes private Cocoa SDK API to fetch internal properties such as user, level, etc. diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt index 03af3283..9c6d0cf8 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt @@ -12,7 +12,7 @@ import io.sentry.kotlin.multiplatform.protocol.UserFeedback import platform.Foundation.NSError import platform.Foundation.NSException -actual abstract class Context +public actual abstract class Context internal expect fun initSentry(configuration: OptionsConfiguration) @@ -68,10 +68,10 @@ internal actual object SentryBridge { private fun configureScopeCallback(scopeCallback: ScopeCallback): (CocoaScope?) -> Unit { return { cocoaScope -> - val cocoaScopeImpl = cocoaScope?.let { - ScopeCocoaImpl(it) + val cocoaScopeProvider = cocoaScope?.let { + CocoaScopeProvider(it) } - cocoaScopeImpl?.let { + cocoaScopeProvider?.let { val scope = Scope(it) scopeCallback.invoke(scope) } @@ -79,10 +79,10 @@ internal actual object SentryBridge { } } -fun Sentry.captureError(error: NSError) { +public fun captureError(error: NSError) { SentrySDK.captureError(error) } -fun Sentry.captureException(exception: NSException) { +public fun captureException(exception: NSException) { SentrySDK.captureException(exception) } diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt index 25ba28dc..acb05ae5 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt @@ -2,29 +2,24 @@ package io.sentry.kotlin.multiplatform.extensions import io.sentry.kotlin.multiplatform.CocoaBreadcrumb import io.sentry.kotlin.multiplatform.protocol.Breadcrumb -import io.sentry.kotlin.multiplatform.protocol.ISentryBreadcrumb -internal fun ISentryBreadcrumb.toCocoaBreadcrumb(): CocoaBreadcrumb { - val outerScope = this - return CocoaBreadcrumb().apply { - setMessage(outerScope.message) - setType(outerScope.type) - outerScope.category?.let { setCategory(it) } - outerScope.level?.let { setLevel(it.toCocoaSentryLevel()) } - setData(outerScope.getData()?.toMap()) - } +internal fun Breadcrumb.toCocoaBreadcrumb() = CocoaBreadcrumb().apply { + val scope = this@toCocoaBreadcrumb + setMessage(scope.message) + setType(scope.type) + scope.category?.let { setCategory(it) } + scope.level?.let { setLevel(it.toCocoaSentryLevel()) } + setData(scope.getData()?.toMap()) } -internal fun CocoaBreadcrumb.toKmpBreadcrumb(): Breadcrumb { - return Breadcrumb().apply { - val funScope = this@toKmpBreadcrumb - message = funScope.message - type = funScope.type - category = funScope.category - val map = funScope.data as? Map - map?.let { - this.setData(it.toMutableMap()) - } - level = funScope.level?.toKmpSentryLevel() +internal fun CocoaBreadcrumb.toKmpBreadcrumb() = Breadcrumb().apply { + val scope = this@toKmpBreadcrumb + message = scope.message + type = scope.type + category = scope.category + val map = scope.data as? Map + map?.let { + this.setData(it.toMutableMap()) } + level = scope.level?.toKmpSentryLevel() } diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/FoundationExtensions.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/FoundationExtensions.kt index 91c8d131..8788c4b4 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/FoundationExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/FoundationExtensions.kt @@ -11,7 +11,7 @@ import platform.Foundation.allKeys import platform.Foundation.create import platform.posix.memcpy -fun NSMutableDictionary.toMutableMap(): MutableMap { +internal fun NSMutableDictionary.toMutableMap(): MutableMap { val keys = this.allKeys val map = mutableMapOf() for (key in keys) { @@ -20,13 +20,13 @@ fun NSMutableDictionary.toMutableMap(): MutableMap { return map } -fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt()).apply { +internal fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt()).apply { usePinned { memcpy(it.addressOf(0), this@toByteArray.bytes, this@toByteArray.length) } } -fun ByteArray.toNSData(): NSData = memScoped { +internal fun ByteArray.toNSData(): NSData = memScoped { NSData.create( bytes = allocArrayOf(this@toNSData), length = this@toNSData.size.toULong().convert() diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt index f657b8d8..baa2bba8 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt @@ -3,23 +3,19 @@ package io.sentry.kotlin.multiplatform.extensions import io.sentry.kotlin.multiplatform.CocoaUser import io.sentry.kotlin.multiplatform.protocol.User -internal fun User.toCocoaUser(): CocoaUser { - val outerScope = this - return CocoaUser().apply { - userId = outerScope.id - username = outerScope.username - email = outerScope.email - ipAddress = outerScope.ipAddress - } +internal fun User.toCocoaUser() = CocoaUser().apply { + val scope = this@toCocoaUser + userId = scope.id + username = scope.username + email = scope.email + ipAddress = scope.ipAddress } -internal fun CocoaUser.toKmpUser(): User { - val outerScope = this - return User().apply { - id = outerScope.userId.toString() - username = outerScope.username.toString() - email = outerScope.email.toString() - ipAddress = outerScope.ipAddress.toString() - setData(outerScope.data) - } +internal fun CocoaUser.toKmpUser() = User().apply { + val scope = this@toKmpUser + id = scope.userId.toString() + username = scope.username.toString() + email = scope.email.toString() + ipAddress = scope.ipAddress.toString() + setData(scope.data) } diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt index e8e5a14d..41561b19 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt @@ -4,7 +4,7 @@ import io.sentry.kotlin.multiplatform.CocoaSentryId import io.sentry.kotlin.multiplatform.CocoaUserFeedback import io.sentry.kotlin.multiplatform.protocol.UserFeedback -fun UserFeedback.toCocoaUserFeedback(): CocoaUserFeedback { +internal fun UserFeedback.toCocoaUserFeedback(): CocoaUserFeedback { val sentryId = CocoaSentryId(sentryId.toString()) return CocoaUserFeedback(sentryId).apply { comments = this@toCocoaUserFeedback.comments.toString() diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/NSException.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/NSException.kt index b0a6640f..8808f442 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/NSException.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/NSException.kt @@ -25,7 +25,7 @@ import kotlin.reflect.KClass * If [appendCausedBy] is `true` then the name, message and stack trace * of the [causes][Throwable.cause] will be appended, else causes are ignored. */ -fun Throwable.asNSException(appendCausedBy: Boolean = false): NSException { +public fun Throwable.asNSException(appendCausedBy: Boolean = false): NSException { val returnAddresses = getFilteredStackTraceAddresses().let { addresses -> if (!appendCausedBy) return@let addresses addresses.toMutableList().apply { diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/Throwable.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/Throwable.kt index e27aa32e..8971f835 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/Throwable.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/nsexception/Throwable.kt @@ -19,7 +19,7 @@ package io.sentry.kotlin.multiplatform.nsexception * The first element will be the cause, the second the cause of the cause, etc. * This function stops once a reference cycles is detected. */ -val Throwable.causes: List get() = buildList { +internal val Throwable.causes: List get() = buildList { val causes = mutableSetOf() var cause = cause while (cause != null && cause !in causes) { @@ -36,7 +36,7 @@ val Throwable.causes: List get() = buildList { * @param commonAddresses a list of addresses used to drop the last common addresses. * @see getStackTraceAddresses */ -fun Throwable.getFilteredStackTraceAddresses( +internal fun Throwable.getFilteredStackTraceAddresses( keepLastInit: Boolean = false, commonAddresses: List = emptyList() ): List = getStackTraceAddresses().dropInitAddresses( diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt index dbcdd5f1..9f054bfe 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt @@ -2,10 +2,10 @@ package io.sentry.kotlin.multiplatform.protocol import io.sentry.kotlin.multiplatform.CocoaSentryId -actual data class SentryId actual constructor(val sentryIdString: String) : ISentryId { +public actual data class SentryId actual constructor(val sentryIdString: String) { - actual companion object { - actual val EMPTY_ID: SentryId = SentryId("") + public actual companion object { + public actual val EMPTY_ID: SentryId = SentryId("") } private var cocoaSentryId: CocoaSentryId? = null diff --git a/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt index 03f5e141..1e71ab25 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt @@ -5,7 +5,7 @@ import cocoapods.Sentry.SentryScope as CocoaScope actual abstract class BaseSentryScopeTest { actual fun initializeScope(): Scope { val cocoaScope = CocoaScope() - val scopeCocoaImpl = ScopeCocoaImpl(cocoaScope) - return Scope(scopeCocoaImpl) + val cocoaScopeProvider = CocoaScopeProvider(cocoaScope) + return Scope(cocoaScopeProvider) } } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt index 7088192c..3fd4131f 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt @@ -1,44 +1,44 @@ package io.sentry.kotlin.multiplatform -actual class Attachment : IAttachment { +public actual class Attachment { - var jvmAttachment: JvmAttachment + internal var jvmAttachment: JvmAttachment - actual override val filename: String + public actual val filename: String get() = jvmAttachment.filename - actual override val pathname: String? + public actual val pathname: String? get() = jvmAttachment.pathname - actual override val bytes: ByteArray? + public actual val bytes: ByteArray? get() = jvmAttachment.bytes - actual override val contentType: String? + public actual val contentType: String? get() = jvmAttachment.contentType - actual companion object { - actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment { + public actual companion object { + public actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment { return Attachment(screenshotBytes, "screenshot.png", "image/png") } } - actual constructor(pathname: String) { + public actual constructor(pathname: String) { jvmAttachment = JvmAttachment(pathname) } - actual constructor(pathname: String, filename: String) { + public actual constructor(pathname: String, filename: String) { jvmAttachment = JvmAttachment(pathname, filename) } - actual constructor(pathname: String, filename: String, contentType: String?) { + public actual constructor(pathname: String, filename: String, contentType: String?) { jvmAttachment = JvmAttachment(pathname, filename, contentType) } - actual constructor(bytes: ByteArray, filename: String) { + public actual constructor(bytes: ByteArray, filename: String) { jvmAttachment = JvmAttachment(bytes, filename) } - actual constructor(bytes: ByteArray, filename: String, contentType: String?) { + public actual constructor(bytes: ByteArray, filename: String, contentType: String?) { jvmAttachment = JvmAttachment(bytes, filename, contentType) } } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/ScopeJvmImpl.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/JvmScopeProvider.kt similarity index 97% rename from sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/ScopeJvmImpl.kt rename to sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/JvmScopeProvider.kt index 725e2a04..7874d4a8 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/ScopeJvmImpl.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/JvmScopeProvider.kt @@ -8,7 +8,7 @@ import io.sentry.kotlin.multiplatform.extensions.toKmpUser import io.sentry.kotlin.multiplatform.protocol.Breadcrumb import io.sentry.kotlin.multiplatform.protocol.User -internal class ScopeJvmImpl(private val scope: JvmScope) : ISentryScope { +internal class JvmScopeProvider(private val scope: JvmScope) : ScopeProvider { override var level: SentryLevel? set(value) { diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt index 1ef31e00..15913c06 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt @@ -22,23 +22,23 @@ internal actual object SentryBridge { } actual fun captureMessage(message: String): SentryId { - val androidSentryId = Sentry.captureMessage(message) - return SentryId(androidSentryId.toString()) + val jvmSentryId = Sentry.captureMessage(message) + return SentryId(jvmSentryId.toString()) } actual fun captureMessage(message: String, scopeCallback: ScopeCallback): SentryId { - val androidSentryId = Sentry.captureMessage(message, configureScopeCallback(scopeCallback)) - return SentryId(androidSentryId.toString()) + val jvmSentryId = Sentry.captureMessage(message, configureScopeCallback(scopeCallback)) + return SentryId(jvmSentryId.toString()) } actual fun captureException(throwable: Throwable): SentryId { - val androidSentryId = Sentry.captureException(throwable) - return SentryId(androidSentryId.toString()) + val jvmSentryId = Sentry.captureException(throwable) + return SentryId(jvmSentryId.toString()) } actual fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId { - val androidSentryId = Sentry.captureException(throwable, configureScopeCallback(scopeCallback)) - return SentryId(androidSentryId.toString()) + val jvmSentryId = Sentry.captureException(throwable, configureScopeCallback(scopeCallback)) + return SentryId(jvmSentryId.toString()) } actual fun captureUserFeedback(userFeedback: UserFeedback) { @@ -63,8 +63,8 @@ internal actual object SentryBridge { private fun configureScopeCallback(scopeCallback: ScopeCallback): (JvmScope) -> Unit { return { - val androidScopeImpl = ScopeJvmImpl(it) - val scope = Scope(androidScopeImpl) + val jvmScopeProvider = JvmScopeProvider(it) + val scope = Scope(jvmScopeProvider) scopeCallback.invoke(scope) } } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt index ef1cd97a..b8f18cdb 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt @@ -2,28 +2,23 @@ package io.sentry.kotlin.multiplatform.extensions import io.sentry.kotlin.multiplatform.JvmBreadcrumb import io.sentry.kotlin.multiplatform.protocol.Breadcrumb -import io.sentry.kotlin.multiplatform.protocol.ISentryBreadcrumb -internal fun ISentryBreadcrumb.toJvmBreadcrumb(): JvmBreadcrumb { - val outerScope = this - return JvmBreadcrumb().apply { - message = outerScope.message - type = outerScope.type - category = outerScope.category - outerScope.getData()?.forEach { - setData(it.key, it.value) - } - level = outerScope.level?.toJvmSentryLevel() +internal fun Breadcrumb.toJvmBreadcrumb() = JvmBreadcrumb().apply { + val scope = this@toJvmBreadcrumb + message = scope.message + type = scope.type + category = scope.category + scope.getData()?.forEach { + setData(it.key, it.value) } + level = scope.level?.toJvmSentryLevel() } -internal fun JvmBreadcrumb.toKmpBreadcrumb(): Breadcrumb { - return Breadcrumb().apply { - val funScope = this@toKmpBreadcrumb - message = funScope.message - type = funScope.type - category = funScope.category - setData(funScope.data.toMutableMap()) - level = funScope.level?.toKmpSentryLevel() - } +internal fun JvmBreadcrumb.toKmpBreadcrumb() = Breadcrumb().apply { + val scope = this@toKmpBreadcrumb + message = scope.message + type = scope.type + category = scope.category + setData(scope.data.toMutableMap()) + level = scope.level?.toKmpSentryLevel() } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryLevelExtensions.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryLevelExtensions.kt index 415b32d9..eb039a06 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryLevelExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryLevelExtensions.kt @@ -13,7 +13,7 @@ internal fun SentryLevel.toJvmSentryLevel(): JvmSentryLevel? { } } -fun JvmSentryLevel.toKmpSentryLevel(): SentryLevel? { +internal fun JvmSentryLevel.toKmpSentryLevel(): SentryLevel? { return when (this) { JvmSentryLevel.DEBUG -> SentryLevel.DEBUG JvmSentryLevel.INFO -> SentryLevel.INFO diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt index c591fe56..4e4ab35c 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt @@ -1,29 +1,24 @@ package io.sentry.kotlin.multiplatform.extensions import io.sentry.kotlin.multiplatform.JvmUser -import io.sentry.kotlin.multiplatform.protocol.ISentryUser import io.sentry.kotlin.multiplatform.protocol.User -internal fun ISentryUser.toJvmUser(): JvmUser { - val outerScope = this - return JvmUser().apply { - id = outerScope.id - username = outerScope.username - email = outerScope.email - ipAddress = outerScope.ipAddress - others = outerScope.other?.toMutableMap() - unknown = outerScope.unknown?.toMutableMap() - } +internal fun User.toJvmUser() = JvmUser().apply { + val scope = this@toJvmUser + id = scope.id + username = scope.username + email = scope.email + ipAddress = scope.ipAddress + others = scope.other?.toMutableMap() + unknown = scope.unknown?.toMutableMap() } -internal fun JvmUser.toKmpUser(): User { - val outerScope = this - return User().apply { - id = outerScope.id.toString() - username = outerScope.username.toString() - email = outerScope.email.toString() - ipAddress = outerScope.ipAddress.toString() - other = outerScope.others?.toMutableMap()?.let { it } - unknown = outerScope.unknown?.toMutableMap()?.let { it } - } +internal fun JvmUser.toKmpUser() = User().apply { + val scope = this@toKmpUser + id = scope.id.toString() + username = scope.username.toString() + email = scope.email.toString() + ipAddress = scope.ipAddress.toString() + other = scope.others?.toMutableMap()?.let { it } + unknown = scope.unknown?.toMutableMap()?.let { it } } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt index e4c2a35b..53183ba9 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt @@ -4,7 +4,7 @@ import io.sentry.kotlin.multiplatform.JvmSentryId import io.sentry.kotlin.multiplatform.JvmUserFeedback import io.sentry.kotlin.multiplatform.protocol.UserFeedback -fun UserFeedback.toJvmUserFeedback(): JvmUserFeedback { +internal fun UserFeedback.toJvmUserFeedback(): JvmUserFeedback { val sentryId = JvmSentryId(sentryId.toString()) return JvmUserFeedback(sentryId).apply { comments = this@toJvmUserFeedback.comments diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt index 20f6da82..1387710c 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt @@ -2,10 +2,10 @@ package io.sentry.kotlin.multiplatform.protocol import io.sentry.kotlin.multiplatform.JvmSentryId -actual data class SentryId actual constructor(val sentryIdString: String) : ISentryId { +public actual data class SentryId actual constructor(val sentryIdString: String) { - actual companion object { - actual val EMPTY_ID: SentryId = SentryId("") + public actual companion object { + public actual val EMPTY_ID: SentryId = SentryId("") } private var jvmSentryId: JvmSentryId? = null diff --git a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt index 8fceac5c..28c631e8 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/BaseSentryScopeTest.kt @@ -4,8 +4,8 @@ import io.sentry.SentryOptions actual abstract class BaseSentryScopeTest { actual fun initializeScope(): Scope { - val androidScope = JvmScope(SentryOptions()) - val scopeAndroidImpl = ScopeJvmImpl(androidScope) - return Scope(scopeAndroidImpl) + val jvmScope = JvmScope(SentryOptions()) + val jvmScopeProvider = JvmScopeProvider(jvmScope) + return Scope(jvmScopeProvider) } } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt index bf7e9974..b72a9d63 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt @@ -1,44 +1,33 @@ package io.sentry.kotlin.multiplatform -expect class Attachment : IAttachment { - - override val filename: String - - override val bytes: ByteArray? - - override val contentType: String? - - override val pathname: String? - - companion object { - fun fromScreenshot(screenshotBytes: ByteArray): Attachment - } - - constructor(bytes: ByteArray, filename: String) - - constructor(bytes: ByteArray, filename: String, contentType: String?) - - constructor(pathname: String) - - constructor(pathname: String, filename: String) - - constructor(pathname: String, filename: String, contentType: String?) -} - -interface IAttachment { +public expect class Attachment { /** The bytes of the attachment. */ - val bytes: ByteArray? + public val bytes: ByteArray? /** * The content type of the attachment. * The server infers "application/octet-stream" if not set. */ - val contentType: String? + public val contentType: String? /** The pathname string of the attachment. */ - val pathname: String? + public val pathname: String? /** The name of the attachment to display in Sentry */ - val filename: String + public val filename: String + + public companion object { + public fun fromScreenshot(screenshotBytes: ByteArray): Attachment + } + + public constructor(bytes: ByteArray, filename: String) + + public constructor(bytes: ByteArray, filename: String, contentType: String?) + + public constructor(pathname: String) + + public constructor(pathname: String, filename: String) + + public constructor(pathname: String, filename: String, contentType: String?) } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Scope.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Scope.kt index 49cf2c17..43261eaf 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Scope.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/Scope.kt @@ -3,118 +3,38 @@ package io.sentry.kotlin.multiplatform import io.sentry.kotlin.multiplatform.protocol.Breadcrumb import io.sentry.kotlin.multiplatform.protocol.User -class Scope constructor(private val scope: ISentryScope) : ISentryScope { - - override var level: SentryLevel? - set(value) { - scope.level = value - } - get() = scope.level - - override var user: User? - set(value) { - scope.user = value - } - get() = scope.user - - override fun addAttachment(attachment: Attachment) { - scope.addAttachment(attachment) - } - - override fun clearAttachments() { - scope.clearAttachments() - } - - override fun getContexts(): MutableMap { - return scope.getContexts() - } - - override fun getTags(): MutableMap { - return scope.getTags() - } - - override fun addBreadcrumb(breadcrumb: Breadcrumb) { - scope.addBreadcrumb(breadcrumb) - } - - override fun clearBreadcrumbs() { - scope.clearBreadcrumbs() - } - - override fun setContext(key: String, value: Any) { - scope.setContext(key, value) - } - - override fun setContext(key: String, value: Boolean) { - scope.setContext(key, value) - } - - override fun setContext(key: String, value: String) { - scope.setContext(key, value) - } - - override fun setContext(key: String, value: Number) { - scope.setContext(key, value) - } - - override fun setContext(key: String, value: Collection<*>) { - scope.setContext(key, value) - } - - override fun setContext(key: String, value: Array<*>) { - scope.setContext(key, value) - } - - override fun setContext(key: String, value: Char) { - scope.setContext(key, value) - } - - override fun removeContext(key: String) { - scope.removeContext(key) - } - - override fun setTag(key: String, value: String) { - scope.setTag(key, value) - } - - override fun removeTag(key: String) { - scope.removeTag(key) - } - - override fun setExtra(key: String, value: String) { - scope.setExtra(key, value) - } - - override fun removeExtra(key: String) { - scope.removeExtra(key) - } - - override fun clear() { - scope.clear() - } -} +/** + * Scope data to be sent with the event + * + * Different platforms have specific providers. + * - JVM: [JvmScopeProvider](io.sentry.kotlin.multiplatform.JvmScopeProvider) + * - Cocoa: [CocoaScopeProvider](io.sentry.kotlin.multiplatform.CocoaScopeProvider) + * + * @constructor ScopeProvider that holds the Scope's data + */ +public class Scope constructor(private val scope: ScopeProvider) : ScopeProvider by scope -interface ISentryScope { +public interface ScopeProvider { /** * Returns the scope's tags */ - fun getTags(): MutableMap + public fun getTags(): MutableMap /** * Returns the Scope's contexts */ - fun getContexts(): MutableMap + public fun getContexts(): MutableMap /** * The Scope's user */ - var user: User? + public var user: User? /** * The Scope's level */ - var level: SentryLevel? + public var level: SentryLevel? /** * Adds an attachment to the Scope's list of attachments. The SDK adds the attachment to every @@ -122,20 +42,20 @@ interface ISentryScope { * * @param attachment The attachment to add to the Scope's list of attachments. */ - fun addAttachment(attachment: Attachment) + public fun addAttachment(attachment: Attachment) /** Clear all attachments */ - fun clearAttachments() + public fun clearAttachments() /** * Adds a breadcrumb to the breadcrumbs queue * * @param breadcrumb the breadcrumb */ - fun addBreadcrumb(breadcrumb: Breadcrumb) + public fun addBreadcrumb(breadcrumb: Breadcrumb) /** Clear all the breadcrumbs */ - fun clearBreadcrumbs() + public fun clearBreadcrumbs() /** * Sets the Scope's contexts @@ -143,7 +63,7 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: Any) + public fun setContext(key: String, value: Any) /** * Sets the Scope's contexts @@ -151,7 +71,7 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: Boolean) + public fun setContext(key: String, value: Boolean) /** * Sets the Scope's context @@ -159,7 +79,7 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: String) + public fun setContext(key: String, value: String) /** * Sets the Scope's context @@ -167,7 +87,7 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: Number) + public fun setContext(key: String, value: Number) /** * Sets the Scope's context @@ -175,7 +95,7 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: Collection<*>) + public fun setContext(key: String, value: Collection<*>) /** * Sets the Scope's context @@ -183,7 +103,7 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: Array<*>) + public fun setContext(key: String, value: Array<*>) /** * Sets the Scope's context @@ -191,14 +111,14 @@ interface ISentryScope { * @param key the context key * @param value the context value */ - fun setContext(key: String, value: Char) + public fun setContext(key: String, value: Char) /** * Removes a value from the Scope's contexts * * @param key the Key */ - fun removeContext(key: String) + public fun removeContext(key: String) /** * Sets a tag to Scope's tags @@ -206,14 +126,14 @@ interface ISentryScope { * @param key the key * @param value the value */ - fun setTag(key: String, value: String) + public fun setTag(key: String, value: String) /** * Removes a tag from the Scope's tags * * @param key the key */ - fun removeTag(key: String) + public fun removeTag(key: String) /** * Sets an extra to the Scope's extra map @@ -221,15 +141,15 @@ interface ISentryScope { * @param key the key * @param value the value */ - fun setExtra(key: String, value: String) + public fun setExtra(key: String, value: String) /** * Removes an extra from the Scope's extras * * @param key the key */ - fun removeExtra(key: String) + public fun removeExtra(key: String) /** Resets the Scope to its default state */ - fun clear() + public fun clear() } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt index f25c565b..3f7cbc08 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt @@ -7,13 +7,13 @@ import io.sentry.kotlin.multiplatform.protocol.UserFeedback import kotlin.experimental.ExperimentalObjCRefinement import kotlin.native.HiddenFromObjC -typealias ScopeCallback = (Scope) -> Unit -typealias OptionsConfiguration = (SentryOptions) -> Unit +public typealias ScopeCallback = (Scope) -> Unit +public typealias OptionsConfiguration = (SentryOptions) -> Unit -expect abstract class Context +public expect abstract class Context /** Sentry Kotlin Multiplatform SDK API entry point */ -object Sentry { +public object Sentry { /** * Sentry initialization with an option configuration handler. @@ -23,7 +23,7 @@ object Sentry { */ @OptIn(ExperimentalObjCRefinement::class) @HiddenFromObjC - fun init(context: Context, configuration: OptionsConfiguration) { + public fun init(context: Context, configuration: OptionsConfiguration) { SentryBridge.init(context, configuration) } @@ -33,7 +33,7 @@ object Sentry { * * @param configuration Options configuration handler. */ - fun init(configuration: OptionsConfiguration) { + public fun init(configuration: OptionsConfiguration) { SentryBridge.init(configuration = configuration) } @@ -42,7 +42,7 @@ object Sentry { * * @param message The message to send. */ - fun captureMessage(message: String): SentryId { + public fun captureMessage(message: String): SentryId { return SentryBridge.captureMessage(message) } @@ -52,7 +52,7 @@ object Sentry { * @param message The message to send. * @param scopeCallback The local scope callback. */ - fun captureMessage(message: String, scopeCallback: ScopeCallback): SentryId { + public fun captureMessage(message: String, scopeCallback: ScopeCallback): SentryId { return SentryBridge.captureMessage(message, scopeCallback) } @@ -61,7 +61,7 @@ object Sentry { * * @param throwable The exception. */ - fun captureException(throwable: Throwable): SentryId { + public fun captureException(throwable: Throwable): SentryId { return SentryBridge.captureException(throwable) } @@ -71,7 +71,7 @@ object Sentry { * @param throwable The exception. * @param scopeCallback The local scope callback. */ - fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId { + public fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId { return SentryBridge.captureException(throwable, scopeCallback) } @@ -80,7 +80,7 @@ object Sentry { * * @param userFeedback The user feedback to send to Sentry. */ - fun captureUserFeedback(userFeedback: UserFeedback) { + public fun captureUserFeedback(userFeedback: UserFeedback) { return SentryBridge.captureUserFeedback(userFeedback) } @@ -89,7 +89,7 @@ object Sentry { * * @param scopeCallback The configure scope callback. */ - fun configureScope(scopeCallback: ScopeCallback) { + public fun configureScope(scopeCallback: ScopeCallback) { SentryBridge.configureScope(scopeCallback) } @@ -98,7 +98,7 @@ object Sentry { * * @param breadcrumb The breadcrumb to add. */ - fun addBreadcrumb(breadcrumb: Breadcrumb) { + public fun addBreadcrumb(breadcrumb: Breadcrumb) { SentryBridge.addBreadcrumb(breadcrumb) } @@ -107,21 +107,21 @@ object Sentry { * * @param user The user to set. */ - fun setUser(user: User?) { + public fun setUser(user: User?) { SentryBridge.setUser(user) } /** * Throws a RuntimeException, useful for testing. */ - fun crash() { + public fun crash() { throw RuntimeException("Uncaught Exception from Kotlin Multiplatform.") } /** * Closes the SDK. */ - fun close() { + public fun close() { SentryBridge.close() } } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryLevel.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryLevel.kt index da69c65f..a6b3e6e1 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryLevel.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryLevel.kt @@ -8,18 +8,18 @@ internal object SentryLevelNumConstants { const val FATAL_LEVEL = 5 } -enum class SentryLevel(val value: Int) { +public enum class SentryLevel(private val value: Int) { DEBUG(SentryLevelNumConstants.DEBUG_LEVEL), INFO(SentryLevelNumConstants.INFO_LEVEL), WARNING(SentryLevelNumConstants.WARNING_LEVEL), ERROR(SentryLevelNumConstants.ERROR_LEVEL), FATAL(SentryLevelNumConstants.FATAL_LEVEL); - fun toInt(): Int { + internal fun toInt(): Int { return this.value } - companion object { + internal companion object { fun fromInt(value: Int): SentryLevel? { return try { values().first { diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryOptions.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryOptions.kt index 23f0e997..8bee81eb 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryOptions.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryOptions.kt @@ -3,67 +3,67 @@ package io.sentry.kotlin.multiplatform import io.sentry.kotlin.multiplatform.protocol.Breadcrumb import io.sentry.kotlin.multiplatform.protocol.SdkVersion -open class SentryOptions { +public open class SentryOptions { /** * The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will * just not send any events. */ - var dsn: String? = null + public var dsn: String? = null /** * When enabled, stack traces are automatically attached to all threads logged. Stack traces are * always attached to exceptions but when this is set stack traces are also sent with threads. If * no threads are logged, we log the current thread automatically. */ - var attachStackTrace = true + public var attachStackTrace: Boolean = true /** When enabled, all the threads are automatically attached to all logged events. */ - var attachThreads = true + public var attachThreads: Boolean = true /** Sets the release. SDK will try to automatically configure a release out of the box */ - var release: String? = null + public var release: String? = null /** * Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging * information if something goes wrong. Default is disabled. */ - var debug: Boolean = false + public var debug: Boolean = false /** * Sets the environment. This string is freeform and not set by default. A release can be * associated with more than one environment to separate them in the UI Think staging vs prod or * similar. */ - var environment: String? = null + public var environment: String? = null /** Sets the distribution. Think about it together with release and environment */ - var dist: String? = null + public var dist: String? = null /** Whether to enable or disable automatic session tracking. */ - var enableAutoSessionTracking = true + public var enableAutoSessionTracking: Boolean = true /** * The session tracking interval in millis. This is the interval to end a session if the App goes * to the background. */ - var sessionTrackingIntervalMillis: Long = 30000 + public var sessionTrackingIntervalMillis: Long = 30000 /** * Enables/Disables capturing screenshots before an error. * Available on iOS and Android. */ - var attachScreenshot = false + public var attachScreenshot: Boolean = false /** Hook that is triggered before a breadcrumb is sent to Sentry */ - var beforeBreadcrumb: ((Breadcrumb) -> Breadcrumb?)? = null + public var beforeBreadcrumb: ((Breadcrumb) -> Breadcrumb?)? = null /** Information about the Sentry SDK that generated this event. */ - var sdk: SdkVersion? = null + public var sdk: SdkVersion? = null /** This variable controls the total amount of breadcrumbs that should be captured. Default is 100. */ - var maxBreadcrumbs = 100 + public var maxBreadcrumbs: Int = 100 /** This variable controls the max attachment size in bytes */ - var maxAttachmentSize: Long = 20 * 1024 * 1024 + public var maxAttachmentSize: Long = 20 * 1024 * 1024 } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/Breadcrumb.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/Breadcrumb.kt index 4be639d4..a32bccf3 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/Breadcrumb.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/Breadcrumb.kt @@ -2,16 +2,24 @@ package io.sentry.kotlin.multiplatform.protocol import io.sentry.kotlin.multiplatform.SentryLevel -data class Breadcrumb constructor( - override var type: String? = null, - override var category: String? = null, - override var message: String? = null, - override var level: SentryLevel? = null, +public data class Breadcrumb constructor( + /** The breadcrumb's level */ + var level: SentryLevel? = null, + + /** The breadcrumb's type */ + var type: String? = null, + + /** The breadcrumb's message */ + var message: String? = null, + + /** The breadcrumb's category */ + var category: String? = null, + private var data: MutableMap? = null -) : ISentryBreadcrumb { +) { - companion object { - fun user(category: String, message: String): Breadcrumb { + public companion object { + public fun user(category: String, message: String): Breadcrumb { return Breadcrumb().apply { this.category = category this.message = message @@ -19,7 +27,7 @@ data class Breadcrumb constructor( } } - fun http(url: String, method: String): Breadcrumb { + public fun http(url: String, method: String): Breadcrumb { return Breadcrumb().apply { this.type = "http" this.category = "http" @@ -28,13 +36,13 @@ data class Breadcrumb constructor( } } - fun http(url: String, method: String, code: Int?): Breadcrumb { + public fun http(url: String, method: String, code: Int?): Breadcrumb { return http(url, method).apply { code?.let { this.setData("status_code", code) } } } - fun navigation(from: String, to: String): Breadcrumb { + public fun navigation(from: String, to: String): Breadcrumb { return Breadcrumb().apply { this.category = "navigation" this.type = "navigation" @@ -43,7 +51,7 @@ data class Breadcrumb constructor( } } - fun transaction(message: String): Breadcrumb { + public fun transaction(message: String): Breadcrumb { return Breadcrumb().apply { this.type = "default" this.category = "sentry.transaction" @@ -51,7 +59,7 @@ data class Breadcrumb constructor( } } - fun debug(message: String): Breadcrumb { + public fun debug(message: String): Breadcrumb { val breadcrumb = Breadcrumb().apply { this.type = "debug" this.message = message @@ -60,7 +68,7 @@ data class Breadcrumb constructor( return breadcrumb } - fun error(message: String): Breadcrumb { + public fun error(message: String): Breadcrumb { return Breadcrumb().apply { this.type = "error" this.message = message @@ -68,7 +76,7 @@ data class Breadcrumb constructor( } } - fun info(message: String): Breadcrumb { + public fun info(message: String): Breadcrumb { return Breadcrumb().apply { this.type = "info" this.message = message @@ -76,14 +84,14 @@ data class Breadcrumb constructor( } } - fun query(message: String): Breadcrumb { + public fun query(message: String): Breadcrumb { return Breadcrumb().apply { this.type = "query" this.message = message } } - fun ui(category: String, message: String): Breadcrumb { + public fun ui(category: String, message: String): Breadcrumb { return Breadcrumb().apply { this.type = "default" this.category = "ui.$category" @@ -91,7 +99,7 @@ data class Breadcrumb constructor( } } - fun userInteraction( + public fun userInteraction( subCategory: String, viewId: String?, viewClass: String?, @@ -111,65 +119,46 @@ data class Breadcrumb constructor( } } - fun userInteraction(subCategory: String, viewId: String?, viewClass: String?): Breadcrumb { + public fun userInteraction( + subCategory: String, + viewId: String?, + viewClass: String? + ): Breadcrumb { return userInteraction(subCategory, viewId, viewClass, emptyMap()) } } - override fun setData(key: String, value: Any) { - if (data == null) data = mutableMapOf() - data?.put(key, value) - } - - override fun setData(map: MutableMap) { - data = map - } - - override fun getData(): MutableMap? { - return data - } - - override fun clear() { - data = null - level = null - category = null - type = null - message = null - } -} - -interface ISentryBreadcrumb { - - /** The breadcrumb's level */ - var level: SentryLevel? - - /** The breadcrumb's type */ - var type: String? - - /** The breadcrumb's message */ - var message: String? - - /** The breadcrumb's category */ - var category: String? - /** * Set's the breadcrumb's data with key, value * * @param key The key * @param value The value */ - fun setData(key: String, value: Any) + public fun setData(key: String, value: Any) { + if (data == null) data = mutableMapOf() + data?.put(key, value) + } /** * Set's the breadcrumb's data with a map * * @param map The map */ - fun setData(map: MutableMap) + public fun setData(map: MutableMap) { + data = map + } /** Returns the breadcrumb's data */ - fun getData(): MutableMap? + public fun getData(): MutableMap? { + return data + } /** Clears the breadcrumb and returns it to the default state */ - fun clear() + public fun clear() { + data = null + level = null + category = null + type = null + message = null + } } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SdkVersion.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SdkVersion.kt index 3a962678..ab397cfb 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SdkVersion.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SdkVersion.kt @@ -1,7 +1,7 @@ package io.sentry.kotlin.multiplatform.protocol /** The SDK Interface describes the Sentry SDK and its configuration used to capture and transmit an event. */ -data class SdkVersion( +public data class SdkVersion( /** The name of the SDK. */ val name: String, @@ -12,14 +12,14 @@ data class SdkVersion( var packages: List? = mutableListOf() private set - fun addPackage(name: String, version: String) { + public fun addPackage(name: String, version: String) { val mutableList = packages?.toMutableList() mutableList?.add(Package(name, version)) packages = mutableList } } -data class Package( +public data class Package( val name: String, val version: String ) diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt index 5ec07916..a7b03933 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.kt @@ -1,15 +1,8 @@ package io.sentry.kotlin.multiplatform.protocol -expect class SentryId(sentryIdString: String) : ISentryId { - companion object { - val EMPTY_ID: SentryId - } - override fun toString(): String -} - -interface ISentryId { - companion object { - val EMPTY_ID: SentryId = SentryId("") +public expect class SentryId(sentryIdString: String) { + public companion object { + public val EMPTY_ID: SentryId } override fun toString(): String } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/User.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/User.kt index b6f6ba43..6706ef5a 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/User.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/User.kt @@ -1,48 +1,38 @@ package io.sentry.kotlin.multiplatform.protocol -data class User( - override var email: String = "", - override var id: String = "", - override var username: String = "", - override var ipAddress: String? = null, - override var other: MutableMap? = null, - override var unknown: MutableMap? = null -) : ISentryUser { - - constructor(user: ISentryUser) : this( - user.email, - user.id, - user.username, - user.ipAddress, - user.other, - user.unknown - ) - - // This secondary constructor allows Swift also to init without specifying nil explicitly - // example: User.init() instead of User.init(user: nil) - constructor() : this("", "", "", null, null, null) -} - -interface ISentryUser { - +public data class User( /** The user's email */ - var email: String + var email: String = "", /** The user's id */ - var id: String + var id: String = "", /** The user's username */ - var username: String + var username: String = "", /** The user's ip address*/ - var ipAddress: String? + var ipAddress: String? = null, /** * Additional arbitrary fields, as stored in the database (and sometimes as sent by clients). All * data from `self.other` should end up here after store normalization. */ - var other: MutableMap? + var other: MutableMap? = null, /** Unknown fields, only internal usage. */ - var unknown: MutableMap? + var unknown: MutableMap? = null +) { + + public constructor(user: User) : this( + user.email, + user.id, + user.username, + user.ipAddress, + user.other, + user.unknown + ) + + // This secondary constructor allows Swift also to init without specifying nil explicitly + // example: User.init() instead of User.init(user: nil) + public constructor() : this("", "", "", null, null, null) } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/UserFeedback.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/UserFeedback.kt index 16888c29..b7dac07d 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/UserFeedback.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/protocol/UserFeedback.kt @@ -1,6 +1,6 @@ package io.sentry.kotlin.multiplatform.protocol -data class UserFeedback(internal val sentryId: SentryId) { +public data class UserFeedback(val sentryId: SentryId) { /** The user's name */ var name: String? = null diff --git a/sentry-kotlin-multiplatform/src/jvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt b/sentry-kotlin-multiplatform/src/jvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt index f870f7b7..48e6e840 100644 --- a/sentry-kotlin-multiplatform/src/jvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt +++ b/sentry-kotlin-multiplatform/src/jvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt @@ -4,9 +4,9 @@ import io.sentry.Sentry import io.sentry.kotlin.multiplatform.extensions.toJvmSentryOptionsCallback // The context is unused here and only implemented to satisfy the expect -actual abstract class Context +public actual abstract class Context -actual fun initSentry(context: Context?, configuration: OptionsConfiguration) { +internal actual fun initSentry(context: Context?, configuration: OptionsConfiguration) { val options = SentryOptions() configuration.invoke(options) Sentry.init(options.toJvmSentryOptionsCallback())