diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d7b75b7bf..c59182f1d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - Fixes ([#2103](https://github.com/getsentry/sentry-dart/issues/2103)) - Fixes ([#2233](https://github.com/getsentry/sentry-dart/issues/2233)) +### Fixes + +- Pass `sampleRate` to native SDKs ([#2200](https://github.com/getsentry/sentry-dart/pull/2200)) + ## 8.9.0 ### Features diff --git a/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt b/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt index d38872f6ee..a70478e6c1 100644 --- a/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt +++ b/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt @@ -151,6 +151,10 @@ class SentryFlutter( data.getIfNotNull>("replay") { updateReplayOptions(options.experimental.sessionReplay, it) } + + data.getIfNotNull("sampleRate") { + options.sampleRate = it + } } fun updateReplayOptions( @@ -168,7 +172,5 @@ private fun Map.getIfNotNull( key: String, callback: (T) -> Unit, ) { - (get(key) as? T)?.let { - callback(it) - } + (get(key) as? T)?.let(callback) } diff --git a/flutter/android/src/test/kotlin/io/sentry/flutter/SentryFlutterTest.kt b/flutter/android/src/test/kotlin/io/sentry/flutter/SentryFlutterTest.kt index efab672972..c8376b9c9f 100644 --- a/flutter/android/src/test/kotlin/io/sentry/flutter/SentryFlutterTest.kt +++ b/flutter/android/src/test/kotlin/io/sentry/flutter/SentryFlutterTest.kt @@ -71,6 +71,8 @@ class SentryFlutterTest { assertEquals(0.5, fixture.options.experimental.sessionReplay.sessionSampleRate) assertEquals(0.6, fixture.options.experimental.sessionReplay.errorSampleRate) + assertEquals(0.751, fixture.options.sampleRate) + // Note: these are currently read-only in SentryReplayOptions so we're only asserting the default values here to // know when there's a change in the native SDK, as it may require a manual change in the Flutter implementation. assertEquals(1, fixture.options.experimental.sessionReplay.frameRate) @@ -157,6 +159,7 @@ class Fixture { "sessionSampleRate" to 0.5, "onErrorSampleRate" to 0.6, ), + "sampleRate" to 0.751 ) fun getSut(): SentryFlutter = diff --git a/flutter/example/ios/RunnerTests/SentryFlutterTests.swift b/flutter/example/ios/RunnerTests/SentryFlutterTests.swift index 4873388f2f..57dddc7100 100644 --- a/flutter/example/ios/RunnerTests/SentryFlutterTests.swift +++ b/flutter/example/ios/RunnerTests/SentryFlutterTests.swift @@ -52,7 +52,8 @@ final class SentryFlutterTests: XCTestCase { "type": "hTtP", // mixed case to check enum mapping "user": "admin", "pass": "0000" - ] + ], + "sampleRate": NSNumber(value: 0.5) ] ) @@ -84,6 +85,8 @@ final class SentryFlutterTests: XCTestCase { XCTAssertEqual(8080, fixture.options.urlSession?.configuration.connectionProxyDictionary?[kCFNetworkProxiesHTTPPort as String] as? Int) XCTAssertEqual("admin", fixture.options.urlSession?.configuration.connectionProxyDictionary?[kCFProxyUsernameKey as String] as? String) XCTAssertEqual("0000", fixture.options.urlSession?.configuration.connectionProxyDictionary?[kCFProxyPasswordKey as String] as? String) + + XCTAssertEqual(0.5, fixture.options.sampleRate) } func testUpdateSocksProxy() { diff --git a/flutter/ios/Classes/SentryFlutter.swift b/flutter/ios/Classes/SentryFlutter.swift index 987528987c..467f66cd9e 100644 --- a/flutter/ios/Classes/SentryFlutter.swift +++ b/flutter/ios/Classes/SentryFlutter.swift @@ -113,6 +113,9 @@ public final class SentryFlutter { (replayOptions["onErrorSampleRate"] as? NSNumber)?.floatValue ?? 0 } #endif + if let sampleRate = data["sampleRate"] as? NSNumber { + options.sampleRate = sampleRate + } } private func logLevelFrom(diagnosticLevel: String) -> SentryLevel { diff --git a/flutter/lib/src/native/sentry_native_channel.dart b/flutter/lib/src/native/sentry_native_channel.dart index 1e4faf4494..767b0bebc9 100644 --- a/flutter/lib/src/native/sentry_native_channel.dart +++ b/flutter/lib/src/native/sentry_native_channel.dart @@ -1,4 +1,5 @@ import 'dart:async'; + // backcompatibility for Flutter < 3.3 // ignore: unnecessary_import import 'dart:typed_data'; @@ -71,6 +72,7 @@ class SentryNativeChannel 'sessionSampleRate': options.experimental.replay.sessionSampleRate, 'onErrorSampleRate': options.experimental.replay.onErrorSampleRate, }, + 'sampleRate': options.sampleRate }); } diff --git a/flutter/test/integrations/init_native_sdk_test.dart b/flutter/test/integrations/init_native_sdk_test.dart index 6f84e946f5..0184aecc2d 100644 --- a/flutter/test/integrations/init_native_sdk_test.dart +++ b/flutter/test/integrations/init_native_sdk_test.dart @@ -69,6 +69,7 @@ void main() { 'sessionSampleRate': null, 'onErrorSampleRate': null, }, + 'sampleRate': null, }); }); @@ -118,7 +119,8 @@ void main() { pass: '0000', ) ..experimental.replay.sessionSampleRate = 0.1 - ..experimental.replay.onErrorSampleRate = 0.2; + ..experimental.replay.onErrorSampleRate = 0.2 + ..sampleRate = 0.751; fixture.options.sdk.addIntegration('foo'); fixture.options.sdk.addPackage('bar', '1'); @@ -174,6 +176,7 @@ void main() { 'sessionSampleRate': 0.1, 'onErrorSampleRate': 0.2, }, + 'sampleRate': 0.751, }); }); } @@ -200,6 +203,7 @@ SentryFlutterOptions createOptions() { class Fixture { late SentryFlutterOptions options; + SentryNativeChannel getSut(MethodChannel channel) { options = createOptions()..methodChannel = channel; return SentryNativeChannel(options);