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
7 changes: 5 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# Abseil's absl::string_view and absl::optional instead.
#
# In the context of an Envoy build, the Abseil libraries point to whatever
# versions Envoy uses.
# versions Envoy uses, including some source patches.
#
# To test this library's Bazel build independent of Envoy, we need to specify
# versions of the Abseil libraries. That is what this file is for.
# versions of the Abseil libraries, including Envoy's patches. That is what this
# file is for.

# These rules are based on <https://abseil.io/docs/cpp/quickstart>,
# accessed December 6, 2022.
Expand All @@ -18,6 +19,8 @@ http_archive(
urls = ["https://github.com/abseil/abseil-cpp/archive/98eb410c93ad059f9bba1bf43f5bb916fc92a5ea.zip"],
sha256 = "aabf6c57e3834f8dc3873a927f37eaf69975d4b28117fc7427dfb1c661542a87",
strip_prefix = "abseil-cpp-98eb410c93ad059f9bba1bf43f5bb916fc92a5ea",
patches = ["//:abseil.patch"],
patch_args = ["-p1"],
)

http_archive(
Expand Down
31 changes: 31 additions & 0 deletions abseil.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/absl/base/options.h b/absl/base/options.h
index 6868c77b..e544fe6c 100644
--- a/absl/base/options.h
+++ b/absl/base/options.h
@@ -135,7 +135,7 @@
// absl::optional is a typedef of std::optional, use the feature macro
// ABSL_USES_STD_OPTIONAL.

-#define ABSL_OPTION_USE_STD_OPTIONAL 2
+#define ABSL_OPTION_USE_STD_OPTIONAL 0


// ABSL_OPTION_USE_STD_STRING_VIEW
@@ -162,7 +162,7 @@
// absl::string_view is a typedef of std::string_view, use the feature macro
// ABSL_USES_STD_STRING_VIEW.

-#define ABSL_OPTION_USE_STD_STRING_VIEW 2
+#define ABSL_OPTION_USE_STD_STRING_VIEW 0

// ABSL_OPTION_USE_STD_VARIANT
//
@@ -188,7 +188,7 @@
// absl::variant is a typedef of std::variant, use the feature macro
// ABSL_USES_STD_VARIANT.

-#define ABSL_OPTION_USE_STD_VARIANT 2
+#define ABSL_OPTION_USE_STD_VARIANT 0


// ABSL_OPTION_USE_INLINE_NAMESPACE
4 changes: 2 additions & 2 deletions src/datadog/collector_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace tracing {
std::string CollectorResponse::key(StringView service, StringView environment) {
std::string result;
result += "service:";
result += service;
append(result, service);
result += ",env:";
result += environment;
append(result, environment);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/datadog/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Expected<void> CurlImpl::post(const HTTPClient::URL &url,
}
log_on_error(curl_multi_wakeup(multi_handle_));

return std::nullopt;
return nullopt;
} catch (CURLcode error) {
return Error{Error::CURL_REQUEST_SETUP_FAILED, curl_easy_strerror(error)};
}
Expand Down Expand Up @@ -445,7 +445,7 @@ Optional<StringView> CurlImpl::HeaderReader::lookup(StringView key) const {

const auto found = response_headers_lower_->find(buffer_);
if (found == response_headers_lower_->end()) {
return std::nullopt;
return nullopt;
}
return found->second;
}
Expand Down
22 changes: 11 additions & 11 deletions src/datadog/datadog_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const StringView traces_api_path = "/v0.4/traces";

HTTPClient::URL traces_endpoint(const HTTPClient::URL& agent_url) {
auto traces_url = agent_url;
traces_url.path += traces_api_path;
append(traces_url.path, traces_api_path);
return traces_url;
}

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

Expand All @@ -78,14 +78,14 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
message +=
"Parsing the Datadog Agent's response to traces we sent it failed. "
"The \"";
message += sample_rates_property;
append(message, sample_rates_property);
message +=
"\" property of the response is expected to be a JSON object, but "
"instead it's a JSON value with type \"";
message += type;
append(message, type);
message += '\"';
message += "\nError occurred for response body (begins on next line):\n";
message += body;
append(message, body);
return message;
}

Expand All @@ -99,10 +99,10 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
"for the key \"";
message += key;
message += "\". Rate should be a number, but it's a \"";
message += type;
append(message, type);
message += "\" instead.";
message += "\nError occurred for response body (begins on next line):\n";
message += body;
append(message, body);
return message;
}
auto maybe_rate = Rate::from(value);
Expand All @@ -115,7 +115,7 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
message += "\": ";
message += error->message;
message += "\nError occurred for response body (begins on next line):\n";
message += body;
append(message, body);
return message;
}
sample_rates.emplace(key, *maybe_rate);
Expand All @@ -128,7 +128,7 @@ std::variant<CollectorResponse, std::string> parse_agent_traces_response(
"JSON error: ";
message += error.what();
message += "\nError occurred for response body (begins on next line):\n";
message += body;
append(message, body);
return message;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ Expected<void> DatadogAgent::send(
std::lock_guard<std::mutex> lock(mutex_);
incoming_trace_chunks_.push_back(
TraceChunk{std::move(spans), response_handler});
return std::nullopt;
return nullopt;
}

nlohmann::json DatadogAgent::config_json() const {
Expand Down
18 changes: 9 additions & 9 deletions src/datadog/datadog_agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Expected<HTTPClient::URL> DatadogAgentConfig::parse(StringView input) {
if (after_scheme == input.end()) {
std::string message;
message += "Datadog Agent URL is missing the \"://\" separator: \"";
message += input;
append(message, input);
message += '\"';
return Error{Error::URL_MISSING_SEPARATOR, std::move(message)};
}
Expand All @@ -31,13 +31,13 @@ Expected<HTTPClient::URL> DatadogAgentConfig::parse(StringView input) {
if (found == std::end(supported)) {
std::string message;
message += "Unsupported URI scheme \"";
message += scheme;
append(message, scheme);
message += "\" in Datadog Agent URL \"";
message += input;
append(message, input);
message += "\". The following are supported:";
for (const auto& supported_scheme : supported) {
message += ' ';
message += supported_scheme;
append(message, supported_scheme);
}
return Error{Error::URL_UNSUPPORTED_SCHEME, std::move(message)};
}
Expand All @@ -59,9 +59,9 @@ Expected<HTTPClient::URL> DatadogAgentConfig::parse(StringView input) {
"Unix domain socket paths for Datadog Agent must be absolute, i.e. "
"must begin with a "
"\"/\". The path \"";
message += authority_and_path;
append(message, authority_and_path);
message += "\" is not absolute. Error occurred for URL: \"";
message += input;
append(message, input);
message += '\"';
return Error{Error::URL_UNIX_DOMAIN_SOCKET_PATH_NOT_ABSOLUTE,
std::move(message)};
Expand Down Expand Up @@ -119,13 +119,13 @@ Expected<FinalizedDatadogAgentConfig> finalize_config(

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

auto url = config.parse(configured_url);
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/dict_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DictReader {
public:
virtual ~DictReader() {}

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

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Optional<StringView> lookup(Variable variable) {
const char *name = variable_names[variable];
const char *value = std::getenv(name);
if (!value) {
return std::nullopt;
return nullopt;
}
return StringView{value};
}
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This component provides a class template, `Expected<T>`, that is either an
// instance of `T` or an instance of `Error`. `Expected<void>` is either
// `std::nullopt` or an instance of `Error`.
// `nullopt` or an instance of `Error`.
//
// `Expected` is inspired by, but incompatible with, C++23's `std::expected`.
//
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/msgpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::string make_overflow_message(StringView type, std::size_t actual,
std::size_t max) {
std::string message;
message += "Cannot msgpack encode ";
message += type;
append(message, type);
message += " of size ";
message += std::to_string(actual);
message += ", which exceeds the protocol maximum of ";
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/net_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace tracing {
Optional<std::string> get_hostname() {
char buffer[256];
if (::gethostname(buffer, sizeof buffer)) {
return std::nullopt;
return nullopt;
}
return buffer;
}
Expand Down
2 changes: 2 additions & 0 deletions src/datadog/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ namespace tracing {
#ifdef DD_USE_ABSEIL_FOR_ENVOY
template <typename Value>
using Optional = absl::optional<Value>;
inline constexpr auto nullopt = absl::nullopt;
#else
template <typename Value>
using Optional = std::optional<Value>;
inline constexpr auto nullopt = std::nullopt;
#endif // defined DD_USE_ABSEIL_FOR_ENVOY

} // namespace tracing
Expand Down
12 changes: 6 additions & 6 deletions src/datadog/parse_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ Expected<Integer> parse_integer(StringView input, int base, StringView kind) {
if (status.ec == std::errc::invalid_argument) {
std::string message;
message += "Is not a valid integer: \"";
message += input;
append(message, input);
message += '\"';
return Error{Error::INVALID_INTEGER, std::move(message)};
} else if (status.ptr != input.end()) {
std::string message;
message += "Integer has trailing characters in: \"";
message += input;
append(message, input);
message += '\"';
return Error{Error::INVALID_INTEGER, std::move(message)};
} else if (status.ec == std::errc::result_out_of_range) {
std::string message;
message += "Integer is not within the range of ";
message += kind;
append(message, kind);
message += ": ";
message += input;
append(message, input);
return Error{Error::OUT_OF_RANGE_INTEGER, std::move(message)};
}
return value;
Expand Down Expand Up @@ -85,13 +85,13 @@ Expected<double> parse_double(StringView input) {
message +=
"Is not a valid number, or is out of the range of double precision "
"floating point: \"";
message += input;
append(message, input);
message += '\"';
return Error{Error::INVALID_DOUBLE, std::move(message)};
} else if (!stream.eof()) {
std::string message;
message += "Number has trailing characters in: \"";
message += input;
append(message, input);
message += '\"';
return Error{Error::INVALID_DOUBLE, std::move(message)};
}
Expand Down
18 changes: 11 additions & 7 deletions src/datadog/span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::uint64_t Span::trace_id() const { return data_->trace_id; }

Optional<std::uint64_t> Span::parent_id() const {
if (data_->parent_id == 0) {
return std::nullopt;
return nullopt;
}
return data_->parent_id;
}
Expand All @@ -77,12 +77,12 @@ bool Span::error() const { return data_->error; }

Optional<StringView> Span::lookup_tag(StringView name) const {
if (tags::is_internal(name)) {
return std::nullopt;
return nullopt;
}

const auto found = data_->tags.find(std::string(name));
if (found == data_->tags.end()) {
return std::nullopt;
return nullopt;
}
return found->second;
}
Expand All @@ -99,12 +99,16 @@ void Span::remove_tag(StringView name) {
}
}

void Span::set_service_name(StringView service) { data_->service = service; }
void Span::set_service_name(StringView service) {
assign(data_->service, service);
}

void Span::set_service_type(StringView type) { data_->service_type = type; }
void Span::set_service_type(StringView type) {
assign(data_->service_type, type);
}

void Span::set_resource_name(StringView resource) {
data_->resource = resource;
assign(data_->resource, resource);
}

void Span::set_error(bool is_error) {
Expand All @@ -130,7 +134,7 @@ void Span::set_error_stack(StringView type) {
data_->tags.insert_or_assign("error.stack", std::string(type));
}

void Span::set_name(StringView value) { data_->name = value; }
void Span::set_name(StringView value) { assign(data_->name, value); }

void Span::set_end_time(std::chrono::steady_clock::time_point end_time) {
end_time_ = end_time;
Expand Down
4 changes: 2 additions & 2 deletions src/datadog/span_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Optional<StringView> lookup(
if (found != map.end()) {
return found->second;
}
return std::nullopt;
return nullopt;
}

} // namespace
Expand Down Expand Up @@ -122,7 +122,7 @@ Expected<void> msgpack_encode(std::string& destination, const SpanData& span) {
});
// clang-format on

return std::nullopt;
return nullopt;
}

} // namespace tracing
Expand Down
Loading