{"id":78186,"date":"2026-03-30T05:04:19","date_gmt":"2026-03-29T23:34:19","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=78186"},"modified":"2026-04-22T11:28:14","modified_gmt":"2026-04-22T05:58:14","slug":"error-monitoring-in-next-js-using-rollbar-beginner-guide","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/error-monitoring-in-next-js-using-rollbar-beginner-guide\/","title":{"rendered":"Error Monitoring in Next.js Using Rollbar (Beginner Guide)"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Applications can fail in a lot of different ways &#8211; API failures, UI errors, server issues, or incorrect input from a user. When something goes wrong in a production environment, it can be difficult for people to replicate the error in their local environment.<\/p>\n<p>To address the above challenge in development, teams can use tools like Rollbar to provide instant feedback on error activity in their applications.<\/p>\n<p>In Today&#8217;s Post<br \/>\nWe will take a close look at how to set up and install Rollbar with your Next.js app and what we can do with Rollbar in order to capture errors from your User Interface (UI).<\/p>\n<h2>Why Do We Need Error Monitoring?<\/h2>\n<p>While you are building your application, you will easily see errors as they are thrown in your Browser Console (or Terminal). After the code is put into production, you lose that visibility of error occurrences.<\/p>\n<p>In the absence of an error monitoring system in production:<\/p>\n<ul>\n<li>Developers will not be aware of any broken code running in production environments<\/li>\n<li>Any bugs that have made it into production will likely go undetected by the development team<\/li>\n<li>Debugging issues will become a more difficult task<\/li>\n<li>The end-user experience will be negatively affected<\/li>\n<\/ul>\n<p>This is where Rollbar can help your team out!<\/p>\n<p>Rollbar will automatically capture:<\/p>\n<ul>\n<li>All client-side errors<\/li>\n<li>Unhandled exceptions<\/li>\n<li>Errors in a React component<\/li>\n<li>Custom logs<\/li>\n<li>Performance-related events<\/li>\n<\/ul>\n<p>The errors that are collected by Rollbar are visible on the Dashboard, where all the developers can work together to troubleshoot and resolve the problem(s).<\/p>\n<h2>What is Rollbar<\/h2>\n<p>Rollbar is a platform for monitoring and debugging errors in production environments, used by developers to detect, track, and fix them. Features include:<\/p>\n<p>\u2013 Real-time error tracking<br \/>\n\u2013 Detailed stack traces<br \/>\n\u2013 Grouping of errors<br \/>\n\u2013 User context information<br \/>\n\u2013 Deployment tracking<br \/>\n\u2013 Alerting and notifications<\/p>\n<p>When an error occurs in your application, Rollbar records the following information:<br \/>\n\u2013 Error message<br \/>\n\u2013 Stack trace<br \/>\n\u2013 Browser\/environment details<br \/>\n\u2013 Route info<\/p>\n<p>This information provides developers with a snapshot of what caused the problem and can help speed up the identification of root causes.<\/p>\n<h2>The Rollbar Workflow<\/h2>\n<p>The basic workflow looks like this (followed by developers):<br \/>\n\u2013 User interacts with your app<br \/>\n\u2013 An error occurs at either the front or back end<br \/>\n\u2013 Rollbar automatically captures the error (or you can log it manually)<br \/>\n\u2013 The error is sent to Rollbar servers<br \/>\n\u2013 Developers can view the error on their Rollbar dashboard<\/p>\n<p>This allows you to better monitor for errors that occur in real-world scenarios.<\/p>\n<h2>Establishing Rollbar In A Project With Next.js As The App Router<\/h2>\n<p>Let\u2019s go step by step.<\/p>\n<h3>Step 1: Install The Rollbar Packages<\/h3>\n<p>You will need to install two dependencies:<\/p>\n<p>npm install rollbar @rollbar\/react<\/p>\n<p>Both packages serve different but complementary purposes to work with this implementation:<\/p>\n<ul>\n<li><strong>rollbar<\/strong> \u2192 is the core Rollbar SDK;<\/li>\n<li><strong>@rollbar\/react<\/strong> \u2192 allows you to use React integration via Error Boundaries and\/or hooks.<\/li>\n<\/ul>\n<h2>Step 2: Configure Your Environment Variables<\/h2>\n<p>You will need to create two Rollbar tokens to configure your Rollbar SDK in the application.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79275\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Tokens.png\" alt=\"Tokens\" width=\"926\" height=\"135\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Tokens.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Tokens-300x44.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Tokens-768x112.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Tokens-624x91.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/p>\n<p>Regarding the above statement:<\/p>\n<p>Variable Purposes<\/p>\n<p>NEXT_PUBLIC_ROLLBAR_ACCESS_TOKEN &#8211; Get used in the browser;<br \/>\nROLLBAR_SERVER_TOKEN &#8211; Get used on the server;<\/p>\n<p>Storing token values as environment variables helps to secure the value while providing different flexible configurations through different environments throughout a project or multiple projects.<\/p>\n<h3>Step 3: Create A Rollbar Configuration<\/h3>\n<p>Create a file: path\/rollbar.js<\/p>\n<div id=\"attachment_79267\" style=\"width: 936px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-79267\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79267\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Configuration-1.png\" alt=\"Rollbar Configuration\" width=\"926\" height=\"465\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Configuration-1.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Configuration-1-300x151.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Configuration-1-768x386.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Configuration-1-624x313.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><p id=\"caption-attachment-79267\" class=\"wp-caption-text\">Rollbar Configuration<\/p><\/div>\n<p>This initializes the Rollbar client used across the application.<\/p>\n<h3>Step 4: Add Rollbar Provider in the Root Layout<\/h3>\n<p>In a Next.js App Router project, we typically wrap our application with providers in the layout.<\/p>\n<div id=\"attachment_79266\" style=\"width: 936px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-79266\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79266\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Provider.png\" alt=\"Rollbar Provider\" width=\"926\" height=\"318\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Provider.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Provider-300x103.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Provider-768x264.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Rollbar-Provider-624x214.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><p id=\"caption-attachment-79266\" class=\"wp-caption-text\">Rollbar Provider<\/p><\/div>\n<p>This makes Rollbar available throughout the application.<\/p>\n<h3>Step 5: Using a Global Error Boundary<\/h3>\n<p>React applications can fail due to runtime errors in components. To catch these errors gracefully, we can use an Error Boundary.<\/p>\n<div id=\"attachment_79268\" style=\"width: 936px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-79268\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79268\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Global-Error-Boundary.png\" alt=\"Global Error Boundary\" width=\"926\" height=\"355\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Global-Error-Boundary.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Global-Error-Boundary-300x115.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Global-Error-Boundary-768x294.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Global-Error-Boundary-624x239.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><p id=\"caption-attachment-79268\" class=\"wp-caption-text\">App Error Boundary<\/p><\/div>\n<p>Usage:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79269\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/AppErrorBoundary.png\" alt=\"App Error Boundary\" width=\"926\" height=\"116\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/AppErrorBoundary.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/AppErrorBoundary-300x38.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/AppErrorBoundary-768x96.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/AppErrorBoundary-624x78.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/p>\n<p>If a component crashes, Rollbar captures the error automatically.<\/p>\n<h3>Step 6: Manual Error Logging<\/h3>\n<p>Sometimes we want to log errors or events manually.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div id=\"attachment_79270\" style=\"width: 936px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-79270\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-79270 size-full\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Manual-Error-Logging.png\" alt=\"Manual Error Logging\" width=\"926\" height=\"227\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Manual-Error-Logging.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Manual-Error-Logging-300x74.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Manual-Error-Logging-768x188.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Manual-Error-Logging-624x153.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><p id=\"caption-attachment-79270\" class=\"wp-caption-text\">Manual Error Logging<\/p><\/div>\n<p><strong>Other logging levels:<\/strong><\/p>\n<div id=\"attachment_79272\" style=\"width: 936px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-79272\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79272\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Info-And-Warning.png\" alt=\"Info And Warning\" width=\"926\" height=\"135\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Info-And-Warning.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Info-And-Warning-300x44.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Info-And-Warning-768x112.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Info-And-Warning-624x91.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><p id=\"caption-attachment-79272\" class=\"wp-caption-text\">Logging Levels<\/p><\/div>\n<p>This helps developers log meaningful events in production.<\/p>\n<h3>Step 7: Logging API Errors using Redux Toolkit and Axios<\/h3>\n<p>Many applications that make calls to an API typically use Redux Toolkit with Axios. You can log API errors when they happen in thunks or service functions. Below is a sample code that will log any exception thrown when calling an API to get user data from the API.<\/p>\n<div id=\"attachment_79271\" style=\"width: 936px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-79271\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-79271\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Logging-Axios-Errors.png\" alt=\"Logging Axios Errors\" width=\"926\" height=\"318\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Logging-Axios-Errors.png 926w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Logging-Axios-Errors-300x103.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Logging-Axios-Errors-768x264.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Logging-Axios-Errors-624x214.png 624w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><p id=\"caption-attachment-79271\" class=\"wp-caption-text\">Logging Axios Errors<\/p><\/div>\n<p>This allows you to see any errors that happen on the backend and still show up in Rollbar.<\/p>\n<h2>Tracking Errors in the Rollbar Dashboard<\/h2>\n<p>When Rollbar captures an error from your Next.js application, it organizes the errors into items. Each item is a distinct error type and contains all information needed for a developer to resolve the error. Below, we will describe the major areas a developer would find useful when troubleshooting errors.<\/p>\n<p><strong>1. Items (Error List)<\/strong><\/p>\n<p>Rollbar \u2192 <strong>Items tab<\/strong><\/p>\n<p>Developers use the Items page as their primary tool to track application errors.<\/p>\n<p>Rollbar divides errors into distinct items that represent different types of errors. Rollbar combines identical errors into one group to prevent excessive error display.<\/p>\n<p>The Items list shows common information, which includes:<\/p>\n<ul>\n<li>Error message<\/li>\n<li>Number of occurrences<\/li>\n<li>Number of affected users<\/li>\n<li>Last occurrence time<\/li>\n<li>Error status<\/li>\n<\/ul>\n<div id=\"attachment_78183\" style=\"width: 945px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-78183\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-78183\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list.png\" alt=\"Error list\" width=\"935\" height=\"487\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list.png 2400w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list-300x156.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list-1024x532.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list-768x399.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list-1536x799.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list-2048x1065.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/Error-list-624x324.png 624w\" sizes=\"(max-width: 935px) 100vw, 935px\" \/><p id=\"caption-attachment-78183\" class=\"wp-caption-text\">Errors list<\/p><\/div>\n<p><strong>2. Stack Trace (Where the Error Happened)<\/strong><\/p>\n<p>Rollbar \u2192 <strong>Error Item<\/strong> \u2192 <strong>Stack Trace section<\/strong><\/p>\n<p>The Rollbar system shows an error detail view, which opens when developers select an error item. The Stack Trace section represents the most critical area in this section.<\/p>\n<p>A stack trace shows exactly where the error occurred in the code.<\/p>\n<p>The stack trace provides information about the following elements<\/p>\n<ul>\n<li>File name<\/li>\n<li>Function name<\/li>\n<li>Line number<\/li>\n<li>Component hierarchy<\/li>\n<\/ul>\n<div id=\"attachment_78184\" style=\"width: 953px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-78184\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-78184\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace.png\" alt=\"Stack Trace\" width=\"943\" height=\"666\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace.png 2572w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace-300x212.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace-1024x724.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace-768x543.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace-1536x1086.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace-2048x1448.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/stackTrace-624x441.png 624w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><p id=\"caption-attachment-78184\" class=\"wp-caption-text\">Stack Trace<\/p><\/div>\n<p>This approach enables developers to find the defective code without delay.<\/p>\n<p><strong>3. Telemetry (Events Before the Error)<\/strong><\/p>\n<p>Rollbar \u2192 <strong>Error Item<\/strong> \u2192 <strong>Telemetry tab<\/strong><\/p>\n<p>The Telemetry section provides a timeline of events that happened just before the error occurred.<\/p>\n<p>This approach proves to be highly effective for reproducing software defects.<\/p>\n<p>Telemetry may include events such as:<\/p>\n<ul>\n<li>User navigation<\/li>\n<li>Button clicks<\/li>\n<li>API requests<\/li>\n<li>Console logs<\/li>\n<li>Custom logs<\/li>\n<\/ul>\n<div id=\"attachment_78185\" style=\"width: 962px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-78185\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-78185\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry.png\" alt=\"Telemetry\" width=\"952\" height=\"462\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry.png 2572w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry-300x146.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry-1024x497.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry-768x373.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry-1536x745.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry-2048x994.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2026\/03\/telemetry-624x303.png 624w\" sizes=\"(max-width: 952px) 100vw, 952px\" \/><p id=\"caption-attachment-78185\" class=\"wp-caption-text\">Telemetry<\/p><\/div>\n<h2>Example Debugging Workflow Using Rollbar<\/h2>\n<p>Here\u2019s how a developer typically investigates an issue using Rollbar:<\/p>\n<ol>\n<li>The Items page should be opened to display all newly created errors<\/li>\n<li>The error that has the most total occurrences should be selected<\/li>\n<li>The Stack Trace should be examined to find the defective code<\/li>\n<li>The Telemetry should be examined to find out what occurred before the system crashed<\/li>\n<li>The developer needs to reproduce the issue on his own system<\/li>\n<li>The developer needs to fix the bug and deploy the update<\/li>\n<\/ol>\n<h2>Final Thoughts<\/h2>\n<p>Modern application development requires error monitoring as a necessary component. Rollbar provides teams with tools that enable them to identify and fix problems, which leads to better system performance and enhanced user satisfaction.<\/p>\n<p>The implementation of Rollbar allows Next.js developers to track production errors, monitor application health, and debug issues more efficiently while achieving better application stability.<\/p>\n<p>Your application will maintain its reliability through proper monitoring methods that allow it to grow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Applications can fail in a lot of different ways &#8211; API failures, UI errors, server issues, or incorrect input from a user. When something goes wrong in a production environment, it can be difficult for people to replicate the error in their local environment. To address the above challenge in development, teams can use [&hellip;]<\/p>\n","protected":false},"author":2115,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[5876],"tags":[7980,8436,5596,2046,5221],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/78186"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/2115"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=78186"}],"version-history":[{"count":17,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/78186\/revisions"}],"predecessor-version":[{"id":79276,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/78186\/revisions\/79276"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=78186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=78186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=78186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}