mononoke: do not upload traces if tracing is disabled

Summary:
It has a few benefits. Firstly, we won't get misleading empty trace ids in the
logs. Secondly, uploading traces takes a noticeable amount of time that affects
the overall latency. That is especially noticeable for getfiles requests.

Reviewed By: farnz

Differential Revision: D8158917

fbshipit-source-id: b4fe2183d9157f4d7c52e25e4efef9a06bb1b5ac
This commit is contained in:
Stanislau Hlebik 2018-05-25 05:26:18 -07:00 committed by Facebook Github Bot
parent bce740ec29
commit dd37633300

View File

@ -210,10 +210,18 @@ fn add_common_stats_and_send_to_scuba(
remote: Remote, remote: Remote,
args: Option<String>, args: Option<String>,
) -> BoxFuture<(), ()> { ) -> BoxFuture<(), ()> {
let trace_upload = if futures_trace::global::is_enabled() {
futures_trace::global::context() futures_trace::global::context()
.upload_trace_async(remote) .upload_trace_async(remote)
.map(|id| Some(id))
.boxify()
} else {
Ok(None).into_future().boxify()
};
trace_upload
.then(move |res| { .then(move |res| {
let trace_id = res.unwrap_or_else(|_| "upload failed".into()); let trace_id = res.unwrap_or_else(|_| Some("upload failed".into()));
if let Some(ref scuba) = scuba { if let Some(ref scuba) = scuba {
sample.add( sample.add(
"time_elapsed_ms", "time_elapsed_ms",
@ -221,7 +229,9 @@ fn add_common_stats_and_send_to_scuba(
); );
sample.add("poll_time_us", stats.poll_time.as_micros_unchecked()); sample.add("poll_time_us", stats.poll_time.as_micros_unchecked());
sample.add("poll_count", stats.poll_count); sample.add("poll_count", stats.poll_count);
if let Some(trace_id) = trace_id {
sample.add("trace", trace_id); sample.add("trace", trace_id);
}
if let Some(args) = args { if let Some(args) = args {
sample.add("args", args); sample.add("args", args);
} }