diff --git a/exporters/otlp/test/otlp_file_exporter_test.cc b/exporters/otlp/test/otlp_file_exporter_test.cc index 16a1306f88..81e1baab44 100644 --- a/exporters/otlp/test/otlp_file_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_exporter_test.cc @@ -25,6 +25,7 @@ #include "nlohmann/json.hpp" #include +#include #include using namespace testing; @@ -112,13 +113,24 @@ class OtlpFileExporterTestPeer : public ::testing::Test provider->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); + if (!check_json.is_discarded()) + { + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + } + else + { + FAIL() << "Failed to parse json:" << check_json_text; + } } } }; diff --git a/exporters/otlp/test/otlp_file_log_record_exporter_test.cc b/exporters/otlp/test/otlp_file_log_record_exporter_test.cc index 9f04bcece4..5bc1e4a473 100644 --- a/exporters/otlp/test/otlp_file_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_log_record_exporter_test.cc @@ -122,8 +122,12 @@ class OtlpFileLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_logs = *check_json["resourceLogs"].begin(); auto scope_logs = *resource_logs["scopeLogs"].begin(); auto scope = scope_logs["scope"]; diff --git a/exporters/otlp/test/otlp_file_metric_exporter_test.cc b/exporters/otlp/test/otlp_file_metric_exporter_test.cc index f08c8854ba..50f60e15b7 100644 --- a/exporters/otlp/test/otlp_file_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_metric_exporter_test.cc @@ -106,8 +106,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test exporter->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_metrics = *check_json["resourceMetrics"].begin(); auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); @@ -167,8 +171,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test exporter->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_metrics = *check_json["resourceMetrics"].begin(); auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); @@ -233,8 +241,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test exporter->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_metrics = *check_json["resourceMetrics"].begin(); auto scope_metrics = *resource_metrics["scopeMetrics"].begin();