Skip to content
2 changes: 1 addition & 1 deletion cmake/compiler/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ else ()
# and so won't link to libc++. So, if any of the FUZZ_* variables are set,
# keep to libstdc++ (the default on most systems).
message(STATUS "C++ standard library: libc++")
add_compile_options(-stdlib=libc++)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++>)
add_link_options(-stdlib=libc++)
endif()

2 changes: 1 addition & 1 deletion src/datadog/config_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace tracing {
struct ConfigUpdate {
Optional<bool> report_traces;
Optional<double> trace_sampling_rate;
Optional<std::vector<StringView>> tags;
Optional<std::vector<std::string>> tags;
const nlohmann::json* trace_sampling_rules = nullptr;
};

Expand Down
19 changes: 14 additions & 5 deletions src/datadog/datadog_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
} // namespace

DatadogAgent::DatadogAgent(
const FinalizedDatadogAgentConfig& config,
FinalizedDatadogAgentConfig& config,
const std::shared_ptr<TracerTelemetry>& tracer_telemetry,
const std::shared_ptr<Logger>& logger,
const TracerSignature& tracer_signature,
Expand All @@ -162,7 +162,7 @@ DatadogAgent::DatadogAgent(
flush_interval_(config.flush_interval),
request_timeout_(config.request_timeout),
shutdown_timeout_(config.shutdown_timeout),
remote_config_(tracer_signature, config_manager),
remote_config_(tracer_signature, config_manager, logger),
tracer_signature_(tracer_signature) {
assert(logger_);
assert(tracer_telemetry_);
Expand Down Expand Up @@ -207,6 +207,15 @@ DatadogAgent::DatadogAgent(
}

if (config.remote_configuration_enabled) {
for (auto&& l : config.rem_cfg_listeners) {
remote_config_.add_listener(std::move(l));
}
config.rem_cfg_listeners.clear();
for (auto&& l : config.rem_cfg_end_listeners) {
remote_config_.add_config_end_listener(std::move(l));
}
config.rem_cfg_end_listeners.clear();

tasks_.emplace_back(event_scheduler_->schedule_recurring_event(
config.remote_configuration_poll_interval,
[this] { get_and_apply_remote_configuration_updates(); }));
Expand Down Expand Up @@ -445,7 +454,7 @@ void DatadogAgent::get_and_apply_remote_configuration_updates() {
return;
}

const auto response_json =
auto response_json =
nlohmann::json::parse(/* input = */ response_body,
/* parser_callback = */ nullptr,
/* allow_exceptions = */ false);
Expand All @@ -458,9 +467,9 @@ void DatadogAgent::get_and_apply_remote_configuration_updates() {

if (!response_json.empty()) {
auto updated_configuration =
remote_config_.process_response(response_json);
remote_config_.process_response(std::move(response_json));
if (!updated_configuration.empty()) {
send_configuration_change(updated_configuration);
send_configuration_change(std::move(updated_configuration));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/datadog_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DatadogAgent : public Collector {
void send_app_closing();

public:
DatadogAgent(const FinalizedDatadogAgentConfig&,
DatadogAgent(FinalizedDatadogAgentConfig&,
const std::shared_ptr<TracerTelemetry>&,
const std::shared_ptr<Logger>&, const TracerSignature& id,
const std::shared_ptr<ConfigManager>& config_manager);
Expand Down
7 changes: 5 additions & 2 deletions src/datadog/datadog_agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ Expected<DatadogAgentConfig> load_datadog_agent_env_config() {
}

Expected<FinalizedDatadogAgentConfig> finalize_config(
const DatadogAgentConfig& user_config,
const std::shared_ptr<Logger>& logger, const Clock& clock) {
DatadogAgentConfig& user_config, const std::shared_ptr<Logger>& logger,
const Clock& clock) {
Expected<DatadogAgentConfig> env_config = load_datadog_agent_env_config();
if (auto error = env_config.if_error()) {
return *error;
Expand Down Expand Up @@ -141,6 +141,9 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
result.metadata[ConfigName::AGENT_URL] =
ConfigMetadata(ConfigName::AGENT_URL, url, origin);

result.rem_cfg_listeners = std::move(user_config.rem_cfg_listeners);
result.rem_cfg_end_listeners = std::move(user_config.rem_cfg_end_listeners);

return result;
}

Expand Down
16 changes: 14 additions & 2 deletions src/datadog/datadog_agent_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "config.h"
#include "expected.h"
#include "http_client.h"
#include "remote_config.h"
#include "string_view.h"

namespace datadog {
Expand Down Expand Up @@ -63,12 +64,20 @@ struct DatadogAgentConfig {
// updates.
Optional<double> remote_configuration_poll_interval_seconds;

// Remote configuration listeners to add
std::vector<std::unique_ptr<remote_config::ProductListener>>
rem_cfg_listeners;

// Callbacks invoked after all the configuration listeners for all products
// have been called, as long as at least one has.
std::vector<std::function<void()>> rem_cfg_end_listeners;

static Expected<HTTPClient::URL> parse(StringView);
};

class FinalizedDatadogAgentConfig {
friend Expected<FinalizedDatadogAgentConfig> finalize_config(
const DatadogAgentConfig&, const std::shared_ptr<Logger>&, const Clock&);
DatadogAgentConfig&, const std::shared_ptr<Logger>&, const Clock&);

FinalizedDatadogAgentConfig() = default;

Expand All @@ -83,10 +92,13 @@ class FinalizedDatadogAgentConfig {
std::chrono::steady_clock::duration shutdown_timeout;
std::chrono::steady_clock::duration remote_configuration_poll_interval;
std::unordered_map<ConfigName, ConfigMetadata> metadata;
std::vector<std::unique_ptr<remote_config::ProductListener>>
rem_cfg_listeners;
std::vector<std::function<void()>> rem_cfg_end_listeners;
};

Expected<FinalizedDatadogAgentConfig> finalize_config(
const DatadogAgentConfig& config, const std::shared_ptr<Logger>& logger,
DatadogAgentConfig& config, const std::shared_ptr<Logger>& logger,
const Clock& clock);

} // namespace tracing
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct Error {
SAMPLING_DELEGATION_RESPONSE_INVALID_JSON = 52,
};

Code code;
Code code{};
std::string message;

Error with_prefix(StringView) const;
Expand Down
6 changes: 6 additions & 0 deletions src/datadog/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class Logger {

virtual void log_error(const Error&);
virtual void log_error(StringView);

// optional operations for debug logging messages
virtual void log_debug(const LogFunc&) {}
virtual void log_debug(StringView message) {
log_debug([message](auto& stream) { stream << message; });
}
};

} // namespace tracing
Expand Down
13 changes: 11 additions & 2 deletions src/datadog/parse_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ std::vector<StringView> parse_list(StringView input) {
return items;
}

template <typename StrType>
Expected<std::unordered_map<std::string, std::string>> parse_tags(
std::vector<StringView> list) {
std::vector<StrType> list) {
std::unordered_map<std::string, std::string> tags;

std::string key;
std::string value;

for (const StringView &token : list) {
for (const auto &token : list) {
const auto separator = token.find(':');

if (separator == std::string::npos) {
Expand All @@ -154,6 +155,14 @@ Expected<std::unordered_map<std::string, std::string>> parse_tags(

return tags;
}
Expected<std::unordered_map<std::string, std::string>> parse_tags(
const std::vector<StringView> &list) {
return parse_tags<StringView>(list);
}
Expected<std::unordered_map<std::string, std::string>> parse_tags(
const std::vector<std::string> &list) {
return parse_tags<std::string>(list);
}

// This function scans the input string to identify a separator (',' or ' ').
// Then, split tags using the identified separator and call `parse_tags` with
Expand Down
10 changes: 9 additions & 1 deletion src/datadog/parse_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
namespace datadog {
namespace tracing {

// Return a `string_view` over the specified range of characters `[begin, end)`.
template <typename Iterator>
StringView range(Iterator begin, Iterator end) {
return StringView{&*begin, std::size_t(end - begin)};
}

bool falsy(StringView input);

// Return a non-negative integer parsed from the specified `input` with respect
Expand All @@ -37,7 +43,9 @@ Expected<double> parse_double(StringView input);
std::vector<StringView> parse_list(StringView input);

Expected<std::unordered_map<std::string, std::string>> parse_tags(
std::vector<StringView> list);
const std::vector<StringView>& list);
Expected<std::unordered_map<std::string, std::string>> parse_tags(
const std::vector<std::string>& list);

Expected<std::unordered_map<std::string, std::string>> parse_tags(
StringView input);
Expand Down
Loading