I would like to request support for Sentry's User Feedback.
I see at least two possibilities on how to do this:
By providing a more elaborate SentryFlutter.captureException like for example:
SentryFlutter.captureException(
exception: error,
stackTrace: stackTrace,
context: context, // this is a BuildContext
);
With a BuildContext one can show a dialog (see showDialog) which can be used to gather the user's feedback.
Another option would be by overriding ErrorWidget.builder (aka Flutter's infamous Red Screen of Death).
This way one could could also capture and report the errors which get passed into ErrorWidget.builder. These are errors
which are happening during the creation of the UI.
An example (more or less pseudo code):
// We assume SentryOptions has a ErrorWidgetBuilder named errorWidgetBuilder which can be defined by the user.
// By providing the same callback it is easy to migrate to this.
class UserFeedback {
// ...
}
class UserFeedbackErrorWidget extends StatefulWidget {
const YellowBird({ Key key, this.details, this.options }) : super(key: key);
final FlutterErrorDetails details;
final SentryOptions options;
@override
_UserFeedbackErrorWidgetState createState() => _UserFeedbackErrorWidgetState();
}
class _UserFeedbackErrorWidgetState extends State<UserFeedbackErrorWidget> {
@override
void initState(){
super.initState();
// one can't open a dialog in initState
// see https://stackoverflow.com/questions/51766977/flutter-showdialogcontext-in-initstate-method
Future.delayed(Duration.zero, askForUserFeedback)
}
@override
Widget build(BuildContext context) {
// This way a user defined widget is shown inline in the ui.
// It's nice for the user, because it is not very intrusive.
return options.errorWidgetBuilder(widget.details);
}
Future<void> askForUserFeedback() {
final error = widget.details;
final sentryId = await Sentry.captureException(error);
// showDialog returns what is given to Navigator.pop(...)
final feedback = await showDialog<UserFeedback>(context, (innerContext){
// show dialog, where the user can input additional information and return it
return UserFeedbackDialog(
onSubmit: (feedback) => Navigator.pop(innerContext, feedback)
);
});
await Sentry.sendFeedback(sentryId, feedback);
}
}
Now we can set ErrorWidget.builder inside an Integration with
ErrorWidget.builder = (FlutterErrorDetails details) => UserFeedbackErrorWidget(details: details, options: sentryOptions);
I guess providing both options would be optimal.
If there are any questions, I'm happy to help.
hey @ueman thanks for this.
The Proposal 2 sounds better and similar to our Native implementations (Android and iOS).
Ideally, we'd offer only a Sentry.captureUserFeedback(...) method.
See: https://github.com/getsentry/sentry-java/blob/main/sentry/src/main/java/io/sentry/Sentry.java#L296-L303
and its documentation https://docs.sentry.io/platforms/android/enriching-events/user-feedback/
UI usually is always written by the final Apps, so I don't think we should include a Sentry's UI Dialog or something, but only the way to input the data and send it over (connecting to a previous event).
To get User Feedback added to the Dart SDK, we will need to get the specs (that will be added through this issue). But we need to implement Envelope support in Dart, to call the envelope endpoint and handle the new rate limit.
The alternative of using the native SDKs will mean that it will only work for iOS and Android (not Web, or Desktop when it comes out). We could do that for the time being though since iOS and Android are the only official supported platforms.
One blocker to get this to work on Android, is this issue: https://github.com/getsentry/sentry-java/issues/1103
I would love user feedback on the web, don't need Flutter at all, and this shouldn't be a Flutter-only thing.
Depends on: #344
Looks like #344 is closed now and this is unblocked. Thanks @ueman!
@denrase worked on it, not me 馃榿
But yeah, now that envelope support has landed there's a lot of new features coming.
User Feedback is one of them.
Oh, whoops!! I must have been looking at something else. Sorry to mis-credit, @denrase! _Super_ excited about seeing that PR land + other things unblocked. Using Sentry everywhere is going to be a _game changer_ for our dev team.
Most helpful comment
I would love user feedback on the web, don't need Flutter at all, and this shouldn't be a Flutter-only thing.