Next-Level JavaScript Error Tracking with Sentry

Rate this content
Bookmark

Discover advanced techniques to track and resolve errors in JavaScript applications, using Sentry as a powerful ally. This session will explore the art of pinpointing issues before they hit users, streamlining your error-handling process, and enhancing application performance.

23 min
15 Feb, 2024

Video Summary and Transcription

We're going to be talking about next level JavaScript error tracking with Sentry. Error tracking is the process of identifying, recording, and managing errors in a web application. Traditional JavaScript error tracking methods have disadvantages and lack context about the device and user. You can automate error tracking with Sentry, an open source error tracking tool that helps developers monitor and fix crashes in real time. Setting up Sentry is simple using the Sentry SDK and configuring with the DSN.

Available in Español

1. Introduction to Error Tracking

Short description:

We're going to be talking about next level JavaScript error tracking with Sentry. Error tracking is the process of identifying, recording, and managing errors in a web application. It involves discovering, diagnosing, and fixing bugs.

Hey everyone, it's so good to join you here today. We're going to be talking about next level JavaScript error tracking with Sentry. My name is Ebenezer Dunn and I'm a developer advocate at CodeGiant, a DevSecOps and an integrated development platform with built in best practices that helps your team deliver faster and more securely.

We're talking about our tracking, but what even is error tracking? And by the way, this is the third time I'm doing a recording of this particular talk for this particular conference, because I've tried the first time I tried after recording. I was like, yeah, I'm done. And I discovered my camera froze while recording. So second time the laptop and everything just went off while recording. And this is the third time and here's to hoping that everything goes smoothly this time. And I'm going to be trying to smile. So kind of frustrated.

What if it is error tracking? Now, it's a process of identifying, recording and managing errors that occur in a web application. So in our case, web application because we're using JavaScript for the web in this particular instance. But error tracking basically identify, recording and managing errors that occur in your application. So this is a process of error tracking. First of all, the discovery has to be there. So you have to discover the error and then you diagnose the error. So you don't just discover the error, like, oh, we found out that there was an error and everyone sits down. No, you have to diagnose the error. And when you diagnose the error, you know, like finding out what's actually causing the error. Why? Why is this error? What is this error? Where is this error? You know, diagnose the error and you don't clap and say, OK, now we discover the error. We know like everything about this error and let's go home. No, you have to fix the bugs. So you find the bugs. You fix the bugs. Is that important? That parts of the error tracking process. You don't just discover that nonsense. You go sit down. So you have to fix the bugs.

Now, components of error tracking. So this is like just a more broken down version of what we've already talked about.

2. Error Tracking Workflow

Short description:

Error detection, logging, notification, analysis, and resolution are essential components of the error tracking process. By tracking errors, you can reduce downtime and enhance user experience.

So the error detection process, same as error discovery, then you have to log the error. This is important. You don't just discover the error or detect the error and you're like, oh, yeah, we discover that error. No, it's important that you log this error. It's important that you store this error in a database or like in CodeGiant, for example, we use Clickhouse for logging. I'm not sure what Sentry uses, but like in the Sentry platform also, this is logged. So you don't just discover the error and then you throw it away.

So you have to log the error and you know, you have to you need a notification system so that you're not kept in the dark. Like you don't just stop at detecting that login. Sorry about that. You don't just stop at detecting and logging the error. So you have to be notified about this error to oh, there's an error. Yep. You need to be notified that there was an error. So we said that we're going to do with Sentry, you know, that comes with a notification system. So once a user encounters an error or once you encounter an error, once there's an error in your application, you get notified and that comes with all the error information. And then next after you're notified, you check out the error and then you analyze the error. You know, you find out what's causing the error, where, you know, and how and why. You know, so every all the details about the error is going to come with a Sentry configuration where we do that now. When there's an error, it comes with like browser information, user device information, IP address, everything you need to resolve. To analyze the error. And then again, you don't clap and go home. You have to resolve the error.

So in summary, you find a box, you fix a box. It's important to have error resolution as part of your error tracking process. So what are the benefits of error tracking? It reduces downtime. So if you're not tracking errors, you know when something is wrong, you know that your users are struggling, you know that your web application is struggling or your JavaScript application, you will know you're struggling. So and if you don't know it's going to keep happening and you're going to keep having downtime. So if you're tracking the errors, you can, you know, get information about this error, get to know about it, resolve the error and reduce downtime. It enhances user experience.

3. Importance of Error Tracking

Short description:

If users encounter errors in your application and you're not tracking them, you may lose users and hinder the user experience. Error tracking provides insights into application performance and helps prioritize development efforts.

Also, if users are struggling and you don't know, again, you know, most times they won't even bother telling you. Then first thing the user will do is go find alternatives unless their life depends on your application. If I go to application and I'm struggling with an error, I just go look for an alternative, you know, that does the same thing. Only if I can find an alternative and yours is my only hope or maybe I've already paid you and I need you to, you know, actually like give me my service that I paid for, then the user would reach out to you and say, hey, I'm encountering this error. So you see if you're not error tracking, you're going to lose a lot of users because many people would even bother telling you to just go look for something else. And, you know, so we're tracking areas where we need your users are happy, you're happy, everyone is happy and assist user experience provides insights into application performance. Yeah. So if you're not tracking the errors, you wouldn't know how your application is performing. I will also cover. Hopefully we should be able to with the time we have application, how you can track transactions, the performance of application and all of that. But if you're not tracking errors in your application, you would know how your application is performing and it also helps prioritize development efforts. I'm sorry, I'm rushing this because I'm looking at the time and it helps prioritize development efforts so that your team knows what to work on and what to push about to the next point.

4. Traditional JavaScript Error Tracking

Short description:

Traditional JavaScript error tracking methods include console.log statements and alerts, but they have disadvantages and lack context about the device and user.

So next. Yeah. So there's a traditional JavaScript error tracking method. So even if you've not worked with Sentry before or a platform like Sentry, many of us or all of us should have done JavaScript error tracking. There's the console.log statement. You know, that's one way to track the errors. It has its disadvantages, which means that you're the only one who knows that you have you did a console.log statement and you're the only one who's going to see it. And it's only doing your own experience using the application. But this is sometimes used in development instead of production. I mean, that's what should be recommended anyway, if you're going to use console.log, but has lots of disadvantages. And then there's the alerts, which is not so cool. You know, you just show the window that use the window, the alert to pop up an error. You know, not really cool and see and you know, you have all that stuff stopping every other thing that the user is working on. But, you know, that's one way to do error tracking in a traditional way.

Displaying the full error message on screen. So this was not like cool at all and I've used some applications or web applications where like you just did a full error message on the screen. Like it's just some gibberish that the user doesn't understand. And then there's a message that says, take this error message and go send it to the application developer. So if you're doing proper error tracking, you would even need to do that. Be sending your users an error. And when there's an error that occurs, you're going to see it and you're going to see what the user was doing. So, you know, before they, you know, go to that to get to that error, you're going to see details about the device. You're not going to be asking the user what device are you using and what browser are you using? Have you made an update? You're going to see all of that. So you have all the information. You know, you don't need to do stuff like sending the user gibberish.

And yeah. So limitations of traditional error tracking. You lack context. So you don't know anything about the device. You don't know anything about the user.

5. Automating Error Tracking with Sentry

Short description:

You can automate error tracking with proper implementation. Traditional tracking lacks efficiency in data aggregation. Setting up Sentry in a JavaScript project is simple using the Sentry SDK and configuring with the DSN. Sentry is an open source error tracking tool that helps developers monitor and fix crashes in real time. Let's see it in action with a demo.

You don't know anything about their actions before the error. You know, it's manual. It's reactive. So everything has to be manual. And you always react. And, you know, if you do proper implementation with Sandro, for example, you can automate things.

And then there's in with the traditional tracking, there's inefficiency in data aggregation. So you're not really logging. You're not doing it right. You know, storing that information so that you can see everything and you can be able to is to even track your application performance or know what is happening in your application.

Now, to set up Sentry in a JavaScript project, you use the Sentry as an SDK. That makes it just really easy and you configure with the DSS. It's really simple. I'm going to show you right now, like we're going to do that together. So Sentry SDK right there you just hit npm install, type npm install and you get it into your application. Then you get your DSN data source name and that's it. You start tracking your error. So it's as simple as that.

This is Sentry, it's an open source error tracking tool that helps developers monitor and fix crashes in real time. We're going to see that's in action. I'm going to be demoing this to you through with an application.

So what is Sentry? Sentry is an open source error tracking tool that helps developers monitor and fix crashes in real time. Yeah. So what do I just call that? What are that is that by the way? Because I like try to rush before any other thing goes wrong with this recording. But this is Sentry, it's an open source error tracking tool that helps developers monitor and fix crashes in real time. We're going to see that's in action. I'm going to be demoing this to you through with an application.

To set up Sentry in a JavaScript project, you use the Sentry as an SDK. That makes it just really easy and you configure with the DSS. It's really simple. I'm going to show you right now, like we're going to do that together. So Sentry SDK right there you just hit npm install, type npm install and you get it into your application. Then you get your DSN data source name and that's it. You start tracking your error. So it's as simple as that. OK, let's stay here and then let's go over to the browser. So this is Sentry.io.

6. Setting up Sentry for Error Tracking

Short description:

This new account comes with a 14-day trial. After the trial, you still get access to Sentry but with limited features. Everything we are doing today is with the free Sentry account. Sentry is open source and can be used with platforms like CodeGiant. Create a project, choose the project type (e.g., React with JavaScript), set the alert frequency, name and assign your project. Install and configure the Sentry SDK in your React application.

This new account comes with 14 day trial. And after the trial, you still get access to Sentry but just with limited features. But everything we are doing today is in the free accounts, the free Sentry account. And I'm also going to show you the good thing about Sentry is that it's open source. So you don't even need to use the Sentry.io platform. If you want, you can use a platform like CodeGiant, which I'm going to show you. And all you need to do, all you really need is that DSN, which I'm going to show you how to get. So that's really one sweet thing about Sentry is that it's open source. But this Sentry platform is also great.

So you click create a project and choose which type of project you want to create. Let's search for React right here and then click React with JavaScript. You set your alert frequency, alert me on every new issue or when there are more than 10 occurrences or you know, you create an alert later. So whichever way you want to do it. So that's the notification part of error tracking. And then name your project and assign it. So JavaScript reacts right here. Same CodeGiant. So I just created the account and then it asks for a company and I have CodeGiant right there. So let's create the project. And so next thing you have the so it's just straightforward from here.

You run npm installs, dash dash save our Sentry slash React. And let's configure the SDK right here. So I'm going to show you my code base. So this is my React application. This application right now is just a simple market list app. And this is the code base. So what you're seeing right here is what I have in the index of JS file of my React application. So what we really need is we installed Sentry npm install. And then you have our Sentry slash React. And we import it online three right here.

7. Configuring Sentry and Capturing Errors

Short description:

Import the necessary imports from our Sentry slash React, initialize the Sentry dot init with the DSN, and configure the setup. Wrap the application components in Sentry dot error boundary to catch default errors. See examples of different types of errors in the error test component and the market list app repository on my GitHub. The Sentry error boundary automatically captures errors thrown in the React component tree.

Imports that Sentry from our Sentry slash React and online seven. So this is what we actually need. Sentry dot init initialize and then eight line eight right here is the DSN. So this is what's important right now. This DSN and this is a DSN for my setup with CodeGiant. But what I'm going to do is come here and take this DSN from this new project I created in Sentry. And I'm going to replace that here on line eight. So we have the setup. This is what's important right here. The DSN and then we have the configuration from line 10 to line 22 here.

So once we have that, the next thing we have right here is this. So what I'm going to do, what we did next online 34 from Sentry, we have Sentry dot error boundary. And then we wrap our application components in the Sentry dot error boundary. So this is going to help catch like defaults error. So let me show you an example right now. If you go to the error test component I created and so these are different types of I'm going to leave a link to this repository or you go to my GitHub. I'm going to show you my give you my GitHub link at the end of this talk. And you just search for market list app.

You're going to see this repository with the code base. So these are different types of errors I created. I don't think we can cover everything because of time. We have just very little time left. But this is one error, for example, on hundred error. This is captured by Sentry dot error boundary in index or GS. This boundary automatically catches on hundred errors thrown in the React component tree. So I left comments in this code so that you can check it out and you just read and understand it. So this boundary automatically captures on hundred errors to react's component tree. Sorry about that. So let's try this. For example, I have already imported all of this different error components in the app GS file.

8. Generating Errors and Viewing in Sentry

Short description:

Uncomment the sinc error components in the app GS file and try generating a hundred errors. View the resulting error message in the React app and check the issues in Sentry. Ensure the DSN in the index GS file is configured correctly.

So right here, the app GS file. All I need to do is uncomment a sinc error components comments. Rather, I think our company does one of the errors I tested out. And then let's try this on hundred errors. What we're going to do is have this. So it's important right here on line four. And then I have it online. Seventy four. Let's save this. And where's our browser? We go back to our browser. So this is the React app and reloads. So look at that. We have this error right here. Error test error from error test components. Next, we go back to sentry and let's click take me to issues. So or you can just click issues right here. And it says we couldn't find any errors that match a few. I wonder why. Let's reload and see. It will get the same thing. Yep. So we have that. So sometimes you just need to reload. I think some things are not instance in this sentry platform. But look at that. So this is the error message. So remember, all we need that for to get this to our sentry accounts is this DSN in the index GS file. So this DSN, we saw that. So this determines where your error information is going to. So this one is the one that came with our sentry project.

9. Reviewing Error Messages and User Context

Short description:

We have the sentry project and look at the error message. Configure the error information or error report. The event ID and tag provide details such as the IP address, Chrome version, and macOS. Review the error with more information and browser type transaction. Error examples with user context are also available in the codebase.

We have the sentry project and look at the error message. So you click the error message right here. Click the arrow right here and then on hundred error test error from error component. And this comes with all the information for the user. So these also you can configure when you're setting up the way in your code rather you can configure what you want to get from the error from the error information or error report.

So here we have the event ID and then tag. So this tells me the IP address. You can't really use my IP address to do anything because it changes every ten minutes or so. So this is the Chrome version and this is the I'm using macOS. So this you show that I'm using the browser Chrome. I'm using macOS X. And this is the error with more information and browser type transaction. Because if you are a right, your localhost three thousand shows environmental production, browser name and all of that. So I think there's one with condescending. We're going to go through that one quickly. So you see that we can have error with user context. Also, let's go back to the codebase.

This is basically that with this, you know, like, look at the error information right here with this, you know exactly what to do and how to resolve the error. So but let's go back to the codebase. We've run out of time. Actually, I think we have just about four minutes left and error test. So I have an error example with user context so that if there's a user and you want to know you want to get context of which the particular user that's encountering the error, you can do that. So like 96 right here, I have sentry that set user and then, you know, the user ID, email user, there's a command and the username. So once you have these right here, your error, the error that comes everywhere, that's you know, that sentry sends or the application sends over to the DSN. The sentry comes with this user context right here. So like 99 here are showing this error. And all we need to do is so let's go back to the app.js file. And this is the user context component. And let's remove the unhandled error right here. So let's save this.

10. Reloading and Testing User Context

Short description:

Go back to our browser and reload to test user context. Check sentry for new error information. If the error doesn't appear, try reloading again. You can also explore different types of errors and learn how to use sentry with other platforms like CodeGiant.io.

Go back to our browser and reload and test user context, check sentry for details. So if we go back to sentry and click issues, we should see the new error information. We should see it, actually. So I think we'll need to reload again. It's a reload button, essentially. No. So we need to reload that, but that should be here already. So don't don't fret. There's everything is all right. And still not here. Why is that? Why is that? I don't know. But we've run out of time. Still not here. That's error from error components, and I don't know why. But I'm going to try to it just works. So I do exactly know why. But we've run out of time. And I want to show you how to do this with code. So these are the different types of errors. I'm going to leave this up in the repository. Maybe by the time we come back, we're going to see it. But this right here is with if we go to CodeGiant.io and you like sign in. So just go to CodeGiant.io, sign in. And this is one way that you can use sentry with other platforms. For example, you click create a new item for workspace and they go to error and APM tracing right here. And let's have sentry. No, let's just have error tracking to.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Node Congress 2022Node Congress 2022
21 min
Mastering Error Handling Node.js
Errors happen to every programmer. Devs have different choices: suppress it, notify the user, report to the team, ignore it or write code to handle the error.
In this talk, you will learn all the important aspects of the Node.js error system, the types of errors, different ways to deliver an error, and patterns to improve error handling - with examples!

Workshops on related topic

Remix Conf Europe 2022Remix Conf Europe 2022
195 min
How to Solve Real-World Problems with Remix
Featured Workshop
- Errors? How to render and log your server and client errorsa - When to return errors vs throwb - Setup logging service like Sentry, LogRocket, and Bugsnag- Forms? How to validate and handle multi-page formsa - Use zod to validate form data in your actionb - Step through multi-page forms without losing data- Stuck? How to patch bugs or missing features in Remix so you can move ona - Use patch-package to quickly fix your Remix installb - Show tool for managing multiple patches and cherry-pick open PRs- Users? How to handle multi-tenant apps with Prismaa - Determine tenant by host or by userb - Multiple database or single database/multiple schemasc - Ensures tenant data always separate from others
React Advanced Conference 2023React Advanced Conference 2023
112 min
Monitoring 101 for React Developers
Top Content
WorkshopFree
If finding errors in your frontend project is like searching for a needle in a code haystack, then Sentry error monitoring can be your metal detector. Learn the basics of error monitoring with Sentry. Whether you are running a React, Angular, Vue, or just “vanilla” JavaScript, see how Sentry can help you find the who, what, when and where behind errors in your frontend project.
TypeScript Congress 2023TypeScript Congress 2023
48 min
Live Coding Workshop to Setup Rollbar Error Monitoring
WorkshopFree
During this session you will learn how to create a new Rollbar account and integrate the Rollbar SDK with your application to monitor errors in real-time and respond and fix those errors. We will also cover how to customize payload data sent to Rollbar to extend your monitoring capabilities.

Agenda:- Create a Rollbar Account (Free Account)- Integrate your application with the Rollbar SDK- Send handled and unhandled errors to Rollbar- Add Custom payload data to your configuration.
JSNation 2023JSNation 2023
44 min
Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
WorkshopFree
You know that annoying bug? The one that doesn’t show up locally? And no matter how many times you try to recreate the environment you can’t reproduce it? You’ve gone through the breadcrumbs, read through the stack trace, and are now playing detective to piece together support tickets to make sure it’s real.
Join Sentry developer Ryan Albrecht in this talk to learn how developers can use Session Replay - a tool that provides video-like reproductions of user interactions - to identify, reproduce, and resolve errors and performance issues faster (without rolling your head on your keyboard).
React Advanced Conference 2021React Advanced Conference 2021
69 min
Building a Sentry: 7 years of open-source React
Workshop
Join Sentry’s Evan Purkhiser and David Wang as they walk through Sentry’s 230k LoC Typescript/React codebase. They’ll tell war stories of the good, the bad, and the ugly. Gaze in wonder at their modern usage of Typescript, react hooks, and styled components. Recoil in disgust at their legacy Reflux usage and perplexing Webpack configuration. Step away from the workshop with a working knowledge of techniques to keep a large-scale frontend codebase modern and maintainable.