chapter six

6 Logging, tracing and debugging

 

This chapter covers:

  • When to use logging, tracing, or debugging in your web service.
  • Overview of the logging options within Rust.
  • Using external crates to improve your logging experience.
  • How tracing works in detail and why to use it for a web service.
  • Using the tracing crate in your web service.
  • Setting up a debugging environment for your Rust web service.
  • Debugging a web service written in Rust.

The first five chapters of the book covered implementing a web service in Rust, why and how to implement asynchronous concepts and the splitting of our Rust code into different modules and libraries. This alone helps to read and understand the code and makes future changes fast to implement. We also learned how to use the rigid nature of the compiler to help spot errors and improve our code.

This chapter covers the instrumentation of your web service. By this, we mean tracing information and diagnosing errors. Even during development, you most probably start to log information to the console to introspect HTTP calls or errors inside functions. This behavior however can be expanded and more streamlined. This is covered by logging and tracing your application.

6.1 Logging in your Rust application

6.1.1 Implementing logging in your web service

6.1.2 Log incoming HTTP requests

6.1.3 Create structured logs

6.2 Tracing in asynchronous applications

6.2.1 Introducing the tracing crate

6.2.2 Integrate tracing in our application

6.3 Debugging Rust applications

6.3.1 Using GDB on the command line

6.3.2 Using Visual Studio Code and LLDB

6.4 Summary