Skip to content
Merged
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
19 changes: 8 additions & 11 deletions src/datadog/telemetry/telemetry_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,27 +617,24 @@ std::string Telemetry::app_started_payload() {
/// is no need to declare it.
if (product.name == Product::Name::tracing) continue;

auto p = nlohmann::json{
{to_string(product.name),
nlohmann::json{
{"version", product.version},
{"enabled", product.enabled},
}},
auto product_details = nlohmann::json{
{"version", product.version},
{"enabled", product.enabled},
};

if (product.error_code || product.error_message) {
auto p_error = nlohmann::json{};
auto product_error = nlohmann::json{};
if (product.error_code) {
p_error.emplace("code", *product.error_code);
product_error.emplace("code", *product.error_code);
}
if (product.error_message) {
p_error.emplace("message", *product.error_message);
product_error.emplace("message", *product.error_message);
}

p.emplace("error", std::move(p_error));
product_details.emplace("error", std::move(product_error));
}

product_json.emplace(std::move(p));
product_json.emplace(to_string(product.name), std::move(product_details));
}

auto app_started_msg = nlohmann::json{
Expand Down
30 changes: 30 additions & 0 deletions test/telemetry/test_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,36 @@ TELEMETRY_IMPLEMENTATION_TEST("Tracer telemetry lifecycle") {
}
}
}

SECTION("Product error is nested under the product name") {
client->clear();

Configuration cfg;
cfg.products.emplace_back(Product{Product::Name::appsec,
false,
"1.2.3",
12,
"Error initializing WAF",
{}});

auto telemetry =
Telemetry::create(*finalize_config(cfg), tracer_signature, logger,
client, scheduler, *url);

const auto message_batch = nlohmann::json::parse(client->request_body);
const auto& appsec = message_batch.at("payload")
.at(0)
.at("payload")
.at("products")
.at("appsec");

CHECK(appsec ==
nlohmann::json{
{"version", "1.2.3"},
{"enabled", false},
{"error",
{{"code", 12}, {"message", "Error initializing WAF"}}}});
}
}

SECTION("dtor send app-closing message") {
Expand Down
Loading