Skip to content

Commit 1b2fd59

Browse files
committed
resolve incompatibilities between absl types and their std equivalents
1 parent 106d6c4 commit 1b2fd59

25 files changed

+158
-140
lines changed

src/datadog/collector_response.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace tracing {
66
std::string CollectorResponse::key(StringView service, StringView environment) {
77
std::string result;
88
result += "service:";
9-
result += service;
9+
append(result, service);
1010
result += ",env:";
11-
result += environment;
11+
append(result, environment);
1212
return result;
1313
}
1414

src/datadog/curl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Expected<void> CurlImpl::post(const HTTPClient::URL &url,
247247
}
248248
log_on_error(curl_multi_wakeup(multi_handle_));
249249

250-
return std::nullopt;
250+
return nullopt;
251251
} catch (CURLcode error) {
252252
return Error{Error::CURL_REQUEST_SETUP_FAILED, curl_easy_strerror(error)};
253253
}
@@ -445,7 +445,7 @@ Optional<StringView> CurlImpl::HeaderReader::lookup(StringView key) const {
445445

446446
const auto found = response_headers_lower_->find(buffer_);
447447
if (found == response_headers_lower_->end()) {
448-
return std::nullopt;
448+
return nullopt;
449449
}
450450
return found->second;
451451
}

src/datadog/datadog_agent.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const StringView traces_api_path = "/v0.4/traces";
2525

2626
HTTPClient::URL traces_endpoint(const HTTPClient::URL& agent_url) {
2727
auto traces_url = agent_url;
28-
traces_url.path += traces_api_path;
28+
append(traces_url.path, traces_api_path);
2929
return traces_url;
3030
}
3131

@@ -59,10 +59,10 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
5959
"Parsing the Datadog Agent's response to traces we sent it failed. "
6060
"The response is expected to be a JSON object, but instead it's a JSON "
6161
"value with type \"";
62-
message += type;
62+
append(message, type);
6363
message += '\"';
6464
message += "\nError occurred for response body (begins on next line):\n";
65-
message += body;
65+
append(message, body);
6666
return message;
6767
}
6868

@@ -78,14 +78,14 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
7878
message +=
7979
"Parsing the Datadog Agent's response to traces we sent it failed. "
8080
"The \"";
81-
message += sample_rates_property;
81+
append(message, sample_rates_property);
8282
message +=
8383
"\" property of the response is expected to be a JSON object, but "
8484
"instead it's a JSON value with type \"";
85-
message += type;
85+
append(message, type);
8686
message += '\"';
8787
message += "\nError occurred for response body (begins on next line):\n";
88-
message += body;
88+
append(message, body);
8989
return message;
9090
}
9191

@@ -99,10 +99,10 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
9999
"for the key \"";
100100
message += key;
101101
message += "\". Rate should be a number, but it's a \"";
102-
message += type;
102+
append(message, type);
103103
message += "\" instead.";
104104
message += "\nError occurred for response body (begins on next line):\n";
105-
message += body;
105+
append(message, body);
106106
return message;
107107
}
108108
auto maybe_rate = Rate::from(value);
@@ -115,7 +115,7 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
115115
message += "\": ";
116116
message += error->message;
117117
message += "\nError occurred for response body (begins on next line):\n";
118-
message += body;
118+
append(message, body);
119119
return message;
120120
}
121121
sample_rates.emplace(key, *maybe_rate);
@@ -128,7 +128,7 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
128128
"JSON error: ";
129129
message += error.what();
130130
message += "\nError occurred for response body (begins on next line):\n";
131-
message += body;
131+
append(message, body);
132132
return message;
133133
}
134134

@@ -161,7 +161,7 @@ Expected<void> DatadogAgent::send(
161161
std::lock_guard<std::mutex> lock(mutex_);
162162
incoming_trace_chunks_.push_back(
163163
TraceChunk{std::move(spans), response_handler});
164-
return std::nullopt;
164+
return nullopt;
165165
}
166166

167167
nlohmann::json DatadogAgent::config_json() const {

src/datadog/datadog_agent_config.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Expected<HTTPClient::URL> DatadogAgentConfig::parse(StringView input) {
1818
if (after_scheme == input.end()) {
1919
std::string message;
2020
message += "Datadog Agent URL is missing the \"://\" separator: \"";
21-
message += input;
21+
append(message, input);
2222
message += '\"';
2323
return Error{Error::URL_MISSING_SEPARATOR, std::move(message)};
2424
}
@@ -31,13 +31,13 @@ Expected<HTTPClient::URL> DatadogAgentConfig::parse(StringView input) {
3131
if (found == std::end(supported)) {
3232
std::string message;
3333
message += "Unsupported URI scheme \"";
34-
message += scheme;
34+
append(message, scheme);
3535
message += "\" in Datadog Agent URL \"";
36-
message += input;
36+
append(message, input);
3737
message += "\". The following are supported:";
3838
for (const auto& supported_scheme : supported) {
3939
message += ' ';
40-
message += supported_scheme;
40+
append(message, supported_scheme);
4141
}
4242
return Error{Error::URL_UNSUPPORTED_SCHEME, std::move(message)};
4343
}
@@ -59,9 +59,9 @@ Expected<HTTPClient::URL> DatadogAgentConfig::parse(StringView input) {
5959
"Unix domain socket paths for Datadog Agent must be absolute, i.e. "
6060
"must begin with a "
6161
"\"/\". The path \"";
62-
message += authority_and_path;
62+
append(message, authority_and_path);
6363
message += "\" is not absolute. Error occurred for URL: \"";
64-
message += input;
64+
append(message, input);
6565
message += '\"';
6666
return Error{Error::URL_UNIX_DOMAIN_SOCKET_PATH_NOT_ABSOLUTE,
6767
std::move(message)};
@@ -119,13 +119,13 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(
119119

120120
std::string configured_url = config.url;
121121
if (auto url_env = lookup(environment::DD_TRACE_AGENT_URL)) {
122-
configured_url = *url_env;
122+
assign(configured_url, *url_env);
123123
} else if (env_host || env_port) {
124124
configured_url.clear();
125125
configured_url += "http://";
126-
configured_url += env_host.value_or("localhost");
126+
append(configured_url, env_host.value_or("localhost"));
127127
configured_url += ':';
128-
configured_url += env_port.value_or("8126");
128+
append(configured_url, env_port.value_or("8126"));
129129
}
130130

131131
auto url = config.parse(configured_url);

src/datadog/dict_reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DictReader {
1616
public:
1717
virtual ~DictReader() {}
1818

19-
// Return the value at the specified `key`, or return `std::nullopt` if there
19+
// Return the value at the specified `key`, or return `nullopt` if there
2020
// is no value at `key`.
2121
virtual Optional<StringView> lookup(StringView key) const = 0;
2222

src/datadog/environment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Optional<StringView> lookup(Variable variable) {
1414
const char *name = variable_names[variable];
1515
const char *value = std::getenv(name);
1616
if (!value) {
17-
return std::nullopt;
17+
return nullopt;
1818
}
1919
return StringView{value};
2020
}

src/datadog/expected.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// This component provides a class template, `Expected<T>`, that is either an
44
// instance of `T` or an instance of `Error`. `Expected<void>` is either
5-
// `std::nullopt` or an instance of `Error`.
5+
// `nullopt` or an instance of `Error`.
66
//
77
// `Expected` is inspired by, but incompatible with, C++23's `std::expected`.
88
//

src/datadog/msgpack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ std::string make_overflow_message(StringView type, std::size_t actual,
2424
std::size_t max) {
2525
std::string message;
2626
message += "Cannot msgpack encode ";
27-
message += type;
27+
append(message, type);
2828
message += " of size ";
2929
message += std::to_string(actual);
3030
message += ", which exceeds the protocol maximum of ";

src/datadog/net_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace tracing {
1212
Optional<std::string> get_hostname() {
1313
char buffer[256];
1414
if (::gethostname(buffer, sizeof buffer)) {
15-
return std::nullopt;
15+
return nullopt;
1616
}
1717
return buffer;
1818
}

src/datadog/optional.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ namespace tracing {
3939
#ifdef DD_USE_ABSEIL_FOR_ENVOY
4040
template <typename Value>
4141
using Optional = absl::optional<Value>;
42+
inline constexpr auto nullopt = absl::nullopt;
4243
#else
4344
template <typename Value>
4445
using Optional = std::optional<Value>;
46+
inline constexpr auto nullopt = std::nullopt;
4547
#endif // defined DD_USE_ABSEIL_FOR_ENVOY
4648

4749
} // namespace tracing

0 commit comments

Comments
 (0)