Skip to content

Commit 9f96750

Browse files
committed
[skip ci] wip
1 parent 9f5c450 commit 9f96750

8 files changed

Lines changed: 210 additions & 252 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
4343
option(DD_TRACE_BUILD_EXAMPLES "Build example programs" OFF)
4444
option(DD_TRACE_BUILD_TESTING "Build the unit tests (test/)" OFF)
4545
option(DD_TRACE_BUILD_FUZZERS "Build fuzzers" OFF)
46+
option(DD_TRACE_BUILD_TOOLS "Build tools" OFF)
4647
option(DD_TRACE_BUILD_BENCHMARK "Build benchmark binaries" OFF)
4748
option(DD_TRACE_ENABLE_COVERAGE "Build code with code coverage profiling instrumentation" OFF)
4849
option(DD_TRACE_ENABLE_SANITIZE "Build with address sanitizer and undefined behavior sanitizer" OFF)
@@ -98,6 +99,11 @@ if (DD_TRACE_BUILD_BENCHMARK)
9899
add_subdirectory(benchmark)
99100
endif ()
100101

102+
if (DD_TRACE_BUILD_TOOLS)
103+
include(cmake/deps/cxxopts.cmake)
104+
add_subdirectory(tools)
105+
endif ()
106+
101107
add_library(dd-trace-cpp-objects OBJECT)
102108
add_library(dd-trace-cpp::obj ALIAS dd-trace-cpp-objects)
103109

CMakePresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"DD_TRACE_ENABLE_SANITIZE": "ON",
3131
"DD_TRACE_BUILD_TESTING": "ON",
3232
"DD_TRACE_BUILD_EXAMPLES": "ON",
33+
"DD_TRACE_BUILD_TOOLS": "ON",
3334
"DD_TRACE_BUILD_FUZZERS": "OFF"
3435
}
3536
},

include/datadog/environment.h

Lines changed: 78 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -9,142 +9,103 @@
99
// `name` returns the name of a specified `Variable`.
1010
//
1111
// `lookup` retrieves the value of `Variable` in the environment.
12-
13-
#include <datadog/environment_registry.h>
1412
#include <datadog/expected.h>
1513
#include <datadog/optional.h>
1614
#include <datadog/string_view.h>
1715

18-
#include <cstdint>
19-
#include <cstdlib>
16+
#include <string>
2017

2118
namespace datadog {
2219
namespace tracing {
2320
namespace environment {
2421

25-
enum class VariableType {
26-
STRING,
27-
BOOLEAN,
28-
INT,
29-
DECIMAL,
30-
ARRAY,
31-
MAP,
32-
};
33-
34-
struct VariableSpec {
35-
StringView name;
36-
VariableType type;
37-
};
38-
39-
#define VARIABLE_ENUM_VALUE(DATA, NAME, TYPE, DEFAULT_VALUE) NAME,
40-
41-
enum Variable { DD_ENVIRONMENT_VARIABLES(VARIABLE_ENUM_VALUE, ~) };
22+
// Central registry for supported environment variables.
23+
// All configurations must be registered here.
24+
//
25+
// This registry is the single source of truth for:
26+
// - env variable name allowlist (`include/datadog/environment.h`)
27+
// - generated metadata (`metadata/supported-configurations.json`)
28+
//
29+
// Each entry has:
30+
// - NAME: environment variable symbol (e.g. DD_SERVICE)
31+
// - TYPE: STRING | BOOLEAN | INT | DECIMAL | ARRAY | MAP
32+
// - DEFAULT: literal default value or a marker token
33+
//
34+
// Marker tokens:
35+
// - ENV_DEFAULT_RESOLVED_IN_CODE("...description...")
36+
// The runtime default is resolved in C++ configuration finalization
37+
// logic. The description is emitted as the "default" field in
38+
// metadata/supported-configurations.json.
39+
#define DD_LIST_ENVIRONMENT_VARIABLES(MACRO) \
40+
MACRO(DD_AGENT_HOST, STRING, "localhost") \
41+
MACRO(DD_ENV, STRING, "") \
42+
MACRO(DD_INSTRUMENTATION_TELEMETRY_ENABLED, BOOLEAN, true) \
43+
MACRO(DD_PROPAGATION_STYLE_EXTRACT, ARRAY, "datadog,tracecontext,baggage") \
44+
MACRO(DD_PROPAGATION_STYLE_INJECT, ARRAY, "datadog,tracecontext,baggage") \
45+
MACRO(DD_REMOTE_CONFIGURATION_ENABLED, BOOLEAN, true) \
46+
MACRO(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS, DECIMAL, 5.0) \
47+
MACRO(DD_SERVICE, STRING, \
48+
ENV_DEFAULT_RESOLVED_IN_CODE("Defaults to process name when unset.")) \
49+
MACRO(DD_SPAN_SAMPLING_RULES, ARRAY, "[]") \
50+
MACRO(DD_SPAN_SAMPLING_RULES_FILE, STRING, "") \
51+
MACRO(DD_TRACE_PROPAGATION_STYLE_EXTRACT, ARRAY, \
52+
"datadog,tracecontext,baggage") \
53+
MACRO(DD_TRACE_PROPAGATION_STYLE_INJECT, ARRAY, \
54+
"datadog,tracecontext,baggage") \
55+
MACRO(DD_TRACE_PROPAGATION_STYLE, ARRAY, "datadog,tracecontext,baggage") \
56+
MACRO(DD_TAGS, MAP, "") \
57+
MACRO(DD_TRACE_AGENT_PORT, INT, 8126) \
58+
MACRO(DD_TRACE_AGENT_URL, STRING, \
59+
ENV_DEFAULT_RESOLVED_IN_CODE( \
60+
"If unset, built from DD_AGENT_HOST and DD_TRACE_AGENT_PORT, " \
61+
"then defaults to http://localhost:8126.")) \
62+
MACRO(DD_TRACE_DEBUG, BOOLEAN, false) \
63+
MACRO(DD_TRACE_ENABLED, BOOLEAN, true) \
64+
MACRO(DD_TRACE_RATE_LIMIT, DECIMAL, 100.0) \
65+
MACRO(DD_TRACE_REPORT_HOSTNAME, BOOLEAN, false) \
66+
MACRO(DD_TRACE_SAMPLE_RATE, DECIMAL, 1.0) \
67+
MACRO(DD_TRACE_SAMPLING_RULES, ARRAY, "[]") \
68+
MACRO(DD_TRACE_STARTUP_LOGS, BOOLEAN, true) \
69+
MACRO(DD_TRACE_TAGS_PROPAGATION_MAX_LENGTH, INT, 512) \
70+
MACRO(DD_VERSION, STRING, "") \
71+
MACRO(DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED, BOOLEAN, true) \
72+
MACRO(DD_TELEMETRY_HEARTBEAT_INTERVAL, DECIMAL, 10) \
73+
MACRO(DD_TELEMETRY_METRICS_ENABLED, BOOLEAN, true) \
74+
MACRO(DD_TELEMETRY_METRICS_INTERVAL_SECONDS, DECIMAL, 60) \
75+
MACRO(DD_TELEMETRY_DEBUG, BOOLEAN, false) \
76+
MACRO(DD_TRACE_BAGGAGE_MAX_ITEMS, INT, 64) \
77+
MACRO(DD_TRACE_BAGGAGE_MAX_BYTES, INT, 8192) \
78+
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED, BOOLEAN, true) \
79+
MACRO(DD_INSTRUMENTATION_INSTALL_ID, STRING, "") \
80+
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE, STRING, "") \
81+
MACRO(DD_INSTRUMENTATION_INSTALL_TIME, STRING, "") \
82+
MACRO(DD_APM_TRACING_ENABLED, BOOLEAN, true) \
83+
MACRO(DD_TRACE_RESOURCE_RENAMING_ENABLED, BOOLEAN, false) \
84+
MACRO(DD_TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT, BOOLEAN, false) \
85+
MACRO(DD_EXTERNAL_ENV, STRING, "")
86+
87+
#define ENV_DEFAULT_RESOLVED_IN_CODE(X) X
88+
#define WITH_COMMA(ARG, TYPE, DEFAULT_VALUE) ARG,
89+
90+
enum Variable { DD_LIST_ENVIRONMENT_VARIABLES(WITH_COMMA) };
4291

4392
// Quoting a macro argument requires this two-step.
4493
#define QUOTED_IMPL(ARG) #ARG
4594
#define QUOTED(ARG) QUOTED_IMPL(ARG)
4695

47-
#define VARIABLE_SPEC_WITH_COMMA(DATA, NAME, TYPE, DEFAULT_VALUE) \
48-
VariableSpec{StringView{QUOTED(NAME)}, VariableType::TYPE},
49-
50-
inline const VariableSpec variable_specs[] = {
51-
DD_ENVIRONMENT_VARIABLES(VARIABLE_SPEC_WITH_COMMA, ~)};
52-
53-
template <VariableType type>
54-
struct LookupResultByType;
55-
56-
template <>
57-
struct LookupResultByType<VariableType::STRING> {
58-
using type = Optional<StringView>;
59-
};
60-
61-
template <>
62-
struct LookupResultByType<VariableType::BOOLEAN> {
63-
using type = Optional<bool>;
64-
};
65-
66-
template <>
67-
struct LookupResultByType<VariableType::INT> {
68-
using type = Expected<Optional<std::uint64_t>>;
69-
};
70-
71-
template <>
72-
struct LookupResultByType<VariableType::DECIMAL> {
73-
using type = Expected<Optional<double>>;
74-
};
75-
76-
template <>
77-
struct LookupResultByType<VariableType::ARRAY> {
78-
using type = Optional<StringView>;
79-
};
80-
81-
template <>
82-
struct LookupResultByType<VariableType::MAP> {
83-
using type = Optional<StringView>;
84-
};
85-
86-
template <Variable variable>
87-
struct VariableTraits;
88-
89-
#define VARIABLE_TRAITS_VALUE(DATA, NAME, TYPE, DEFAULT_VALUE) \
90-
template <> \
91-
struct VariableTraits<NAME> { \
92-
static constexpr VariableType variable_type = VariableType::TYPE; \
93-
static constexpr const char *name() { return QUOTED(NAME); } \
94-
using lookup_result = typename LookupResultByType<variable_type>::type; \
95-
};
96-
97-
DD_ENVIRONMENT_VARIABLES(VARIABLE_TRAITS_VALUE, ~)
98-
99-
template <Variable variable>
100-
using LookupResult = typename VariableTraits<variable>::lookup_result;
101-
102-
namespace detail {
103-
template <VariableType>
104-
inline constexpr bool unsupported_variable_type_v = false;
105-
106-
template <Variable variable>
107-
Optional<StringView> lookup_raw() {
108-
const char *value = std::getenv(VariableTraits<variable>::name());
109-
if (!value) {
110-
return nullopt;
111-
}
112-
return StringView{value};
113-
}
114-
115-
Optional<bool> lookup_bool_from_raw(Optional<StringView> value);
116-
Expected<Optional<std::uint64_t>> lookup_uint64_from_raw(
117-
Optional<StringView> value);
118-
Expected<Optional<double>> lookup_double_from_raw(Optional<StringView> value);
119-
} // namespace detail
96+
#define QUOTED_WITH_COMMA(ARG, TYPE, DEFAULT_VALUE) \
97+
WITH_COMMA(QUOTED(ARG), TYPE, DEFAULT_VALUE)
12098

121-
template <Variable variable>
122-
LookupResult<variable> lookup() {
123-
constexpr VariableType type = VariableTraits<variable>::variable_type;
124-
const auto raw = detail::lookup_raw<variable>();
125-
if constexpr (type == VariableType::STRING || type == VariableType::ARRAY ||
126-
type == VariableType::MAP) {
127-
return raw;
128-
} else if constexpr (type == VariableType::BOOLEAN) {
129-
return detail::lookup_bool_from_raw(raw);
130-
} else if constexpr (type == VariableType::INT) {
131-
return detail::lookup_uint64_from_raw(raw);
132-
} else if constexpr (type == VariableType::DECIMAL) {
133-
return detail::lookup_double_from_raw(raw);
134-
} else {
135-
static_assert(detail::unsupported_variable_type_v<type>,
136-
"Unsupported environment variable type");
137-
}
138-
}
99+
inline const char *const variable_names[] = {
100+
DD_LIST_ENVIRONMENT_VARIABLES(QUOTED_WITH_COMMA)};
139101

140-
#undef VARIABLE_SPEC_WITH_COMMA
141-
#undef VARIABLE_TRAITS_VALUE
142102
#undef QUOTED
143103
#undef QUOTED_IMPL
144-
#undef VARIABLE_ENUM_VALUE
104+
#undef WITH_COMMA
105+
#undef ENV_DEFAULT_RESOLVED_IN_CODE
106+
#undef LIST_ENVIRONMENT_VARIABLES
145107

146-
// Return the metadata for the specified environment `variable`.
147-
const VariableSpec &spec(Variable variable);
108+
Optional<StringView> lookup(Variable variable);
148109

149110
// Return the name of the specified environment `variable`.
150111
StringView name(Variable variable);

include/datadog/environment_registry.h

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)