Skip to content

Commit

Permalink
feat(common): include the request/response type name in the RPC log (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
devbww authored Dec 23, 2021
1 parent 6b4e66f commit 1f8432e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
5 changes: 4 additions & 1 deletion google/cloud/internal/log_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "google/cloud/internal/log_wrapper.h"
#include "google/cloud/internal/absl_str_cat_quiet.h"
#include <google/protobuf/text_format.h>
#include <atomic>

Expand All @@ -26,11 +27,13 @@ std::string DebugString(google::protobuf::Message const& m,
std::string str;
google::protobuf::TextFormat::Printer p;
p.SetSingleLineMode(options.single_line_mode());
if (!options.single_line_mode()) p.SetInitialIndentLevel(1);
p.SetUseShortRepeatedPrimitives(options.use_short_repeated_primitives());
p.SetTruncateStringFieldLongerThan(
options.truncate_string_field_longer_than());
p.PrintToString(m, &str);
return str;
return absl::StrCat(m.GetTypeName(), " {",
(options.single_line_mode() ? " " : "\n"), str, "}");
}

std::string RequestIdForLogging() {
Expand Down
60 changes: 33 additions & 27 deletions google/cloud/internal/log_wrapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TEST(LogWrapper, DefaultOptions) {
TracingOptions tracing_options;
// clang-format off
std::string const text =
R"pb(google.spanner.v1.Mutation { )pb"
R"pb(insert { )pb"
R"pb(table: "Singers" )pb"
R"pb(columns: "SingerId" )pb"
Expand All @@ -72,7 +73,8 @@ TEST(LogWrapper, DefaultOptions) {
R"pb(values { string_value: "test-fname-2" } )pb"
R"pb(values { string_value: "test-lname-2" } )pb"
R"pb(} )pb"
R"pb(} )pb";
R"pb(} )pb"
R"pb(})pb";
// clang-format on
EXPECT_EQ(text, internal::DebugString(MakeMutation(), tracing_options));
}
Expand All @@ -81,35 +83,36 @@ TEST(LogWrapper, MultiLine) {
TracingOptions tracing_options;
tracing_options.SetOptions("single_line_mode=off");
// clang-format off
std::string const text = R"pb(insert {
table: "Singers"
columns: "SingerId"
columns: "FirstName"
columns: "LastName"
values {
values {
string_value: "1"
}
std::string const text = R"pb(google.spanner.v1.Mutation {
insert {
table: "Singers"
columns: "SingerId"
columns: "FirstName"
columns: "LastName"
values {
string_value: "test-fname-1"
}
values {
string_value: "test-lname-1"
}
}
values {
values {
string_value: "2"
}
values {
string_value: "test-fname-2"
values {
string_value: "1"
}
values {
string_value: "test-fname-1"
}
values {
string_value: "test-lname-1"
}
}
values {
string_value: "test-lname-2"
values {
string_value: "2"
}
values {
string_value: "test-fname-2"
}
values {
string_value: "test-lname-2"
}
}
}
}
)pb";
})pb";
// clang-format on
EXPECT_EQ(text, internal::DebugString(MakeMutation(), tracing_options));
}
Expand All @@ -118,7 +121,9 @@ TEST(LogWrapper, Truncate) {
TracingOptions tracing_options;
tracing_options.SetOptions("truncate_string_field_longer_than=8");
// clang-format off
std::string const text =R"pb(insert { )pb"
std::string const text =
R"pb(google.spanner.v1.Mutation { )pb"
R"pb(insert { )pb"
R"pb(table: "Singers" )pb"
R"pb(columns: "SingerId" )pb"
R"pb(columns: "FirstNam...<truncated>..." )pb"
Expand All @@ -130,7 +135,8 @@ TEST(LogWrapper, Truncate) {
R"pb(values { string_value: "test-fna...<truncated>..." } )pb"
R"pb(values { string_value: "test-lna...<truncated>..." } )pb"
R"pb(} )pb"
R"pb(} )pb";
R"pb(} )pb"
R"pb(})pb";
// clang-format on
EXPECT_EQ(text, internal::DebugString(MakeMutation(), tracing_options));
}
Expand Down

0 comments on commit 1f8432e

Please sign in to comment.