Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bp/1.27] tracing: dd-trace-cpp v0.1.12 (#31526) #32015

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,13 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "Datadog C++ Tracing Library",
project_desc = "Datadog distributed tracing for C++",
project_url = "https://github.com/DataDog/dd-trace-cpp",
version = "0.1.8",
sha256 = "77162c26ba976b8b18e6daf50beaec39389286840733b08e1627d4e5572d4b51",
version = "0.1.12",
sha256 = "9609a9192fecf730473743662e9f5ed57b4c348c12a0e16dd11ed2e592462ebe",
strip_prefix = "dd-trace-cpp-{version}",
urls = ["https://github.com/DataDog/dd-trace-cpp/archive/v{version}.tar.gz"],
use_category = ["observability_ext"],
extensions = ["envoy.tracers.datadog"],
release_date = "2023-03-31",
release_date = "2023-11-17",
cpe = "N/A",
license = "Apache-2.0",
license_url = "https://github.com/DataDog/dd-trace-cpp/blob/v{version}/LICENSE.md",
Expand Down
35 changes: 24 additions & 11 deletions source/extensions/tracers/datadog/agent_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace Datadog {

AgentHTTPClient::AgentHTTPClient(Upstream::ClusterManager& cluster_manager,
const std::string& cluster, const std::string& reference_host,
TracerStats& stats)
TracerStats& stats, TimeSource& time_source)
: collector_cluster_(cluster_manager, cluster), cluster_(cluster),
reference_host_(reference_host), stats_(stats) {}
reference_host_(reference_host), stats_(stats), time_source_(time_source) {}

AgentHTTPClient::~AgentHTTPClient() {
for (const auto& [request_ptr, _] : handlers_) {
Expand All @@ -38,12 +38,10 @@ AgentHTTPClient::~AgentHTTPClient() {

// datadog::tracing::HTTPClient

datadog::tracing::Expected<void> AgentHTTPClient::post(const URL& url, HeadersSetter set_headers,
std::string body,
ResponseHandler on_response,
ErrorHandler on_error) {
ENVOY_LOG(debug, "flushing traces");

datadog::tracing::Expected<void>
AgentHTTPClient::post(const URL& url, HeadersSetter set_headers, std::string body,
ResponseHandler on_response, ErrorHandler on_error,
std::chrono::steady_clock::time_point deadline) {
auto message = std::make_unique<Http::RequestMessageImpl>();
Http::RequestHeaderMap& headers = message->headers();
headers.setReferenceMethod(Http::Headers::get().MethodValues.Post);
Expand All @@ -54,7 +52,23 @@ datadog::tracing::Expected<void> AgentHTTPClient::post(const URL& url, HeadersSe
set_headers(writer);

message->body().add(body);
ENVOY_LOG(debug, "submitting trace(s) to {} with payload size {}", url.path, body.size());

const auto timeout = std::chrono::duration_cast<std::chrono::milliseconds>(
deadline - time_source_.monotonicTime());
if (timeout.count() <= 0) {
std::string message = "request deadline expired already";
if (timeout.count() < 0) {
message += ' ';
message += std::to_string(-timeout.count());
message += " milliseconds ago";
}
stats_.reports_dropped_.inc();
return datadog::tracing::Error{datadog::tracing::Error::ENVOY_HTTP_CLIENT_FAILURE,
std::move(message)};
}

ENVOY_LOG(debug, "submitting data to {} with payload size {} and {} ms timeout", url.path,
body.size(), timeout.count());

if (!collector_cluster_.threadLocalCluster().has_value()) {
ENVOY_LOG(debug, "collector cluster '{}' does not exist", cluster_);
Expand All @@ -64,8 +78,7 @@ datadog::tracing::Expected<void> AgentHTTPClient::post(const URL& url, HeadersSe

Http::AsyncClient::Request* request =
collector_cluster_.threadLocalCluster()->get().httpAsyncClient().send(
std::move(message), *this,
Http::AsyncClient::RequestOptions().setTimeout(std::chrono::milliseconds(1000)));
std::move(message), *this, Http::AsyncClient::RequestOptions().setTimeout(timeout));
if (!request) {
stats_.reports_failed_.inc();
return datadog::tracing::Error{datadog::tracing::Error::ENVOY_HTTP_CLIENT_FAILURE,
Expand Down
13 changes: 8 additions & 5 deletions source/extensions/tracers/datadog/agent_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class AgentHTTPClient : public datadog::tracing::HTTPClient,
* @param reference_host the value to use for the "Host" HTTP request header
* @param stats a collection of counters used to keep track of events, such as
* when a request fails
* @param time_source clocks used for calculating request timeouts
*/
AgentHTTPClient(Upstream::ClusterManager& cluster_manager, const std::string& cluster,
const std::string& reference_host, TracerStats& stats);
const std::string& reference_host, TracerStats& stats, TimeSource& time_source);
~AgentHTTPClient() override;

// datadog::tracing::HTTPClient
Expand All @@ -66,13 +67,14 @@ class AgentHTTPClient : public datadog::tracing::HTTPClient,
* @param body data to send as POST request body
* @param on_response callback to invoke when a complete response is received
* @param on_error callback to invoke when an error occurs before a complete
* response is received.
* response is received
* @param deadline time after which a response is not expected
* @return \c datadog::tracing::Error if an error occurs, or
* \c datadog::tracing::nullopt otherwise.
* \c datadog::tracing::nullopt otherwise
*/
datadog::tracing::Expected<void> post(const URL& url, HeadersSetter set_headers, std::string body,
ResponseHandler on_response,
ErrorHandler on_error) override;
ResponseHandler on_response, ErrorHandler on_error,
std::chrono::steady_clock::time_point deadline) override;

/**
* \c drain has no effect. It's a part of the \c datadog::tracing::HTTPClient
Expand All @@ -98,6 +100,7 @@ class AgentHTTPClient : public datadog::tracing::HTTPClient,
const std::string cluster_;
const std::string reference_host_;
TracerStats& stats_;
TimeSource& time_source_;
};

} // namespace Datadog
Expand Down
6 changes: 4 additions & 2 deletions source/extensions/tracers/datadog/config.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "source/extensions/tracers/datadog/config.h"

#include <datadog/runtime_id.h>
#include <datadog/tracer_config.h>

#include <memory>
Expand Down Expand Up @@ -43,10 +44,11 @@ std::string DatadogTracerFactory::makeCollectorReferenceHost(
Tracing::DriverSharedPtr DatadogTracerFactory::createTracerDriverTyped(
const envoy::config::trace::v3::DatadogConfig& proto_config,
Server::Configuration::TracerFactoryContext& context) {
auto& factory_context = context.serverFactoryContext();
return std::make_shared<Tracer>(
proto_config.collector_cluster(), makeCollectorReferenceHost(proto_config),
makeConfig(proto_config), context.serverFactoryContext().clusterManager(),
context.serverFactoryContext().scope(), context.serverFactoryContext().threadLocal());
makeConfig(proto_config), factory_context.clusterManager(), factory_context.scope(),
factory_context.threadLocal(), factory_context.timeSource());
}

/**
Expand Down
14 changes: 8 additions & 6 deletions source/extensions/tracers/datadog/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ namespace {
std::shared_ptr<Tracer::ThreadLocalTracer> makeThreadLocalTracer(
datadog::tracing::TracerConfig config, Upstream::ClusterManager& cluster_manager,
const std::string& collector_cluster, const std::string& collector_reference_host,
TracerStats& tracer_stats, Event::Dispatcher& dispatcher, spdlog::logger& logger) {
TracerStats& tracer_stats, Event::Dispatcher& dispatcher, spdlog::logger& logger,
TimeSource& time_source) {
config.logger = std::make_shared<Logger>(logger);
config.agent.event_scheduler = std::make_shared<EventScheduler>(dispatcher);
config.agent.http_client = std::make_shared<AgentHTTPClient>(
cluster_manager, collector_cluster, collector_reference_host, tracer_stats);
cluster_manager, collector_cluster, collector_reference_host, tracer_stats, time_source);

datadog::tracing::Expected<datadog::tracing::FinalizedTracerConfig> maybe_config =
datadog::tracing::finalize_config(config);
Expand All @@ -57,7 +58,7 @@ Tracer::ThreadLocalTracer::ThreadLocalTracer(const datadog::tracing::FinalizedTr
Tracer::Tracer(const std::string& collector_cluster, const std::string& collector_reference_host,
const datadog::tracing::TracerConfig& config,
Upstream::ClusterManager& cluster_manager, Stats::Scope& scope,
ThreadLocal::SlotAllocator& thread_local_slot_allocator)
ThreadLocal::SlotAllocator& thread_local_slot_allocator, TimeSource& time_source)
: tracer_stats_(makeTracerStats(scope)),
thread_local_slot_(
ThreadLocal::TypedSlot<ThreadLocalTracer>::makeUnique(thread_local_slot_allocator)) {
Expand All @@ -66,10 +67,11 @@ Tracer::Tracer(const std::string& collector_cluster, const std::string& collecto
allow_added_via_api);

thread_local_slot_->set([&logger = ENVOY_LOGGER(), collector_cluster, collector_reference_host,
config, &tracer_stats = tracer_stats_,
&cluster_manager](Event::Dispatcher& dispatcher) {
config, &tracer_stats = tracer_stats_, &cluster_manager,
&time_source](Event::Dispatcher& dispatcher) {
return makeThreadLocalTracer(config, cluster_manager, collector_cluster,
collector_reference_host, tracer_stats, dispatcher, logger);
collector_reference_host, tracer_stats, dispatcher, logger,
time_source);
});
}

Expand Down
5 changes: 3 additions & 2 deletions source/extensions/tracers/datadog/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class Tracer : public Tracing::Driver, private Logger::Loggable<Logger::Id::trac
* cluster is retrieved in order to send HTTP request containing traces
* @param scope statistics scope from which \c TracerStats can be created
* @param thread_local_slot_allocator slot allocator for installing a
* thread-local instance of the tracer.
* thread-local instance of the tracer
* @param time_source clocks used for calculating HTTP request timeouts
*/
explicit Tracer(const std::string& collector_cluster, const std::string& collector_reference_host,
const datadog::tracing::TracerConfig& config,
Upstream::ClusterManager& cluster_manager, Stats::Scope& scope,
ThreadLocal::SlotAllocator& thread_local_slot_allocator);
ThreadLocal::SlotAllocator& thread_local_slot_allocator, TimeSource& time_source);

struct ThreadLocalTracer : public ThreadLocal::ThreadLocalObject {
/**
Expand Down
Loading
Loading