This is an automated email from the ASF dual-hosted git repository.

lorinlee pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/brpc.git

commit 39804c311f06880f02ffc285ddeb8b533cc68a68
Author: Weibing Wang <wwb...@163.com>
AuthorDate: Thu Oct 12 20:15:53 2023 +0800

    Escape span method name (#2411)
    
    * Escape span method name
    
    * Reuse WebEscape
---
 src/brpc/builtin/rpcz_service.cpp | 10 +++++-----
 src/brpc/controller.cpp           |  6 ++++++
 src/brpc/controller.h             |  1 +
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/brpc/builtin/rpcz_service.cpp 
b/src/brpc/builtin/rpcz_service.cpp
index d4374e47..3625c068 100644
--- a/src/brpc/builtin/rpcz_service.cpp
+++ b/src/brpc/builtin/rpcz_service.cpp
@@ -194,7 +194,7 @@ static void PrintAnnotations(
         while (extractors[i]->PopAnnotation(cur_time, &anno_time, &a)) {
             PrintRealTime(os, anno_time);
             PrintElapse(os, anno_time, last_time);
-            os << ' ' << a;
+            os << ' ' << WebEscape(a);
             if (a.empty() || butil::back_char(a) != '\n') {
                 os << '\n';
             }
@@ -249,7 +249,7 @@ static void PrintClientSpan(
     if (abs_remote_side.ip == loopback_ip) {
         abs_remote_side.ip = butil::my_ip();
     }
-    os << " Requesting " << span.full_method_name() << '@' << remote_side
+    os << " Requesting " << WebEscape(span.full_method_name()) << '@' << 
remote_side
        << ' ' << protocol_name << ' ' << LOG_ID_STR << '=';
     if (FLAGS_rpcz_hex_log_id) {
         os << Hex(span.log_id());
@@ -346,7 +346,7 @@ static void PrintServerSpan(std::ostream& os, const 
RpczSpan& span,
             os, span.start_callback_real_us(),
             &last_time, extr, ARRAY_SIZE(extr))) {
         entered_user_method = true;
-        os << " Enter " << span.full_method_name() << std::endl;
+        os << " Enter " << WebEscape(span.full_method_name()) << std::endl;
     }
 
     const int nclient = span.client_spans_size();
@@ -359,7 +359,7 @@ static void PrintServerSpan(std::ostream& os, const 
RpczSpan& span,
             os, span.start_send_real_us(),
             &last_time, extr, ARRAY_SIZE(extr))) {
         if (entered_user_method) {
-            os << " Leave " << span.full_method_name() << std::endl;
+            os << " Leave " << WebEscape(span.full_method_name()) << std::endl;
         } else {
             os << " Responding" << std::endl;
         }
@@ -665,7 +665,7 @@ void 
RpczService::default_method(::google::protobuf::RpcController* cntl_base,
             } else {
                 os << span.log_id();
             }
-            os << ' ' << span.full_method_name() << '(' << span.request_size()
+            os << ' ' << WebEscape(span.full_method_name()) << '(' << 
span.request_size()
                << ")=" << span.response_size();
             
             if (span.error_code() == 0) {
diff --git a/src/brpc/controller.cpp b/src/brpc/controller.cpp
index 338ad66c..7ff0d26a 100644
--- a/src/brpc/controller.cpp
+++ b/src/brpc/controller.cpp
@@ -1391,6 +1391,12 @@ void WebEscape(const std::string& source, std::string* 
output) {
     }
 }
 
+std::string WebEscape(const std::string& source) {
+    std::string output;
+    WebEscape(source, &output);
+    return output;
+}
+
 void Controller::reset_sampled_request(SampledRequest* req) {
     delete _sampled_request;
     _sampled_request = req;
diff --git a/src/brpc/controller.h b/src/brpc/controller.h
index f27dd54f..82988269 100644
--- a/src/brpc/controller.h
+++ b/src/brpc/controller.h
@@ -844,6 +844,7 @@ google::protobuf::Closure* DoNothing();
 
 // Convert non-web symbols to web equivalence.
 void WebEscape(const std::string& source, std::string* output);
+std::string WebEscape(const std::string& source);
 
 // True if Ctrl-C is ever pressed.
 bool IsAskedToQuit();


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to