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
5 changes: 4 additions & 1 deletion src/datadog/datadog_agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ namespace datadog::tracing {
namespace {

Optional<std::string> build_agent_url_from_environment_variables() {
if (Optional<StringView> url_env = lookup(environment::DD_TRACE_AGENT_URL)) {
Optional<StringView> url_env = lookup(environment::DD_TRACE_AGENT_URL);
if (url_env && !url_env->empty()) {
return std::string{*url_env};
}

Optional<StringView> env_host = lookup(environment::DD_AGENT_HOST);
if (env_host && env_host->empty()) env_host = nullopt;
Optional<StringView> env_port = lookup(environment::DD_TRACE_AGENT_PORT);
if (env_port && env_port->empty()) env_port = nullopt;
if (env_host || env_port) {
std::string agent_url = "http://";
const StringView host = env_host.value_or("localhost");
Expand Down
16 changes: 8 additions & 8 deletions test/test_tracer_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,18 +504,18 @@ TRACER_CONFIG_TEST("TracerConfig::agent") {
};

auto test_case = GENERATE(values<TestCase>({
{"override host with default port", "dd-agent", nullopt, nullopt,
"http", "dd-agent:8126"},
{"override port and host", "dd-agent", "8080", nullopt, "http",
{"all defaults", nullopt, nullopt, nullopt, "http", "localhost:8126"},
{"override host", "dd-agent", nullopt, nullopt, "http",
"dd-agent:8126"},
{"override port", nullopt, "8080", nullopt, "http", "localhost:8080"},
{"override host and port", "dd-agent", "8080", nullopt, "http",
"dd-agent:8080"},
{"override port with default host", nullopt, "8080", nullopt, "http",
"localhost:8080"},
{"empty URL", "dd-agent", "8080", "", "http", "dd-agent:8080"},
{"empty host", "", nullopt, nullopt, "http", "localhost:8126"},
{"empty port", nullopt, "", nullopt, "http", "localhost:8126"},
{"IPv6 host", "::1", nullopt, nullopt, "http", "[::1]:8126"},
{"IPv6 host with brackets", "[::1]", nullopt, nullopt, "http",
"[::1]:8126"},
// A bogus port number will cause an error in the TCPClient, not
// during configuration. For the purposes of configuration, any
// value is accepted.
{"we don't parse port", nullopt, "bogus", nullopt, "http",
"localhost:bogus"},
{"URL", nullopt, nullopt, "http://dd-agent:8080", "http",
Expand Down
Loading