Skip to content

Commit 3f8357e

Browse files
authored
Set addFeatureFlag value parameter to dynamic and ignore non-boolean values (#2849)
* Set feature flag api to dynamic and ignore non-boolean values * Update test name * Format
1 parent f249f33 commit 3f8357e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

dart/lib/src/sentry.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ class Sentry {
360360
/// Gets the current active transaction or span bound to the scope.
361361
static ISentrySpan? getSpan() => _hub.getSpan();
362362

363-
static Future<void> addFeatureFlag(String name, bool value) async {
363+
static Future<void> addFeatureFlag(String name, dynamic value) async {
364+
if (value is! bool) {
365+
return;
366+
}
367+
364368
final featureFlagsIntegration = currentHub.options.integrations
365369
.whereType<FeatureFlagsIntegration>()
366370
.firstOrNull;

dart/test/sentry_test.dart

+16-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void main() {
301301
);
302302
}, onPlatform: {'vm': Skip()});
303303

304-
test('should add feature flagg FeatureFlagsIntegration', () async {
304+
test('should add feature flag FeatureFlagsIntegration', () async {
305305
await Sentry.init(
306306
options: defaultTestOptions(),
307307
(options) => options.dsn = fakeDsn,
@@ -321,6 +321,21 @@ void main() {
321321
);
322322
});
323323

324+
test('addFeatureFlag should ignore non-boolean values', () async {
325+
await Sentry.init(
326+
options: defaultTestOptions(),
327+
(options) => options.dsn = fakeDsn,
328+
);
329+
330+
await Sentry.addFeatureFlag('foo1', 'some string');
331+
await Sentry.addFeatureFlag('foo2', 123);
332+
await Sentry.addFeatureFlag('foo3', 1.23);
333+
334+
final featureFlagsContext =
335+
Sentry.currentHub.scope.contexts[SentryFeatureFlags.type];
336+
expect(featureFlagsContext, isNull);
337+
});
338+
324339
test('should close integrations', () async {
325340
final integration = MockIntegration();
326341

0 commit comments

Comments
 (0)