Skip to content
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
15 changes: 7 additions & 8 deletions src/datadog/extraction_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <unordered_map>

#include "extracted_data.h"
#include "json.hpp"
#include "logger.h"
#include "parse_util.h"
#include "string_util.h"
Expand Down Expand Up @@ -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 << "]";
}
Expand Down
4 changes: 3 additions & 1 deletion src/datadog/propagation_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<PropagationStyle>& styles) {
std::vector<nlohmann::json> styles_json;
for (const auto style : styles) {
Expand Down
1 change: 1 addition & 0 deletions src/datadog/propagation_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropagationStyle>& styles);

Expand Down
7 changes: 7 additions & 0 deletions test/test_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down