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
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Follow [AGENTS.md](AGENTS.md).
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Before submitting new features or changes to current functionality, please [open
issue](https://github.com/DataDog/dd-trace-cpp/issues/new) and discuss your ideas or propose the
changes you wish to make. After a resolution is reached, a PR can be submitted for review.

Sefer to the [documentation](docs) to learn about the architecture of the Datadog C++ Tracer Library
Refer to the [documentation](docs) to learn about the architecture of the Datadog C++ Tracer Library
and its development processes. In particular, review:

- [Conventions](docs/conventions.md);
Expand Down
10 changes: 2 additions & 8 deletions include/datadog/datadog_agent_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@
// Typical usage of `DatadogAgentConfig` is implicit as part of `TracerConfig`.
// See `tracer_config.h`.

#include <chrono>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "clock.h"
#include "config.h"
#include "expected.h"
#include "http_client.h"
#include "remote_config/listener.h"

namespace datadog {
namespace tracing {
namespace datadog::tracing {

class EventScheduler;
class Logger;
Expand Down Expand Up @@ -100,5 +95,4 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
const DatadogAgentConfig& config, const std::shared_ptr<Logger>& logger,
const Clock& clock);

} // namespace tracing
} // namespace datadog
} // namespace datadog::tracing
57 changes: 36 additions & 21 deletions src/datadog/datadog_agent_config.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
#include <datadog/datadog_agent_config.h>
#include <datadog/environment.h>

#include <algorithm>
#include <chrono>
#include <cstddef>

#include "default_http_client.h"
#include "parse_util.h"
#include "platform_util.h"
#include "threaded_event_scheduler.h"

namespace datadog {
namespace tracing {
namespace datadog::tracing {

namespace {

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

Optional<StringView> env_host = lookup(environment::DD_AGENT_HOST);
Optional<StringView> env_port = lookup(environment::DD_TRACE_AGENT_PORT);
if (env_host || env_port) {
std::string agent_url = "http://";
const StringView host = env_host.value_or("localhost");
const bool is_ipv6_without_brackets =
(host.find(':') != StringView::npos) && (host.front() != '[');
if (is_ipv6_without_brackets) {
agent_url += '[';
}
append(agent_url, host);
if (is_ipv6_without_brackets) {
agent_url += ']';
}
agent_url += ':';
append(agent_url, env_port.value_or("8126"));
return agent_url;
}

return nullopt;
}

} // namespace

Expected<DatadogAgentConfig> load_datadog_agent_env_config() {
DatadogAgentConfig env_config;
Expand All @@ -31,18 +56,9 @@ Expected<DatadogAgentConfig> load_datadog_agent_env_config() {
env_config.remote_configuration_poll_interval_seconds = *res;
}

auto env_host = lookup(environment::DD_AGENT_HOST);
auto env_port = lookup(environment::DD_TRACE_AGENT_PORT);

if (auto url_env = lookup(environment::DD_TRACE_AGENT_URL)) {
env_config.url = std::string{*url_env};
} else if (env_host || env_port) {
std::string configured_url = "http://";
append(configured_url, env_host.value_or("localhost"));
configured_url += ':';
append(configured_url, env_port.value_or("8126"));

env_config.url = std::move(configured_url);
if (Optional<std::string> agent_url =
build_agent_url_from_environment_variables()) {
env_config.url = *std::move(agent_url);
}

return env_config;
Expand Down Expand Up @@ -158,5 +174,4 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
return result;
}

} // namespace tracing
} // namespace datadog
} // namespace datadog::tracing
2 changes: 1 addition & 1 deletion test/test_otel_process_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace datadog::tracing;

namespace {

#ifdef __linux__
std::map<std::string, std::string> to_map(const char** key_value_array) {
std::map<std::string, std::string> out;
if (key_value_array == nullptr) return out;
Expand All @@ -23,7 +24,6 @@ std::map<std::string, std::string> to_map(const char** key_value_array) {
return out;
}

#ifdef __linux__
std::unique_ptr<Tracer> make_tracer(
const RuntimeID& runtime_id, const std::string& service = "otel-ctx-svc",
std::shared_ptr<Logger> logger = std::make_shared<MockLogger>()) {
Expand Down
29 changes: 8 additions & 21 deletions test/test_tracer_config.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include <datadog/id_generator.h>
#include <datadog/optional.h>
#include <datadog/propagation_style.h>
#include <datadog/threaded_event_scheduler.h>
#include <datadog/tracer.h>
#include <datadog/tracer_config.h>

#if defined(__linux__)
#ifdef __linux__
// Used to test writing to the `datadog-tracer-info` file; this is a Linux-only
// feature.
#include <dirent.h>
Expand All @@ -15,19 +11,8 @@
#include <msgpack.hpp>
#endif

#include <chrono>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <limits>
#include <ostream>
#include <stdexcept>
#include <string>
#include <system_error>
#include <unordered_map>

#include "common/environment.h"
#include "mocks/collectors.h"
Expand All @@ -36,23 +21,21 @@
#include "null_logger.h"
#include "test.h"

#if defined(__linux__)
#ifdef __linux__
// Used to test writing to the `datadog-tracer-info` file; this is a Linux-only
// feature.
#include "common/ctx_sharing_helpers.h"
#include "platform_util.h"
#include "string_util.h"
#endif

namespace datadog {
namespace tracing {
namespace datadog::tracing {

std::ostream& operator<<(std::ostream& stream, PropagationStyle style) {
return stream << to_string_view(style);
}

} // namespace tracing
} // namespace datadog
} // namespace datadog::tracing

using namespace datadog::test;
using namespace datadog::tracing;
Expand Down Expand Up @@ -480,6 +463,7 @@ TRACER_CONFIG_TEST("TracerConfig::agent") {
{"http://dd-agent:8126", nullopt, "http", "dd-agent:8126", ""},
{"http://dd-agent:8126/", nullopt, "http", "dd-agent:8126", "/"},
{"https://dd-agent:8126/", nullopt, "https", "dd-agent:8126", "/"},
{"http://[::1]:8126/", nullopt, "http", "[::1]:8126", "/"},
{"unix:///var/run/datadog/trace-agent.sock", nullopt, "unix",
"/var/run/datadog/trace-agent.sock"},
{"unix://var/run/datadog/trace-agent.sock",
Expand Down Expand Up @@ -526,6 +510,9 @@ TRACER_CONFIG_TEST("TracerConfig::agent") {
"dd-agent:8080"},
{"override port with default host", nullopt, "8080", nullopt, "http",
"localhost:8080"},
{"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.
Expand Down
Loading