Brother Cat said
This Sentry is an error collection platform solution, and personal projects are free.
Now it is very mature for Flutter, and can collect errors from Dart, Flutter, and native terminals at the same time.
Brother Mao built the Sentry service by himself in the enterprise, which can be privatized.
Old iron remember to forward, Brother Mao will present more Flutter good articles~~~~
WeChat group ducafecat
b Station https://space.bilibili.com/404904528
original
https://medium.com/podiihq/error-reporting-using-sentry-in-flutter-c4e7c8030b88
Code
In this way, you will be able to monitor and get notifications of errors and resolve them in advance before customers start complaining. Because the work code == happy customers.
reference
text
Imagine that you are an independent developer. You develop a new feature before you go on vacation, and you deploy it to the production environment a few days before the weekend. When customers start to use it actively, users’ problems and complaints begin to appear, and you Your holiday mood has been opened. As the usual slogan says, "Customers are always right", you decide to prioritize customer satisfaction over vacations and restore your work mood. It can be frustrating, right?
The following is how to report errors to the service, so as to avoid unknown potential errors or problems before the customer, because the working code is equivalent to the satisfied customer.
You can report code errors to many services. However, in this article, you will learn how to monitor applications and potential errors or bugs, and use Sentry to report them.
What is Sentry?
Sentry is an application monitoring platform that enables developers to monitor, diagnose, repair, and optimize the performance of their code.
let's start
Create an account with Sentry
If you don’t have an account on Sentry yet, create one here:
Create a new Sentry Flutter app
Next, log in to the Sentry account you just created and create a Flutter application.
Follow the steps below to successfully create a new project.
- Create a new project
After logging in, select the create project icon to create a new project.
- Choose a development platform
There are various development platforms that support Sentry, including Python, Express, Spring Boot, Android, etc., but this article only focuses on Flutter. Therefore, select Flutter from the list.
- Set default alert settings
Next, set the default alert settings to the frequency of when and how to get alerts in the event of any errors. In this article, I will choose the option to get alerts for any new issues, but you can always choose any option you want.
- Finally, give your project a name
In this article, I will name it Flutter Test, and then create the project.
- Get DSN from Sentry
In order to report errors to Sentry, you need a DSN (data source name), which will uniquely identify your application with the Sentry service. Therefore, after creating the project on Sentry, we will copy the DSN from the application created in the steps above.
To get the DSN, in the project you just created from above, navigate to the project settings and scroll down to the client key (DSN) as shown below:
Next, after selecting the client key, the client key tab will be displayed, from there you will copy the DSN as shown below:
Create a Flutter application to report errors to Sentry
This step assumes that you already have some practical experience on how to create a new Flutter project. If you are new to Flutter, check the official Flutter documentation. You can also check out my article "How to Start with Flutter"
Now let's create a sample Flutter application for reporting errors to the Sentry service.
On the terminal, enter $flutter create Command followed by the name of the application. In this case, we will use the name flutter sentry test.
$ flutter create flutter_sentry_test
Note: You can also create applications in their respective IDEs according to your preferences.
Import the Flutter Sentry package
Install Sentry in the application and add it to the pubspec.yaml file
Configure and initialize Sentry SDK
In the main.dart file, import the sentry package.
Next, add a configuration that will catch unhandled exceptions in the application. In this step, replace the DSN url with the Sentry DSN in the application you created in step 2. Get a DSN from Sentry above.
You can also configure SENTRY \_ dsn through Dart environment variables by passing the - Dart-define flag to the compiler, as shown in the following example:
--dart-define SENTRY_DSN = 'https://your-sentry.io DSN'
verification
Finally, in this step, for testing purposes, verify whether an error was sent by adding a conscious error to the code.
This will throw a State Error, which will be sent to the Sentry.io service
You can confirm this by navigating to your Sentry app
In my case, here is the State Error sent to my Flutter Sentry application
The following is a demonstration of how the sample application sends errors to Sentry:
Click here to view the complete code snippet:
https://github.com/JosephineAkello/flutter_sentry_test
In this way, you will be able to monitor and get notifications of errors and resolve them in advance before customers start complaining. Because the work code == happy customers.
© Cat brother
Past
Open source
GetX Quick Start
https://github.com/ducafecat/getx_quick_start
News client
https://github.com/ducafecat/flutter_learn_news
strapi manual translation
WeChat discussion group ducafecat
Series collection
Translation
https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/
Open source project
https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/
Dart programming language basics
https://space.bilibili.com/404904528/channel/detail?cid=111585
Getting started with Flutter zero foundation
https://space.bilibili.com/404904528/channel/detail?cid=123470
Flutter actual combat from scratch news client
https://space.bilibili.com/404904528/channel/detail?cid=106755
Flutter component development
https://space.bilibili.com/404904528/channel/detail?cid=144262
Flutter Bloc
https://space.bilibili.com/404904528/channel/detail?cid=177519
Flutter Getx4
https://space.bilibili.com/404904528/channel/detail?cid=177514
Docker Yapi
https://space.bilibili.com/404904528/channel/detail?cid=130578
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。