Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change OTLP Json field name to camelCase #2162

Merged
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
2 changes: 1 addition & 1 deletion exporters/otlp/src/otlp_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static void ConvertGenericMessageToJson(nlohmann::json &value,
{
const google::protobuf::FieldDescriptor *field_descriptor = fields_with_data[i];
nlohmann::json &child_value = options.use_json_name ? value[field_descriptor->json_name()]
: value[field_descriptor->name()];
: value[field_descriptor->camelcase_name()];
if (field_descriptor->is_repeated())
{
ConvertListFieldToJson(child_value, message, field_descriptor, options);
Expand Down
12 changes: 6 additions & 6 deletions exporters/otlp/test/otlp_http_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ class OtlpHttpExporterTestPeer : public ::testing::Test
std::shared_ptr<opentelemetry::ext::http::client::EventHandler> callback) {
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);
auto resource_span = *check_json["resource_spans"].begin();
auto scope_span = *resource_span["scope_spans"].begin();
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["trace_id"].get<std::string>();
auto received_trace_id = span["traceId"].get<std::string>();
EXPECT_EQ(received_trace_id, report_trace_id);

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
Expand Down Expand Up @@ -256,10 +256,10 @@ class OtlpHttpExporterTestPeer : public ::testing::Test
std::shared_ptr<opentelemetry::ext::http::client::EventHandler> callback) {
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);
auto resource_span = *check_json["resource_spans"].begin();
auto scope_span = *resource_span["scope_spans"].begin();
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["trace_id"].get<std::string>();
auto received_trace_id = span["traceId"].get<std::string>();
EXPECT_EQ(received_trace_id, report_trace_id);

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
Expand Down
30 changes: 15 additions & 15 deletions exporters/otlp/test/otlp_http_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
std::shared_ptr<opentelemetry::ext::http::client::EventHandler> callback) {
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);
auto resource_logs = *check_json["resource_logs"].begin();
auto scope_logs = *resource_logs["scope_logs"].begin();
auto resource_logs = *check_json["resourceLogs"].begin();
auto scope_logs = *resource_logs["scopeLogs"].begin();
auto scope = scope_logs["scope"];
auto log = *scope_logs["log_records"].begin();
auto received_trace_id = log["trace_id"].get<std::string>();
auto received_span_id = log["span_id"].get<std::string>();
auto log = *scope_logs["logRecords"].begin();
auto received_trace_id = log["traceId"].get<std::string>();
auto received_span_id = log["spanId"].get<std::string>();
EXPECT_EQ(received_trace_id, report_trace_id);
EXPECT_EQ(received_span_id, report_span_id);
EXPECT_EQ("Log message", log["body"]["string_value"].get<std::string>());
EXPECT_EQ("Log message", log["body"]["stringValue"].get<std::string>());
EXPECT_LE(15, log["attributes"].size());
auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end());
Expand All @@ -188,7 +188,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
if ("scope_key1" == attribute["key"])
{
check_scope_attribute = true;
EXPECT_EQ("scope_value", attribute["value"]["string_value"].get<std::string>());
EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get<std::string>());
}
}
ASSERT_TRUE(check_scope_attribute);
Expand Down Expand Up @@ -277,21 +277,21 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
std::shared_ptr<opentelemetry::ext::http::client::EventHandler> callback) {
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);
auto resource_logs = *check_json["resource_logs"].begin();
auto scope_logs = *resource_logs["scope_logs"].begin();
auto schema_url = scope_logs["schema_url"].get<std::string>();
auto resource_logs = *check_json["resourceLogs"].begin();
auto scope_logs = *resource_logs["scopeLogs"].begin();
auto schema_url = scope_logs["schemaUrl"].get<std::string>();
auto scope = scope_logs["scope"];
auto scope_name = scope["name"];
auto scope_version = scope["version"];
auto log = *scope_logs["log_records"].begin();
auto received_trace_id = log["trace_id"].get<std::string>();
auto received_span_id = log["span_id"].get<std::string>();
auto log = *scope_logs["logRecords"].begin();
auto received_trace_id = log["traceId"].get<std::string>();
auto received_span_id = log["spanId"].get<std::string>();
EXPECT_EQ(schema_url, "https://opentelemetry.io/schemas/1.2.0");
EXPECT_EQ(scope_name, "opentelelemtry_library");
EXPECT_EQ(scope_version, "1.2.0");
EXPECT_EQ(received_trace_id, report_trace_id);
EXPECT_EQ(received_span_id, report_span_id);
EXPECT_EQ("Log message", log["body"]["string_value"].get<std::string>());
EXPECT_EQ("Log message", log["body"]["stringValue"].get<std::string>());
EXPECT_LE(15, log["attributes"].size());
auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end());
Expand All @@ -311,7 +311,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
if ("scope_key1" == attribute["key"])
{
check_scope_attribute = true;
EXPECT_EQ("scope_value", attribute["value"]["string_value"].get<std::string>());
EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get<std::string>());
}
}
ASSERT_TRUE(check_scope_attribute);
Expand Down
70 changes: 35 additions & 35 deletions exporters/otlp/test/otlp_http_metric_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);

auto resource_metrics = *check_json["resource_metrics"].begin();
auto scope_metrics = *resource_metrics["scope_metrics"].begin();
auto resource_metrics = *check_json["resourceMetrics"].begin();
auto scope_metrics = *resource_metrics["scopeMetrics"].begin();
auto scope = scope_metrics["scope"];
EXPECT_EQ("library_name", scope["name"].get<std::string>());
EXPECT_EQ("1.5.0", scope["version"].get<std::string>());
Expand All @@ -171,9 +171,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
EXPECT_EQ("metrics_description", metric["description"].get<std::string>());
EXPECT_EQ("metrics_unit", metric["unit"].get<std::string>());

auto data_points = metric["sum"]["data_points"];
EXPECT_EQ(10.0, data_points[0]["as_double"].get<double>());
EXPECT_EQ(20.0, data_points[1]["as_double"].get<double>());
auto data_points = metric["sum"]["dataPoints"];
EXPECT_EQ(10.0, data_points[0]["asDouble"].get<double>());
EXPECT_EQ(20.0, data_points[1]["asDouble"].get<double>());

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end());
Expand Down Expand Up @@ -341,8 +341,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);

auto resource_metrics = *check_json["resource_metrics"].begin();
auto scope_metrics = *resource_metrics["scope_metrics"].begin();
auto resource_metrics = *check_json["resourceMetrics"].begin();
auto scope_metrics = *resource_metrics["scopeMetrics"].begin();
auto scope = scope_metrics["scope"];
EXPECT_EQ("library_name", scope["name"].get<std::string>());
EXPECT_EQ("1.5.0", scope["version"].get<std::string>());
Expand All @@ -352,9 +352,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
EXPECT_EQ("metrics_description", metric["description"].get<std::string>());
EXPECT_EQ("metrics_unit", metric["unit"].get<std::string>());

auto data_points = metric["gauge"]["data_points"];
EXPECT_EQ(10.0, data_points[0]["as_double"].get<double>());
EXPECT_EQ(20l, JsonToInteger<int64_t>(data_points[1]["as_int"]));
auto data_points = metric["gauge"]["dataPoints"];
EXPECT_EQ(10.0, data_points[0]["asDouble"].get<double>());
EXPECT_EQ(20l, JsonToInteger<int64_t>(data_points[1]["asInt"]));

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end());
Expand Down Expand Up @@ -536,8 +536,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
auto check_json =
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);

auto resource_metrics = *check_json["resource_metrics"].begin();
auto scope_metrics = *resource_metrics["scope_metrics"].begin();
auto resource_metrics = *check_json["resourceMetrics"].begin();
auto scope_metrics = *resource_metrics["scopeMetrics"].begin();
auto scope = scope_metrics["scope"];
EXPECT_EQ("library_name", scope["name"].get<std::string>());
EXPECT_EQ("1.5.0", scope["version"].get<std::string>());
Expand All @@ -547,43 +547,43 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
EXPECT_EQ("metrics_description", metric["description"].get<std::string>());
EXPECT_EQ("metrics_unit", metric["unit"].get<std::string>());

auto data_points = metric["histogram"]["data_points"];
auto data_points = metric["histogram"]["dataPoints"];
EXPECT_EQ(3, JsonToInteger<int64_t>(data_points[0]["count"]));
EXPECT_EQ(900.5, data_points[0]["sum"].get<double>());
EXPECT_EQ(1.8, data_points[0]["min"].get<double>());
EXPECT_EQ(19, data_points[0]["max"].get<double>());
EXPECT_EQ(4, data_points[0]["bucket_counts"].size());
if (4 == data_points[0]["bucket_counts"].size())
EXPECT_EQ(4, data_points[0]["bucketCounts"].size());
if (4 == data_points[0]["bucketCounts"].size())
{
EXPECT_EQ(200, JsonToInteger<int64_t>(data_points[0]["bucket_counts"][0]));
EXPECT_EQ(300, JsonToInteger<int64_t>(data_points[0]["bucket_counts"][1]));
EXPECT_EQ(400, JsonToInteger<int64_t>(data_points[0]["bucket_counts"][2]));
EXPECT_EQ(500, JsonToInteger<int64_t>(data_points[0]["bucket_counts"][3]));
EXPECT_EQ(200, JsonToInteger<int64_t>(data_points[0]["bucketCounts"][0]));
EXPECT_EQ(300, JsonToInteger<int64_t>(data_points[0]["bucketCounts"][1]));
EXPECT_EQ(400, JsonToInteger<int64_t>(data_points[0]["bucketCounts"][2]));
EXPECT_EQ(500, JsonToInteger<int64_t>(data_points[0]["bucketCounts"][3]));
}
EXPECT_EQ(3, data_points[0]["explicit_bounds"].size());
if (3 == data_points[0]["explicit_bounds"].size())
EXPECT_EQ(3, data_points[0]["explicitBounds"].size());
if (3 == data_points[0]["explicitBounds"].size())
{
EXPECT_EQ(10.1, data_points[0]["explicit_bounds"][0].get<double>());
EXPECT_EQ(20.2, data_points[0]["explicit_bounds"][1].get<double>());
EXPECT_EQ(30.2, data_points[0]["explicit_bounds"][2].get<double>());
EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get<double>());
EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get<double>());
EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get<double>());
}

EXPECT_EQ(3, JsonToInteger<int64_t>(data_points[1]["count"]));
EXPECT_EQ(900.0, data_points[1]["sum"].get<double>());
EXPECT_EQ(4, data_points[1]["bucket_counts"].size());
if (4 == data_points[1]["bucket_counts"].size())
EXPECT_EQ(4, data_points[1]["bucketCounts"].size());
if (4 == data_points[1]["bucketCounts"].size())
{
EXPECT_EQ(200, JsonToInteger<int64_t>(data_points[1]["bucket_counts"][0]));
EXPECT_EQ(300, JsonToInteger<int64_t>(data_points[1]["bucket_counts"][1]));
EXPECT_EQ(400, JsonToInteger<int64_t>(data_points[1]["bucket_counts"][2]));
EXPECT_EQ(500, JsonToInteger<int64_t>(data_points[1]["bucket_counts"][3]));
EXPECT_EQ(200, JsonToInteger<int64_t>(data_points[1]["bucketCounts"][0]));
EXPECT_EQ(300, JsonToInteger<int64_t>(data_points[1]["bucketCounts"][1]));
EXPECT_EQ(400, JsonToInteger<int64_t>(data_points[1]["bucketCounts"][2]));
EXPECT_EQ(500, JsonToInteger<int64_t>(data_points[1]["bucketCounts"][3]));
}
EXPECT_EQ(3, data_points[1]["explicit_bounds"].size());
if (3 == data_points[1]["explicit_bounds"].size())
EXPECT_EQ(3, data_points[1]["explicitBounds"].size());
if (3 == data_points[1]["explicitBounds"].size())
{
EXPECT_EQ(10.0, data_points[1]["explicit_bounds"][0].get<double>());
EXPECT_EQ(20.0, data_points[1]["explicit_bounds"][1].get<double>());
EXPECT_EQ(30.0, data_points[1]["explicit_bounds"][2].get<double>());
EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get<double>());
EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get<double>());
EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get<double>());
}

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
Expand Down