Skip to content

Commit aa2447b

Browse files
committed
deps: bump up dd_trace_cpp to v1.0.0
Signed-off-by: Rohit Agrawal <[email protected]>
1 parent f2a1a61 commit aa2447b

File tree

10 files changed

+229
-231
lines changed

10 files changed

+229
-231
lines changed

bazel/repository_locations.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,13 +634,13 @@ REPOSITORY_LOCATIONS_SPEC = dict(
634634
project_name = "Datadog C++ Tracing Library",
635635
project_desc = "Datadog distributed tracing for C++",
636636
project_url = "https://github.com/DataDog/dd-trace-cpp",
637-
version = "0.2.2",
638-
sha256 = "ee524a9b70d39dcfd815b90d9d6fc5599db7989dff072980bff90bae81c4daf7",
637+
version = "1.0.0",
638+
sha256 = "d0c91edef22e5526d75c914729a6c153ec53648e9400bf9e93dfb08058493a6f",
639639
strip_prefix = "dd-trace-cpp-{version}",
640640
urls = ["https://github.com/DataDog/dd-trace-cpp/archive/v{version}.tar.gz"],
641641
use_category = ["observability_ext"],
642642
extensions = ["envoy.tracers.datadog"],
643-
release_date = "2024-06-21",
643+
release_date = "2024-09-17",
644644
cpe = "N/A",
645645
license = "Apache-2.0",
646646
license_url = "https://github.com/DataDog/dd-trace-cpp/blob/v{version}/LICENSE.md",

source/extensions/tracers/datadog/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ envoy_cc_library(
4949
"//source/common/version:version_lib",
5050
"//source/extensions/tracers/common:factory_base_lib",
5151
"@com_github_datadog_dd_trace_cpp//:dd_trace_cpp",
52+
"@com_github_nlohmann_json//:json",
5253
],
5354
)
5455

source/extensions/tracers/datadog/agent_http_client.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "datadog/dict_reader.h"
1616
#include "datadog/dict_writer.h"
1717
#include "datadog/error.h"
18-
#include "datadog/json.hpp"
18+
#include "nlohmann/json.hpp"
1919

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

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

94+
std::string AgentHTTPClient::config() const { return config_json().dump(); }
95+
9496
nlohmann::json AgentHTTPClient::config_json() const {
9597
return nlohmann::json::object({
9698
{"type", "Envoy::Extensions::Tracers::Datadog::AgentHTTPClient"},

source/extensions/tracers/datadog/agent_http_client.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "absl/container/flat_hash_map.h"
1111
#include "datadog/http_client.h"
12+
#include "nlohmann/json.hpp"
1213

1314
namespace Envoy {
1415
namespace Extensions {
@@ -82,11 +83,16 @@ class AgentHTTPClient : public datadog::tracing::HTTPClient,
8283
*/
8384
void drain(std::chrono::steady_clock::time_point) override;
8485

86+
/**
87+
* Implementation of the required config() method from datadog::tracing::HTTPClient
88+
*/
89+
std::string config() const override;
90+
8591
/**
8692
* Return a JSON representation of this object's configuration. This function
8793
* is used in the startup banner logged by \c dd-trace-cpp.
8894
*/
89-
nlohmann::json config_json() const override;
95+
nlohmann::json config_json() const;
9096

9197
// Http::AsyncClient::Callbacks
9298

source/extensions/tracers/datadog/event_scheduler.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
#include "datadog/json.hpp"
8+
#include "nlohmann/json.hpp"
99

1010
namespace Envoy {
1111
namespace Extensions {
@@ -64,6 +64,8 @@ EventScheduler::schedule_recurring_event(std::chrono::steady_clock::duration int
6464
};
6565
}
6666

67+
std::string EventScheduler::config() const { return config_json().dump(); }
68+
6769
nlohmann::json EventScheduler::config_json() const {
6870
return nlohmann::json::object({
6971
{"type", "Envoy::Extensions::Tracers::Datadog::EventScheduler"},

source/extensions/tracers/datadog/event_scheduler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "absl/container/flat_hash_set.h"
77
#include "datadog/event_scheduler.h"
8+
#include "nlohmann/json.hpp"
89

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

38-
nlohmann::json config_json() const override;
39+
// Implementation of the required config() method from datadog::tracing::EventScheduler
40+
std::string config() const override;
41+
42+
// Provides JSON configuration for debug logging
43+
nlohmann::json config_json() const;
3944

4045
private:
4146
Event::Dispatcher& dispatcher_;

test/extensions/tracers/datadog/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ envoy_extension_cc_test(
5555
"//test/mocks/upstream:thread_local_cluster_mocks",
5656
"//test/test_common:utility_lib",
5757
"@com_github_datadog_dd_trace_cpp//:dd_trace_cpp",
58+
"@com_github_nlohmann_json//:json",
5859
"@envoy_api//envoy/config/trace/v3:pkg_cc_proto",
5960
],
6061
)

test/extensions/tracers/datadog/agent_http_client_test.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include "datadog/dict_writer.h"
1717
#include "datadog/error.h"
1818
#include "datadog/expected.h"
19-
#include "datadog/json.hpp"
2019
#include "datadog/optional.h"
2120
#include "gtest/gtest.h"
21+
#include "nlohmann/json.hpp"
2222

2323
namespace Envoy {
2424
namespace Extensions {
@@ -678,6 +678,16 @@ TEST_F(DatadogAgentHttpClientTest, SkipReportIfCollectorClusterHasBeenRemoved) {
678678
}
679679
}
680680

681+
TEST_F(DatadogAgentHttpClientTest, ConfigJson) {
682+
// Verify that the config() method returns valid JSON
683+
const std::string config = client_.config();
684+
// Parse the config string to verify it's valid JSON
685+
EXPECT_NO_THROW({
686+
auto json = nlohmann::json::parse(config);
687+
EXPECT_TRUE(json.is_object());
688+
});
689+
}
690+
681691
} // namespace
682692
} // namespace Datadog
683693
} // namespace Tracers

test/extensions/tracers/datadog/event_scheduler_test.cc

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,110 @@
11
#include <chrono>
2+
#include <string>
3+
4+
#include "envoy/event/dispatcher.h"
25

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

58
#include "test/mocks/event/mocks.h"
69
#include "test/mocks/thread_local/mocks.h"
710

8-
#include "datadog/json.hpp"
911
#include "gmock/gmock.h"
1012
#include "gtest/gtest.h"
13+
#include "nlohmann/json.hpp"
14+
15+
using testing::NiceMock;
16+
using testing::StrictMock;
1117

1218
namespace Envoy {
1319
namespace Extensions {
1420
namespace Tracers {
1521
namespace Datadog {
1622
namespace {
1723

18-
TEST(DatadogEventSchedulerTest, ScheduleRecurringEventCallsCreatesATimer) {
19-
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
24+
// Test class to verify Datadog EventScheduler behaviors
25+
class DatadogEventSchedulerTest : public testing::Test {
26+
public:
27+
DatadogEventSchedulerTest()
28+
: thread_local_storage_(std::make_shared<NiceMock<ThreadLocal::MockInstance>>()),
29+
scheduler_(thread_local_storage_->dispatcher_) {}
30+
31+
protected:
32+
std::shared_ptr<NiceMock<ThreadLocal::MockInstance>> thread_local_storage_;
33+
EventScheduler scheduler_;
34+
};
35+
36+
// Verify that the config() method produces a valid string that can be parsed as JSON
37+
TEST_F(DatadogEventSchedulerTest, ConfigJson) {
38+
const std::string config = scheduler_.config();
39+
40+
// Verify it's not empty
41+
EXPECT_FALSE(config.empty());
42+
43+
// Parse the config string to verify it's valid JSON
44+
EXPECT_NO_THROW({
45+
auto json = nlohmann::json::parse(config);
46+
EXPECT_TRUE(json.is_object());
47+
EXPECT_EQ("Envoy::Extensions::Tracers::Datadog::EventScheduler", json["type"]);
48+
});
49+
}
50+
51+
// Test config_json returns expected content
52+
TEST_F(DatadogEventSchedulerTest, ConfigJsonMethod) {
53+
nlohmann::json config = scheduler_.config_json();
54+
EXPECT_EQ("Envoy::Extensions::Tracers::Datadog::EventScheduler", config["type"]);
55+
}
2056

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

29-
EXPECT_CALL(thread_local_storage_.dispatcher_, createTimer_(testing::_));
66+
EXPECT_CALL(thread_local_storage_->dispatcher_, createTimer_(_));
3067

31-
scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
68+
scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
3269
}
3370

3471
// This could be tested above, but introducing an `Event::MockTimer` disrupts
3572
// our ability to track calls to `MockDispatcher::createTimer_`. So, two
3673
// separate tests.
37-
TEST(DatadogEventSchedulerTest, ScheduleRecurringEventEnablesATimer) {
38-
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
39-
auto* const timer = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);
40-
41-
EventScheduler scheduler{thread_local_storage_.dispatcher_};
74+
TEST_F(DatadogEventSchedulerTest, ScheduleRecurringEventEnablesATimer) {
75+
auto* const timer = new NiceMock<Event::MockTimer>(&thread_local_storage_->dispatcher_);
4276
testing::MockFunction<void()> callback;
4377
const std::chrono::milliseconds interval(2000);
4478

45-
EXPECT_CALL(*timer, enableTimer(interval, testing::_));
79+
EXPECT_CALL(*timer, enableTimer(interval, _));
4680

47-
scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
81+
scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
4882
}
4983

50-
TEST(DatadogEventSchedulerTest, TriggeredTimerInvokesCallbackAndReschedulesItself) {
51-
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
52-
auto* const timer = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);
53-
54-
EventScheduler scheduler{thread_local_storage_.dispatcher_};
84+
// Test that the timer's callback properly invokes the user-supplied callback and reschedules
85+
TEST_F(DatadogEventSchedulerTest, TriggeredTimerInvokesCallbackAndReschedulesItself) {
86+
auto* const timer = new NiceMock<Event::MockTimer>(&thread_local_storage_->dispatcher_);
5587
testing::MockFunction<void()> callback;
5688
const std::chrono::milliseconds interval(2000);
5789

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

63-
scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
95+
scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
6496
timer->invokeCallback();
6597
}
6698

67-
TEST(DatadogEventSchedulerTest, CancellationFunctionCallsDisableTimerOnce) {
68-
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
69-
auto* const timer = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);
70-
71-
EventScheduler scheduler{thread_local_storage_.dispatcher_};
99+
// Test that the cancellation function properly disables the timer
100+
TEST_F(DatadogEventSchedulerTest, CancellationFunctionCallsDisableTimerOnce) {
101+
auto* const timer = new NiceMock<Event::MockTimer>(&thread_local_storage_->dispatcher_);
72102
testing::MockFunction<void()> callback;
73103
const std::chrono::milliseconds interval(2000);
74104

75105
EXPECT_CALL(*timer, disableTimer());
76106

77-
const auto cancel = scheduler.schedule_recurring_event(interval, callback.AsStdFunction());
107+
const auto cancel = scheduler_.schedule_recurring_event(interval, callback.AsStdFunction());
78108
cancel();
79109
cancel(); // idempotent
80110
cancel(); // idempotent
@@ -83,13 +113,6 @@ TEST(DatadogEventSchedulerTest, CancellationFunctionCallsDisableTimerOnce) {
83113
cancel(); // idempotent
84114
}
85115

86-
TEST(DatadogEventSchedulerTest, ConfigJson) {
87-
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
88-
EventScheduler scheduler{thread_local_storage_.dispatcher_};
89-
nlohmann::json config = scheduler.config_json();
90-
EXPECT_EQ("Envoy::Extensions::Tracers::Datadog::EventScheduler", config["type"]);
91-
}
92-
93116
} // namespace
94117
} // namespace Datadog
95118
} // namespace Tracers

0 commit comments

Comments
 (0)