Observability for React Developers

Rate this content
Bookmark

Observability is the ability to measure the current state of a system. Backend engineers are becoming more familiar with the 3 pillars of observability, and technologies such as OpenTelemetry that can be used to instrument applications and diagnose issues. Yet in the frontend world, we're behind the curve.
Join me as I dive into the tools and techniques we can use to instrument, monitor and diagnose issues in our production React applications. I'll cover RUM agents and React framework extensions, and the metrics and traces they provide, how to combine them with backend tracing for a holistic picture, and how Synthetic Monitoring and alerting in Observability platforms can help us be alerted to issues impacting users in the UIs we build and maintain.

This talk has been presented at React Advanced 2024, check out the latest edition of this React Conference.

FAQ

Open telemetry is recommended because it offers an open standard for telemetry data collection that is compatible with various vendor observability platforms, allowing for comprehensive front-to-back tracing.

Synthetic monitoring involves running scripts at fixed intervals to simulate user interactions or ping endpoints, helping catch issues before users encounter them. Tools like Playwright for JavaScript can be used for this purpose.

A RUM (Real User Monitoring) agent is a tool used within JavaScript applications to collect metrics, diagnostic information, and tracing data to identify bottlenecks and performance issues in the front-end.

Carly Richmond's talk focuses on observability for both front-end and back-end services in web applications, particularly for React applications.

The tools discussed include Rome agents, open telemetry, and synthetic monitoring.

The three types of telemetry information are logs, metrics, and traces.

Synthetic monitoring can be integrated into the CI pipeline by using tools like GitHub Actions to run monitors as code during development and deployment stages, ensuring they are in sync with application changes.

Playwright allows for end-to-end testing by automating user interactions and can be used to simulate user behavior on different devices, providing insights into application performance.

Logs, metrics, and traces help React developers by providing insights into application behavior, identifying bottlenecks, and diagnosing performance issues in both front-end and back-end services.

Code examples for RUM and synthetic monitoring can be found in the resources mentioned in Carly Richmond's talk.

Carly Richmond
Carly Richmond
20 min
28 Oct, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
In this talk, observability in React web applications is discussed, covering Rome agents, open telemetry, and synthetic monitoring. The importance of logs, metrics, and traces in tracking application behavior and identifying issues is explained. The concept of a real user monitoring agent (rum agent) for JavaScript applications is introduced. Instrumenting the rum agent and React applications is explained, along with the caution to be mindful of the bundle size. Traces, open telemetry, and instrumentation are explored, including how Core Web Vitals, traces, and open telemetry can provide insights and enable auto-instrumentation. Synthetic monitoring using Playwright tests and the process of converting tests into monitors with configuration is covered. Finally, running and monitoring definitions in production is discussed, highlighting the ability to evaluate user behavior, simulate activities, and address issues proactively.

1. Observability in React Web Applications

Short description:

In this talk, I will discuss observability in React web applications, including both front-end and back-end services. We'll cover Rome agents, open telemetry, and synthetic monitoring. The three pillars of observability are logs, metrics, and traces. I'll explain each of them and their importance in tracking application behavior and identifying issues. Additionally, I'll introduce the concept of a real user monitoring agent (rum agent) for JavaScript applications, which helps in identifying bottlenecks and optimizing React applications.

Hi, React Advanced London. Welcome to Remote Day. It's great to see you all. My name is Carly Richmond, and I'm here today to talk about observability, but not as you may traditionally think about it. When we think about observability, we focus too heavily often on back-end services and what they're doing, when we need to understand the behavior of our web applications in the front-end as well. So we're going to talk about how we do that with React web applications in addition to seeing what's happening in the back-end services, too.

The tools we're going to cover are Rome agents, open telemetry, and synthetic monitoring. I'll show you some examples. We'll have snippets you can dive into afterwards if you want to have another look. But if also you want to ask me any questions afterwards, feel free to contact me online and on various places on the interwebs. I'm a principal developer advocate and manager at Elastic, so you'll be able to find me easily on LinkedIn, too. Before that, I was actually a front-end engineer for ten years working at a large investment bank, so this is problems I've dealt with firsthand, which means I've got a lot of opinions on how this should be done.

But first, we need to talk about pillars. Quite often when you start diving into observability, people start saying, oh, well, we need to talk about the pillars. Let's talk about them as signals, because that's effectively what they are. These are three types of telemetry information that we can use in our applications to figure out what's going on and identify behaviors and remediate issues that we might not necessarily anticipate are going to happen. So the first signal we tend to talk about is logs. And logs, we all know what they are. They're those wacky messages that we see that we're putting into the browser console that we can see when we're diagnosing issues in our application. The second is metrics, which are simply values that give us a rough indication of performance that we can use to track over time. So you might think of throughput and latency, but we also have Google Core Web Vitals, which are a good indication for user performance, at least as a rough guide. And then we have traces. Now, you might think, well, what are these? But actually, you've been using these for a while and not necessarily thinking about it. These are the simple kind of bars with underlying spans you can see up in here that we've seen for showing the amount of time it takes to go through different stages in our application, or even for seeing how long particular network calls are taking to come back, which we're all used to when we're diagnosing issues with React applications trying to connect to back end services and serverless functions.

But we need to crack out the rum. And sadly, I'm not talking about Jack's favorite drink here. I'm talking about a real user monitoring agent. This is a simple agent that you initialize within your JavaScript application that's going to collect metrics and diagnostic information along with tracing in the front end application. And that means that we can use it to identify bottlenecks, see if we've got particular scripts that are taking a long time to load, and other pieces of useful information when we're trying to figure out what the bottleneck is within our React application. I'm talking about a rum agent because at this moment in time, unless someone wants to correct me, we don't have anything that's generic enough in cross vendor.

2. Instrumenting the RUM Agent and React Applications

Short description:

To instrument the rum agent, you can use a script tag, although it's not recommended for older HTML or React applications. It's better to install the APM rum extension using MPM and add the necessary options. The agent requires information such as service name, distributed tracing origins, server URL, and optional attributes like service version and environment. For React applications, custom framework integrations may be necessary, such as the APM run react extension. However, be cautious about the bundle size, as adding agents can increase it significantly.

You need to use the rum agent that's associated with the observability platform that you're going to be ingesting data into. However, keep your eyes peeled on the client instrumentation group for open telemetry. If you want to join the SIG, the details are there on their site as well. And that's really the group that's looking to try and have more of an open standard that's not so vendor locked in. But for the we're going to use the elastic one.

So there's two ways to instrument them. And this tends to be similar patterns across different agents. So you can either use a script tag. Generally, I don't recommend this in an HTML application or in a React app that perhaps is old that you're not touching anymore and you just want to have some basic telemetry included. So you just include the script tag. But generally, the pattern I would recommend is that you install the APM rum extension, sorry, elastic APM rum extension using MPM and then you use the inits and add in the appropriate options.

So the things you need to tell the agent that it's going to send that basically going to categorize the signals that your application is going to send is service name. If you're working on loads of different applications, which was certainly my experience, you need to know which application the signals are corresponding to. And also, if it's the React front end, or those back end services, when we get to front to back tracing. You then got distributed tracing origins, this is needed because by default, the rum agent operates on the same origin policy. So you need to make sure that it's able to add the trace parent header to those HTTP requests going back to back end services, so that you can actually see the full trace, which we'll see later. Then got the server URL, this is the L deployment you're gonna be sending to. And then you've got optional attributes of service version and environment, which well not necessary, you can use them to make sure that maybe you want to compare errors, see how many service versions it goes back to try and identify the source of the problem. Or even if you're doing environmental comparisons, these attributes can be useful to add in.

But we also need to think about the React element because different SPA frameworks behave differently. And sometimes we may need to add particular custom framework integrations alongside, to make sure that we get the appropriate telemetry for our application. And in this particular example, you use the APM run react extension, which is another MPM install. And you use that to access the APM routes component that is then wrapped alongside your react route and your DOM routes. This is as of version six. So if you're using earlier versions, please make sure that you're using the right pattern. It's all covered in the documentation.

Now, just a warning, we need to think about the types of agents that we're adding into our applications. Because if we're not careful, and we're not using the appropriate optimizations, they are going to bloat the build, there's no way around it, doesn't matter if we're using a rum agent, Google Analytics, Hotjar, or something else, these things can really ramp up the bundle size. So make sure you're also following the appropriate instructions for the bundler you're using to make sure you optimize the production version as well. But getting back to what these things give us, they give us all sorts of different metrics are captured.

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

Multithreaded Logging with Pino
JSNation Live 2021JSNation Live 2021
19 min
Multithreaded Logging with Pino
Top Content
Today's Talk is about logging with Pino, one of the fastest loggers for Node.js. Pino's speed and performance are achieved by avoiding expensive logging and optimizing event loop processing. It offers advanced features like async mode and distributed logging. The use of Worker Threads and Threadstream allows for efficient data processing. Pino.Transport enables log processing in a worker thread with various options for log destinations. The Talk concludes with a demonstration of logging output and an invitation to reach out for job opportunities.
Observability for Microfrontends
DevOps.js Conf 2022DevOps.js Conf 2022
24 min
Observability for Microfrontends
Microfrontends follow the microservices paradigm and observability is crucial for debugging runtime production issues. Error boundaries and tracking errors help identify and resolve issues. Automation of alerts improves incident response. Observability can help minimize the time it takes to understand and resolve production issues. Catching errors from the client and implementing boundaries can be done with tools like OpenTelemetry.
Observability with diagnostics_channel and AsyncLocalStorage
Node Congress 2023Node Congress 2023
21 min
Observability with diagnostics_channel and AsyncLocalStorage
Observability with Diagnostics Channel and async local storage allows for high-performance event tracking and propagation of values through calls, callbacks, and promise continuations. Tracing involves five events and separate channels for each event, capturing errors and return values. The span object in async local storage stores data about the current execution and is reported to the tracer when the end is triggered.
How Grafana Uses React to Power the World of Observability
React Summit 2023React Summit 2023
7 min
How Grafana Uses React to Power the World of Observability
Watch video: How Grafana Uses React to Power the World of Observability
Grafana uses React to power its open source platform, leveraging its vast ecosystem, improved performance, and community contributions. The choice of state management tool depends on the team's problem space. React Hooks have posed challenges but have also been a powerful tool for developers. The new Scenes library simplifies development and reduces the learning curve. Despite challenges, React remains a powerful tool for complex frontends, and Grafana will continue to use it.
GraphQL Observability
GraphQL Galaxy 2020GraphQL Galaxy 2020
8 min
GraphQL Observability
This Talk discusses how to tool Apollo server with open tracing for observability. OpenTracing is a vendor-agnostic format that works well with distributed systems in microservices. It allows for converting GraphQL tracing data to a vendor-agnostic format and enriching information from GraphQL servers. If providers support OpenTracing, it can be easily integrated.
Creating an innovation engine with observability
Node Congress 2023Node Congress 2023
27 min
Creating an innovation engine with observability
Baseline provides observability for serverless architectures and has created an innovation engine within their team. They measure team performance using Dora metrics and the Accelerate book. Baseline emphasizes the importance of foundations, streamlined testing, and fast deployment. They practice observability-driven development and incorporate observability as part of their development lifecycle. Baseline believes in building a culture that fosters ownership and democratizes production.

Workshops on related topic

Scaling Databases For Global Serverless Applications
Node Congress 2022Node Congress 2022
83 min
Scaling Databases For Global Serverless Applications
WorkshopFree
Ben Hagan
Ben Hagan
This workshop discusses the challenges Enterprises are facing when scaling the data tier to support multi-region deployments and serverless environments. Serverless edge functions and lightweight container orchestration enables applications and business logic to be easily deployed globally, often leaving the database as the latency and scaling bottleneck.
Join us to understand how PolyScale.ai solves these scaling challenges intelligently caching database data at the edge, without sacrificing transactionality or consistency. Get hands on with PolyScale for implementation, query observability and global latency testing with edge functions.
Table of contents- Introduction to PolyScale.ai- Enterprise Data Gravity- Why data scaling is hard- Options for Scaling the data tier- Database Observability- Cache Management AI- Hands on with PolyScale.ai