diff --git a/src/datadog/extraction_util.cpp b/src/datadog/extraction_util.cpp index 9eaf6484..4eedcd7b 100644 --- a/src/datadog/extraction_util.cpp +++ b/src/datadog/extraction_util.cpp @@ -7,7 +7,6 @@ #include #include "extracted_data.h" -#include "json.hpp" #include "logger.h" #include "parse_util.h" #include "string_util.h" @@ -223,15 +222,15 @@ std::string extraction_error_prefix( std::ostringstream stream; stream << "While extracting trace context"; if (style) { - stream << " in the " << to_json(*style) << " propagation style"; + stream << " in the " << to_string_view(*style) << " propagation style"; } - auto it = headers_examined.begin(); - if (it != headers_examined.end()) { - stream << " from the following headers: ["; - stream << nlohmann::json(it->first + ": " + it->second); + + if (!headers_examined.empty()) { + auto it = headers_examined.begin(); + stream << " from the following headers: [" << it->first << ": " + << it->second; for (++it; it != headers_examined.end(); ++it) { - stream << ", "; - stream << nlohmann::json(it->first + ": " + it->second); + stream << ", " << it->first << ": " << it->second; } stream << "]"; } diff --git a/src/datadog/propagation_style.cpp b/src/datadog/propagation_style.cpp index 58284fec..19241374 100644 --- a/src/datadog/propagation_style.cpp +++ b/src/datadog/propagation_style.cpp @@ -8,7 +8,7 @@ namespace datadog { namespace tracing { -nlohmann::json to_json(PropagationStyle style) { +StringView to_string_view(PropagationStyle style) { // Note: Make sure that these strings are consistent (modulo case) with // `parse_propagation_styles` in `tracer_config.cpp`. switch (style) { @@ -24,6 +24,8 @@ nlohmann::json to_json(PropagationStyle style) { } } +nlohmann::json to_json(PropagationStyle style) { return to_string_view(style); } + nlohmann::json to_json(const std::vector& styles) { std::vector styles_json; for (const auto style : styles) { diff --git a/src/datadog/propagation_style.h b/src/datadog/propagation_style.h index b573b817..47958169 100644 --- a/src/datadog/propagation_style.h +++ b/src/datadog/propagation_style.h @@ -27,6 +27,7 @@ enum class PropagationStyle { NONE, }; +StringView to_string_view(PropagationStyle style); nlohmann::json to_json(PropagationStyle style); nlohmann::json to_json(const std::vector& styles); diff --git a/test/test_tracer.cpp b/test/test_tracer.cpp index 428cca00..e108d100 100644 --- a/test/test_tracer.cpp +++ b/test/test_tracer.cpp @@ -383,6 +383,13 @@ TEST_CASE("span extraction") { {PropagationStyle::B3}, {{"x-b3-traceid", "0"}, {"x-b3-spanid", "123"}, {"x-b3-sampled", "0"}}, Error::ZERO_TRACE_ID}, + {__LINE__, + "character encoding", + {PropagationStyle::DATADOG}, + {{"x-datadog-trace-id", "\xFD\xD0\x6C\x6C\x6F\x2C\x20\xC3\xB1\x21"}, + {"x-datadog-parent-id", "1234"}, + {"x-datadog-sampling-priority", "0"}}, + Error::INVALID_INTEGER}, })); CAPTURE(test_case.line);