This section will illustrate how to add instrumentation with Jaeger and OpenTracing to an existing application. We'll use the opentracing-cpp and jaeger-client-cpp libraries.
First, we want to set up the tracer:
#include <jaegertracing/Tracer.h>
void setUpTracer()
{
// We want to read the sampling server configuration from the
// environment variables
auto config = jaegertracing::Config;
config.fromEnv();
// Jaeger provides us with ConsoleLogger and NullLogger
auto tracer = jaegertracing::Tracer::make(
"customer", config, jaegertracing::logging::consoleLogger());
opentracing::Tracer::InitGlobal(
std::static_pointer_cast<opentracing::Tracer>(tracer));
}
The two preferred methods for configuring a sampling server are either by using the environment variable, as we did, or by using a YAML configuration file. When using environment variables, we will...