Skip to content

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
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Add `message` parameter to `captureException()` ([#2882](https://github.com/getsentry/sentry-dart/pull/2882))
- Report Flutter framework feature flags ([#2991](https://github.com/getsentry/sentry-dart/pull/2991))

## 9.0.0

Expand Down
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

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.

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);
}
options.sdk.addIntegration('FlutterFrameworkFeatureFlagIntegration');
}
}

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());

Check warning on line 39 in flutter/lib/src/integrations/flutter_framework_feature_flag_integration.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/integrations/flutter_framework_feature_flag_integration.dart#L39

Added line #L39 was not covered by tests
}
}
}
4 changes: 4 additions & 0 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'file_system_transport.dart';
import 'flutter_exception_type_identifier.dart';
import 'frame_callback_handler.dart';
import 'integrations/connectivity/connectivity_integration.dart';
import 'integrations/flutter_framework_feature_flag_integration.dart';
import 'integrations/frames_tracking_integration.dart';
import 'integrations/integrations.dart';
import 'integrations/native_app_start_handler.dart';
Expand Down Expand Up @@ -172,6 +173,9 @@ mixin SentryFlutter {
// This tracks Flutter application events, such as lifecycle events.
integrations.add(WidgetsBindingIntegration());

// Adds Flutter framework feature flags.
integrations.addFlutterFrameworkFeatureFlagIntegration();

// The ordering here matters, as we'd like to first start the native integration.
// That allow us to send events to the network and then the Flutter integrations.
final native = _native;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/src/integrations/flutter_framework_feature_flag_integration.dart';

import '../mocks.dart';
import '../mocks.mocks.dart';

void main() {
group(FlutterFrameworkFeatureFlagIntegration, () {
test('adds sdk integration', () {
final options = defaultTestOptions();
FlutterFrameworkFeatureFlagIntegration(flags: 'foo,bar,baz')
.call(MockHub(), options);

expect(
options.sdk.integrations
.contains('FlutterFrameworkFeatureFlagIntegration'),
true);
});

test('adds feature flags', () {
final options = defaultTestOptions();
FlutterFrameworkFeatureFlagIntegration(flags: 'foo,bar,baz')
.call(MockHub(), options);

// TODO what expect to write here?
});
});
}
Loading