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

feat(common): include the request/response type name in the RPC log #7782

Merged
merged 1 commit into from
Dec 23, 2021
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this could be a single raw string, maybe for another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the lack of newlines dooms this to being some form of concatenation.

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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

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