top of page
  • Writer's pictureIvan Brko

Instrumenting Rust web application with Tracing and OpenTelemetry (and exporting the traces to Jaeger and GCP)

In this series of posts we'll explore how to achieve good observability of our Rust web application, by using the Tokio Tracing crate ecosystem in combination with OpenTelemetry.


We'll configure our Tracing (logging) spans to automatically create OpenTelemetry traces and see how to export those traces to Jaeger and GCP Trace Explorer.

The purpose of this tutorial is not to provide a strong theoretical background in OpenTelemetry but to provide an easy way to start leveraging some of its features with Rust.


Expected prior knowledge


No prior knowledge is assumed for Tracing and OpenTelemetry, but this is not an in-depth guide for those technologies, so you still should consult some other resources in combination with this tutorial.

Basic prior knowledge of Rust is assumed.

The last part of the tutorial configures our application to correctly export traces and logs when running in the GCP environment. It is not needed for other topics covered in the tutorial, but if you want to follow along, you will have to have your application running in GCP, and we don't cover how to achieve that. To get your application up and running on GCP quickly, I suggest trying GCP Cloud Run.


Naming

The same set of names is used for features provided by different libraries and ecosystems. To reduce ambiguity we'll use the following names wherever it is not clear from the text what we are referring to:

  • OTEL → OpenTelemetry, an abbreviation often used in the OpenTelemetry (OTEL) ecosystem

  • Tracing → Refers to the Tokio Tracing crate and all the other crates in its ecosystem

  • OTEL Tracing → OpenTelemetry process of collecting application traces and exporting them to some Trace Collector

  • Span → Span in the context of the Tokio Tracing crate

  • OTEL Span → Span in the context of OpenTelemetry

  • Instrumentalization → Instrumentalization in the context of the Tokio Tracing crate

  • OTEL Instrumentalization → Instrumentalization in the context of OpenTelemetry

  • Trace Collector → Tools like Jaeger and GCP Trace Explorer… wherever we can export OTEL traces from our application


Parts of the tutorial

  1. The first part gives a quick introduction to the concepts we'll be using, both for the Tokio Tracing crate and OpenTelemetry (if you are familiar with both, feel free to skip it)

  2. The second part walks us through setting up logging and tracing in our application and exporting traces and logs to Jaeger

  3. The third part changes the code from the second part to export the traces to GCP Trace Explorer instead and to print logs in the format expected by GCP Log Explorer


Library versions

OTEL ecosystem is still not stable and examples might break with different library versions, so make sure to use the libraries versions used in the tutorial.


Final code of the tutorial can be found in https://github.com/ivan-brko/rust-tracing-otel-tutorial. GCP code is in the gcp branch.

215 views0 comments

Comentários


bottom of page