diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/jaeger-client-cpp/examples/App.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/jaeger-client-cpp/examples/App.cpp')
-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; +} |