Skip to content

Commit 16cf1eb

Browse files
authored
api: remove json_fwd.h from the public API (#146)
1 parent ccb72da commit 16cf1eb

17 files changed

+149
-331
lines changed

BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cc_library(
2828
"src/datadog/runtime_id.cpp",
2929
"src/datadog/span.cpp",
3030
"src/datadog/span_data.cpp",
31-
"src/datadog/span_defaults.cpp",
3231
"src/datadog/span_matcher.cpp",
3332
"src/datadog/span_sampler_config.cpp",
3433
"src/datadog/span_sampler.cpp",
@@ -56,6 +55,7 @@ cc_library(
5655
"src/datadog/glob.h",
5756
"src/datadog/hex.h",
5857
"src/datadog/json.hpp",
58+
"src/datadog/json_serializer.h",
5959
"src/datadog/limiter.h",
6060
"src/datadog/metrics.h",
6161
"src/datadog/msgpack.h",
@@ -88,7 +88,6 @@ cc_library(
8888
"include/datadog/http_client.h",
8989
"include/datadog/id_generator.h",
9090
"include/datadog/injection_options.h",
91-
"include/datadog/json_fwd.hpp",
9291
"include/datadog/logger.h",
9392
"include/datadog/null_collector.h",
9493
"include/datadog/optional.h",

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ target_sources(dd_trace_cpp-objects
114114
src/datadog/runtime_id.cpp
115115
src/datadog/span.cpp
116116
src/datadog/span_data.cpp
117-
src/datadog/span_defaults.cpp
118117
src/datadog/span_matcher.cpp
119118
src/datadog/span_sampler_config.cpp
120119
src/datadog/span_sampler.cpp

include/datadog/environment.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <datadog/optional.h>
1818
#include <datadog/string_view.h>
1919

20-
#include "json_fwd.hpp"
21-
2220
namespace datadog {
2321
namespace tracing {
2422
namespace environment {
@@ -80,7 +78,7 @@ StringView name(Variable variable);
8078
// `nullopt` if that variable is not set in the environment.
8179
Optional<StringView> lookup(Variable variable);
8280

83-
nlohmann::json to_json();
81+
std::string to_json();
8482

8583
} // namespace environment
8684
} // namespace tracing

include/datadog/json_fwd.hpp

Lines changed: 0 additions & 175 deletions
This file was deleted.

include/datadog/span_defaults.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <string>
88
#include <unordered_map>
99

10-
#include "json_fwd.hpp"
11-
1210
namespace datadog {
1311
namespace tracing {
1412

@@ -21,9 +19,12 @@ struct SpanDefaults {
2119
std::unordered_map<std::string, std::string> tags;
2220
};
2321

24-
nlohmann::json to_json(const SpanDefaults&);
25-
26-
bool operator==(const SpanDefaults&, const SpanDefaults&);
22+
inline bool operator==(const SpanDefaults& lhs, const SpanDefaults& rhs) {
23+
#define EQ(FIELD) lhs.FIELD == rhs.FIELD
24+
return EQ(service) && EQ(service_type) && EQ(environment) && EQ(version) &&
25+
EQ(name) && EQ(tags);
26+
#undef EQ
27+
}
2728

2829
} // namespace tracing
2930
} // namespace datadog

include/datadog/span_matcher.h

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

1515
#include "expected.h"
16-
#include "json_fwd.hpp"
1716

1817
namespace datadog {
1918
namespace tracing {
@@ -29,9 +28,6 @@ struct SpanMatcher {
2928
std::unordered_map<std::string, std::string> tags;
3029

3130
bool match(const SpanData&) const;
32-
nlohmann::json to_json() const;
33-
34-
static Expected<SpanMatcher> from_json(const nlohmann::json&);
3531

3632
bool operator==(const SpanMatcher& other) const {
3733
return (service == other.service && name == other.name &&

include/datadog/trace_sampler_config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ struct TraceSamplerRule final {
2424
Rate rate;
2525
SpanMatcher matcher;
2626
SamplingMechanism mechanism;
27-
28-
nlohmann::json to_json() const;
2927
};
3028

3129
struct TraceSamplerConfig {

src/datadog/config_manager.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "config_manager.h"
22

3+
#include "json_serializer.h"
34
#include "parse_util.h"
45
#include "string_util.h"
56
#include "trace_sampler.h"
@@ -8,6 +9,20 @@ namespace datadog {
89
namespace tracing {
910
namespace {
1011

12+
nlohmann::json to_json(const SpanDefaults& defaults) {
13+
auto result = nlohmann::json::object({});
14+
#define TO_JSON(FIELD) \
15+
if (!defaults.FIELD.empty()) result[#FIELD] = defaults.FIELD
16+
TO_JSON(service);
17+
TO_JSON(service_type);
18+
TO_JSON(environment);
19+
TO_JSON(version);
20+
TO_JSON(name);
21+
TO_JSON(tags);
22+
#undef TO_JSON
23+
return result;
24+
}
25+
1126
using Rules = std::vector<TraceSamplerRule>;
1227

1328
Expected<Rules> parse_trace_sampling_rules(const nlohmann::json& json_rules) {
@@ -20,7 +35,7 @@ Expected<Rules> parse_trace_sampling_rules(const nlohmann::json& json_rules) {
2035
}
2136

2237
for (const auto& json_rule : json_rules) {
23-
auto matcher = SpanMatcher::from_json(json_rule);
38+
auto matcher = from_json(json_rule);
2439
if (auto* error = matcher.if_error()) {
2540
std::string prefix;
2641
return error->with_prefix(prefix);

src/datadog/environment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Optional<StringView> lookup(Variable variable) {
1919
return StringView{value};
2020
}
2121

22-
nlohmann::json to_json() {
22+
std::string to_json() {
2323
auto result = nlohmann::json::object({});
2424

2525
for (const char *name : variable_names) {
@@ -28,7 +28,7 @@ nlohmann::json to_json() {
2828
}
2929
}
3030

31-
return result;
31+
return result.dump();
3232
}
3333

3434
} // namespace environment

0 commit comments

Comments
 (0)