Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Today, Iâm going to tell you about a real-time errors tracking in React application. The frontend app usually doesnât use error tracking. Some companies often postpone error tracking, coming back to it after documentation, tests, and other things. However, if you can change your product for the better, Just do it!
đ Plan:
- Why do you need Sentry?
- Sign In and create a project
- Integrate Sentry in app
- First error tracking
- Use Sentry with APIÂ Endpoint
1. Why do you need Sentry?
I assume you are interested in real litem error tracking in production
Do you think thatâs not enough? đ
Okay, letâs look at the details.
The main reasons for developers:
- Getting rid of risks to deploy code with bugs
- Helping QA with testing code
- Getting a quick notification about troubles
- Allowing a fast turnaround with bug fixes
- Receiving a convenient display errors in admin panel
- Sorting the errors by user / browser segments
The main reasons for CEO / Lead Project
- Saving money
- Getting userâs feedback
- Understanding what is wrong with your project in real time
- Understanding the number of issues people are having with your app
- Finding where your developers have messed up đ
I think developers would be interested in this article primarily. You also can use this list of reasons to convince the superiors to integrate Sentry.
đĄ Be careful with the last item in list for business. đ
Are you interested already?
Sentry is Open-source error tracking that helps developers to monitor, fix crashes in real time. Donât forget about boosting the efficiency, improving user experience. Sentry has support for JavaScript, Node, Python, PHP, Ruby, Java and other programming languages.
đšâđ» Letâs get started
2. Sign in and Create a project
- Open your Sentry Account. You might need to sign in. Go here
- Next step create a project
- Choose your language from the list(Weâre going to pick React. Click âCreate Projectâ)
Configure your application. The base example How to integrate Sentry in a container, you can see below:
Sentry has a useful wizard that helps you understand what you should do next. You can follow these steps. I want to show you how to create the first error handler. Well done, weâve created a project! Go to the next step.
3. Sentry integration
First of all, we should install npm package in your project.
npm i @sentry/browser
Initialize Sentry in your container:
Sentry.init({ // dsn: #dsnUrl,});
DSN property has in Projects -> Settings -> Client Keys. Or you can find Client Keys in search input.
4. First error tracking
I used a simple music app with API Deezer in a hurry, just for example. You can see it here. We need to create an error. One way is to refer to a property of âundefinedâ
We should create a button that calls console.log with user.email. After this action, we have to get an error message: âUncaught TypeError (Cannot read property âemailâ of undefined)â due to the lack of user object. You also can use javascript throw exception.
The entire container looks like this:
After integrating this button, you should test it in a browser.
We have our first issue đ
Whoo-hoo! đ đ đ
If you click title error, youâll see a stack trace.
The Messages look bad. Of course, we have seen error messages, not understanding where this code is. Itâs about a source map by default in ReactJS because they arenât configured.
I would like to provide instructions for source map configuration as well, but it would make this article much longer than I originally intended.
You could explore this topic here. If you are interested in this article, click more claps and Iâll post second part about the integration of source map. So, click more likes and follow me in order not to miss the second part. đâ€ïž
5. Use Sentry with APIÂ Endpoint
Okay. We covered javascript exception in previous points. However, what are we going to do with XHR errors?Sentry also has custom error handling. I used it for tracking api errors.
Sentry.captureException(err)
You can customize error name, level, add data, unique user data with your app, email, etc.
Iâd like to use a common function for api catch.
Import this function to api call.
Letâs check the methods out:
- setLevel allows to insert level error in sentry dashboard. It has propertiesâââ(âfatalâ, âerrorâ, âwarningâ, âlogâ, âinfo, âdebugâ, âcriticalâ).
- setUser helps to save any user data (id, email, payment plan and etc).
- setExtra allows to set any data that you need, for example, the store.
If you want to get user feedbacks about error, you should use function showReportDialog.
Sentry.showReportDialog();
Conclusion:
Today weâve described at one of the ways to integrate sentry in react app.
Your Expectations after integrating sentry.
In reality
Of course, it is a joke =)I hope your projects will be clear without any errors.
Good luck with your project.
đ You also should read next article:Â đ
â€ïž Thanks for Reading
Have fun, keep learning, and always keep coding. Follow me on Medium & Linkedin.
đ Like, Share, Leave your comment
If you have any questions or feedback, let me know in the comments below đ
Tracking Errors In React App With Sentry was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.