Skip to content
ImagineWorld

Real User Monitoring with Grafana

node_idnode-book_observability-with-grafana_chapter-12-real-user-monitoring-with-grafana
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num12
chapter_titleReal User Monitoring with Grafana
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 12 — Real User Monitoring with Grafana

Section titled “Chapter 12 — Real User Monitoring with Grafana”

In this chapter, we will investigate real user monitoring (RUM) with Grafana Cloud Frontend Observability and the Faro Web SDK. We’ll explore what RUM is, how we use it to solve real user problems, and some important metrics to consider. We will then look at how to set up Frontend Observability in your Grafana Cloud instance and the prebuilt dashboards that are included. We will explore how Frontend Observability data can be correlated with backend telemetry for a more complete picture. To finish, we will look at best practices for collecting frontend data.

In this chapter, we are going to cover the following main topics:

  • Introducing RUM
  • Setting up Grafana Frontend Observability
  • Exploring Web Vitals
  • Pivoting from frontend to backend data
  • Enhancements and custom configurations

RUM is the term used to describe the collection and processing of telemetry that describes the health of the frontend of your web applications. It gives us a bird’s-eye view of user transactions as they happen, live from the user’s browser all the way through to the backend system. The benefit of this telemetry is in the insight into the experience real users are having with the performance of your application.

Grafana implements RUM with a combination of the following:

  • The Grafana Faro Web SDK, which, when embedded in your web application, collects the following telemetry by default:
    • Web Vitals performance metrics
      • Unhandled exceptions
      • Browser environment information
      • Page URL changes
      • Session identification (for data correlation)
      • Activity traces In addition to the defaults, the SDK can be configured to send custom metadata, measurements, and metrics into Grafana to enhance Frontend Observability. The Faro Web SDK integrates with opentelemetry-js to provide Open Telemetry-based tracing in your application. This SDK is open source, and the repository can be found at https://github.com/grafana/faro-web-sdk; it has comprehensive documentation along with some demonstration code.
  • A cloud-hosted receiver of browser telemetry (you can alternatively deploy a Grafana Agent on your own infrastructure). The cloud-hosted receiver is created and configured when you activate application observability in Grafana Cloud (we will talk you through the setup steps in the next section).
  • A dedicated Grafana app interface for each Frontend Observability app you create with included dashboards as tabs (we look at these dashboard tabs later in this chapter).

The following diagram shows the relationship between your frontend application in the left box, with the Faro Web SDK installed, and the Grafana Cloud components in the right box for ingesting, storing, and presenting your telemetry:

Figure 12.1 – Frontend relationship diagram

The Grafana Faro Web SDK collects telemetry and forwards it to the collector endpoint in Grafana Cloud where it is processed and sent to the appropriate backend – Loki for logs and Tempo for traces. Metrics are generated from logs using Loki’s LogQL metric queries we discussed in Chapter 4. The generated metrics are visualized in the Grafana Cloud Frontend Observability application dashboards.

Let’s now look at the setup for Grafana Frontend Observability.

To get started with monitoring your application frontend and configure Grafana Cloud Frontend Observability, follow these steps:

  1. In your Grafana instance, select Observability | Frontend from the menu:

Figure 12.2 – Grafana Observability menu

  1. The Frontend Apps landing page will be displayed. If this is your first time here, you will have a Start observing button – go ahead and click on it:

Figure 12.3 – Grafana Cloud Frontend Observability screen

If you have already set up frontend apps, they will be listed here and there will be a Create New button instead of the Start observing button. Clicking either of these buttons shows the Create New App modal window.

  1. The Create New App modal window shown in Figure 12*.4* requires an app name, Cross Origin Resource Sharing (CORS) addresses, and additional label details (these are labels to add to Loki logs as they come into Grafana Cloud). Additionally, you will be asked to confirm the cloud costs associated with the additional telemetry from this feature:

Figure 12.4 – Create New App screen

  1. Once you have completed the form, you are provided with a few options for integrating the Faro Web SDK into your frontend application using NPM, CDN with Tracing, or CDN without Tracing. You will have to decide which suits your application development requirements best:

Figure 12. 5 – Web SDK configuration

When you have connected the Faro Web SDK in your application to Grafana, the default telemetry we identified at the beginning of this section will begin sending.

The Overview tab of your observability frontend app will look similar to the following screenshot, with the main dashboard included in Grafana Frontend Observability showing key metrics:

Figure 12.6 – Frontend Observability Overview tab

Next to the Overview tab are the Errors and Sessions tabs, which help you investigate your app. Let’s look at these tabs in more detail:

  • The top row on the dashboard in the Overview tab shows important Web Vitals metrics, including Core Web Vitals. Web Vitals is an initiative by Google that provides unified guidance for signals that are essential to reporting user experience on the web.
  • The Errors tab details any frontend exceptions, where they happened, and the browsers affected:

Figure 12.7 – Frontend Observability Errors tab

  • The Sessions tab shows a list of the available user sessions to analyze. We will explore this in more detail in the Pivoting from frontend to backend data section.

The Settings and Web SDK Configuration tabs help you configure the connection (Settings allows you to modify the values entered in step 3 earlier in this section, and Web SDK Configuration provides the config seen in step 4).

In the next section, let’s look at Web Vitals metrics in more detail to understand the information we are capturing and reporting for our frontend applications.

To explain the quality of experience delivered to users, the Web Vitals metrics report on several areas of a user’s interaction. Web Vitals is a Google initiative that provides unified guidance for quality signals that are essential for delivering a great web user experience. You can read about the Web Vitals project in more detail at https://web.dev/articles/vitals and specifically Core Web Vitals at https://web.dev/vitals/#core-web-vitals.

The important Web Vitals metrics used in the Overview tab are as follows:

Metric

Description

Core Web Vitals

Largest Contentful Paint (LCP)

The LCP metric measures the display time of the largest visible section in relation to the page starting to load. This could be text or an image that completely loads on the visitor’s screen.

A target LCP of <= 2.5 seconds is promoted.

For more details, refer to https://web.dev/articles/lcp.

First Input Delay (FID)

The FID metric measures the time from when a visitor clicks a link to the time the browser starts processing the event.

A target FID of <= 100 milliseconds is promoted.

For more details, refer to https://web.dev/articles/fid.

There are plans to replace FID with Interaction To Next Paint (INP) as a Core Web Vital in March 2024.

Cumulative Layout Shift (CLS)

The CLS metric measures any time a visible element changes its position. As the visitor experiences layout changes, the duration is captured and the cumulative score is reported.

A target CLS of <= 0.1 is the aim.

For more details, refer to https://web.dev/articles/cls.

Other Web Vitals

Time To First Byte (TTFB)

The TTFB metric measures the time between the request for a web resource and when the very first byte of a response starts to arrive. This will not be obvious to the visitor, but it is a good indicator of responsiveness of getting content to the visitor.

A target TTFB of <= 0.8 seconds is the objective.

For more details, refer to https://web.dev/articles/ttfb.

First Contentful Paint (FCP)

The FCP metric measures the time from when the page starts loading to when any part of the page is displayed on the screen – essentially, when your visitor actually sees an interaction with the website requested.

A target FCP of <= 1.8 seconds is the aim.

For more details, refer to https://web.dev/articles/fcp.

Interaction to Next Paint (INP)

The INP metric measures the responsiveness of a page throughout a visitor’s session. It does this by observing the latency of every click, tap, and keyboard interaction by a visitor and takes the longest (ignoring outliers).

The target value for the INP is <= 200 milliseconds.

For more details, refer to https://web.dev/articles/inp.

Table 12.1 – Important Web Vitals metrics

Now that we have looked at some of the important frontend metrics to consider, let’s look at how we can pivot to backend telemetry when investigating issues.

Once you have started collecting Frontend Observability data, you will be able to correlate it with backend and infrastructure telemetry. Grafana provides simple interfaces for this when you are using Loki for logs, Tempo for traces, and Mimir for metrics.

Within the Grafana Cloud Frontend Observability app, there are readymade dashboards that make navigation and investigation simple. As discussed in the Setting up GrafanaFrontend Observability section, the app menu has three main sections, namely, Overview, Errors, and Sessions. The Sessions tab allows us to jump into other telemetry that our system is producing and sending to Grafana. You can see in the following screenshot multiple requests to different page URLs alongside the associated session IDs:

Figure 12.8 – The Sessions tab

Clicking a Session Id entry will take you to a detailed view, where you can see the Web Vitals for that specific visitor session, associated exceptions, and, if you have instrumented the rest of your system, links to Traces:

Figure 12.9 – The Session Details screen

Selecting Traces takes you into an Explore view of full system traces, where you can easily navigate to associated Loki logs from the backend, providing you with the ability to traverse your system. This demonstrates the additional value that can be gained with full end-to-end observability instrumentation:

Figure 12.10 – The Explore view for system traces

A default session is defined by the following:

  • Session start: The visitor navigates to a web page, Faro is initialized, and a new session is started
  • Session end: The visitor navigates away and the session is destroyed (by default, a session end event is not sent)

However, you can define session logic as you prefer, to fit your use case. The Faro docs for session instrumentation at https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/faro-web-sdk/components/provided-instrumentations/#session-tracking show available configurations.

Let’s now look at some best practices to consider with Frontend Observability.

With all observability, you need to consider your use case. This is especially important when considering Frontend Observability as you will be operating in your visitor’s browser. There are several enhancements you can make to Frontend Observability over the default implementation. However, these enhancements come with the overhead of additional configuration, additional developer effort, and a potentially greater impact on your visitor’s browser. However, they can dramatically increase the value provided by Frontend Observability instrumentation.

Let’s explore the enhancements for Frontend Observability:

  • Frontend Tracing: This provides improved correlation between real user interactions and backend events. It requires the additional OpenTelemetry SDK configurations and adds some overhead to your visitor’s browser, so consider the implications carefully and test for any impact.
  • Custom Errors: This provides improved observability for systems that have error handling. Additional configuration is required to manually add the Faro Web SDK to the error handling pipeline to push errors to Grafana.
  • Custom Measurements: This provides enhanced telemetry with application-specific data. Additional configuration is required to manually add the Faro Web SDK to push additional measurements to Grafana.
  • Custom Logs: This provides the ability to send supporting metadata along with telemetry to help you understand your visitors’ experiences. It requires additional configuration and development effort to instrument.
  • Custom Events: This provides additional correlation to help with issue investigation and data presentation. Events are ingested by Loki as logs with a specific label, kind=event. We learned all about Loki labels in Chapter 4.

If you do not have a frontend app ready to instrument, there is a demo project as part of the Faro Web SDK that you can experiment with. It will help you understand in more detail what is happening and how it works: https://github.com/grafana/faro-web-sdk/blob/main/demo/README.md.

Let’s now wrap up this chapter with a summary and look toward the following chapter.

In this chapter, we have explored user monitoring and the additional value gained with full end-to-end observability instrumentation. We looked at how Grafana provides this capability with Grafana Frontend Observability and the Faro Web SDK. We then looked at the Web Vitals metrics, which are important for interpreting visitor experience. We also looked at the built-in dashboards that help you navigate to your backend telemetry in Grafana, giving you the ability to fully diagnose problems. Finally, we looked at some best practices and custom configurations for Frontend Observability.

In the next chapter, we will learn about different aspects of application performance with Pyroscope and k6 from Grafana.