Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: add-sample-rate-native #2200

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ class SentryFlutter(
data.getIfNotNull<Map<String, Any>>("replay") {
updateReplayOptions(options.experimental.sessionReplay, it)
}

data.getIfNotNull<Double>("sampleRate") {
options.sampleRate = it
}
}

fun updateReplayOptions(
Expand All @@ -168,7 +172,5 @@ private fun <T> Map<String, Any>.getIfNotNull(
key: String,
callback: (T) -> Unit,
) {
(get(key) as? T)?.let {
callback(it)
}
(get(key) as? T)?.let(callback)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -157,6 +159,7 @@ class Fixture {
"sessionSampleRate" to 0.5,
"onErrorSampleRate" to 0.6,
),
"sampleRate" to 0.751
)

fun getSut(): SentryFlutter =
Expand Down
5 changes: 4 additions & 1 deletion flutter/example/ios/RunnerTests/SentryFlutterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
)

Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions flutter/ios/Classes/SentryFlutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions flutter/lib/src/native/sentry_native_channel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

// backcompatibility for Flutter < 3.3
// ignore: unnecessary_import
import 'dart:typed_data';
Expand Down Expand Up @@ -71,6 +72,7 @@ class SentryNativeChannel
'sessionSampleRate': options.experimental.replay.sessionSampleRate,
'onErrorSampleRate': options.experimental.replay.onErrorSampleRate,
},
'sampleRate': options.sampleRate
});
}

Expand Down
6 changes: 5 additions & 1 deletion flutter/test/integrations/init_native_sdk_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void main() {
'sessionSampleRate': null,
'onErrorSampleRate': null,
},
'sampleRate': null,
});
});

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -174,6 +176,7 @@ void main() {
'sessionSampleRate': 0.1,
'onErrorSampleRate': 0.2,
},
'sampleRate': 0.751,
});
});
}
Expand All @@ -200,6 +203,7 @@ SentryFlutterOptions createOptions() {

class Fixture {
late SentryFlutterOptions options;

SentryNativeChannel getSut(MethodChannel channel) {
options = createOptions()..methodChannel = channel;
return SentryNativeChannel(options);
Expand Down
Loading