Skip to content

deps: bump up dd_trace_cpp to v1.0.0 #39409

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -634,13 +634,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.2.2",
sha256 = "ee524a9b70d39dcfd815b90d9d6fc5599db7989dff072980bff90bae81c4daf7",
version = "1.0.0",
sha256 = "d0c91edef22e5526d75c914729a6c153ec53648e9400bf9e93dfb08058493a6f",
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 = "2024-06-21",
release_date = "2024-09-17",
cpe = "N/A",
license = "Apache-2.0",
license_url = "https://github.com/DataDog/dd-trace-cpp/blob/v{version}/LICENSE.md",
Expand Down
1 change: 1 addition & 0 deletions source/extensions/tracers/datadog/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ envoy_cc_library(
"//source/common/version:version_lib",
"//source/extensions/tracers/common:factory_base_lib",
"@com_github_datadog_dd_trace_cpp//:dd_trace_cpp",
"@com_github_nlohmann_json//:json",
],
)

Expand Down
4 changes: 3 additions & 1 deletion source/extensions/tracers/datadog/agent_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "datadog/dict_reader.h"
#include "datadog/dict_writer.h"
#include "datadog/error.h"
#include "datadog/json.hpp"
#include "nlohmann/json.hpp"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -91,6 +91,8 @@ AgentHTTPClient::post(const URL& url, HeadersSetter set_headers, std::string bod

void AgentHTTPClient::drain(std::chrono::steady_clock::time_point) {}

std::string AgentHTTPClient::config() const { return config_json().dump(); }

nlohmann::json AgentHTTPClient::config_json() const {
return nlohmann::json::object({
{"type", "Envoy::Extensions::Tracers::Datadog::AgentHTTPClient"},
Expand Down
8 changes: 7 additions & 1 deletion source/extensions/tracers/datadog/agent_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "absl/container/flat_hash_map.h"
#include "datadog/http_client.h"
#include "nlohmann/json.hpp"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -82,11 +83,16 @@ class AgentHTTPClient : public datadog::tracing::HTTPClient,
*/
void drain(std::chrono::steady_clock::time_point) override;

/**
* Implementation of the required config() method from datadog::tracing::HTTPClient
*/
std::string config() const override;

/**
* Return a JSON representation of this object's configuration. This function
* is used in the startup banner logged by \c dd-trace-cpp.
*/
nlohmann::json config_json() const override;
nlohmann::json config_json() const;

// Http::AsyncClient::Callbacks

Expand Down
4 changes: 3 additions & 1 deletion source/extensions/tracers/datadog/event_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "source/common/common/assert.h"

#include "datadog/json.hpp"
#include "nlohmann/json.hpp"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -64,6 +64,8 @@ EventScheduler::schedule_recurring_event(std::chrono::steady_clock::duration int
};
}

std::string EventScheduler::config() const { return config_json().dump(); }

nlohmann::json EventScheduler::config_json() const {
return nlohmann::json::object({
{"type", "Envoy::Extensions::Tracers::Datadog::EventScheduler"},
Expand Down
7 changes: 6 additions & 1 deletion source/extensions/tracers/datadog/event_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "absl/container/flat_hash_set.h"
#include "datadog/event_scheduler.h"
#include "nlohmann/json.hpp"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -35,7 +36,11 @@ class EventScheduler : public datadog::tracing::EventScheduler {
Cancel schedule_recurring_event(std::chrono::steady_clock::duration interval,
std::function<void()> callback) override;

nlohmann::json config_json() const override;
// Implementation of the required config() method from datadog::tracing::EventScheduler
std::string config() const override;

// Provides JSON configuration for debug logging
nlohmann::json config_json() const;

private:
Event::Dispatcher& dispatcher_;
Expand Down
1 change: 1 addition & 0 deletions test/extensions/tracers/datadog/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ envoy_extension_cc_test(
"//test/mocks/upstream:thread_local_cluster_mocks",
"//test/test_common:utility_lib",
"@com_github_datadog_dd_trace_cpp//:dd_trace_cpp",
"@com_github_nlohmann_json//:json",
"@envoy_api//envoy/config/trace/v3:pkg_cc_proto",
],
)
12 changes: 11 additions & 1 deletion test/extensions/tracers/datadog/agent_http_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "datadog/dict_writer.h"
#include "datadog/error.h"
#include "datadog/expected.h"
#include "datadog/json.hpp"
#include "datadog/optional.h"
#include "gtest/gtest.h"
#include "nlohmann/json.hpp"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -678,6 +678,16 @@ TEST_F(DatadogAgentHttpClientTest, SkipReportIfCollectorClusterHasBeenRemoved) {
}
}

TEST_F(DatadogAgentHttpClientTest, ConfigJson) {
// Verify that the config() method returns valid JSON
const std::string config = client_.config();
// Parse the config string to verify it's valid JSON
EXPECT_NO_THROW({
auto json = nlohmann::json::parse(config);
EXPECT_TRUE(json.is_object());
});
}

} // namespace
} // namespace Datadog
} // namespace Tracers
Expand Down
89 changes: 56 additions & 33 deletions test/extensions/tracers/datadog/event_scheduler_test.cc
Original file line number Diff line number Diff line change
@@ -1,80 +1,110 @@
#include <chrono>
#include <string>

#include "envoy/event/dispatcher.h"

#include "source/extensions/tracers/datadog/event_scheduler.h"

#include "test/mocks/event/mocks.h"
#include "test/mocks/thread_local/mocks.h"

#include "datadog/json.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "nlohmann/json.hpp"

using testing::NiceMock;
using testing::StrictMock;

namespace Envoy {
namespace Extensions {
namespace Tracers {
namespace Datadog {
namespace {

TEST(DatadogEventSchedulerTest, ScheduleRecurringEventCallsCreatesATimer) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
// Test class to verify Datadog EventScheduler behaviors
class DatadogEventSchedulerTest : public testing::Test {
public:
DatadogEventSchedulerTest()
: thread_local_storage_(std::make_shared<NiceMock<ThreadLocal::MockInstance>>()),
scheduler_(thread_local_storage_->dispatcher_) {}

protected:
std::shared_ptr<NiceMock<ThreadLocal::MockInstance>> thread_local_storage_;
EventScheduler scheduler_;
};

// Verify that the config() method produces a valid string that can be parsed as JSON
TEST_F(DatadogEventSchedulerTest, ConfigJson) {
const std::string config = scheduler_.config();

// Verify it's not empty
EXPECT_FALSE(config.empty());

// Parse the config string to verify it's valid JSON
EXPECT_NO_THROW({
auto json = nlohmann::json::parse(config);
EXPECT_TRUE(json.is_object());
EXPECT_EQ("Envoy::Extensions::Tracers::Datadog::EventScheduler", json["type"]);
});
}

// Test config_json returns expected content
TEST_F(DatadogEventSchedulerTest, ConfigJsonMethod) {
nlohmann::json config = scheduler_.config_json();
EXPECT_EQ("Envoy::Extensions::Tracers::Datadog::EventScheduler", config["type"]);
}

EventScheduler scheduler{thread_local_storage_.dispatcher_};
// Test that the scheduler creates a timer when scheduling an event
TEST_F(DatadogEventSchedulerTest, ScheduleRecurringEventCallsCreatesATimer) {
testing::MockFunction<void()> callback;
// The interval is arbitrary in these tests; we just have to be able to
// compare it to what was passed to the mocks.
// The only requirement is that it be divisible by milliseconds, because
// that's what `Timer::enableTimer` accepts.
const std::chrono::milliseconds interval(2000);

EXPECT_CALL(thread_local_storage_.dispatcher_, createTimer_(testing::_));
EXPECT_CALL(thread_local_storage_->dispatcher_, createTimer_(_));

scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
}

// This could be tested above, but introducing an `Event::MockTimer` disrupts
// our ability to track calls to `MockDispatcher::createTimer_`. So, two
// separate tests.
TEST(DatadogEventSchedulerTest, ScheduleRecurringEventEnablesATimer) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
auto* const timer = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);

EventScheduler scheduler{thread_local_storage_.dispatcher_};
TEST_F(DatadogEventSchedulerTest, ScheduleRecurringEventEnablesATimer) {
auto* const timer = new NiceMock<Event::MockTimer>(&thread_local_storage_->dispatcher_);
testing::MockFunction<void()> callback;
const std::chrono::milliseconds interval(2000);

EXPECT_CALL(*timer, enableTimer(interval, testing::_));
EXPECT_CALL(*timer, enableTimer(interval, _));

scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
}

TEST(DatadogEventSchedulerTest, TriggeredTimerInvokesCallbackAndReschedulesItself) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
auto* const timer = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);

EventScheduler scheduler{thread_local_storage_.dispatcher_};
// Test that the timer's callback properly invokes the user-supplied callback and reschedules
TEST_F(DatadogEventSchedulerTest, TriggeredTimerInvokesCallbackAndReschedulesItself) {
auto* const timer = new NiceMock<Event::MockTimer>(&thread_local_storage_->dispatcher_);
testing::MockFunction<void()> callback;
const std::chrono::milliseconds interval(2000);

// Once for the initial round, and then again when the callback is invoked.
EXPECT_CALL(*timer, enableTimer(interval, testing::_)).Times(2);
EXPECT_CALL(*timer, enableTimer(interval, _)).Times(2);
// The user-supplied callback is called once when the timer triggers.
EXPECT_CALL(callback, Call());

scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
timer->invokeCallback();
}

TEST(DatadogEventSchedulerTest, CancellationFunctionCallsDisableTimerOnce) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
auto* const timer = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);

EventScheduler scheduler{thread_local_storage_.dispatcher_};
// Test that the cancellation function properly disables the timer
TEST_F(DatadogEventSchedulerTest, CancellationFunctionCallsDisableTimerOnce) {
auto* const timer = new NiceMock<Event::MockTimer>(&thread_local_storage_->dispatcher_);
testing::MockFunction<void()> callback;
const std::chrono::milliseconds interval(2000);

EXPECT_CALL(*timer, disableTimer());

const auto cancel = scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
const auto cancel = scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
cancel();
cancel(); // idempotent
cancel(); // idempotent
Expand All @@ -83,13 +113,6 @@ TEST(DatadogEventSchedulerTest, CancellationFunctionCallsDisableTimerOnce) {
cancel(); // idempotent
}

TEST(DatadogEventSchedulerTest, ConfigJson) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
EventScheduler scheduler{thread_local_storage_.dispatcher_};
nlohmann::json config = scheduler.config_json();
EXPECT_EQ("Envoy::Extensions::Tracers::Datadog::EventScheduler", config["type"]);
}

} // namespace
} // namespace Datadog
} // namespace Tracers
Expand Down
Loading