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

Support configuration for generating 128 bit trace ids #254

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/jaegertracing/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ void Config::fromEnv()
_disabled = disabled.second;
}

const auto traceId128Bit =
utils::EnvVariable::getBoolVariable(kJAEGER_JAEGER_TRACEID_128BIT_ENV_PROP);
if (traceId128Bit.first) {
_traceId128Bit = traceId128Bit.second;
}

const auto serviceName =
utils::EnvVariable::getStringVariable(kJAEGER_SERVICE_NAME_ENV_PROP);
if (!serviceName.empty()) {
Expand Down
10 changes: 9 additions & 1 deletion src/jaegertracing/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Config {
static constexpr auto kJAEGER_SERVICE_NAME_ENV_PROP = "JAEGER_SERVICE_NAME";
static constexpr auto kJAEGER_TAGS_ENV_PROP = "JAEGER_TAGS";
static constexpr auto kJAEGER_JAEGER_DISABLED_ENV_PROP = "JAEGER_DISABLED";
static constexpr auto kJAEGER_JAEGER_TRACEID_128BIT_ENV_PROP = "JAEGER_TRACEID_128BIT";

#ifdef JAEGERTRACING_WITH_YAML_CPP

Expand All @@ -48,6 +49,8 @@ class Config {

const auto disabled =
utils::yaml::findOrDefault<bool>(configYAML, "disabled", false);
const auto traceId128Bit =
utils::yaml::findOrDefault<bool>(configYAML, "traceid_128bit", false);
const auto samplerNode = configYAML["sampler"];
const auto sampler = samplers::Config::parse(samplerNode);
const auto reporterNode = configYAML["reporter"];
Expand All @@ -58,12 +61,13 @@ class Config {
const auto baggageRestrictions =
baggage::RestrictionsConfig::parse(baggageRestrictionsNode);
return Config(
disabled, sampler, reporter, headers, baggageRestrictions, serviceName);
disabled, traceId128Bit, sampler, reporter, headers, baggageRestrictions, serviceName);
}

#endif // JAEGERTRACING_WITH_YAML_CPP

explicit Config(bool disabled = false,
bool traceId128Bit = false,
const samplers::Config& sampler = samplers::Config(),
const reporters::Config& reporter = reporters::Config(),
const propagation::HeadersConfig& headers =
Expand All @@ -73,6 +77,7 @@ class Config {
const std::string& serviceName = "",
const std::vector<Tag>& tags = std::vector<Tag>())
: _disabled(disabled)
, _traceId128Bit(traceId128Bit)
, _serviceName(serviceName)
, _tags(tags)
, _sampler(sampler)
Expand All @@ -84,6 +89,8 @@ class Config {

bool disabled() const { return _disabled; }

bool traceId128Bit() const { return _traceId128Bit; }

const samplers::Config& sampler() const { return _sampler; }

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

private:
bool _disabled;
bool _traceId128Bit;
std::string _serviceName;
std::vector< Tag > _tags;
samplers::Config _sampler;
Expand Down
8 changes: 8 additions & 0 deletions src/jaegertracing/ConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TEST(Config, testParse)
{
constexpr auto kConfigYAML = R"cfg(
disabled: true
traceid_128bit: true
sampler:
type: probabilistic
param: 0.001
Expand Down Expand Up @@ -62,6 +63,7 @@ disabled: true
{
Config::parse(YAML::Load(R"cfg(
disabled: false
traceid_128bit: false
sampler: 1
reporter: 2
headers: 3
Expand Down Expand Up @@ -103,6 +105,7 @@ TEST(Config, testFromEnv)
tags.emplace_back("my.app.version", std::string("1.2.3"));

Config config(false,
false,
samplers::Config("probabilistic",
0.7,
"http://host34:57/sampling",
Expand Down Expand Up @@ -146,6 +149,8 @@ TEST(Config, testFromEnv)
testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "AService");
testutils::EnvVariable::setEnv("JAEGER_TAGS", "hostname=foobar,my.app.version=4.5.6");

testutils::EnvVariable::setEnv("JAEGER_TRACEID_128BIT", "true");

config.fromEnv();

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

ASSERT_EQ(false, config.disabled());

ASSERT_EQ(true, config.traceId128Bit());

testutils::EnvVariable::setEnv("JAEGER_DISABLED", "TRue"); // case-insensitive
testutils::EnvVariable::setEnv("JAEGER_AGENT_PORT", "445");

Expand All @@ -190,6 +197,7 @@ TEST(Config, testFromEnv)
testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "");
testutils::EnvVariable::setEnv("JAEGER_TAGS", "");
testutils::EnvVariable::setEnv("JAEGER_DISABLED", "");
testutils::EnvVariable::setEnv("JAEGER_TRACE_ID_128BIT", "");
}

} // namespace jaegertracing
2 changes: 1 addition & 1 deletion src/jaegertracing/Tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Tracer : public opentracing::Tracer,
const std::shared_ptr<logging::Logger>& logger,
metrics::StatsFactory& statsFactory)
{
return make(serviceName, config, logger, statsFactory, 0);
return make(serviceName, config, logger, statsFactory, config.traceId128Bit() ? kGen128BitOption : 0);
}
static std::shared_ptr<opentracing::Tracer>
make(const std::string& serviceName,
Expand Down
26 changes: 26 additions & 0 deletions src/jaegertracing/TracerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ TEST(Tracer, testConstructorFailure)
TEST(Tracer, testDisabledConfig)
{
Config config(true,
false,
samplers::Config(),
reporters::Config(),
propagation::HeadersConfig(),
Expand Down Expand Up @@ -470,6 +471,7 @@ TEST(Tracer, testTracerTags)
tags.emplace_back("my.app.version", std::string("1.2.3"));

Config config(
false,
false,
samplers::Config(
"const", 1, "", 0, samplers::Config::Clock::duration()),
Expand Down Expand Up @@ -552,4 +554,28 @@ TEST(Tracer, testTracerSpanSelfRefWithOtherRefs)
tracer->Close();
}

TEST(Tracer, testTracerWithTraceId128Bit)
{
Config config(
false,
true,
samplers::Config(
"const", 1, "", 0, samplers::Config::Clock::duration()),
reporters::Config(0, std::chrono::milliseconds(100), false, "", ""),
propagation::HeadersConfig(),
baggage::RestrictionsConfig(),
"test-service",
std::vector<Tag>());

auto tracer = Tracer::make(config);

opentracing::StartSpanOptions options;
std::unique_ptr<Span> span(static_cast<Span*>(
tracer->StartSpanWithOptions("test-operation", options).release()));

auto traceID = span->context().traceID();

ASSERT_GT(traceID.high(), 0);
}

} // namespace jaegertracing
2 changes: 2 additions & 0 deletions src/jaegertracing/testutils/TracerUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ std::shared_ptr<ResourceHandle> installGlobalTracer()
samplingServerURLStream
<< "http://" << handle->_mockAgent->samplingServerAddress().authority();
Config config(
false,
false,
samplers::Config("const",
1,
Expand All @@ -61,6 +62,7 @@ std::shared_ptr<opentracing::Tracer> buildTracer(const std::string& endpoint)
{
std::ostringstream samplingServerURLStream;
Config config(
false,
false,
samplers::Config("const",
1,
Expand Down