diff options
Diffstat (limited to '')
-rw-r--r-- | src/jaegertracing/jaeger-client-cpp/examples/App.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/jaegertracing/jaeger-client-cpp/examples/App.cpp b/src/jaegertracing/jaeger-client-cpp/examples/App.cpp new file mode 100644 index 000000000..f7df8a2af --- /dev/null +++ b/src/jaegertracing/jaeger-client-cpp/examples/App.cpp @@ -0,0 +1,45 @@ +#include <iostream> + +#include <yaml-cpp/yaml.h> + +#include <jaegertracing/Tracer.h> + +namespace { + +void setUpTracer(const char* configFilePath) +{ + auto configYAML = YAML::LoadFile(configFilePath); + auto config = jaegertracing::Config::parse(configYAML); + auto tracer = jaegertracing::Tracer::make( + "example-service", config, jaegertracing::logging::consoleLogger()); + opentracing::Tracer::InitGlobal( + std::static_pointer_cast<opentracing::Tracer>(tracer)); +} + +void tracedSubroutine(const std::unique_ptr<opentracing::Span>& parentSpan) +{ + auto span = opentracing::Tracer::Global()->StartSpan( + "tracedSubroutine", { opentracing::ChildOf(&parentSpan->context()) }); +} + +void tracedFunction() +{ + auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction"); + tracedSubroutine(span); +} + +} // anonymous namespace + +int main(int argc, char* argv[]) +{ + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " <config-yaml-path>\n"; + return 1; + } + setUpTracer(argv[1]); + tracedFunction(); + // Not stricly necessary to close tracer, but might flush any buffered + // spans. See more details in opentracing::Tracer::Close() documentation. + opentracing::Tracer::Global()->Close(); + return 0; +} |