Created
July 1, 2019 11:00
-
-
Save ideepika/2f96832109d8d3b94a45492620aaeb54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef TRACER_H_ | |
| #define TRACER_H_ | |
| #include <iostream> | |
| #include <yaml-cpp/yaml.h> | |
| #include <jaegertracing/Tracer.h> | |
| namespace JTracer { | |
| static inline void setUpTracer(const char* serviceToTrace) { | |
| static auto configYAML = YAML::LoadFile("../jaegertracing/config.yml"); | |
| static auto config = jaegertracing::Config::parse(configYAML); | |
| static auto tracer = jaegertracing::Tracer::make( | |
| serviceToTrace, config, jaegertracing::logging::consoleLogger()); | |
| opentracing::Tracer::InitGlobal( | |
| std::static_pointer_cast<opentracing::Tracer>(tracer)); | |
| } | |
| typedef std::unique_ptr<opentracing::Span> jspan; | |
| jspan tracedSubroutine( | |
| jspan& parentSpan, | |
| const char* subRoutineContext) { | |
| auto span = opentracing::Tracer::Global()->StartSpan( | |
| subRoutineContext, {opentracing::ChildOf(&parentSpan->context())}); | |
| span->Finish(); | |
| return span; | |
| } | |
| jspan tracedFunction(const char* funcContext) { | |
| auto span = opentracing::Tracer::Global()->StartSpan(funcContext); | |
| span->Finish(); | |
| return span; | |
| } | |
| std::string inject(jspan& span, const char* name) { | |
| std::stringstream ss; | |
| if (!span) { | |
| auto span = opentracing::Tracer::Global()->StartSpan(name); | |
| } | |
| auto err = opentracing::Tracer::Global()->Inject(span->context(), ss); | |
| assert(err); | |
| return ss.str(); | |
| } | |
| void extract(jspan& span, const char* name, | |
| std::string t_meta) { | |
| std::stringstream ss(t_meta); | |
| // if(!tracer){ | |
| // } | |
| // setUpTracer("Extract-service"); | |
| auto span_context_maybe = opentracing::Tracer::Global()->Extract(ss); | |
| assert(span_context_maybe); | |
| // Propogation span | |
| auto _span = opentracing::Tracer::Global()->StartSpan( | |
| "propagationSpan", {ChildOf(span_context_maybe->get())}); | |
| auto span1 = std::move(_span); | |
| } | |
| } // namespace JTracer | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment