Skip to content

Commit 39804c3

Browse files
wwbmmmlei.li
authored and
lei.li
committed
Escape span method name (#2411)
* Escape span method name * Reuse WebEscape
1 parent d2b73ec commit 39804c3

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/brpc/builtin/rpcz_service.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static void PrintAnnotations(
194194
while (extractors[i]->PopAnnotation(cur_time, &anno_time, &a)) {
195195
PrintRealTime(os, anno_time);
196196
PrintElapse(os, anno_time, last_time);
197-
os << ' ' << a;
197+
os << ' ' << WebEscape(a);
198198
if (a.empty() || butil::back_char(a) != '\n') {
199199
os << '\n';
200200
}
@@ -249,7 +249,7 @@ static void PrintClientSpan(
249249
if (abs_remote_side.ip == loopback_ip) {
250250
abs_remote_side.ip = butil::my_ip();
251251
}
252-
os << " Requesting " << span.full_method_name() << '@' << remote_side
252+
os << " Requesting " << WebEscape(span.full_method_name()) << '@' << remote_side
253253
<< ' ' << protocol_name << ' ' << LOG_ID_STR << '=';
254254
if (FLAGS_rpcz_hex_log_id) {
255255
os << Hex(span.log_id());
@@ -346,7 +346,7 @@ static void PrintServerSpan(std::ostream& os, const RpczSpan& span,
346346
os, span.start_callback_real_us(),
347347
&last_time, extr, ARRAY_SIZE(extr))) {
348348
entered_user_method = true;
349-
os << " Enter " << span.full_method_name() << std::endl;
349+
os << " Enter " << WebEscape(span.full_method_name()) << std::endl;
350350
}
351351

352352
const int nclient = span.client_spans_size();
@@ -359,7 +359,7 @@ static void PrintServerSpan(std::ostream& os, const RpczSpan& span,
359359
os, span.start_send_real_us(),
360360
&last_time, extr, ARRAY_SIZE(extr))) {
361361
if (entered_user_method) {
362-
os << " Leave " << span.full_method_name() << std::endl;
362+
os << " Leave " << WebEscape(span.full_method_name()) << std::endl;
363363
} else {
364364
os << " Responding" << std::endl;
365365
}
@@ -665,7 +665,7 @@ void RpczService::default_method(::google::protobuf::RpcController* cntl_base,
665665
} else {
666666
os << span.log_id();
667667
}
668-
os << ' ' << span.full_method_name() << '(' << span.request_size()
668+
os << ' ' << WebEscape(span.full_method_name()) << '(' << span.request_size()
669669
<< ")=" << span.response_size();
670670

671671
if (span.error_code() == 0) {

src/brpc/controller.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,12 @@ void WebEscape(const std::string& source, std::string* output) {
13911391
}
13921392
}
13931393

1394+
std::string WebEscape(const std::string& source) {
1395+
std::string output;
1396+
WebEscape(source, &output);
1397+
return output;
1398+
}
1399+
13941400
void Controller::reset_sampled_request(SampledRequest* req) {
13951401
delete _sampled_request;
13961402
_sampled_request = req;

src/brpc/controller.h

+1
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ google::protobuf::Closure* DoNothing();
844844

845845
// Convert non-web symbols to web equivalence.
846846
void WebEscape(const std::string& source, std::string* output);
847+
std::string WebEscape(const std::string& source);
847848

848849
// True if Ctrl-C is ever pressed.
849850
bool IsAskedToQuit();

0 commit comments

Comments
 (0)