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

Commit 772af75

Browse files
authored
Example app (#101)
* 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]>
1 parent b749aed commit 772af75

File tree

10 files changed

+68
-39
lines changed

10 files changed

+68
-39
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ find_package(nlohmann_json CONFIG REQUIRED)
6363
list(APPEND LIBS nlohmann_json)
6464
list(APPEND package_deps nlohmann_json)
6565

66+
option(JAEGERTRACING_BUILD_EXAMPLES "Build examples" ON)
67+
6668
option(JAEGERTRACING_COVERAGE "Build with coverage" $ENV{COVERAGE})
6769
option(JAEGERTRACING_BUILD_CROSSDOCK "Build crossdock" $ENV{CROSSDOCK})
6870
cmake_dependent_option(
@@ -240,6 +242,11 @@ configure_file(
240242
src/jaegertracing/Constants.h
241243
@ONLY)
242244

245+
if(JAEGERTRACING_BUILD_EXAMPLES)
246+
add_executable(app examples/App.cpp)
247+
target_link_libraries(app PUBLIC ${JAEGERTRACING_LIB})
248+
endif()
249+
243250
if(BUILD_TESTING)
244251
add_library(testutils
245252
src/jaegertracing/testutils/TUDPTransport.cpp

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md).
1010
## Generated files
1111

1212
This project uses Apache Thrift for wire-format protocol support code
13-
generation. It currently requires exactly Thrift 0.9.2 or 0.9.3. Patches have
14-
been applied to the generated code so it cannot be directly re-generated from
15-
the IDL in the `idl` submodule
16-
17-
(see https://github.com/jaegertracing/jaeger-client-cpp/issues/45)
13+
generation. It currently requires Thrift 0.11.0.
1814

1915
The code can be re-generated with
2016

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

2823
## License
2924

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

examples/App.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
3+
#include <yaml-cpp/yaml.h>
4+
5+
#include <jaegertracing/Tracer.h>
6+
7+
namespace {
8+
9+
void setUpTracer(const char* configFilePath)
10+
{
11+
auto configYAML = YAML::LoadFile(configFilePath);
12+
auto config = jaegertracing::Config::parse(configYAML);
13+
auto tracer = jaegertracing::Tracer::make(
14+
"example-service", config, jaegertracing::logging::consoleLogger());
15+
opentracing::Tracer::InitGlobal(
16+
std::static_pointer_cast<opentracing::Tracer>(tracer));
17+
}
18+
19+
void tracedSubroutine(const std::unique_ptr<opentracing::Span>& parentSpan)
20+
{
21+
auto span = opentracing::Tracer::Global()->StartSpan(
22+
"tracedSubroutine", { opentracing::ChildOf(&parentSpan->context()) });
23+
}
24+
25+
void tracedFunction()
26+
{
27+
auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction");
28+
tracedSubroutine(span);
29+
}
30+
31+
} // anonymous namespace
32+
33+
int main(int argc, char* argv[])
34+
{
35+
if (argc < 2) {
36+
std::cerr << "usage: " << argv[0] << " <config-yaml-path>\n";
37+
return 1;
38+
}
39+
setUpTracer(argv[1]);
40+
tracedFunction();
41+
// Not stricly necessary to close tracer, but might flush any buffered
42+
// spans. See more details in opentracing::Tracer::Close() documentation.
43+
opentracing::Tracer::Global()->Close();
44+
return 0;
45+
}

examples/config.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
service_name: test-service
21
disabled: false
3-
sampler:
4-
type: probabilistic
5-
param: 0.001
62
reporter:
7-
queueSize: 100
8-
bufferFlushInterval: 10
9-
logSpans: false
10-
localAgentHostPort: 127.0.0.1:6831
11-
headers:
12-
jaegerDebugHeader: debug-id
13-
jaegerBaggageHeader: baggage
14-
TraceContextHeaderName: trace-id
15-
traceBaggageHeaderPrefix: testctx-
16-
baggage_restrictions:
17-
denyBaggageOnInitializationFailure: false
18-
hostPort: 127.0.0.1:5778
19-
refreshInterval: 60
3+
logSpans: true
4+
sampler:
5+
type: const
6+
param: 1

src/jaegertracing/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Config {
3232

3333
static Config parse(const YAML::Node& configYAML)
3434
{
35-
if (!configYAML.IsMap()) {
35+
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
3636
return Config();
3737
}
3838

src/jaegertracing/TracerFactoryTest.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "jaegertracing/Constants.h"
1817
#include "jaegertracing/TracerFactory.h"
18+
#include "jaegertracing/Constants.h"
1919
#include <gtest/gtest.h>
2020

2121
namespace jaegertracing {
@@ -26,10 +26,6 @@ TEST(TracerFactory, testInvalidConfig)
2626
"abc: {",
2727
R"({
2828
"service_name": {}
29-
})",
30-
R"({
31-
"service_name": "t",
32-
"badField": 97
3329
})" };
3430
TracerFactory tracerFactory;
3531
for (auto&& invalidConfig : invalidConfigTestCases) {

src/jaegertracing/baggage/RestrictionsConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RestrictionsConfig {
3333

3434
static RestrictionsConfig parse(const YAML::Node& configYAML)
3535
{
36-
if (!configYAML.IsMap()) {
36+
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
3737
return RestrictionsConfig();
3838
}
3939

src/jaegertracing/propagation/HeadersConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class HeadersConfig {
3030

3131
static HeadersConfig parse(const YAML::Node& configYAML)
3232
{
33-
if (!configYAML.IsMap()) {
33+
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
3434
return HeadersConfig();
3535
}
3636

src/jaegertracing/reporters/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Config {
4949

5050
static Config parse(const YAML::Node& configYAML)
5151
{
52-
if (!configYAML.IsMap()) {
52+
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
5353
return Config();
5454
}
5555

src/jaegertracing/samplers/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Config {
5454

5555
static Config parse(const YAML::Node& configYAML)
5656
{
57-
if (!configYAML.IsMap()) {
57+
if (!configYAML.IsDefined() || !configYAML.IsMap()) {
5858
return Config();
5959
}
6060

0 commit comments

Comments
 (0)