Book Image

Mastering Distributed Tracing

By : Yuri Shkuro
Book Image

Mastering Distributed Tracing

By: Yuri Shkuro

Overview of this book

Mastering Distributed Tracing will equip you to operate and enhance your own tracing infrastructure. Through practical exercises and code examples, you will learn how end-to-end tracing can be used as a powerful application performance management and comprehension tool. The rise of Internet-scale companies, like Google and Amazon, ushered in a new era of distributed systems operating on thousands of nodes across multiple data centers. Microservices increased that complexity, often exponentially. It is harder to debug these systems, track down failures, detect bottlenecks, or even simply understand what is going on. Distributed tracing focuses on solving these problems for complex distributed systems. Today, tracing standards have developed and we have much faster systems, making instrumentation less intrusive and data more valuable. Yuri Shkuro, the creator of Jaeger, a popular open-source distributed tracing system, delivers end-to-end coverage of the field in Mastering Distributed Tracing. Review the history and theoretical foundations of tracing; solve the data gathering problem through code instrumentation, with open standards like OpenTracing, W3C Trace Context, and OpenCensus; and discuss the benefits and applications of a distributed tracing infrastructure for understanding, and profiling, complex systems.
Table of Contents (21 chapters)
Mastering Distributed Tracing
Contributors
Preface
Other Books You May Enjoy
Leave a review - let other readers know what you think
15
Afterword
Index

Exercise 3 – tracing functions and passing context


When looking at the trace generated by the version of the Hello application from the second exercise, we noticed that the log entry we added to the span happens very close to the end of the span. We hypothesized that this is because most of the time is spent querying the database, but this is why we are doing distributed tracing in the first place: not to guess, but to measure! We already have the main chunks of the logic, the database access and formatting of the greeting, separated into functions, so let's give each of them a span and get a more meaningful trace.

In this exercise we will:

  • Trace individual functions

  • Combine multiple spans into a single trace

  • Learn to propagate the context in-process

Step 1 – trace individual functions

Let's start with adding spans in our two "worker" functions: reading from the database and formatting the greeting.

Trace individual functions in Go

Our FormatGreeting() function is located in the main package, so...