Beyond the Console: Navigating JavaScript With Observability

Rate this content
Bookmark

Embark on a journey beyond console logs! This session unveils the power of observability in the world of JavaScript, offering practical insights and real-world examples to supercharge your development workflow. From pinpointing elusive bugs to optimizing user experiences, discover the art of making your code transparent, traceable, and resilient. Elevate your JavaScript craftsmanship with the mastery of observability.


JavaScript development is evolving, and so should your approach to understanding and optimizing code. This session arms you with the knowledge and tools needed to stay ahead in the ever-changing landscape of web development.

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

FAQ

Nathan Mars is the tech lead of data visualization at Grafana Labs.

The primary focus of Nathan Mars' talk is how to bring observability to JavaScript applications.

Observability refers to how well you can understand what's going on internally in a system based on its outputs.

The three main data types necessary for understanding the performance and health of applications are metrics, logs, and traces.

OpenTelemetry is a collection of tools, APIs, and SDKs used to instrument, generate, collect, and export telemetry data.

OpenTelemetry provides a standardization for describing what distributed systems are doing, no matter what programming language or computer systems you're using.

Grafana is the leading open source technology for dashboards and visualization, used to analyze and monitor application data.

To start using OpenTelemetry with a Node application, you need to install the OpenTelemetry API and auto-instrumentation node packages, configure your application to export telemetry data, and set up a free account in Grafana Cloud to visualize the data.

In Grafana Cloud, you can monitor your services' metrics, logs, traces, and profiles, configure alerts and on-call, trigger incidents, and run machine learning analysis via SIFT investigations.

Yes, observability can be configured for front-end applications to collect metrics such as page load, errors, user sessions, custom logs, and events.

Nathan Marrs
Nathan Marrs
7 min
17 Jun, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Nathan Mars, tech lead at Grafana Labs, introduces observability for JavaScript applications, highlighting the effectiveness of debugging and troubleshooting with observability. Open Telemetry is presented as a standardized way to obtain system data and Grafana as a platform for monitoring metrics, logs, traces, and profiles. The talk also emphasizes the applicability of observability to the front end using GrafanaFerro to collect metrics like page load, errors, and user sessions.

1. Introduction to Observability

Short description:

Hi, I'm Nathan Mars, the tech lead at Grafana Labs. Let me show you how to bring observability to your JavaScript applications. Learn how to debug and troubleshoot modern apps effectively using observability.

Hi, my name is Nathan Mars and I'm the tech lead of data visualization at Grafana Labs. Today I'm excited to share with you how to bring observability to your JavaScript applications. If you want to figure out why your app is running too slow, is broken, or you just want to improve its code quality, this is the talk for you.

Let's start with the story. Picture this. It's a Friday afternoon and you get a message from your boss that there's a mysterious bug in production. Is it time to panic? Will you have a weekend? Maybe or maybe not. Luckily for you, this fictional company only has a single monolith server, and both your server and frontend is written in JavaScript. So you have a secret weapon. The old faithful console.log.

You dig into the code and add dozens of console.log statements in an attempt to pinpoint the root cause of the error. After a lot of trial and error, you locate the issue in your node server's delete cart logic. You fix the bug and push the code directly to production. Crisis averted. But what if you were more realistically working at a company that has much more complexity, where your application is deployed across the world and every request interacts with a swarm of microservices? This is where console.log fails us. So what can we do to make sure that debugging and troubleshooting our modern applications is not a nightmare? The answer is observability.

What is observability? It means how well you can understand what's going on internally in a system based on its outputs. As systems become more distributed and complex, it's hard to see what's going on inside your application and why things may be going wrong. When talking about observability, we needed to define the data types necessary to understand the performance and health of our applications. Broadly, these are metrics, logs, and traces. Metrics are measurements collected at regular intervals. Most have a timestamp, a name, and one or more numeric values. Examples include error rate, response time, or output. Logs come directly from your app, exporting detailed data and context around an event. Engineers can recreate what has happened millisecond by millisecond. Logs should be very familiar as they are essentially more scalable and useful console.logs. Traces follow a request from the initial request to the returned output. They record the causal chain of events to determine relationships between different entities. Traces are very valuable for highlighting inefficiencies, bottlenecks, and roadblocks in user experience as they can be used to show the end-to-end latency of individual requests throughout an entire distributed architecture. Okay, great.

2. Open Telemetry and Grafana for Observability

Short description:

We have an idea of what observability is and what data it is made up of. Open telemetry is the answer to getting this data, providing a standardized way of describing what your system is doing. Once we have open telemetry set up, we can export the collected data to Grafana, where we can monitor our applications' metrics, logs, traces, and profiles. Observability is not limited to the back end; it can also be configured for the front end using GrafanaFerro to collect metrics such as page load, errors, and user sessions.

We have an idea of what observability is and what data it is made up of. This brings up an important question. How can we get this data? Should we manually instrument every single service, layer by layer? No, this would take as much time as writing the code itself. Luckily, there are some awesome open source projects as well as companies that make this a lot easier.

The answer is open telemetry. What do we mean by open telemetry? Let's start off with the name itself. We have open, so like open source, and then telemetry, which is the process of gathering, analyzing, and transmitting data from remote sources to monitor the performance of systems. The word itself comes from the Greek words tele, meaning remote, and metron, meaning measure.

With any app, when you're looking at this kind of data, you have two parts that need to come together. The first is figuring out how to generate and transmit that data. The second part is deciding what you're going to do with that data. Open telemetry deals with the first part. Up until recently, there really hasn't been a standardized way of describing what your system is doing. This problem has been compounded by the vast variety of programming languages and computers in use, making it difficult to build standardized observability tooling. Solving this problem is the core of the open telemetry project, providing a standardization for describing what distributed systems are doing, no matter what programming language or computer systems you're using. Today, the open telemetry project can be described as a collection of tools, APIs, and SDKs used to instrument, generate, collect, and export telemetry data so we can analyze that data with whatever platform we wish.

Once we have open telemetry set up, we are collecting data and now need to export it somewhere to visualize it. Let's take a look at how you can use Grafana, the leading open source technology for dashboards and visualization, to analyze this data and to monitor your application. To begin with, you need to first install the instrumentation libraries. In the case of a node application, you will need to install both the open telemetry API and auto-instrumentation node packages. Next, you need to configure your application to export telemetry data. We will be writing a basic bash script that sets up open telemetry and runs our application. To get the authentication environment variables, you will need to set up a free account in Grafana Cloud and configure open telemetry for your Grafana Cloud stack. Then, you can choose a service name. Let's say this is our cart service, and then run your application via the shell script and make requests to the service to send telemetry data to Grafana Cloud.

Within Grafana Cloud, you can now observe your service and application observability. Inside of application observability, you can monitor your services' metrics, logs, traces, and profiles. Profiles we haven't mentioned yet, they identify performance bottlenecks in your application's code. Now that we have this data, what can you do with it? Well, you can configure alerts and on-call to help your team know when something's going wrong, such as if your node's application CPU usage goes above a certain threshold. Within application observability, you can also trigger an incident that automatically includes the important context from interim data. While investigating an incident, you can even run machine learning analysis via SIFT investigations, a powerful diagnostic assistant that helps you holistically analyze your system's telemetry during investigations. It does this through checks such as grouping similar error logs, identifying resources that had a recent deployment, identifying cube crashes, and more. Observability is not just confined to the back end. You can also configure observability for your front end to collect metrics such as page load, errors, user sessions, custom logs and events, and more. To start capturing telemetry from your front-end applications within Grafana, you can configure GrafanaFerro in your JavaScript initialization code. There we have it, how you can gain valuable insight and improve your JavaScript applications beyond relying on console.logs.

Thank you for your time today.

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

Modern Web Debugging
JSNation 2023JSNation 2023
29 min
Modern Web Debugging
Top Content
This Talk discusses modern web debugging and the latest updates in Chrome DevTools. It highlights new features that help pinpoint issues quicker, improved file visibility and source mapping, and ignoring and configuring files. The Breakpoints panel in DevTools has been redesigned for easier access and management. The Talk also covers the challenges of debugging with source maps and the efforts to standardize the source map format. Lastly, it provides tips for improving productivity with DevTools and emphasizes the importance of reporting bugs and using source maps for debugging production code.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
From Friction to Flow: Debugging With Chrome DevTools
JSNation 2024JSNation 2024
32 min
From Friction to Flow: Debugging With Chrome DevTools
The Talk discusses the importance of removing frictions in the debugging process and being aware of the tools available in Chrome DevTools. It highlights the use of the 'Emulate a Focus Page' feature for debugging disappearing elements and the improvement of debugging tools and workflow. The Talk also mentions enhancing error understanding, improving debugging efficiency and performance, and the continuous improvement of DevTools. It emphasizes the importance of staying updated with new features and providing feedback to request new features.
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.
Debugging with Chrome DevTools
JSNation Live 2021JSNation Live 2021
11 min
Debugging with Chrome DevTools
Here are some tips for better utilizing DevTools, including using the run command, customizing keyboard shortcuts, and emulating the focus effect. Learn how to inspect memory, use the network panel for more control over network requests, and take advantage of console utilities. Save frequently used code as snippets and use local overrides for easy editing. Optimize images by using a more optimized format like AVIF and track changes in the network panel to see the reduced data size.
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.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
React Performance Debugging
React Advanced Conference 2023React Advanced Conference 2023
148 min
React Performance Debugging
Workshop
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
The Clinic.js Workshop
JSNation 2022JSNation 2022
71 min
The Clinic.js Workshop
Workshop
Rafael Gonzaga
Rafael Gonzaga
Learn the ways of the clinic suite of tools, which help you detect performance issues in your Node.js applications. This workshop walks you through a number of examples, and the knowledge required to do benchmarking and debug I/O and Event Loop issues.
Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
JSNation 2023JSNation 2023
44 min
Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
WorkshopFree
Ryan Albrecht
Ryan Albrecht
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).
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