File tree Expand file tree Collapse file tree 8 files changed +83
-6
lines changed
sentry-kotlin-multiplatform/src
commonAppleMain/kotlin/io/sentry/kotlin/multiplatform
commonJvmMain/kotlin/io/sentry/kotlin/multiplatform
commonMain/kotlin/io/sentry/kotlin/multiplatform
commonTest/kotlin/io/sentry/kotlin/multiplatform Expand file tree Collapse file tree 8 files changed +83
-6
lines changed Original file line number Diff line number Diff line change 11package io.sentry.kotlin.multiplatform
22
33import cocoapods.Sentry.SentrySDK
4+ import io.sentry.kotlin.multiplatform.extensions.toCocoaBreadcrumb
5+ import io.sentry.kotlin.multiplatform.extensions.toCocoaUser
46import io.sentry.kotlin.multiplatform.extensions.toCocoaUserFeedback
57import io.sentry.kotlin.multiplatform.nsexception.asNSException
8+ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
69import io.sentry.kotlin.multiplatform.protocol.SentryId
10+ import io.sentry.kotlin.multiplatform.protocol.User
711import io.sentry.kotlin.multiplatform.protocol.UserFeedback
812import platform.Foundation.NSError
913import platform.Foundation.NSException
@@ -50,6 +54,14 @@ internal actual object SentryBridge {
5054 SentrySDK .configureScope(configureScopeCallback(scopeCallback))
5155 }
5256
57+ actual fun addBreadcrumb (breadcrumb : Breadcrumb ) {
58+ SentrySDK .addBreadcrumb(breadcrumb.toCocoaBreadcrumb())
59+ }
60+
61+ actual fun setUser (user : User ? ) {
62+ SentrySDK .setUser(user?.toCocoaUser())
63+ }
64+
5365 actual fun close () {
5466 SentrySDK .close()
5567 }
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
2828 this .debug = options.debug
2929 this .sessionTrackingIntervalMillis = options.sessionTrackingIntervalMillis.convert()
3030 this .enableAutoSessionTracking = options.enableAutoSessionTracking
31+ this .maxAttachmentSize = options.maxAttachmentSize.convert()
32+ this .maxBreadcrumbs = options.maxBreadcrumbs.convert()
3133 this .beforeSend = { event ->
3234 dropKotlinCrashEvent(event as NSExceptionSentryEvent ? ) as SentryEvent ?
3335
@@ -53,6 +55,6 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
5355 PrivateSentrySDKOnly .setSdkName(options.sdk.name, options.sdk.version)
5456 this .beforeBreadcrumb = { cocoaBreadcrumb ->
5557 cocoaBreadcrumb?.toKmpBreadcrumb()
56- . apply { this ?.let { options.beforeBreadcrumb?.invoke(it) } }?.toCocoaBreadcrumb()
58+ ?.let { options.beforeBreadcrumb?.invoke(it) }?.toCocoaBreadcrumb()
5759 }
5860}
Original file line number Diff line number Diff line change 11package io.sentry.kotlin.multiplatform
22
33import io.sentry.Sentry
4+ import io.sentry.kotlin.multiplatform.extensions.toJvmBreadcrumb
5+ import io.sentry.kotlin.multiplatform.extensions.toJvmUser
46import io.sentry.kotlin.multiplatform.extensions.toJvmUserFeedback
7+ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
58import io.sentry.kotlin.multiplatform.protocol.SentryId
9+ import io.sentry.kotlin.multiplatform.protocol.User
610import io.sentry.kotlin.multiplatform.protocol.UserFeedback
711
812internal expect fun initSentry (context : Context ? = null, configuration : OptionsConfiguration )
@@ -45,6 +49,14 @@ internal actual object SentryBridge {
4549 Sentry .configureScope(configureScopeCallback(scopeCallback))
4650 }
4751
52+ actual fun addBreadcrumb (breadcrumb : Breadcrumb ) {
53+ Sentry .addBreadcrumb(breadcrumb.toJvmBreadcrumb())
54+ }
55+
56+ actual fun setUser (user : User ? ) {
57+ Sentry .setUser(user?.toJvmUser())
58+ }
59+
4860 actual fun close () {
4961 Sentry .close()
5062 }
Original file line number Diff line number Diff line change @@ -28,10 +28,9 @@ internal fun JvmSentryOptions.applyJvmBaseOptions(options: SentryOptions) {
2828 this .isDebug = options.debug
2929 this .sessionTrackingIntervalMillis = options.sessionTrackingIntervalMillis
3030 this .isEnableAutoSessionTracking = options.enableAutoSessionTracking
31+ this .maxAttachmentSize = options.maxAttachmentSize
32+ this .maxBreadcrumbs = options.maxBreadcrumbs
3133 this .setBeforeBreadcrumb { jvmBreadcrumb, _ ->
32- jvmBreadcrumb
33- .toKmpBreadcrumb()
34- .apply { options.beforeBreadcrumb?.invoke(this ) }
35- .toJvmBreadcrumb()
34+ options.beforeBreadcrumb?.invoke(jvmBreadcrumb.toKmpBreadcrumb())?.toJvmBreadcrumb()
3635 }
3736}
Original file line number Diff line number Diff line change 11package io.sentry.kotlin.multiplatform
22
3+ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
34import io.sentry.kotlin.multiplatform.protocol.SentryId
5+ import io.sentry.kotlin.multiplatform.protocol.User
46import io.sentry.kotlin.multiplatform.protocol.UserFeedback
57
68internal expect object SentryBridge {
@@ -21,5 +23,9 @@ internal expect object SentryBridge {
2123
2224 fun captureUserFeedback (userFeedback : UserFeedback )
2325
26+ fun addBreadcrumb (breadcrumb : Breadcrumb )
27+
28+ fun setUser (user : User ? )
29+
2430 fun close ()
2531}
Original file line number Diff line number Diff line change 11package io.sentry.kotlin.multiplatform
22
3+ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
34import io.sentry.kotlin.multiplatform.protocol.SentryId
5+ import io.sentry.kotlin.multiplatform.protocol.User
46import io.sentry.kotlin.multiplatform.protocol.UserFeedback
57
68typealias ScopeCallback = (Scope ) -> Unit
@@ -87,6 +89,24 @@ object Sentry {
8789 SentryBridge .configureScope(scopeCallback)
8890 }
8991
92+ /* *
93+ * Adds a breadcrumb to the current Scope.
94+ *
95+ * @param breadcrumb The breadcrumb to add.
96+ */
97+ fun addBreadcrumb (breadcrumb : Breadcrumb ) {
98+ SentryBridge .addBreadcrumb(breadcrumb)
99+ }
100+
101+ /* *
102+ * Sets the user to the current scope.
103+ *
104+ * @param user The user to set.
105+ */
106+ fun setUser (user : User ? ) {
107+ SentryBridge .setUser(user)
108+ }
109+
90110 /* *
91111 * Throws a RuntimeException, useful for testing.
92112 */
Original file line number Diff line number Diff line change @@ -56,8 +56,14 @@ open class SentryOptions {
5656 var attachScreenshot = false
5757
5858 /* * Hook that is triggered before a breadcrumb is sent to Sentry */
59- var beforeBreadcrumb: ((Breadcrumb ) -> Breadcrumb )? = null
59+ var beforeBreadcrumb: ((Breadcrumb ) -> Breadcrumb ? )? = null
6060
6161 /* * Information about the Sentry SDK that generated this event. */
6262 var sdk: SdkVersion = SdkVersion (BuildKonfig .SENTRY_KOTLIN_MULTIPLATFORM_SDK_NAME , BuildKonfig .VERSION_NAME )
63+
64+ /* * This variable controls the total amount of breadcrumbs that should be captured. Default is 100. */
65+ var maxBreadcrumbs = 100
66+
67+ /* * This variable controls the max attachment size in bytes */
68+ var maxAttachmentSize: Long = 20 * 1024 * 1024
6369}
Original file line number Diff line number Diff line change @@ -43,4 +43,24 @@ class SentryOptionsTest {
4343
4444 assertEquals(expectedBreadcrumb, modifiedBreadcrumb)
4545 }
46+
47+ @Test
48+ fun `Breadcrumb can be dropped via beforeBreadcrumb hook` () {
49+ val options = SentryOptions ()
50+
51+ fun mockInit (configuration : (SentryOptions ) -> Unit ) {
52+ configuration.invoke(options)
53+ }
54+
55+ mockInit {
56+ it.beforeBreadcrumb = { breadcrumb ->
57+ breadcrumb.message = " message"
58+ null
59+ }
60+ }
61+
62+ val modifiedBreadcrumb = options.beforeBreadcrumb?.invoke(Breadcrumb ())
63+
64+ assertEquals(null , modifiedBreadcrumb)
65+ }
4666}
You can’t perform that action at this time.
0 commit comments