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
13 changes: 9 additions & 4 deletions mod_datadog/src/common_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ void* merge_dir_conf(apr_pool_t* pool, void* base, void* add) {
void* final_ptr = init_dir_conf(pool, nullptr);
auto conf = static_cast<Directory*>(final_ptr);

conf->tracing_enabled = child->tracing_enabled || parent->tracing_enabled;

conf->trust_inbound_span =
child->trust_inbound_span || parent->trust_inbound_span;
// Tri-state merge: an explicit directive in the child scope wins over
// whatever the parent had (including the default). Only fall back to the
// parent when the child never set the directive.
conf->tracing_enabled =
child->tracing_enabled ? child->tracing_enabled : parent->tracing_enabled;
Comment thread
xlamorlette-datadog marked this conversation as resolved.

conf->trust_inbound_span = child->trust_inbound_span
? child->trust_inbound_span
: parent->trust_inbound_span;
Comment thread
xlamorlette-datadog marked this conversation as resolved.

conf->tags = child->tags;
auto tmp = parent->tags;
Expand Down
8 changes: 6 additions & 2 deletions mod_datadog/src/common_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <datadog/tracer_config.h>

#include <optional>
#include <string>
#include <unordered_map>

Expand All @@ -18,8 +19,11 @@ struct Module final {
};

struct Directory final {
bool tracing_enabled = true;
bool trust_inbound_span = true;
// `std::nullopt` means "inherit from the enclosing scope"; any concrete
// value (true/false) was set explicitly via a directive and wins over the
// parent during merge. The effective default at read sites is `true`.
std::optional<bool> tracing_enabled;
std::optional<bool> trust_inbound_span;
std::unordered_map<std::string, std::string> tags;

// RUM
Expand Down
12 changes: 8 additions & 4 deletions mod_datadog/src/tracing/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ int on_fixups(request_rec* r, Tracer& g_tracer, module* datadog_module) {
// subrequests/internal redirection?
request_rec* main_r = r->prev ? r->prev : r->main;

auto* dir_conf = static_cast<conf::Directory*>(
auto* dir_conf = static_cast<datadog::conf::Directory*>(
ap_get_module_config(main_r->per_dir_config, datadog_module));
if (dir_conf == nullptr || !dir_conf->tracing_enabled) return DECLINED;
if (dir_conf == nullptr || !dir_conf->tracing_enabled.value_or(true)) {
return DECLINED;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add braces when if … return is not on a single line (to avoid potential bug when adding a line before the return).
Same below, line 121.

}

void* data = ap_get_module_config(main_r->request_config, datadog_module);
if (!data) return DECLINED;
Expand All @@ -116,7 +118,9 @@ int on_fixups(request_rec* r, Tracer& g_tracer, module* datadog_module) {
// Trace request
auto* dir_conf = static_cast<datadog::conf::Directory*>(
ap_get_module_config(r->per_dir_config, datadog_module));
if (dir_conf == nullptr || !dir_conf->tracing_enabled) return DECLINED;
if (dir_conf == nullptr || !dir_conf->tracing_enabled.value_or(true)) {
return DECLINED;
}

void* data = ap_get_module_config(r->request_config, datadog_module);
if (data)
Expand All @@ -127,7 +131,7 @@ int on_fixups(request_rec* r, Tracer& g_tracer, module* datadog_module) {

// In case we fail to use the inbound span, then, start a new trace
// ¯\_(ツ)_/¯ There is nothing we can do about it.
if (dir_conf->trust_inbound_span) {
if (dir_conf->trust_inbound_span.value_or(true)) {
auto extracted_span =
g_tracer.extract_span(utils::HeaderReader(r->headers_in), options);
if (auto error = extracted_span.if_error()) {
Expand Down
Loading