Skip to content
Merged
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
27 changes: 16 additions & 11 deletions src/tracing_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ std::string_view or_default(std::string_view config_json) {

} // namespace

dd::Expected<dd::Tracer> TracingLibrary::make_tracer(const datadog_main_conf_t& nginx_conf) {
dd::Expected<dd::Tracer> TracingLibrary::make_tracer(const datadog_main_conf_t &nginx_conf) {
dd::TracerConfig config;
config.logger = std::make_shared<NgxLogger>();
config.agent.event_scheduler = std::make_shared<NgxEventScheduler>();
config.integration_name = "nginx";
config.integration_version = NGINX_VERSION;

if (!nginx_conf.propagation_styles.empty()) {
config.injection_styles = config.extraction_styles = nginx_conf.propagation_styles;
Expand Down Expand Up @@ -71,11 +73,11 @@ dd::Expected<dd::Tracer> TracingLibrary::make_tracer(const datadog_main_conf_t&
// order in which we try the rules doesn't change the outcome.
// Deeper directives are more likely to match a given request, though, and
// so this can be thought of as an optimization.
const auto by_depth_descending = [](const auto& left, const auto& right) {
const auto by_depth_descending = [](const auto &left, const auto &right) {
return *left.depth > *right.depth;
};
std::stable_sort(rules.begin(), rules.end(), by_depth_descending);
for (sampling_rule_t& rule : rules) {
for (sampling_rule_t &rule : rules) {
config.trace_sampler.rules.push_back(std::move(rule.rule));
}

Expand All @@ -88,7 +90,7 @@ dd::Expected<dd::Tracer> TracingLibrary::make_tracer(const datadog_main_conf_t&
}

dd::Expected<std::vector<std::string_view>> TracingLibrary::propagation_header_names(
const std::vector<dd::PropagationStyle>& configured_styles, dd::Logger& logger) {
const std::vector<dd::PropagationStyle> &configured_styles, dd::Logger &logger) {
std::vector<std::string_view> result;

// Create a tracer config that contains `configured_styles` (or the default
Expand All @@ -105,16 +107,19 @@ dd::Expected<std::vector<std::string_view>> TracingLibrary::propagation_header_n
minimal_config.extraction_styles = configured_styles;
}
auto finalized_config = dd::finalize_config(minimal_config);
if (auto* error = finalized_config.if_error()) {
if (auto *error = finalized_config.if_error()) {
return std::move(*error);
}

if (!configured_styles.empty() && configured_styles != finalized_config->injection_styles) {
logger.log_error([&](std::ostream& log) {
log << "Actual injection propagation styles differ from that specified in the nginx "
"configuration. The datadog_propagation_styles directive indicated the values "
logger.log_error([&](std::ostream &log) {
log << "Actual injection propagation styles differ from that specified "
"in the nginx "
"configuration. The datadog_propagation_styles directive "
"indicated the values "
<< dd::to_json(configured_styles)
<< ", but after applying environment variables, the final values are instead "
<< ", but after applying environment variables, the final values are "
"instead "
<< dd::to_json(finalized_config->injection_styles);
});
}
Expand Down Expand Up @@ -179,10 +184,10 @@ class SpanContextJSONWriter : public dd::DictWriter {
output_object_[std::move(normalized_key)] = value;
}

nlohmann::json& json() { return output_object_; }
nlohmann::json &json() { return output_object_; }
};

std::string span_property(std::string_view key, const dd::Span& span) {
std::string span_property(std::string_view key, const dd::Span &span) {
const auto not_found = "-";

if (key == "trace_id") {
Expand Down