Skip to content

Commit 8166499

Browse files
authored
Merge pull request #5 from DataDog/david.goffredo/no-typeid
More startup JSON logging: - don't use mangled symbol names - use return values instead of output parameters
2 parents 51cd7ba + 7fca525 commit 8166499

32 files changed

+122
-100
lines changed

src/datadog/collector.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ class Collector {
3333
std::vector<std::unique_ptr<SpanData>>&& spans,
3434
const std::shared_ptr<TraceSampler>& response_handler) = 0;
3535

36-
// Assign to the specified `destination` a JSON representation of this
37-
// object's configuration. The JSON representation is an object with
38-
// the following properties:
36+
// Return a JSON representation of this object's configuration. The JSON
37+
// representation is an object with the following properties:
3938
//
40-
// - "type" is the unmangled, unqualified name of the most-derived class, e.g.
41-
// "DatadogAgent".
39+
// - "type" is the unmangled, qualified name of the most-derived class, e.g.
40+
// "datadog::tracing::DatadogAgent".
4241
// - "config" is an object containing this object's configuration. "config"
4342
// may be omitted if the derived class has no configuration.
44-
virtual void config_json(nlohmann::json& destination) const = 0;
43+
virtual nlohmann::json config_json() const = 0;
4544

4645
virtual ~Collector() {}
4746
};

src/datadog/curl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "dict_reader.h"
2020
#include "dict_writer.h"
2121
#include "http_client.h"
22+
#include "json.hpp"
2223
#include "logger.h"
2324
#include "parse_util.h"
2425

@@ -125,6 +126,10 @@ void Curl::drain(std::chrono::steady_clock::time_point deadline) {
125126
impl_->drain(deadline);
126127
}
127128

129+
nlohmann::json Curl::config_json() const {
130+
return nlohmann::json::object({{"type", "datadog::tracing::Curl"}});
131+
}
132+
128133
CurlImpl::CurlImpl(const std::shared_ptr<Logger> &logger)
129134
: logger_(logger), shutting_down_(false), num_active_handles_(0) {
130135
curl_global_init(CURL_GLOBAL_ALL);

src/datadog/curl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <string>
1515

1616
#include "http_client.h"
17+
#include "json_fwd.hpp"
1718

1819
namespace datadog {
1920
namespace tracing {
@@ -35,6 +36,8 @@ class Curl : public HTTPClient {
3536
ErrorHandler on_error) override;
3637

3738
void drain(std::chrono::steady_clock::time_point deadline) override;
39+
40+
nlohmann::json config_json() const override;
3841
};
3942

4043
} // namespace tracing

src/datadog/datadog_agent.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,20 @@ Expected<void> DatadogAgent::send(
164164
return std::nullopt;
165165
}
166166

167-
void DatadogAgent::config_json(nlohmann::json& destination) const {
167+
nlohmann::json DatadogAgent::config_json() const {
168168
const auto& url = traces_endpoint_; // brevity
169169
const auto flush_interval_milliseconds =
170170
std::chrono::duration_cast<std::chrono::milliseconds>(flush_interval_)
171171
.count();
172172

173173
// clang-format off
174-
destination = nlohmann::json::object({
175-
{"type", "DatadogAgent"},
174+
return nlohmann::json::object({
175+
{"type", "datadog::tracing::DatadogAgent"},
176176
{"config", nlohmann::json::object({
177177
{"url", (url.scheme + "://" + url.authority + url.path)},
178178
{"flush_interval_milliseconds", flush_interval_milliseconds},
179-
{"http_client_typeid", typeid(*http_client_).name()},
180-
{"event_scheduler_typeid", typeid(*event_scheduler_).name()},
179+
{"http_client", http_client_->config_json()},
180+
{"event_scheduler", event_scheduler_->config_json()},
181181
})},
182182
});
183183
// clang-format on

src/datadog/datadog_agent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DatadogAgent : public Collector {
5555
std::vector<std::unique_ptr<SpanData>>&& spans,
5656
const std::shared_ptr<TraceSampler>& response_handler) override;
5757

58-
void config_json(nlohmann::json& destination) const override;
58+
nlohmann::json config_json() const override;
5959
};
6060

6161
} // namespace tracing

src/datadog/environment.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ std::optional<std::string_view> lookup(Variable variable) {
1919
return std::string_view{value};
2020
}
2121

22-
void to_json(nlohmann::json &destination) {
23-
destination = nlohmann::json::object({});
22+
nlohmann::json to_json() {
23+
auto result = nlohmann::json::object({});
24+
2425
for (const char *name : variable_names) {
2526
if (const char *value = std::getenv(name)) {
26-
destination[name] = value;
27+
result[name] = value;
2728
}
2829
}
30+
31+
return result;
2932
}
3033

3134
} // namespace environment

src/datadog/environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ std::string_view name(Variable variable);
7272
// `std::nullptr` if that variable is not set in the environment.
7373
std::optional<std::string_view> lookup(Variable variable);
7474

75-
void to_json(nlohmann::json& destination);
75+
nlohmann::json to_json();
7676

7777
} // namespace environment
7878
} // namespace tracing

src/datadog/event_scheduler.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <functional>
1414

1515
#include "error.h"
16+
#include "json_fwd.hpp"
1617

1718
namespace datadog {
1819
namespace tracing {
@@ -29,6 +30,15 @@ class EventScheduler {
2930
std::chrono::steady_clock::duration interval,
3031
std::function<void()> callback) = 0;
3132

33+
// Return a JSON representation of this object's configuration. The JSON
34+
// representation is an object with the following properties:
35+
//
36+
// - "type" is the unmangled, qualified name of the most-derived class, e.g.
37+
// "datadog::tracing::ThreadedEventScheduler".
38+
// - "config" is an object containing this object's configuration. "config"
39+
// may be omitted if the derived class has no configuration.
40+
virtual nlohmann::json config_json() const = 0;
41+
3242
virtual ~EventScheduler() = default;
3343
};
3444

src/datadog/http_client.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "error.h"
1616
#include "expected.h"
17+
#include "json_fwd.hpp"
1718

1819
namespace datadog {
1920
namespace tracing {
@@ -51,6 +52,15 @@ class HTTPClient {
5152
// `deadline`.
5253
virtual void drain(std::chrono::steady_clock::time_point deadline) = 0;
5354

55+
// Return a JSON representation of this object's configuration. The JSON
56+
// representation is an object with the following properties:
57+
//
58+
// - "type" is the unmangled, qualified name of the most-derived class, e.g.
59+
// "datadog::tracing::Curl".
60+
// - "config" is an object containing this object's configuration. "config"
61+
// may be omitted if the derived class has no configuration.
62+
virtual nlohmann::json config_json() const = 0;
63+
5464
virtual ~HTTPClient() = default;
5565
};
5666

src/datadog/null_collector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace datadog {
66
namespace tracing {
77

8-
void NullCollector::config_json(nlohmann::json& destination) const {
8+
nlohmann::json NullCollector::config_json() const {
99
// clang-format off
10-
destination = nlohmann::json::object({
11-
{"type", "NullCollector"},
10+
return nlohmann::json::object({
11+
{"type", "datadog::tracing::NullCollector"},
1212
{"config", nlohmann::json::object({})},
1313
});
1414
// clang-format on

0 commit comments

Comments
 (0)