Skip to content

Commit

Permalink
save span with minmum latency us
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglimingcn committed Apr 22, 2024
1 parent e2e5e49 commit 14c6f58
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/brpc/span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ BRPC_VALIDATE_GFLAG(rpcz_keep_span_seconds, PositiveInteger);

DEFINE_bool(rpcz_keep_span_db, false, "Don't remove DB of rpcz at program's exit");

DEFINE_int64(rpcz_save_span_min_latency_us, 0, "The minimum latency microseconds of span saved");
BRPC_VALIDATE_GFLAG(rpcz_save_span_min_latency_us, NonNegativeInteger);

struct IdGen {
bool init;
uint16_t seq;
Expand Down Expand Up @@ -574,6 +577,11 @@ leveldb::Status SpanDB::Index(const Span* span, std::string* value_buf) {
// of time window.

const int64_t start_time = span->GetStartRealTimeUs();
const int64_t latency_us = span->GetEndRealTimeUs() - start_time;
// if latency_us < FLAGS_rpcz_save_span_min_latency_us, don't save this span
if (latency_us < FLAGS_rpcz_save_span_min_latency_us) {
return leveldb::Status::OK();
}
BriefSpan brief;
brief.set_trace_id(span->trace_id());
brief.set_span_id(span->span_id());
Expand All @@ -583,7 +591,7 @@ leveldb::Status SpanDB::Index(const Span* span, std::string* value_buf) {
brief.set_request_size(span->request_size());
brief.set_response_size(span->response_size());
brief.set_start_real_us(start_time);
brief.set_latency_us(span->GetEndRealTimeUs() - start_time);
brief.set_latency_us(latency_us);
brief.set_full_method_name(span->full_method_name());
if (!brief.SerializeToString(value_buf)) {
return leveldb::Status::InvalidArgument(
Expand Down

0 comments on commit 14c6f58

Please sign in to comment.