Monitor React application

Introduction

Monitoring a React application in production is about continuously tracking the application’s health, performance, and user experience to identify issues before they significantly impact users. Unlike development, where errors can be reproduced locally, production applications are used by thousands of users across different browsers, devices, and network conditions. Therefore, it’s important to collect real-time telemetry, analyze it, and configure alerts so the development team can respond quickly.

To effectively monitor a React application, we focus on four key areas:

  1. Errors – Monitor JavaScript exceptions, React Error Boundary errors, unhandled promise rejections, and API failures to detect application crashes and bugs.
  2. Performance – Track page load time, Core Web Vitals (LCP, INP, CLS), component render time, bundle size, and memory usage to ensure the application remains fast and responsive.
  3. Network Activity – Monitor API response times, failed requests, HTTP status codes, and timeout rates to identify backend or connectivity issues affecting the frontend.
  4. User Experience (UX) – Analyze user interactions, navigation flow, session duration, and real user performance metrics to understand how users experience the application.

Based on these metrics, we can configure dashboards and alerting using tools such as Splunk, Grafana, Sentry, or Datadog, so that when predefined thresholds are exceeded (for example, a spike in JavaScript errors, high API latency, or degraded Core Web Vitals), notifications are automatically sent through slack , email or any other communication tool enabling the team to investigate and resolve issues quickly.

Monitoring Architecture

                           Users
                             │
                             ▼
                     React Application
                             │
     ┌───────────────┬───────────────┬────────────────┐
     │               │               │                │
     ▼               ▼               ▼                ▼
   Errors      Performance      Network         User Experience
 (JS Errors)   (LCP, INP, CLS) (API Calls)    (Navigation, Clicks)
     │               │               │                │
     └───────────────┴───────────────┴────────────────┘
                             │
                             ▼
                    Telemetry Collection
        (OpenTelemetry / Browser SDK / Custom Logs)
                             │
                             ▼
                 Monitoring & Analytics Platform
      (Splunk / Grafana / Datadog / New Relic / Sentry)
                             │
          ┌──────────────────┼──────────────────┐
          │                  │                  │
          ▼                  ▼                  ▼
     Dashboards          Log Analysis      Performance Reports
                             │
                             ▼
                        Alert Engine
                             │
         ┌───────────────────┼───────────────────┐
         ▼                   ▼                   ▼
       Slack              Email            PagerDuty

What should be monitored?

S.NoMonitoring AreaWhat to MonitorWhy It Matters
1Error MonitoringJavaScript exceptions, React Error Boundary errors, unhandled promise rejections, API failuresDetect application crashes and bugs quickly.
2Performance MonitoringPage load time, Core Web Vitals (LCP, INP, CLS), component render timeEnsure the application remains fast and responsive.
3API & Network MonitoringAPI latency, failed requests, HTTP status codes, timeout rateIdentify backend or network-related issues.
4React Rendering MonitoringSlow renders, frequent re-renders, component mount timeDetect unnecessary re-renders and improve UI performance.
5Memory MonitoringJavaScript heap size, detached DOM nodes, event listener leaksPrevent memory leaks and browser slowdowns.
6Session Replay MonitoringUser clicks, scrolls, navigation flow, console errorsReproduce and debug real user issues.
7Bundle MonitoringJavaScript bundle size, lazy-loaded chunks, download timeReduce application load time and improve performance.
8Real User Monitoring (RUM)Browser, device, network speed, page load time, user interactionsMeasure the actual experience of real users.
9Alerting StrategyError rate, API latency, Core Web Vitals, memory usage, crash rateNotify the team when application health degrades.

1. Error Monitoring

Capture:

  • Runtime errors
  • React Error Boundaries
  • Promise rejections
  • API failures

Example –

try {
   await api.getUsers();
}
catch(error){
   Sentry.captureException(error);
}

2. Measure Web Vitals

What are Web Vitals?

Web Vitals are a set of user-centric performance metrics that measure how fast, responsive, and visually stable a web application is. They help evaluate the real user experience and identify performance issues that can impact usability.

The three Core Web Vitals are:

S.NoMetricFull FormMeasuresGood ValueCommon IssuesOptimization Techniques
1LCPLargest Contentful PaintTime taken to render the largest visible element (image, heading, video, etc.) in the viewport. Measures loading performance.≤ 2.5 sLarge images, slow server response, render-blocking CSS/JSOptimize images, lazy load assets, enable caching/CDN, minimize render-blocking resources
2INPInteraction to Next PaintMeasures the delay between a user interaction (click, tap, keyboard input) and the next visual update. Measures responsiveness.≤ 200 msLong JavaScript tasks, expensive React re-renders, synchronous processingCode splitting, memoization (React.memo, useMemo, useCallback), defer non-critical work
3CLSCumulative Layout ShiftMeasures unexpected movement of page elements while loading. Measures visual stability.≤ 0.1Images without dimensions, dynamic content insertion, late-loading fontsReserve space for media, preload fonts, avoid inserting content above existing elements

Why are Core Web Vitals important?

BenefitDescription
Improved User ExperienceFaster loading, smoother interactions, and stable layouts increase user satisfaction.
Better Performance MonitoringProvides measurable KPIs to evaluate frontend performance over time.
SEO BenefitsCore Web Vitals are part of Google’s Page Experience signals and can influence search rankings.
Higher User EngagementFaster websites typically have lower bounce rates and better conversion rates.
Early Performance DetectionHelps identify performance regressions before they affect a large number of users.

React App:

import { onLCP, onCLS, onINP } from 'web-vitals';

onLCP(console.log);
onCLS(console.log);
onINP(console.log);

These metrics are sent to:

  • Google Analytics
  • Datadog
  • New Relic

3. API Monitoring

Track:

  • API latency
  • HTTP errors
  • Timeout
  • Retry count

Example Axios Interceptor:

axios.interceptors.response.use(
  response => response,
  error => {
      Sentry.captureException(error);
      return Promise.reject(error);
  }
);

Dashboard

Average API latency
95th percentile latency
500 errors
404 errors
Timeout rate

4. React Rendering Performance

React DevTools Profiler helps during development.

In production monitor:

  • Slow renders
  • Frequent re-renders
  • Component mount time

Example:

ProductList rendered 120 times
Should only render 10 times
Performance issue detected

5. Memory Monitoring

Monitor:

  • JS Heap Size
  • Detached DOM nodes
  • Event listener leaks

Symptoms:

Memory 100 MB -> 250 MB -> 500 MB -> Browser crash

Possible causes:

  • Missing cleanup in useEffect
  • Timers not cleared
  • WebSocket not disconnected

6. Network Monitoring

Track:

  • Failed requests
  • Slow requests
  • Offline users
  • Retry attempts

Useful metrics:

Average latency
P95 latency
P99 latency
Failure %
Bandwidth

7. Session Replay

Sometimes logs aren’t enough.

Use:

  • LogRocket
  • FullStory
  • Microsoft Clarity

They record:

  • Clicks
  • Scrolls
  • Mouse movement
  • Console errors
  • Network requests

You can replay exactly what the user experienced.

8. Bundle Monitoring

Monitor:

  • Bundle size
  • Lazy loaded chunks
  • Download time

Example:

Previous Bundle420 KB -> Current Bundle900 KB -> Alert!

Tools:

  • Webpack Bundle Analyzer
  • Source Map Explorer

9. Real User Monitoring (RUM)

Instead of lab testing, monitor actual users.

Popular tools:

  • Datadog RUM
  • New Relic Browser
  • Dynatrace
  • Elastic APM

Metrics collected:

  • Device
  • Browser
  • Country
  • Network speed
  • Load time
  • API latency
  • Errors

10. Alerting Strategy

Alerts should be actionable.

ConditionAlert
JS Errors > 100/minSlack
API Failure Rate > 5%PagerDuty
LCP > 4 secSlack
INP > 300 msEmail
CLS > 0.25Slack
Memory > 400 MBEmail
Crash Rate > 2%PagerDuty

Best Practices

PracticeBenefit
Implement React Error BoundariesPrevent the entire app from crashing due to a component error.
Capture unhandled exceptions and promise rejectionsDetect unexpected failures in production.
Monitor Core Web Vitals (LCP, INP, CLS)Measure real user performance and UX quality.
Use Real User Monitoring (RUM)Collect performance data from actual users across devices and networks.
Track API latency and failure ratesIdentify backend or network bottlenecks affecting the UI.
Monitor memory usage and clean up resourcesPrevent memory leaks caused by timers, subscriptions, or event listeners.
Record user sessions for critical errorsReproduce issues faster with session replay tools.
Track JavaScript bundle size in CI/CDPrevent performance regressions due to oversized bundles.
Define meaningful alert thresholdsReduce alert fatigue by notifying only on significant issues.
Correlate frontend telemetry with backend logs using trace IDsSpeed up root-cause analysis across distributed systems.
Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *