Skip to content

Commit

Permalink
Fix json-related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Aug 22, 2024
1 parent 3eff8b9 commit a42b961
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/datadog/null_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class NullCollector : public Collector {
std::string config() const override {
// clang-format off
return R"({
{"type", "datadog::tracing::NullCollector"},
{"config", {}}
"type": "datadog::tracing::NullCollector",
"config": {}
})";
// clang-format on
};
Expand Down
4 changes: 2 additions & 2 deletions src/datadog/datadog_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ std::string DatadogAgent::config() const {
{"flush_interval_milliseconds", std::chrono::duration_cast<std::chrono::milliseconds>(flush_interval_).count() },
{"request_timeout_milliseconds", std::chrono::duration_cast<std::chrono::milliseconds>(request_timeout_).count() },
{"shutdown_timeout_milliseconds", std::chrono::duration_cast<std::chrono::milliseconds>(shutdown_timeout_).count() },
{"http_client", http_client_->config()},
{"event_scheduler", event_scheduler_->config()},
{"http_client", nlohmann::json::parse(http_client_->config())},
{"event_scheduler", nlohmann::json::parse(event_scheduler_->config())},
})},
}).dump();
// clang-format on
Expand Down
5 changes: 2 additions & 3 deletions src/datadog/span_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ nlohmann::json SpanSampler::config_json() const {
}

return nlohmann::json::object({
{"rules", rules},
})
.dump();
{"rules", rules},
});
}

} // namespace tracing
Expand Down
18 changes: 15 additions & 3 deletions src/datadog/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,27 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
}
}

namespace {
template <typename T>
std::vector<std::string> to_string_vec(const std::vector<T>& vec) {
std::vector<std::string> result{vec.size()};
result.reserve(vec.size());
std::transform(vec.begin(), vec.end(), result.begin(), [](const T& item) {
return std::string{to_string_view(item)};
});
return result;
}
} // namespace

std::string Tracer::config() const {
// clang-format off
auto config = nlohmann::json::object({
{"version", tracer_version_string},
{"runtime_id", runtime_id_.string()},
{"collector", collector_->config()},
{"collector", nlohmann::json::parse(collector_->config())},
{"span_sampler", span_sampler_->config_json()},
{"injection_styles", join_propagation_styles(injection_styles_)},
{"extraction_styles", join_propagation_styles(extraction_styles_)},
{"injection_styles", to_string_vec(injection_styles_)},
{"extraction_styles", to_string_vec(extraction_styles_)},
{"tags_header_size", tags_header_max_size_},
{"environment_variables", environment::to_json()},
});
Expand Down

0 comments on commit a42b961

Please sign in to comment.