From 703028fcb0de1b232b68b2581508f98f53c5d1b7 Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Mon, 13 Sep 2021 18:41:28 +0200 Subject: [PATCH] Added support for setting tracer tags via the configuration (#284) Signed-off-by: Tobias Stadler Co-authored-by: Yuri Shkuro --- src/jaegertracing/Config.h | 9 ++++++++- src/jaegertracing/ConfigTest.cpp | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/jaegertracing/Config.h b/src/jaegertracing/Config.h index 1c8a997..90696d1 100644 --- a/src/jaegertracing/Config.h +++ b/src/jaegertracing/Config.h @@ -68,6 +68,13 @@ class Config { const auto baggageRestrictionsNode = configYAML["baggage_restrictions"]; const auto baggageRestrictions = baggage::RestrictionsConfig::parse(baggageRestrictionsNode); + + std::vector tags; + const auto node = configYAML["tags"]; + for(YAML::const_iterator it = node.begin(); it != node.end(); ++it) { + tags.emplace_back(it->first.as(), it->second.as()); + } + return Config(disabled, traceId128Bit, sampler, @@ -75,7 +82,7 @@ class Config { headers, baggageRestrictions, serviceName, - std::vector(), + tags, propagationFormat); } diff --git a/src/jaegertracing/ConfigTest.cpp b/src/jaegertracing/ConfigTest.cpp index 15e91d2..f0e3326 100644 --- a/src/jaegertracing/ConfigTest.cpp +++ b/src/jaegertracing/ConfigTest.cpp @@ -107,6 +107,21 @@ propagation_format: w3c } } +TEST(Config, testTags) +{ + { + constexpr auto kConfigYAML = R"cfg( +tags: + foo: bar +)cfg"; + const auto config = Config::parse(YAML::Load(kConfigYAML)); + + std::vector expectedTags; + expectedTags.emplace_back("foo", std::string("bar")); + ASSERT_EQ(expectedTags, config.tags()); + } +} + #endif // JAEGERTRACING_WITH_YAML_CPP TEST(Config, testFromEnv)