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

Commit d64d606

Browse files
Added support for generating 128 bit trace ids (#254)
Signed-off-by: Tobias Stadler <[email protected]>
1 parent fd2989a commit d64d606

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

src/jaegertracing/Config.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ void Config::fromEnv()
3232
_disabled = disabled.second;
3333
}
3434

35+
const auto traceId128Bit =
36+
utils::EnvVariable::getBoolVariable(kJAEGER_JAEGER_TRACEID_128BIT_ENV_PROP);
37+
if (traceId128Bit.first) {
38+
_traceId128Bit = traceId128Bit.second;
39+
}
40+
3541
const auto serviceName =
3642
utils::EnvVariable::getStringVariable(kJAEGER_SERVICE_NAME_ENV_PROP);
3743
if (!serviceName.empty()) {

src/jaegertracing/Config.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Config {
3434
static constexpr auto kJAEGER_SERVICE_NAME_ENV_PROP = "JAEGER_SERVICE_NAME";
3535
static constexpr auto kJAEGER_TAGS_ENV_PROP = "JAEGER_TAGS";
3636
static constexpr auto kJAEGER_JAEGER_DISABLED_ENV_PROP = "JAEGER_DISABLED";
37+
static constexpr auto kJAEGER_JAEGER_TRACEID_128BIT_ENV_PROP = "JAEGER_TRACEID_128BIT";
3738

3839
#ifdef JAEGERTRACING_WITH_YAML_CPP
3940

@@ -48,6 +49,8 @@ class Config {
4849

4950
const auto disabled =
5051
utils::yaml::findOrDefault<bool>(configYAML, "disabled", false);
52+
const auto traceId128Bit =
53+
utils::yaml::findOrDefault<bool>(configYAML, "traceid_128bit", false);
5154
const auto samplerNode = configYAML["sampler"];
5255
const auto sampler = samplers::Config::parse(samplerNode);
5356
const auto reporterNode = configYAML["reporter"];
@@ -58,12 +61,13 @@ class Config {
5861
const auto baggageRestrictions =
5962
baggage::RestrictionsConfig::parse(baggageRestrictionsNode);
6063
return Config(
61-
disabled, sampler, reporter, headers, baggageRestrictions, serviceName);
64+
disabled, traceId128Bit, sampler, reporter, headers, baggageRestrictions, serviceName);
6265
}
6366

6467
#endif // JAEGERTRACING_WITH_YAML_CPP
6568

6669
explicit Config(bool disabled = false,
70+
bool traceId128Bit = false,
6771
const samplers::Config& sampler = samplers::Config(),
6872
const reporters::Config& reporter = reporters::Config(),
6973
const propagation::HeadersConfig& headers =
@@ -73,6 +77,7 @@ class Config {
7377
const std::string& serviceName = "",
7478
const std::vector<Tag>& tags = std::vector<Tag>())
7579
: _disabled(disabled)
80+
, _traceId128Bit(traceId128Bit)
7681
, _serviceName(serviceName)
7782
, _tags(tags)
7883
, _sampler(sampler)
@@ -84,6 +89,8 @@ class Config {
8489

8590
bool disabled() const { return _disabled; }
8691

92+
bool traceId128Bit() const { return _traceId128Bit; }
93+
8794
const samplers::Config& sampler() const { return _sampler; }
8895

8996
const reporters::Config& reporter() const { return _reporter; }
@@ -103,6 +110,7 @@ class Config {
103110

104111
private:
105112
bool _disabled;
113+
bool _traceId128Bit;
106114
std::string _serviceName;
107115
std::vector< Tag > _tags;
108116
samplers::Config _sampler;

src/jaegertracing/ConfigTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ TEST(Config, testParse)
3333
{
3434
constexpr auto kConfigYAML = R"cfg(
3535
disabled: true
36+
traceid_128bit: true
3637
sampler:
3738
type: probabilistic
3839
param: 0.001
@@ -62,6 +63,7 @@ disabled: true
6263
{
6364
Config::parse(YAML::Load(R"cfg(
6465
disabled: false
66+
traceid_128bit: false
6567
sampler: 1
6668
reporter: 2
6769
headers: 3
@@ -103,6 +105,7 @@ TEST(Config, testFromEnv)
103105
tags.emplace_back("my.app.version", std::string("1.2.3"));
104106

105107
Config config(false,
108+
false,
106109
samplers::Config("probabilistic",
107110
0.7,
108111
"http://host34:57/sampling",
@@ -146,6 +149,8 @@ TEST(Config, testFromEnv)
146149
testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "AService");
147150
testutils::EnvVariable::setEnv("JAEGER_TAGS", "hostname=foobar,my.app.version=4.5.6");
148151

152+
testutils::EnvVariable::setEnv("JAEGER_TRACEID_128BIT", "true");
153+
149154
config.fromEnv();
150155

151156
ASSERT_EQ(std::string("http://host34:56567"), config.reporter().endpoint());
@@ -171,6 +176,8 @@ TEST(Config, testFromEnv)
171176

172177
ASSERT_EQ(false, config.disabled());
173178

179+
ASSERT_EQ(true, config.traceId128Bit());
180+
174181
testutils::EnvVariable::setEnv("JAEGER_DISABLED", "TRue"); // case-insensitive
175182
testutils::EnvVariable::setEnv("JAEGER_AGENT_PORT", "445");
176183

@@ -190,6 +197,7 @@ TEST(Config, testFromEnv)
190197
testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "");
191198
testutils::EnvVariable::setEnv("JAEGER_TAGS", "");
192199
testutils::EnvVariable::setEnv("JAEGER_DISABLED", "");
200+
testutils::EnvVariable::setEnv("JAEGER_TRACE_ID_128BIT", "");
193201
}
194202

195203
} // namespace jaegertracing

src/jaegertracing/Tracer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Tracer : public opentracing::Tracer,
8282
const std::shared_ptr<logging::Logger>& logger,
8383
metrics::StatsFactory& statsFactory)
8484
{
85-
return make(serviceName, config, logger, statsFactory, 0);
85+
return make(serviceName, config, logger, statsFactory, config.traceId128Bit() ? kGen128BitOption : 0);
8686
}
8787
static std::shared_ptr<opentracing::Tracer>
8888
make(const std::string& serviceName,

src/jaegertracing/TracerTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ TEST(Tracer, testConstructorFailure)
325325
TEST(Tracer, testDisabledConfig)
326326
{
327327
Config config(true,
328+
false,
328329
samplers::Config(),
329330
reporters::Config(),
330331
propagation::HeadersConfig(),
@@ -470,6 +471,7 @@ TEST(Tracer, testTracerTags)
470471
tags.emplace_back("my.app.version", std::string("1.2.3"));
471472

472473
Config config(
474+
false,
473475
false,
474476
samplers::Config(
475477
"const", 1, "", 0, samplers::Config::Clock::duration()),
@@ -552,4 +554,28 @@ TEST(Tracer, testTracerSpanSelfRefWithOtherRefs)
552554
tracer->Close();
553555
}
554556

557+
TEST(Tracer, testTracerWithTraceId128Bit)
558+
{
559+
Config config(
560+
false,
561+
true,
562+
samplers::Config(
563+
"const", 1, "", 0, samplers::Config::Clock::duration()),
564+
reporters::Config(0, std::chrono::milliseconds(100), false, "", ""),
565+
propagation::HeadersConfig(),
566+
baggage::RestrictionsConfig(),
567+
"test-service",
568+
std::vector<Tag>());
569+
570+
auto tracer = Tracer::make(config);
571+
572+
opentracing::StartSpanOptions options;
573+
std::unique_ptr<Span> span(static_cast<Span*>(
574+
tracer->StartSpanWithOptions("test-operation", options).release()));
575+
576+
auto traceID = span->context().traceID();
577+
578+
ASSERT_GT(traceID.high(), 0);
579+
}
580+
555581
} // namespace jaegertracing

src/jaegertracing/testutils/TracerUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ std::shared_ptr<ResourceHandle> installGlobalTracer()
3939
samplingServerURLStream
4040
<< "http://" << handle->_mockAgent->samplingServerAddress().authority();
4141
Config config(
42+
false,
4243
false,
4344
samplers::Config("const",
4445
1,
@@ -61,6 +62,7 @@ std::shared_ptr<opentracing::Tracer> buildTracer(const std::string& endpoint)
6162
{
6263
std::ostringstream samplingServerURLStream;
6364
Config config(
65+
false,
6466
false,
6567
samplers::Config("const",
6668
1,

0 commit comments

Comments
 (0)