Coder Social home page Coder Social logo

getsentry / sentry-dart Goto Github PK

View Code? Open in Web Editor NEW
727.0 94.0 224.0 15.13 MB

Sentry SDK for Dart and Flutter

Home Page: https://sentry.io/for/flutter/

License: MIT License

Dart 97.28% Shell 0.21% Kotlin 0.48% CMake 0.34% C++ 0.62% Ruby 0.20% Swift 0.72% Objective-C 0.03% HTML 0.07% CSS 0.01% C 0.04%
dart flutter sentry crash-reporting hacktoberfest tag-production

sentry-dart's People

Contributors

alestiago avatar aliakberaakash avatar bruno-garcia avatar brustolin avatar buenaflor avatar denrase avatar dependabot[bot] avatar dotdoom avatar filiph avatar fzyzcjy avatar getsentry-bot avatar github-actions[bot] avatar kamilogorek avatar kf6gpe avatar krystofwoldrich avatar kuhnroyal avatar m123-dev avatar marandaneto avatar mattjohnsonpint avatar mnordine avatar philipphofmann avatar rxlabz avatar slightfoot avatar stefanosiano avatar truongsinh avatar ueman avatar vaind avatar yjbanov avatar yrom avatar zoechi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sentry-dart's Issues

Add a Debug mode to the sentry plugin

Use case

Sentry's SDKs have a Debug mode which helps troubleshoot issues with the SDK itself.

Proposal

Add the ability to opt-in to internal SDK logging and replace the actual logging object.

Changes:

The SDK still misses a SentryOptions class used to hold options used for initialization of the SDK. That means we'd add:

  • class named SentryOptions and allow initializing the SDK with it
  • boolean option called debug to SentryOptions
  • SDKs like .NET and Android have an abstraction to allow replacing the logger. Consider adding one

This allows us to see what's going on in the SDK when using logcat for example. It'd also be possible to adapt to a logger library so that logs are persisted to disk or sent to a logging aggregation service.

Copied over from flutter/flutter#59075

[sentry_flutter] Sentry will automatically uploads 'Flutter Error', Uncontrolled

On sentry_flutter: ^4.0.0-alpha.2

After initialize sentry, sentry will automatically uploads 'Flutter Error', Uncontrolled. Full code:

// main.dart
import 'dart:async';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:flutter/material.dart';

void main() {
  // release: true, debug|profile: false
  // As suggested by: https://twitter.com/FlutterDev/status/1048278525432791041
  const bool isProduction = const bool.fromEnvironment('dart.vm.product');

  // handle Flutter error
  FlutterError.onError = (FlutterErrorDetails details,) async {
    if (!isProduction) {
      FlutterError.dumpErrorToConsole(details);
      return;
    }
    // turn to Zone
    Zone.current.handleUncaughtError(details.exception, details.stack);
  };

  // Handle dart error
  runZonedGuarded<Future<void>>(() async {
    SentryFlutter.init((options) => options.dsn = 'xxx',
      () {
        runApp(MyApp());
      },
    );
  }, (Object error,  StackTrace stackTrace) async {
    if (!isProduction) {
      print(error);
      print(stackTrace);
      return;
    }
    // Only upload error on release mode
    Sentry.captureException(
      error,
      stackTrace: stackTrace,
    );
  });
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Exception Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
      backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text('Error test'),
        ),
        // https://flutter.dev/docs/testing/common-errors#a-renderflex-overflowed
        body: Row(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("Title", style: Theme.of(context).textTheme.headline4),
                Text(
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed"
                " do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua. Ut enim ad minim veniam, quis nostrud "
                "exercitation ullamco laboris nisi ut aliquip ex ea "
                "commodo consequat."),
              ],
            ),
          ],
        )
      )
    );
  }
}

The above code triggered a Flutter error(layout error).
In debug mode running, Sentry still upload error.

Identify the signed in user after the client is initialized

Setting up Sentry on our flutter app, we instantiate the SentryClient just by adding the dsn param and no other context as instructed. Exceptions get catched in the guarded zone and using FlutterError.onError.

Later on the the execution of the code, a user signs in, so we'd like to add that information to next errors. I don't see a client.identify method, which is the strategy crashlytics uses (what we use now) FirebaseCrashlytics.instance.setUserIdentifier(_currentUser.userId);. We can't add that context on app start, and we can't access current user since it's not global.

How should we make Sentry aware of that context at any point of the code?

Adding context information to events (LoadContextsIntegration)

This might not be a full feature request maybe more of a documentation request, not sure. It is about Flutter integration.

With the 3.x version I have manually built SentryEvents and added all the context information like Device, App, OperatingSystem and so on, using a bunch of different plugins (connectivity, timezone, platform etc.). For me it is not very clear which of this information is now automatically added due to the native integrations. So there are a couple questions that I have not found (fully) answered in code or documentation.

  1. Which device information does the LoadContextsIntegration produce?
  2. Is it planned to support LoadContextsIntegration on Android?
  3. When there are multiple EventProcessors it is currently hard to add information to the nested structure of the event. Only SentryEvent has a copyWith(...) function. Ideally there could be similar copy functions for all the nested context classes so that one could do things like the following which is currently very hard to achieve as all the children have to be rebuild completely.
final connectivityResult = await Connectivity().checkConnectivity();
final online = connectivityResult != ConnectivityResult.none;

return event.copyWith(
  contexts: event.contexts.copyWith(
    device: (event.contexts.device ?? Device()).copyWith(
      online: online,
    ),
  ),
);

Add support to null safety

Flutter is gearing up towards null-safety.

This issue is to track progress adding support to it.

  • Support on sentry #298
  • Support on sentry_flutter #337
  • CI uses new Action #334
  • Rename conflicting classes #250

Related to #99

The migration steps are here: https://dart.dev/null-safety/migration-guide

Important to note we should start by migrating our dependencies to the null safety version.

Sentry.configureScope not synchronize in native

sentry_flutter: ^4.0.0-alpha.2

Sentry.configureScope((Scope scope) async {
    scope.user = User(id: xxx);
});

The user information was set in the flutter and did not synchronize in native(Android).

Hope to add this feature, thanks

[sentry-flutter] Support for navigation Breadcrumbs

I would like to request support for navigation breadcrumbs.

The motivation is, that a developer can better recreate the user flow to track down the reported crash.

This can be implemented using Flutters NavigatorObserver or RouteObserver.

A very simplisitic example of this feature could like this:
(Please note that I haven't confirmed if this actually compiles. It is just meant as an illustration of possible solution.)

import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
  await SentryFlutter.init(
    (options) {
      options.dsn = 'https://[email protected]/add-your-dsn-here';
      // For better groupping, change the 'example' below with your own App's package.
      options.addInAppInclude('sentry_flutter_example');
    },
    () {
        runApp(MyApp())
    },
   );
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: [
        SentryNavigatorObserver(),
      ],
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class SentryNavigatorObserver extends NavigatorObserver {
  void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
    addBreadcrumb(route.settings.name, "wasPushed");
  }

  void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
    addBreadcrumb(route.settings.name, "wasPopped");
  }

  void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) {
    addBreadcrumb(route.settings.name, "wasRemoved");
  }

  void didReplace({ Route<dynamic> newRoute, Route<dynamic> oldRoute }) {
    addBreadcrumb(newRoute.settings.name, "didReplace");
  }

  void addBreadCrumb(String routeName, String type) {
    Sentry.addBreadcrumb(Breadcrumb(
      message: routeName,
      category: "navigation",
      type: type,
    ));
  }

  void didStartUserGesture(Route<dynamic> route, Route<dynamic> previousRoute) { 
        // no breadcrumb needed
  }

  void didStopUserGesture() {
    // no breadcrumb needed
  }
}

Error log about /system/xbin/which not found

On debug mode, on app startup, I am seeing this log:

/Sentry  (24193): sentry-debug-meta.properties file was not found.
I/Sentry  (24193): Initializing SDK with DSN: 'https://xxxxx.ingest.sentry.io/xxxx'
D/Sentry  (24193): SU doesn't exist.
D/Sentry  (24193): java.io.IOException: Cannot run program "/system/xbin/which": error=2, No such file or directory
D/Sentry  (24193): 	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
D/Sentry  (24193): 	at java.lang.Runtime.exec(Runtime.java:698)
D/Sentry  (24193): 	at java.lang.Runtime.exec(Runtime.java:563)
D/Sentry  (24193): 	at io.sentry.android.core.util.RootChecker.checkSUExist(RootChecker.java:135)
D/Sentry  (24193): 	at io.sentry.android.core.util.RootChecker.isDeviceRooted(RootChecker.java:90)
D/Sentry  (24193): 	at io.sentry.android.core.DefaultAndroidEventProcessor.loadContextData(DefaultAndroidEventProcessor.java:114)
D/Sentry  (24193): 	at io.sentry.android.core.DefaultAndroidEventProcessor.lambda$new$0$DefaultAndroidEventProcessor(DefaultAndroidEventProcessor.java:102)
D/Sentry  (24193): 	at io.sentry.android.core.-$$Lambda$DefaultAndroidEventProcessor$NYQ5qA7CeWYLjnxHfVDRm7bpPQ0.call(Unknown Source:2)
D/Sentry  (24193): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
D/Sentry  (24193): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
D/Sentry  (24193): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
D/Sentry  (24193): 	at java.lang.Thread.run(Thread.java:919)
D/Sentry  (24193): Caused by: java.io.IOException: error=2, No such file or directory
D/Sentry  (24193): 	at java.lang.UNIXProcess.forkAndExec(Native Method)
D/Sentry  (24193): 	at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
D/Sentry  (24193): 	at java.lang.ProcessImpl.start(ProcessImpl.java:141)
D/Sentry  (24193): 	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
D/Sentry  (24193): 	... 11 more

It's not causing any crash apparently, but I'd prefer to double check before shipping it :)

  1. Include the output of the command flutter doctor below:
[✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.7 19H15 darwin-x64, locale es-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.51.1)
[✓] Connected device (1 available)

I am using alpha

  sentry_flutter: ^4.0.0-alpha.2

[sentry] Support for HTTP breadcrumbs

I would like to request support for HTTP breadcrumbs for Sentry-Dart.

A possible solution could look like this:

import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:sentry/sentry.dart';

class SentryHttpClient extends http.BaseClient {
  SentryHttpClient(this._inner);

  final http.Client _inner;

  @override
  Future<StreamedResponse> send(BaseRequest request) async {
    final response = await _inner.send(request);
    Sentry.addBreadcrumbs(
      Breadcrumb(
        message: null,
        type: 'http',
        data: {
          'url': request.url.toString(),
          'method': request.method,
          'status_code': response.statusCode.toString(),
          'reason': response.reasonPhrase,
        },
      ),
    );
    return response;
  }
}

Performance Monitoring SDK for Flutter

There is very little support for Flutter web at the moment. However, just want to know if its possible for there to be a support for Flutter SDK. The performance monitoring feature is a amazing and I would like to implementing it in my Flutter web project.

App crash with: tgkill (SIGABRT Abort)

  1. Please describe the issue and how to reproduce it, or link to a small reproducible application:
    When flutter app crashes on Android, I don't know if the error below is the cause of the crash or it's a sentry bug that can't send the stacktrace or something similar (smartlook/smartlook-android-sdk#13)

Screenshot 2020-12-18 at 15 39 59

OS Version: Android 5.1.1 (LMY47V.T280XXU0AQJ1)
Report Version: 104

Exception Type: Unknown (SIGABRT)

Application Specific Information:
Abort

Thread 0 Crashed:
0   libc.so                         0xb6e59eb4          tgkill
1   libc.so                         0xb6e36735          pthread_kill
2   libc.so                         0xb6e3734b          raise
3   libc.so                         0xb6e33be5          <unknown> + 3068345317
4   libc.so                         0xb6e31f74          <unknown> + 3068338036
5   libflutter.so                   0xa2da3cbb          <unknown> + 2732211387
6   <unknown>                       0xa2a495c8          <unknown>
  1. Include the output of the command flutter doctor below:
[✓] Flutter (Channel stable, 1.22.3, on macOS 11.0.1 20B29, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.52.0)

Appreciate if someone share any thoughts about this kind of error.
Thanks!!

Redundant api signatures

Client method calls have redundant naming.

client.captureEvent(event: event);

should be:

client.captureEvent(event);

Same for client.captureException()

Support for user feedback

I would like to request support for Sentry's User Feedback.

I see at least two possibilities on how to do this:

Proposal 1:

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.

Proposal 2:

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.

The function 'runZonedGuarded' isn't defined

  1. Please describe the issue and how to reproduce it, or link to a small reproducible application:
    I am trying to use sentry and i am getting the error undefined method.
    The function 'runZonedGuarded' isn't defined. Try importing the library that defines 'runZonedGuarded', correcting the name to the name of an existing function, or defining a function named 'runZonedGuarded'

  2. Include the output of the command flutter doctor below:

[✓] Flutter (Channel beta, 1.20.2, on Mac OS X 10.14.5 18F132, locale en-GB)
 
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[!] Android Studio (version 3.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

Sentry configureScope in flutter is throwing Error in the 'configureScope' callback.

  1. Please describe the issue and how to reproduce it, or link to a small reproducible application:

I am trying to setup sentry for flutter and while configuring the configureScope it throws

[error] Error in the 'configureScope' callback.

Code:

sentry_flutter: ^4.0.0

main.dart:

import 'package:sentry_flutter/sentry_flutter.dart';
  await SentryFlutter.init((options) {
    options.dsn = ServiceKeys.SENTRY_DSN;
    options.useFlutterBreadcrumbTracking();
    options.useNativeBreadcrumbTracking();
  });

log.dart

    import 'package:sentry_flutter/sentry_flutter.dart';

    Sentry.configureScope((scope) => scope
      ..setTag('App version', '1.1.1+1')
      ..user = User(
              id: '1234',
              email: '[email protected]',
            );

    Sentry.captureException(
      _errorBody,
      stackTrace: stackTrace,
    );

Interestingly, the errors aren't showing up in the sentry dashboard when I use sentry_flutter package, but when I use the sentry package, instead, the exceptions are getting logged and the configureScope works perfectly alright.

What do I do?

  1. Include the output of the command flutter doctor below:
[✓] Flutter (Channel stable, 1.22.3, on Mac OS X 10.15.6 19G73, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version
    29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Connected device (1 available)

Change sentry default Ip Address

I install self host sentry by docker. In my flutter Application by using runZonedGuarded:

void main() => runZonedGuarded(() async {
      await SentryFlutter.init(
        (options) {
          options.dsn =
              "http://[email protected]:9000/2";
          options.debug = true;
        },
        appRunner: () => runApp(MyApp()),
      );
    }, (exception, StackTrace stackTrace) async {
      await Sentry.captureException(
        exception,
        stackTrace: stackTrace,
      );
    });

I am trying to report exception on Android emulator but i got:
java.net.ConnectException: Failed to connect to /127.0.0.1:9000

How can i change 127.0.0.1 on sentry ?It is possible to change from dashboard?

Provide a way to cause an example native crash from Flutter

I am trying to migrate from the flutter_sentry package which has this option.
In hindsight I found myself using this often to test the correct integration.

It would be great if there was something like SentryFlutter.nativeCrash() which would use the method channel to create an example crash on the native side.

Add the build version to the reports

Hi,

Everytime I see crashes into the Sentry Console, I'm unable to know which app version has encountered the bug. The crash report doesn't specify the app version (build version).
I tried to manually specify it in the Sentry initialization but there are no methods for that yet.

Do you plan to add it in a near future ? This is very hard to know if the crash has been fixed in newer versions because we can't see which app version the user has got neither if it's an Android or Apple device.

Best regards,

dependencies: sentry: ">=4.0.0 <5.0.0" not working

  1. Please describe the issue and how to reproduce it, or link to a small reproducible application:

Added version in flutter project

dependencies:
sentry: ">=4.0.0 <5.0.0"

However am getting the error
Because app depends on sentry ^4.0.0 which doesn't match any versions, version solving failed.
pub get failed (1; Because app depends on sentry ^4.0.0 which doesn't match any versions, version solving failed.)

  1. Include the output of the command flutter doctor below:

Consider changing Breadcrumb.data from Map<String, String> to Map<String, dynamic>

Sentry accepts the breadcrumb data as complex JSON content.
This is currently not possible to send as the data field is currently final Map<String, String> data;.

Other SDKs also accept object types as values.
When the data fields are JSON objects, data scrubbing would work on the fields. Atm I have to transform objects to Strings and data scrubbing doesn't work.

Btw, the issue templates are still for the sentry_flutter package if anyone can change this.

Min Dart SDK version

We're releasing 4.0.0 which is a big major version so it's time to discuss the min Dart SDK version we want to support on the sentry package.

Important notes:

  • Dart just released 2.10
  • Extension methods were introduced on 2.7
  • 2.7 was introduced in December 2019
  • Flutter's new releases often update to the latest Dart SDK version
    • i.e: Version note: As of Flutter 1.21, the Flutter SDK includes the full Dart SDK. This site’s documentation and examples use version 2.10.0 of the Dart SDK.

I'd propose we set the min version to 2.7:

sdk: ^2.0.0

To clarify: What would we leaving behind? Is there a reason folks using AngularDart can't be on Dart 2.7?

Sentry doesn't log dart errors (it logs only Flutter-specific errors)

I tried to implement sentry package to my Flutter application.
It happens to successfully log Flutter-specific errors (like UI crashes or Platform Exceptions), but when it comes to logging the non-crashing exceptions (or dart errors) - it just fails.
I tried with runZoned, but it doesn't work also.
Here's my code:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  RemoteConfigModel remoteConfigModel = GetIt.instance<RemoteConfigModel>();
  
SentryClient sentryClient = new SentryClient(dsn: remoteConfigModel.sentryDSN);
  runZonedGuarded( () {
           runApp(MyApp());
        },
        (Object error, StackTrace stackTrace) {
            print("Enters onError.");
            try {
                sentryClient.captureException(
                  exception: error,
                  stackTrace: stackTrace,
                );
            } catch (e) {
              debugPrint("ERROR::: Logging in sentry failed. Exception $e");
              debugPrint('Original error: $error');
            }
          }
  );
  
  FlutterError.onError = (details, {bool forceReport = false}) {
    debugPrint("Flutter-specific error.");
    try {
        sentryClient.captureException(
          exception: details.exception,
          stackTrace: details.stack,
        );
    } catch (e) {
      print('Sending report to sentry.io failed: $e');
    } finally {
      FlutterError.dumpErrorToConsole(details, forceReport: forceReport);
    }
  };
}

Add Sentry static API

We'd like to add the Sentry static API to Dart:

https://develop.sentry.dev/sdk/unified-api/#static-api

the idea is one will be able to Sentry.captureException(x), Sentry.captureMessage(x), Sentry.captureEvent(x), Sentry.init(options -> {})
Today the SDK is initialized via SentryClient which has no Hub and Scope.

https://github.com/getsentry/sentry-java/blob/main/sentry/src/main/java/io/sentry/Sentry.java#L104-L111

we don't need to care for globalHubMode that we have on Java.
Also, we don't need a ThreadLocal on Dart because the language is already single-threaded (is that the right term?).

This issue could have sub-issues like:

  • Adding SentryOptions to configure the SDK (only the bare min. now)
  • Adding a diagnostic logger (so we can log the SDK ops)
  • Adding the Hub
  • Adding the Scope class (we can start with the bare min. as well)
  • Adding a Breadcrumb ring buffer (it doesn't need to be thread-safe because of Dart)

So TLDR:

The Sentry.init creates a Hub, the Hub creates and maintains a SentryClient and a Scope.
See the workflow: https://develop.sentry.dev/sdk/unified-api/#simplified-visualization

We could have a feature branch for this issue as we'd need to collaborate together, and each item of this task would depend on each other.

Reporting on native crashes ?

  1. Please describe the issue and how to reproduce it, or link to a small reproducible application:

We have a production app that crashes under certain conditions. The crash does not seem to be reported in Sentry.

  1. Include the output of the command flutter doctor below:

not relevant

--

Would Sentry pick up a native code crash, f.e. something with a plugin or an exception not happening in dart/flutter?

I can see the source code asks for Sentry cocoa sdk to be installed and configured. Just wanted to double check before we go around adding native Sentry SDK libraries as well to catch additional errors.

Thanks!

Error while sending more throughout FlutterErrorDetails

  1. Please describe the issue and how to reproduce it, or link to a small reproducible application:
    I'm trying to get a better and more details error report but I get the following exception
E/FileObserver(13655): Unhandled exception in FileObserver io.sentry.android.core.EnvelopeFileObserver@94251ab
E/FileObserver(13655): java.lang.IllegalArgumentException: Invalid envelope. Item at index '1'. has no header delimiter.
E/FileObserver(13655): 	at io.sentry.EnvelopeReader.read(EnvelopeReader.java:80)
E/FileObserver(13655): 	at io.sentry.OutboxSender.processFile(OutboxSender.java:60)
E/FileObserver(13655): 	at io.sentry.OutboxSender.processEnvelopeFile(OutboxSender.java:100)
E/FileObserver(13655): 	at io.sentry.android.core.EnvelopeFileObserver.onEvent(EnvelopeFileObserver.java:58)
E/FileObserver(13655): 	at android.os.FileObserver$ObserverThread.onEvent(FileObserver.java:163)
E/FileObserver(13655): 	at android.os.FileObserver$ObserverThread.observe(Native Method)
E/FileObserver(13655): 	at android.os.FileObserver$ObserverThread.run(FileObserver.java:113)

To reproduce the issue checkout this branch and press the Open Scaffold with UI error button.

It only happens on Android, iOS works just fine.

  1. Include the output of the command flutter doctor below:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.0.1 20B29 darwin-x64, locale de-DE)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
[!] Android Studio (version 4.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.51.1)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.

Motivation

This change in the linked branch improve the error message from

FlutterError
A RenderFlex overflowed by 1175 pixels on the right.

to


════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 1175 pixels on the right.

The relevant error-causing widget was
Row
lib/scaffold_with_ui_error.dart:33
The overflowing RenderFlex has an orientation of Axis.horizontal.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#550f0 OVERFLOWING
════════════════════════════════════════════════════════════════════════════════

This is really helpful as it includes the class from which the error was thrown.

Support Source Context

Originally posted on flutter: flutter/flutter#63276

Users would like to see the source context around the stack trace. This is a feature supported in Python, JavaScript and other script languages. Native has this support with source bundles.

Relates to (Java, .NET)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.