-
-
Notifications
You must be signed in to change notification settings - Fork 266
Report Flutter framework feature flags #2991
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
Open
ueman
wants to merge
19
commits into
getsentry:main
Choose a base branch
from
ueman:add-framework-feature-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−1
Open
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e61bb9f
Add framework feature flags
ueman e91d492
explanation how that works
ueman 0240727
extract constant
ueman 3716ca5
changelog
ueman c04a532
Merge branch 'main' into add-framework-feature-flags
ueman f14ca90
Merge branch 'main' into add-framework-feature-flags
ueman 20d5c01
Merge branch 'main' into add-framework-feature-flags
ueman cb4f4b4
add tests
ueman b0fa43f
format
ueman 8cc7f7e
Merge branch 'main' into add-framework-feature-flags
ueman f8946dd
Change integration name
ueman 23deec5
tests are complete
ueman 8b94e60
Merge branch 'main' into add-framework-feature-flags
ueman 1f82112
Merge branch 'main' into add-framework-feature-flags
ueman b54db3c
Update CHANGELOG.md
ueman 2ff79f5
Merge branch 'main' into add-framework-feature-flags
buenaflor 4d09084
prefix flags
ueman 1d6314e
Update flutter/lib/src/integrations/flutter_framework_feature_flag_in…
ueman 8e94480
Merge branch 'main' into add-framework-feature-flags
ueman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
flutter/lib/src/integrations/flutter_framework_feature_flag_integration.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:sentry/sentry.dart'; | ||
|
||
const _featureFlag = 'FLUTTER_ENABLED_FEATURE_FLAGS'; | ||
|
||
// The Flutter framework feature flag works like this: | ||
// An enabled (experimental) feature gets added to the `FLUTTER_ENABLED_FEATURE_FLAGS` | ||
// dart define. Being in there means the feature is enabled, the feature is disabled | ||
// if it's not in there. | ||
// As a result, we also don't know the whole list of flags, but only the active ones. | ||
// | ||
// See https://github.com/flutter/flutter/pull/168437 | ||
ueman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class FlutterFrameworkFeatureFlagIntegration | ||
extends Integration<SentryOptions> { | ||
final String flags; | ||
|
||
FlutterFrameworkFeatureFlagIntegration({ | ||
@visibleForTesting this.flags = const String.fromEnvironment(_featureFlag), | ||
}); | ||
|
||
@override | ||
FutureOr<void> call(Hub hub, SentryOptions options) { | ||
final enabledFeatureFlags = flags.split(','); | ||
|
||
for (final featureFlag in enabledFeatureFlags) { | ||
Sentry.addFeatureFlag(featureFlag, true); | ||
ueman marked this conversation as resolved.
Show resolved
Hide resolved
ueman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
options.sdk.addIntegration('FlutterFrameworkFeatureFlag'); | ||
} | ||
} | ||
|
||
extension FlutterFrameworkFeatureFlagIntegrationX | ||
on List<Integration<SentryOptions>> { | ||
/// For better tree-shake-ability we only add the integration if any feature flag is enabled. | ||
void addFlutterFrameworkFeatureFlagIntegration() { | ||
if (const bool.hasEnvironment(_featureFlag)) { | ||
add(FlutterFrameworkFeatureFlagIntegration()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
flutter/test/integrations/flutter_framework_feature_flag_integration_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:sentry/sentry.dart'; | ||
import 'package:sentry_flutter/src/integrations/flutter_framework_feature_flag_integration.dart'; | ||
|
||
void main() { | ||
group(FlutterFrameworkFeatureFlagIntegration, () { | ||
late Fixture fixture; | ||
|
||
setUp(() async { | ||
fixture = Fixture(); | ||
|
||
await Sentry.init((options) { | ||
options.dsn = 'https://example.com/sentry-dsn'; | ||
}); | ||
|
||
// ignore: invalid_use_of_internal_member | ||
fixture.hub = Sentry.currentHub; | ||
// ignore: invalid_use_of_internal_member | ||
fixture.options = fixture.hub.options; | ||
}); | ||
|
||
tearDown(() { | ||
Sentry.close(); | ||
}); | ||
|
||
test('adds sdk integration', () { | ||
final sut = fixture.getSut('foo,bar,baz'); | ||
sut.call(fixture.hub, fixture.options); | ||
|
||
expect( | ||
fixture.options.sdk.integrations | ||
.contains('FlutterFrameworkFeatureFlag'), | ||
true); | ||
}); | ||
|
||
test('adds feature flags', () { | ||
final sut = fixture.getSut('foo,bar,baz'); | ||
sut.call(fixture.hub, fixture.options); | ||
|
||
// ignore: invalid_use_of_internal_member | ||
final featureFlags = fixture.hub.scope.contexts[SentryFeatureFlags.type] | ||
as SentryFeatureFlags?; | ||
|
||
expect(featureFlags, isNotNull); | ||
expect(featureFlags?.values.length, 3); | ||
expect(featureFlags?.values.first.flag, 'foo'); | ||
expect(featureFlags?.values.first.result, true); | ||
expect(featureFlags?.values[1].flag, 'bar'); | ||
expect(featureFlags?.values[1].result, true); | ||
expect(featureFlags?.values[2].flag, 'baz'); | ||
expect(featureFlags?.values[2].result, true); | ||
}); | ||
}); | ||
} | ||
|
||
class Fixture { | ||
late Hub hub; | ||
late SentryOptions options; | ||
|
||
FlutterFrameworkFeatureFlagIntegration getSut(String features) { | ||
return FlutterFrameworkFeatureFlagIntegration(flags: features); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I'm sure you're aware but this reaches into Flutter internals that aren't meant to be public. This isn't covered by Flutter's breaking change policy. I'd assume the format of
FLUTTER_ENABLED_FEATURE_FLAGS
can and will change, even in a patch release. The current changes seem reasonable, but I'd consider documenting this so that future contributors are aware as well.