File tree Expand file tree Collapse file tree 9 files changed +66
-3
lines changed
sentry-kotlin-multiplatform
commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions
commonAppleTest/kotlin/io/sentry/kotlin/multiplatform
commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions
commonMain/kotlin/io/sentry/kotlin/multiplatform
commonTest/kotlin/io/sentry/kotlin/multiplatform Expand file tree Collapse file tree 9 files changed +66
-3
lines changed Original file line number Diff line number Diff line change 44
55### Features
66
7+ - Add sample & trace rate configuration ([ #144 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/144 ) )
78- Remove need for context in Sentry.init for Android ([ #117 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/117 ) )
89
910### Dependencies
Original file line number Diff line number Diff line change @@ -26,4 +26,7 @@ complexity:
2626 " **/JvmScopeProvider.kt" ,
2727 " **/Breadcrumb.kt" ,
2828 ]
29+ LongMethod :
30+ excludes :
31+ - " **/SentryOptionsExtensions.*"
2932
Original file line number Diff line number Diff line change @@ -173,8 +173,10 @@ public class io/sentry/kotlin/multiplatform/SentryOptions {
173173 public final fun getMaxAttachmentSize ()J
174174 public final fun getMaxBreadcrumbs ()I
175175 public final fun getRelease ()Ljava/lang/String;
176+ public final fun getSampleRate ()Ljava/lang/Double;
176177 public final fun getSdk ()Lio/sentry/kotlin/multiplatform/protocol/SdkVersion;
177178 public final fun getSessionTrackingIntervalMillis ()J
179+ public final fun getTracesSampleRate ()Ljava/lang/Double;
178180 public final fun setAttachScreenshot (Z)V
179181 public final fun setAttachStackTrace (Z)V
180182 public final fun setAttachThreads (Z)V
@@ -192,8 +194,10 @@ public class io/sentry/kotlin/multiplatform/SentryOptions {
192194 public final fun setMaxAttachmentSize (J)V
193195 public final fun setMaxBreadcrumbs (I)V
194196 public final fun setRelease (Ljava/lang/String;)V
197+ public final fun setSampleRate (Ljava/lang/Double;)V
195198 public final fun setSdk (Lio/sentry/kotlin/multiplatform/protocol/SdkVersion;)V
196199 public final fun setSessionTrackingIntervalMillis (J)V
200+ public final fun setTracesSampleRate (Ljava/lang/Double;)V
197201}
198202
199203public final class io/sentry/kotlin/multiplatform/protocol/Breadcrumb {
Original file line number Diff line number Diff line change @@ -170,8 +170,10 @@ public class io/sentry/kotlin/multiplatform/SentryOptions {
170170 public final fun getMaxAttachmentSize ()J
171171 public final fun getMaxBreadcrumbs ()I
172172 public final fun getRelease ()Ljava/lang/String;
173+ public final fun getSampleRate ()Ljava/lang/Double;
173174 public final fun getSdk ()Lio/sentry/kotlin/multiplatform/protocol/SdkVersion;
174175 public final fun getSessionTrackingIntervalMillis ()J
176+ public final fun getTracesSampleRate ()Ljava/lang/Double;
175177 public final fun setAttachScreenshot (Z)V
176178 public final fun setAttachStackTrace (Z)V
177179 public final fun setAttachThreads (Z)V
@@ -189,8 +191,10 @@ public class io/sentry/kotlin/multiplatform/SentryOptions {
189191 public final fun setMaxAttachmentSize (J)V
190192 public final fun setMaxBreadcrumbs (I)V
191193 public final fun setRelease (Ljava/lang/String;)V
194+ public final fun setSampleRate (Ljava/lang/Double;)V
192195 public final fun setSdk (Lio/sentry/kotlin/multiplatform/protocol/SdkVersion;)V
193196 public final fun setSessionTrackingIntervalMillis (J)V
197+ public final fun setTracesSampleRate (Ljava/lang/Double;)V
194198}
195199
196200public final class io/sentry/kotlin/multiplatform/protocol/Breadcrumb {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import io.sentry.kotlin.multiplatform.SentryEvent
99import io.sentry.kotlin.multiplatform.SentryOptions
1010import io.sentry.kotlin.multiplatform.nsexception.dropKotlinCrashEvent
1111import kotlinx.cinterop.convert
12+ import platform.Foundation.NSNumber
1213import NSException.Sentry.SentryEvent as NSExceptionSentryEvent
1314
1415internal fun SentryOptions.toCocoaOptionsConfiguration (): (CocoaSentryOptions ? ) -> Unit = {
@@ -32,6 +33,12 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
3233 enableAutoSessionTracking = options.enableAutoSessionTracking
3334 maxAttachmentSize = options.maxAttachmentSize.convert()
3435 maxBreadcrumbs = options.maxBreadcrumbs.convert()
36+ options.sampleRate?.let {
37+ sampleRate = NSNumber (double = it)
38+ }
39+ options.tracesSampleRate?.let {
40+ tracesSampleRate = NSNumber (double = it)
41+ }
3542 beforeSend = { event ->
3643 val cocoaName = BuildKonfig .SENTRY_COCOA_PACKAGE_NAME
3744 val cocoaVersion = BuildKonfig .SENTRY_COCOA_VERSION
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import kotlin.test.assertContentEquals
1111import kotlin.test.assertEquals
1212
1313class FoundationTest {
14-
1514 @Test
1615 fun `convert string to NSData and ByteArray is correct` () {
1716 val text = " $!()I!(DKDASKDKSD(#(ldkiadjk91jd"
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ internal fun JvmSentryOptions.applyJvmBaseOptions(options: SentryOptions) {
4040 isEnableAutoSessionTracking = options.enableAutoSessionTracking
4141 maxAttachmentSize = options.maxAttachmentSize
4242 maxBreadcrumbs = options.maxBreadcrumbs
43+ sampleRate = options.sampleRate
44+ tracesSampleRate = options.tracesSampleRate
4345 setBeforeBreadcrumb { jvmBreadcrumb, _ ->
4446 if (options.beforeBreadcrumb == null ) {
4547 jvmBreadcrumb
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ private const val DEFAULT_SESSION_INTERVAL_MILLIS = 30000L
99
1010/* * Sentry options that can be used to configure the SDK. */
1111public open class SentryOptions {
12-
1312 /* *
1413 * The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will
1514 * just not send any events.
@@ -107,4 +106,18 @@ public open class SentryOptions {
107106 * Available on Apple.
108107 */
109108 public var failedRequestTargets: List <String > = listOf (" .*" )
109+
110+ /* *
111+ * Configures the sample rate as a percentage of events to be sent in the range of 0.0 to 1.0. if
112+ * 1.0 is set it means that 100% of events are sent. If set to 0.1 only 10% of events will be
113+ * sent. Events are picked randomly. Default is null (disabled)
114+ */
115+ public var sampleRate: Double? = null
116+
117+ /* *
118+ * Configures the sample rate as a percentage of transactions to be sent in the range of 0.0 to
119+ * 1.0. if 1.0 is set it means that 100% of transactions are sent. If set to 0.1 only 10% of
120+ * transactions will be sent. Transactions are picked randomly. Default is null (disabled)
121+ */
122+ public var tracesSampleRate: Double? = null
110123}
Original file line number Diff line number Diff line change 11package io.sentry.kotlin.multiplatform
22
33import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
4+ import io.sentry.kotlin.multiplatform.utils.fakeDsn
45import kotlin.test.Test
56import kotlin.test.assertEquals
67
7- class SentryOptionsTest {
8+ class SentryOptionsTest : BaseSentryTest () {
9+ @Test
10+ fun `GIVEN sample rate WHEN set in Sentry init THEN does not crash` () {
11+ // GIVEN
12+ val sampleRate = 0.5
13+
14+ // WHEN
15+ sentryInit {
16+ it.dsn = fakeDsn
17+ it.sampleRate = sampleRate
18+ }
19+
20+ // THEN
21+ // does not crash
22+ }
23+
24+ @Test
25+ fun `GIVEN traces sample rate WHEN set in Sentry init THEN does not crash` () {
26+ // GIVEN
27+ val traceSampleRate = 0.5
28+
29+ // WHEN
30+ sentryInit {
31+ it.dsn = fakeDsn
32+ it.tracesSampleRate = traceSampleRate
33+ }
34+
35+ // THEN
36+ // does not crash
37+ }
838
939 @Test
1040 fun `Breadcrumb can be modified via callback in init and should return the modified Breadcrumb` () {
You can’t perform that action at this time.
0 commit comments