Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Example app (#101)
Browse files Browse the repository at this point in the history
* Update README regarding Thrift, begin example application

Signed-off-by: Isaac Hier <[email protected]>

* Fix dynamic load test

Signed-off-by: Isaac Hier <[email protected]>

* Fix configs and example

Signed-off-by: Isaac Hier <[email protected]>

* Close tracer just in case

Signed-off-by: Isaac Hier <[email protected]>

* Update README regarding Thrift, begin example application

Signed-off-by: Isaac Hier <[email protected]>

* Fix configs and example

Signed-off-by: Isaac Hier <[email protected]>

* Close tracer just in case

Signed-off-by: Isaac Hier <[email protected]>

* Remove broken test case

Signed-off-by: Isaac Hier <[email protected]>
  • Loading branch information
isaachier authored May 16, 2018
1 parent b749aed commit 772af75
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 39 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ find_package(nlohmann_json CONFIG REQUIRED)
list(APPEND LIBS nlohmann_json)
list(APPEND package_deps nlohmann_json)

option(JAEGERTRACING_BUILD_EXAMPLES "Build examples" ON)

option(JAEGERTRACING_COVERAGE "Build with coverage" $ENV{COVERAGE})
option(JAEGERTRACING_BUILD_CROSSDOCK "Build crossdock" $ENV{CROSSDOCK})
cmake_dependent_option(
Expand Down Expand Up @@ -240,6 +242,11 @@ configure_file(
src/jaegertracing/Constants.h
@ONLY)

if(JAEGERTRACING_BUILD_EXAMPLES)
add_executable(app examples/App.cpp)
target_link_libraries(app PUBLIC ${JAEGERTRACING_LIB})
endif()

if(BUILD_TESTING)
add_library(testutils
src/jaegertracing/testutils/TUDPTransport.cpp
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md).
## Generated files

This project uses Apache Thrift for wire-format protocol support code
generation. It currently requires exactly Thrift 0.9.2 or 0.9.3. Patches have
been applied to the generated code so it cannot be directly re-generated from
the IDL in the `idl` submodule

(see https://github.com/jaegertracing/jaeger-client-cpp/issues/45)
generation. It currently requires Thrift 0.11.0.

The code can be re-generated with

git submodule init
git submodule update
find idl/thrift/ -type f -name \*.thrift -exec thrift -gen cpp -out src/jaegertracing/thrift-gen {} \;

but at time of writing (Thrift 0.11.0) the resulting code is invalid due to
https://issues.apache.org/jira/browse/THRIFT-4484.
```bash
$ git submodule update --init
$ find idl/thrift/ -type f -name \*.thrift -exec thrift -gen cpp -out src/jaegertracing/thrift-gen {} \;
$ git apply scripts/thrift-gen.patch
```

## License

Expand All @@ -35,4 +30,3 @@ https://issues.apache.org/jira/browse/THRIFT-4484.
[cov]: https://codecov.io/gh/jaegertracing/jaeger-client-cpp
[ot-img]: https://img.shields.io/badge/OpenTracing--1.0-enabled-blue.svg
[ot-url]: http://opentracing.io

45 changes: 45 additions & 0 deletions examples/App.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 4 additions & 17 deletions examples/config.yml
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
2 changes: 1 addition & 1 deletion src/jaegertracing/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Config {

static Config parse(const YAML::Node& configYAML)
{
if (!configYAML.IsMap()) {
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
return Config();
}

Expand Down
6 changes: 1 addition & 5 deletions src/jaegertracing/TracerFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

#include "jaegertracing/Constants.h"
#include "jaegertracing/TracerFactory.h"
#include "jaegertracing/Constants.h"
#include <gtest/gtest.h>

namespace jaegertracing {
Expand All @@ -26,10 +26,6 @@ TEST(TracerFactory, testInvalidConfig)
"abc: {",
R"({
"service_name": {}
})",
R"({
"service_name": "t",
"badField": 97
})" };
TracerFactory tracerFactory;
for (auto&& invalidConfig : invalidConfigTestCases) {
Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/baggage/RestrictionsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RestrictionsConfig {

static RestrictionsConfig parse(const YAML::Node& configYAML)
{
if (!configYAML.IsMap()) {
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
return RestrictionsConfig();
}

Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/propagation/HeadersConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HeadersConfig {

static HeadersConfig parse(const YAML::Node& configYAML)
{
if (!configYAML.IsMap()) {
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
return HeadersConfig();
}

Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/reporters/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Config {

static Config parse(const YAML::Node& configYAML)
{
if (!configYAML.IsMap()) {
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
return Config();
}

Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/samplers/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Config {

static Config parse(const YAML::Node& configYAML)
{
if (!configYAML.IsMap()) {
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
return Config();
}

Expand Down

0 comments on commit 772af75

Please sign in to comment.