Skip to content

Commit 75f564e

Browse files
committed
fixup! do not log, instead just bail instrumentation
1 parent 08d7a07 commit 75f564e

7 files changed

Lines changed: 150 additions & 137 deletions

File tree

include/datadog/trace_sampler_config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "config.h"
1414
#include "expected.h"
15-
#include "logger.h"
1615
#include "optional.h"
1716
#include "rate.h"
1817
#include "sampling_mechanism.h"
@@ -43,7 +42,7 @@ struct TraceSamplerConfig {
4342

4443
class FinalizedTraceSamplerConfig {
4544
friend Expected<FinalizedTraceSamplerConfig> finalize_config(
46-
const TraceSamplerConfig& config, Logger& logger);
45+
const TraceSamplerConfig& config);
4746
friend class FinalizedTracerConfig;
4847

4948
FinalizedTraceSamplerConfig() = default;
@@ -59,7 +58,7 @@ class FinalizedTraceSamplerConfig {
5958
};
6059

6160
Expected<FinalizedTraceSamplerConfig> finalize_config(
62-
const TraceSamplerConfig& config, Logger& logger);
61+
const TraceSamplerConfig& config);
6362

6463
} // namespace tracing
6564
} // namespace datadog

src/datadog/datadog_agent_config.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace tracing {
1616

1717
namespace env = environment;
1818

19-
DatadogAgentConfig load_datadog_agent_env_config(Logger& logger) {
19+
Expected<DatadogAgentConfig> load_datadog_agent_env_config() {
2020
DatadogAgentConfig env_config;
2121

2222
if (auto rc_enabled = env::lookup<env::DD_REMOTE_CONFIGURATION_ENABLED>()) {
@@ -26,8 +26,8 @@ DatadogAgentConfig load_datadog_agent_env_config(Logger& logger) {
2626
auto raw_rc_poll_interval_value =
2727
env::lookup<env::DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS>();
2828
if (auto error = raw_rc_poll_interval_value.if_error()) {
29-
logger.log_error(error->with_prefix(
30-
"DatadogAgent: Remote Configuration poll interval error "));
29+
return error->with_prefix(
30+
"DatadogAgent: Remote Configuration poll interval error ");
3131
} else if (*raw_rc_poll_interval_value) {
3232
env_config.remote_configuration_poll_interval_seconds =
3333
**raw_rc_poll_interval_value;
@@ -37,8 +37,7 @@ DatadogAgentConfig load_datadog_agent_env_config(Logger& logger) {
3737
Optional<std::uint64_t> env_port = nullopt;
3838
const auto raw_env_port = env::lookup<env::DD_TRACE_AGENT_PORT>();
3939
if (auto* error = raw_env_port.if_error()) {
40-
logger.log_error(
41-
error->with_prefix("DatadogAgent: Agent port parsing error "));
40+
return error->with_prefix("DatadogAgent: Agent port parsing error ");
4241
} else {
4342
env_port = *raw_env_port;
4443
}
@@ -60,7 +59,10 @@ DatadogAgentConfig load_datadog_agent_env_config(Logger& logger) {
6059
Expected<FinalizedDatadogAgentConfig> finalize_config(
6160
const DatadogAgentConfig& user_config,
6261
const std::shared_ptr<Logger>& logger, const Clock& clock) {
63-
DatadogAgentConfig env_config = load_datadog_agent_env_config(*logger);
62+
Expected<DatadogAgentConfig> env_config = load_datadog_agent_env_config();
63+
if (auto error = env_config.if_error()) {
64+
return *error;
65+
}
6466

6567
FinalizedDatadogAgentConfig result;
6668

@@ -89,7 +91,7 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
8991
user_config.remote_configuration_listeners;
9092

9193
if (auto flush_interval_milliseconds =
92-
value_or(env_config.flush_interval_milliseconds,
94+
value_or(env_config->flush_interval_milliseconds,
9395
user_config.flush_interval_milliseconds, 2000);
9496
flush_interval_milliseconds > 0) {
9597
result.flush_interval =
@@ -101,7 +103,7 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
101103
}
102104

103105
if (auto request_timeout_milliseconds =
104-
value_or(env_config.request_timeout_milliseconds,
106+
value_or(env_config->request_timeout_milliseconds,
105107
user_config.request_timeout_milliseconds, 2000);
106108
request_timeout_milliseconds > 0) {
107109
result.request_timeout =
@@ -113,7 +115,7 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
113115
}
114116

115117
if (auto shutdown_timeout_milliseconds =
116-
value_or(env_config.shutdown_timeout_milliseconds,
118+
value_or(env_config->shutdown_timeout_milliseconds,
117119
user_config.shutdown_timeout_milliseconds, 2000);
118120
shutdown_timeout_milliseconds > 0) {
119121
result.shutdown_timeout =
@@ -125,7 +127,7 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
125127
}
126128

127129
if (double rc_poll_interval_seconds =
128-
value_or(env_config.remote_configuration_poll_interval_seconds,
130+
value_or(env_config->remote_configuration_poll_interval_seconds,
129131
user_config.remote_configuration_poll_interval_seconds, 5.0);
130132
rc_poll_interval_seconds >= 0.0) {
131133
result.remote_configuration_poll_interval =
@@ -138,11 +140,11 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
138140
}
139141

140142
result.remote_configuration_enabled =
141-
value_or(env_config.remote_configuration_enabled,
143+
value_or(env_config->remote_configuration_enabled,
142144
user_config.remote_configuration_enabled, true);
143145

144146
const auto [origin, url] =
145-
pick(env_config.url, user_config.url, "http://localhost:8126");
147+
pick(env_config->url, user_config.url, "http://localhost:8126");
146148
auto parsed_url = HTTPClient::URL::parse(url);
147149
if (auto* error = parsed_url.if_error()) {
148150
return std::move(*error);

src/datadog/telemetry/configuration.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ tracing::Expected<Configuration> load_telemetry_env_config() {
3030

3131
auto metrics_interval_seconds =
3232
env::lookup<env::DD_TELEMETRY_METRICS_INTERVAL_SECONDS>();
33-
if (!metrics_interval_seconds.if_error() && *metrics_interval_seconds) {
33+
if (auto error = metrics_interval_seconds.if_error()) {
34+
return *error;
35+
} else if (*metrics_interval_seconds) {
3436
env_cfg.metrics_interval_seconds = **metrics_interval_seconds;
3537
}
3638

3739
auto heartbeat_interval_seconds =
3840
env::lookup<env::DD_TELEMETRY_HEARTBEAT_INTERVAL>();
39-
if (!heartbeat_interval_seconds.if_error() && *heartbeat_interval_seconds) {
41+
if (auto error = heartbeat_interval_seconds.if_error()) {
42+
return *error;
43+
} else if (*heartbeat_interval_seconds) {
4044
env_cfg.heartbeat_interval_seconds = **heartbeat_interval_seconds;
4145
}
4246

src/datadog/trace_sampler_config.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace env = environment;
1717

1818
namespace {
1919

20-
Expected<TraceSamplerConfig> load_trace_sampler_env_config(Logger &logger) {
20+
Expected<TraceSamplerConfig> load_trace_sampler_env_config() {
2121
TraceSamplerConfig env_config;
2222

2323
if (auto rules_env = env::lookup<env::DD_TRACE_SAMPLING_RULES>()) {
@@ -111,16 +111,22 @@ Expected<TraceSamplerConfig> load_trace_sampler_env_config(Logger &logger) {
111111

112112
const auto sample_rate_env = env::lookup<env::DD_TRACE_SAMPLE_RATE>();
113113
if (auto *error = sample_rate_env.if_error()) {
114-
logger.log_error(
115-
error->with_prefix("Unable to parse DD_TRACE_SAMPLE_RATE: "));
114+
std::string prefix;
115+
prefix += "While parsing ";
116+
append(prefix, name(env::DD_TRACE_SAMPLE_RATE));
117+
prefix += ": ";
118+
return error->with_prefix(prefix);
116119
} else if (*sample_rate_env) {
117120
env_config.sample_rate = **sample_rate_env;
118121
}
119122

120123
const auto limit_env = env::lookup<env::DD_TRACE_RATE_LIMIT>();
121124
if (auto *error = limit_env.if_error()) {
122-
logger.log_error(
123-
error->with_prefix("Unable to parse DD_TRACE_RATE_LIMIT: "));
125+
std::string prefix;
126+
prefix += "While parsing ";
127+
append(prefix, name(env::DD_TRACE_RATE_LIMIT));
128+
prefix += ": ";
129+
return error->with_prefix(prefix);
124130
} else if (*limit_env) {
125131
env_config.max_per_second = **limit_env;
126132
}
@@ -144,9 +150,8 @@ std::string to_string(const std::vector<TraceSamplerConfig::Rule> &rules) {
144150
TraceSamplerConfig::Rule::Rule(const SpanMatcher &base) : SpanMatcher(base) {}
145151

146152
Expected<FinalizedTraceSamplerConfig> finalize_config(
147-
const TraceSamplerConfig &config, Logger &logger) {
148-
Expected<TraceSamplerConfig> env_config =
149-
load_trace_sampler_env_config(logger);
153+
const TraceSamplerConfig &config) {
154+
Expected<TraceSamplerConfig> env_config = load_trace_sampler_env_config();
150155
if (auto error = env_config.if_error()) {
151156
return *error;
152157
}

src/datadog/tracer_config.cpp

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ Optional<StringView> lookup_propagation_env(environment::Variable variable) {
9292
}
9393

9494
// Return a `std::vector<PropagationStyle>` parsed from the specified `env_var`.
95-
// If `env_var` is not in the environment, return `nullopt`.
96-
// If parsing fails, log and ignore the environment variable.
95+
// If `env_var` is not in the environment, return `nullopt`. If an error occurs,
96+
// throw an `Error`.
9797
Optional<std::vector<PropagationStyle>> styles_from_env(
98-
environment::Variable env_var, Logger &logger) {
98+
environment::Variable env_var) {
9999
const auto styles_env = lookup_propagation_env(env_var);
100100
if (!styles_env) {
101101
return {};
@@ -107,8 +107,7 @@ Optional<std::vector<PropagationStyle>> styles_from_env(
107107
prefix += "Unable to parse ";
108108
append(prefix, name(env_var));
109109
prefix += " environment variable: ";
110-
logger.log_error(error->with_prefix(prefix));
111-
return {};
110+
throw error->with_prefix(prefix);
112111
}
113112
return *styles;
114113
}
@@ -134,10 +133,9 @@ Expected<TracerConfig> load_tracer_env_config(Logger &logger) {
134133
prefix += "Unable to parse ";
135134
append(prefix, name(env::DD_TAGS));
136135
prefix += " environment variable: ";
137-
logger.log_error(error->with_prefix(prefix));
138-
} else {
139-
env_cfg.tags = std::move(*tags);
136+
return error->with_prefix(prefix);
140137
}
138+
env_cfg.tags = std::move(*tags);
141139
}
142140

143141
if (auto startup_env = env::lookup<env::DD_TRACE_STARTUP_LOGS>()) {
@@ -168,16 +166,14 @@ Expected<TracerConfig> load_tracer_env_config(Logger &logger) {
168166
// Baggage
169167
const auto baggage_items_env = env::lookup<env::DD_TRACE_BAGGAGE_MAX_ITEMS>();
170168
if (auto *error = baggage_items_env.if_error()) {
171-
logger.log_error(error->with_prefix(
172-
"Unable to parse DD_TRACE_BAGGAGE_MAX_ITEMS environment variable: "));
169+
return *error;
173170
} else if (*baggage_items_env) {
174171
env_cfg.baggage_max_items = std::move(**baggage_items_env);
175172
}
176173

177174
const auto baggage_bytes_env = env::lookup<env::DD_TRACE_BAGGAGE_MAX_BYTES>();
178175
if (auto *error = baggage_bytes_env.if_error()) {
179-
logger.log_error(error->with_prefix(
180-
"Unable to parse DD_TRACE_BAGGAGE_MAX_BYTES environment variable: "));
176+
return *error;
181177
} else if (*baggage_bytes_env) {
182178
env_cfg.baggage_max_bytes = std::move(**baggage_bytes_env);
183179
}
@@ -252,27 +248,31 @@ Expected<TracerConfig> load_tracer_env_config(Logger &logger) {
252248
warn_message(var_name, *value, var_name_override, *value_override)});
253249
}
254250

255-
const auto global_styles =
256-
styles_from_env(environment::DD_TRACE_PROPAGATION_STYLE, logger);
251+
try {
252+
const auto global_styles =
253+
styles_from_env(environment::DD_TRACE_PROPAGATION_STYLE);
257254

258-
if (auto trace_extraction_styles = styles_from_env(
259-
environment::DD_TRACE_PROPAGATION_STYLE_EXTRACT, logger)) {
260-
env_cfg.extraction_styles = std::move(*trace_extraction_styles);
261-
} else if (auto extraction_styles = styles_from_env(
262-
environment::DD_PROPAGATION_STYLE_EXTRACT, logger)) {
263-
env_cfg.extraction_styles = std::move(*extraction_styles);
264-
} else {
265-
env_cfg.extraction_styles = global_styles;
266-
}
255+
if (auto trace_extraction_styles =
256+
styles_from_env(environment::DD_TRACE_PROPAGATION_STYLE_EXTRACT)) {
257+
env_cfg.extraction_styles = std::move(*trace_extraction_styles);
258+
} else if (auto extraction_styles =
259+
styles_from_env(environment::DD_PROPAGATION_STYLE_EXTRACT)) {
260+
env_cfg.extraction_styles = std::move(*extraction_styles);
261+
} else {
262+
env_cfg.extraction_styles = global_styles;
263+
}
267264

268-
if (auto trace_injection_styles = styles_from_env(
269-
environment::DD_TRACE_PROPAGATION_STYLE_INJECT, logger)) {
270-
env_cfg.injection_styles = std::move(*trace_injection_styles);
271-
} else if (auto injection_styles = styles_from_env(
272-
environment::DD_PROPAGATION_STYLE_INJECT, logger)) {
273-
env_cfg.injection_styles = std::move(*injection_styles);
274-
} else {
275-
env_cfg.injection_styles = global_styles;
265+
if (auto trace_injection_styles =
266+
styles_from_env(environment::DD_TRACE_PROPAGATION_STYLE_INJECT)) {
267+
env_cfg.injection_styles = std::move(*trace_injection_styles);
268+
} else if (auto injection_styles =
269+
styles_from_env(environment::DD_PROPAGATION_STYLE_INJECT)) {
270+
env_cfg.injection_styles = std::move(*injection_styles);
271+
} else {
272+
env_cfg.injection_styles = global_styles;
273+
}
274+
} catch (Error &error) {
275+
return std::move(error);
276276
}
277277

278278
return env_cfg;
@@ -429,8 +429,7 @@ Expected<FinalizedTracerConfig> finalize_config(const TracerConfig &user_config,
429429
return std::move(*error);
430430
}
431431

432-
if (auto trace_sampler_config =
433-
finalize_config(user_config.trace_sampler, *logger)) {
432+
if (auto trace_sampler_config = finalize_config(user_config.trace_sampler)) {
434433
// Merge metadata vectors
435434
for (auto &[key, values] : trace_sampler_config->metadata) {
436435
auto &dest = final_config.metadata[key];

test/telemetry/test_configuration.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ TELEMETRY_CONFIGURATION_TEST("validation") {
130130
auto final_cfg = telemetry::finalize_config();
131131
REQUIRE(!final_cfg);
132132
}
133+
134+
SECTION("environment variable parse error") {
135+
ddtest::EnvGuard env("DD_TELEMETRY_METRICS_INTERVAL_SECONDS", "nope");
136+
auto final_cfg = telemetry::finalize_config();
137+
REQUIRE(!final_cfg);
138+
REQUIRE(final_cfg.error().code == tracing::Error::INVALID_DOUBLE);
139+
}
133140
}
134141

135142
SECTION("heartbeat interval validation") {
@@ -146,6 +153,13 @@ TELEMETRY_CONFIGURATION_TEST("validation") {
146153
auto final_cfg = telemetry::finalize_config();
147154
REQUIRE(!final_cfg);
148155
}
156+
157+
SECTION("environment variable parse error") {
158+
ddtest::EnvGuard env("DD_TELEMETRY_HEARTBEAT_INTERVAL", "bogus");
159+
auto final_cfg = telemetry::finalize_config();
160+
REQUIRE(!final_cfg);
161+
REQUIRE(final_cfg.error().code == tracing::Error::INVALID_DOUBLE);
162+
}
149163
}
150164
}
151165

0 commit comments

Comments
 (0)