We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Tracing

Tracing records the execution path of a request through a (possibly distributed) system.

You're no doubt familiar with the concept of a "stack trace":

panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
main.(*User).GetName(0x0)
	/app/user.go:42 +0x12
main.validateUser(0x0)
	/app/validate.go:18 +0x3e
main.main()
	/app/main.go:12 +0x2c

In Go, a stack trace is really just a more-or-less human-readable version of a goroutine's stack. And a stack does show some tracing data, because it shows the function at the top of the stack and all of its callers.

But this is more like a "trace snapshot" than a proper trace.

Request Tracing

A full request trace ideally shows us all the interesting things that happen throughout the lifecycle of a request – not just a snapshot in time (as a stack trace provides). It can also show us timing information, like this:

Notice that the trace shows the entire path of the request, and it's made up of a series of spans. Each span represents a single unit of work. This lets us break the request down into the parts we care about. For example, if we're talking about a request to a handler that:

  1. Authenticates the user
  2. Fetches data from a database
  3. Makes an API call to a third party service
  4. Renders a template

We can create one span for each of those steps. When requests are reportedly "slow", we can see which operation is to blame!

OpenTelemetry & Jaeger

We'll focus on two popular open source tools: OpenTelemetry and Jaeger.

Similar to the way that Prometheus and Grafana complement each other to provide a complete metrics ingestion and display package, OpenTelemetry and Jaeger work together to gather and display traces.

OpenTelemetry can do much more than traces, including logging, and metrics. And while there are good reasons to use OpenTelemetry for more than tracing in some cases, we'll be focusing just on tracing for this course.