This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Example app #101
Merged
Merged
Example app #101
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
45476a9
Update README regarding Thrift, begin example application
eaacd9f
Fix dynamic load test
3a22376
Fix configs and example
14e11b9
Close tracer just in case
isaachier 027e4f9
Update README regarding Thrift, begin example application
cf81d6d
Fix configs and example
bbc2b81
Close tracer just in case
isaachier 82bf37e
Merge branch 'example-app' of github.com:isaachier/jaeger-client-cpp …
isaachier 14b2a42
Remove broken test case
isaachier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#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(); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,6 @@ | ||
service_name: test-service | ||
disabled: false | ||
sampler: | ||
type: probabilistic | ||
param: 0.001 | ||
reporter: | ||
queueSize: 100 | ||
bufferFlushInterval: 10 | ||
logSpans: false | ||
localAgentHostPort: 127.0.0.1:6831 | ||
headers: | ||
jaegerDebugHeader: debug-id | ||
jaegerBaggageHeader: baggage | ||
TraceContextHeaderName: trace-id | ||
traceBaggageHeaderPrefix: testctx- | ||
baggage_restrictions: | ||
denyBaggageOnInitializationFailure: false | ||
hostPort: 127.0.0.1:5778 | ||
refreshInterval: 60 | ||
logSpans: true | ||
sampler: | ||
type: const | ||
param: 1 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you need to close/flush the tracer before exit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Luckily, no. At least not for the Jaeger client. My favorite thing about C++ is that most things are auto-closing (formally called RAII). Spans must be auto-closing according to OT C++ spec, but the
Tracer::Close()
definition is a little more vague (see https://github.com/opentracing/opentracing-cpp/blob/master/include/opentracing/tracer.h#L149-L153). As of now, we aren't using close any differently here than for spans. Might add it just in case I change my mind.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, when the main function exits, the global tracer shared pointer is destroyed, invoking the Tracer destructor, which invokes
Tracer::close
on its own. We could manually invoke any of these methods, but there is no need to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not saying you are wrong, but I'd expect that behavior if you had a locally scoped variable that would get destroyed upon exiting the main scope. That global variables behave the same way is a surprise to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya it's a bit confusing. Here's a source quoting the standard about it: https://stackoverflow.com/a/2204628/1930331.